HDK常用记录

目录

1. Attribute和Group的常用操作

2. Node相关

3. 常用VEX函数的复现


1. Attribute和Group的常用操作

//获取点属性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就是结果
}

2. Node相关

//多线程声明方式
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!");


3. 常用VEX函数的复现

//Matrix3的dihedral函数,需要引入变量使用。
UT_Vector3 a = {0, 1, 0}, b = {0, 0, 1};
UT_Matrix3 m;
m.dihedral(a, b);
//实现vex中neighbours函数,后续如何改成基于半边查找?
UT_Array<GA_Offset> getPointOffNeighbours(GA_Offset ptoff) {
	GA_OffsetArray verticles;
	gdp->getVerticesReferencingPoint(verticles, ptoff);
	UT_Array<GA_Offset> _neighbour = UT_Array<GA_Offset>();
	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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值