目录
1. Attribute和Group的常用操作
2. Node相关
3. 常用VEX函数的复现
//获取点属性N
GA_RWHandleV3 N_attrib = GA_RWHandleV3(gdp, GA_ATTRIB_POINT, "N");
N_attrib.get(ptoff);
//Group间的“or”、“and”...操作
GA_PointGroup* GroupA = gdp->newInternalPointGroup();
GA_PointGroup* GroupB = gdp->findPointGroup("B")
*GroupA ^= *GroupB;
*GroupA &= *GroupB;
//PrimVolume相关操作
//读取height数据
int counter = 0;
GA_FOR_ALL_PRIMITIVES(gdp, prim) {
if (prim->getTypeId() == GEO_PRIMVOLUME)
if (GA_RWHandleS(name_attrib).get(counter++) == "height") {
GEO_PrimVolume* vol = (GEO_PrimVolume*)gdp->getPrimitive(counter);
for (int i = 0; i < 1025; i += 100)
for (int j = 0; j < 1025; j += 100) {
vol->getValueAtIndex(i, j, 0);
}
//写入height数据
GEO_PrimVolume* vol = (GEO_PrimVolume*)gdp->getPrimitive(0);
UT_VoxelArrayWriteHandleF tmp = vol->getVoxelWriteHandle();
float height = 0;
for (int i = 0; i < 1025; i ++)
for (int j = 0; j < 1025; j++)
tmp.get()->setValue(i, j, 0, height);
//获取一个HeightField的Height层的分辨率。
GA_FOR_ALL_PRIMITIVES(gdp, prim) {
if (prim->getTypeId() == GEO_PRIMVOLUME)
if (GA_RWHandleS(name_attrib).get(counter++) == "height") {
GA_LocalIntrinsic _voxelresolution = prim->findIntrinsic("voxelresolution");
UT_Vector3 resolution = UT_Vector3();
prim->getIntrinsic(_voxelresolution, resolution);
//resolution就是结果
}
//多线程声明方式
THREADED_METHOD(
GL_SOP_cliffRockPlacement,
1 > 0,
resetSearched
);
void resetSearchedPartial(const UT_JobInfo& info);
THREADED_METHOD1(
GL_SOP_cliffRockPlacement,
1 > 0,
findSuitableBoundings,
int32, count
);
void findSuitableBoundingsPartial(int32 count, const UT_JobInfo& info);
//InputLabel和OutputLabel的定义方式。
const char*
GL_SOP_cliffRockPlacement::inputLabel(unsigned idx) const {
switch (idx) {
case 0: return "Terrain Searching Mesh";
case 1: return "Rock Asset Point";
default: return "";
}
}
const char*
GL_SOP_cliffRockPlacement::outputLabel(unsigned idx) const {
return "Rock Instant Points";
}
//添加节点“报错”,“警报”,“信息”。
addError(SOP_ERR_BAD_POINTGROUP, "startPoints");
addWarning(SOP_MESSAGE, "startPoints Contains No Points.");
addMessage(SOP_MESSAGE, "Rock Assets were Not Found!");
//Matrix3的dihedral函数,需要引入变量使用。
UT_Vector3 a = {0, 1, 0}, b = {0, 0, 1};
UT_Matrix3 m;
m.dihedral(a, b);
//实现vex中neighbours函数,后续如何改成基于半边查找?
UT_Array getPointOffNeighbours(GA_Offset ptoff) {
GA_OffsetArray verticles;
gdp->getVerticesReferencingPoint(verticles, ptoff);
UT_Array _neighbour = UT_Array();
for (GA_OffsetArray::iterator iter = verticles.begin(); iter != verticles.end(); iter++) {
GA_Offset primoff = gdp->vertexPrimitive(*iter);
if (gdp->getPrimitive(primoff)->getVertexCount() != 2) continue; //getPointOffNeighbours函数只作用于“两点一线”,故在这里加判断限制。
if (gdp->getPrimitive(primoff)->getPointOffset(0) == ptoff)
_neighbour.insert(gdp->getPrimitive(primoff)->getPointOffset(1));
else
_neighbour.insert(gdp->getPrimitive(primoff)->getPointOffset(0));
}
return _neighbour;
}