I wish to click on any target (mesh object) and attach a standard size sphere mesh object to it. If the target mesh has been scaled other than (1,1,1) the following code will adjust the scaling of the attached marker sphere so that the plotted radius of the latter remains standard.
我希望单击任何目标(网格对象)并将标准大小的球体网格对象附加到它。如果目标网格已经缩放而不是(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;
However if the clicked-on target mesh is a child of a parent mesh (or a child of a parent Object3D) and the parent has non-unitary scaling then it will be neccessary to factor the parent scaling into the marker sphere scaling. Things get even more complicated if the target is a grand-child.
但是,如果单击的目标网格是父网格(或父Object3D的子网格)的子网格,并且父网格具有非单一缩放,那么将父网格缩放纳入标记球体缩放是必要的。如果目标是一个大孩子,事情会变得更加复杂。
An alternative way would be to find out the most senior (non-Scene) object in the target's "ancestry hierarchy" and then define the attached marker sphere position and scaling parameters relative to the respective values of the senior object.
另一种方法是在目标的“祖先层次结构”中找出*(非场景)对象,然后定义相对于高级对象的相应值的附加标记球体位置和缩放参数。
QUESTION
So is there a simple/robust way to find the "senior" object in the ancestry hierarchy of a mesh object?
那么有一种简单/可靠的方法来在网格对象的祖先层次结构中找到“高级”对象吗?
1 个解决方案
#1
0
This seems to work for a sample of different objects..
这似乎适用于不同对象的样本..
//... 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;
#1
0
This seems to work for a sample of different objects..
这似乎适用于不同对象的样本..
//... 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;