I am trying to showcase a model in Three.js that includes triangles and isolated vertices. The model is encoded in a PLY format. I am using THREE.Mesh to display the triangles and THREE.Points to show the isolated vertices, using the same geometry
object for both. However, only the vertices that are part of triangles are being displayed.
I conducted a test where I kept the vertices but removed all the triangles (faces) in the PLY file. Surprisingly, in that scenario, all vertices are displayed...
How can I achieve a display of both triangles and isolated vertices?
I have included a small test PLY file with 4 vertices, 3 of which are part of a triangle. When loaded with the provided code, only the 3 vertices in the triangle are visible.
const meshString = `ply
format ascii 1.0
element vertex 4
property float x
property float y
property float z
element face 1
property list uchar int vertex_indices
element edge 0
property int vertex1
property int vertex2
end_header
-1 1 0.000000
1 1 0.000000
1 -1 0.000000
-1 -1 0.000000
3 0 1 3
`;
const loader = new THREE.PLYLoader();
geometry = loader.parse( meshString );
const meshPoints = new THREE.Points( geometry, pointsMaterial );
scene.add(meshPoints);
Edit 1
Here is an illustration depicting the desired outcome versus the current result: https://i.sstatic.net/STplb.png
Edit 2
I have created a CodePen demonstrating the issue.
Edit 3
I have identified the root cause of the problem, but I am still eager to find an effective solution. It appears that the PLYLoader generates an index when faces are present, and this index only includes vertices linked to faces. If there are no faces, index=null, resulting in all vertices being displayed. Even using geometry.toNonIndexed
does not resolve this, as only vertices associated with faces are retained. One potential fix is manually setting geometry.index=null
, which allows the missing vertices to be rendered.