Пример #1
0
void bvhtree_update_from_cloth(ClothModifierData *clmd, int moving)
{	
	unsigned int i = 0;
	Cloth *cloth = clmd->clothObject;
	BVHTree *bvhtree = cloth->bvhtree;
	ClothVertex *verts = cloth->verts;
	MFace *mfaces;
	float co[12], co_moving[12];
	int ret = 0;
	
	if(!bvhtree)
		return;
	
	mfaces = cloth->mfaces;
	
	// update vertex position in bvh tree
	if(verts && mfaces)
	{
		for(i = 0; i < cloth->numfaces; i++, mfaces++)
		{
			copy_v3_v3(&co[0*3], verts[mfaces->v1].txold);
			copy_v3_v3(&co[1*3], verts[mfaces->v2].txold);
			copy_v3_v3(&co[2*3], verts[mfaces->v3].txold);
			
			if(mfaces->v4)
				copy_v3_v3(&co[3*3], verts[mfaces->v4].txold);
		
			// copy new locations into array
			if(moving)
			{
				// update moving positions
				copy_v3_v3(&co_moving[0*3], verts[mfaces->v1].tx);
				copy_v3_v3(&co_moving[1*3], verts[mfaces->v2].tx);
				copy_v3_v3(&co_moving[2*3], verts[mfaces->v3].tx);
				
				if(mfaces->v4)
					copy_v3_v3(&co_moving[3*3], verts[mfaces->v4].tx);
				
				ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, (mfaces->v4 ? 4 : 3));
			}
			else
			{
				ret = BLI_bvhtree_update_node(bvhtree, i, co, NULL, (mfaces->v4 ? 4 : 3));
			}
			
			// check if tree is already full
			if(!ret)
				break;
		}
		
		BLI_bvhtree_update_tree(bvhtree);
	}
}
Пример #2
0
void bvhtree_update_from_cloth(ClothModifierData *clmd, bool moving)
{	
	unsigned int i = 0;
	Cloth *cloth = clmd->clothObject;
	BVHTree *bvhtree = cloth->bvhtree;
	ClothVertex *verts = cloth->verts;
	const MVertTri *vt;
	
	if (!bvhtree)
		return;
	
	vt = cloth->tri;
	
	/* update vertex position in bvh tree */
	if (verts && vt) {
		for (i = 0; i < cloth->tri_num; i++, vt++) {
			float co[3][3], co_moving[3][3];
			bool ret;

			copy_v3_v3(co[0], verts[vt->tri[0]].txold);
			copy_v3_v3(co[1], verts[vt->tri[1]].txold);
			copy_v3_v3(co[2], verts[vt->tri[2]].txold);

			/* copy new locations into array */
			if (moving) {
				/* update moving positions */
				copy_v3_v3(co_moving[0], verts[vt->tri[0]].tx);
				copy_v3_v3(co_moving[1], verts[vt->tri[1]].tx);
				copy_v3_v3(co_moving[2], verts[vt->tri[2]].tx);

				ret = BLI_bvhtree_update_node(bvhtree, i, co[0], co_moving[0], 3);
			}
			else {
				ret = BLI_bvhtree_update_node(bvhtree, i, co[0], NULL, 3);
			}
			
			/* check if tree is already full */
			if (ret == false) {
				break;
			}
		}
		
		BLI_bvhtree_update_tree(bvhtree);
	}
}
Пример #3
0
void bvhselftree_update_from_cloth(ClothModifierData *clmd, bool moving)
{	
	unsigned int i = 0;
	Cloth *cloth = clmd->clothObject;
	BVHTree *bvhtree = cloth->bvhselftree;
	ClothVertex *verts = cloth->verts;
	const MVertTri *vt;
	
	if (!bvhtree)
		return;

	vt = cloth->tri;

	/* update vertex position in bvh tree */
	if (verts && vt) {
		for (i = 0; i < cloth->mvert_num; i++, verts++) {
			const float *co, *co_moving;
			bool ret;

			co = verts->txold;

			/* copy new locations into array */
			if (moving) {
				/* update moving positions */
				co_moving = verts->tx;
				ret = BLI_bvhtree_update_node(bvhtree, i, co, co_moving, 1);
			}
			else {
				ret = BLI_bvhtree_update_node(bvhtree, i, co, NULL, 1);
			}

			/* check if tree is already full */
			if (ret == false) {
				break;
			}
		}
		
		BLI_bvhtree_update_tree(bvhtree);
	}
}