[英]How to hide parts of 3D objects that stick out of the back of other (complex) 3D objects?
I'm rendering a complex 3D mesh with Three.js (an iliac bone). 我正在使用Three.js(an骨)渲染复杂的3D网格。 Then I'm rendering some simple spheres along with this mesh to mark certain points on the surface (where muscles would attach):
然后,我将一些简单的球体与此网格一起渲染,以标记表面上的某些点(肌肉将附着的位置):
The problem is, the mesh is quite thin in some areas, and the markers will stick out the back. 问题是,某些区域的网格很薄,标记会从背面伸出。
Assume that the marker coordinates are always closer to the front face of the mesh than the back face, and that the spheres always show more surface area / volume on the front of the mesh than on the back: 假设标记坐标始终比背面更靠近网格的正面,并且球体始终在网格的正面比背面显示更多的表面积/体积:
How could I hide the parts that extrude out the back without manually intervening for specific markers? 我如何隐藏不突出手动突出特定标记的部分?
Edit: Here's a (naive?) way of how I might do it. 编辑:这是我可能的一种(幼稚的)方法。 I would like feedback on the feasibility of the idea, and (some pointers to writing) actual code to do it:
我想要有关该想法的可行性的反馈,并希望获得(一些写作提示)实际代码:
I'm not sure how to code any of those steps. 我不确定如何对任何这些步骤进行编码。 Nor am I sure if this is even a sensible approach.
我也不确定这是否是明智的选择。
Draw hemispheres instead of full spheres. 绘制半球而不是完整的球。 Use
phiStart
and phiLength
parameters of the SphereGeometry constructor. 使用
phiStart
和phiLength
的参数SphereGeometry构造。
The centers of the spheres will still be on the surface of the bone (a vertex). 球体的中心仍将位于骨骼表面(顶点)上。
The orientation of one sphere will be given by the normal
calculated in the sphere origin. 一个球体的方向将由球体原点中计算出的
normal
给出。
Three.js already calculates the normals for a mesh in order to determine how light will bounce from the mesh. Three.js已经计算出网格的法线,以确定光线如何从网格反射。 You can use the
VertexNormalsHelper
to display normals for your mesh: 您可以使用
VertexNormalsHelper
来显示网格的法线:
var bone = ...; // bone mesh
var scene = ...; //your THREE.Scene
scene.add(new THREE.VertexNormalsHelper(bone));
The source code for VertexNormalsHelper
can be found here: VertexNormalsHelper 可在此处找到
VertexNormalsHelper
的源代码: VertexNormalsHelper
You have to calculate the difference angles between the normal vector and oZ
axis so you obtain difX
and difY
. 您必须计算法线向量和
oZ
轴之间的角度差,以便获得difX
和difY
。 These are the ammounts you must rotate your sphere in the X
and Y
directions to make it perpendicular on the local surface of the bone. 这些是必须在
X
和Y
方向上旋转球体以使其垂直于骨骼局部表面的量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.