简体   繁体   English

如何隐藏伸出其他(复杂)3D对象背面的3D对象部分?

[英]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: 我想要有关该想法的可行性的反馈,并希望获得(一些写作提示)实际代码:

  • for each marker sphere: 对于每个标记球:
    • find all faces of the mesh that intersect with the sphere 查找与球体相交的网格的所有面
    • compute all outward-facing normal vectors of those faces (vertex-normals? face-normals?) 计算这些面的所有面向外的法线向量(顶点法线或面法线?)
    • compute all distances from the center of the face to the center of the sphere 计算从脸部中心到球体中心的所有距离
    • add all those normal vectors, weighed by their respective distances 将所有这些法线向量相加,并乘以它们各自的距离
    • given the (normalized?) result vector, hide the hemisphere pointing in that direction 给定(归一化?)结果向量,隐藏指向该方向的半球

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. 使用phiStartphiLength的参数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轴之间的角度差,以便获得difXdifY 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. 这些是必须在XY方向上旋转球体以使其垂直于骨骼局部表面的量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM