我想点击任何目标(网格物体)并将标准尺寸的球体网格物体附加到它上面。 如果目标网格已经缩放而不是(1,1,1),则以下代码将调整附加标记球体的缩放比例,以便后者的绘制半径保持标准。
//...attach marker sphere to clicked object
intersected_object.add ( marker_sphere );
var positionV3 = new THREE.Vector3();
positionV3 = intersected_object.worldToLocal( intersects[ 0 ].point );
xxx = F_Position_Copy_from_vector3_to_Object3D( positionV3, marker_sphere );
marker_sphere.scale.x = 1/ intersected_object.scale.x;
marker_sphere.scale.y = 1/ intersected_object.scale.y;
marker_sphere.scale.z = 1/ intersected_object.scale.z;
但是,如果单击的目标网格是父网格(或父Object3D的子网格)的子网格,并且父网格具有非单一缩放,那么将父网格缩放纳入标记球体缩放是必要的。如果目标是一个大孩子,情况会变得更加复杂。
另一种方法是找出目标"祖先等级中的最高级(非场景)对象"然后定义相对于高级对象的相应值的附加标记球体位置和缩放参数。
问题
有没有一种简单/健壮的方式来找到"高级"网格对象的祖先层次结构中的对象?
答案 0 :(得分:0)
这似乎适用于不同对象的样本..
//... find senior parent (non-Scene) object
var thisOb = intersected_object; //...default
var done = false;
while ( done == false)
{
if ( thisOb.parent != "" ) //... not undefined
{
if ( thisOb.parent.type == "Scene" ) //... got to the top
{
done = true;
var senior_object = thisOb;
}
else
{
thisOb = thisOb.parent
}
}
else //... no parentOb
{
alert ('ehhh???');
done = true;
}
}//... end while
//... attach sphere to object at click point on object
senior_object.add ( marker_sphere );
//... position marker sphere relative to clicked object
var positionV3 = new THREE.Vector3();
positionV3 = senior_object.worldToLocal( intersects[ 0 ].point );
xxx = SOW_F_Position_Copy_from_vector3_to_Object3D( positionV3, marker_sphere );
marker_sphere.scale.x = 1/ senior_object.scale.x;
marker_sphere.scale.y = 1/ senior_object.scale.y;
marker_sphere.scale.z = 1/ senior_object.scale.z;