My scene includes a THREE.Geometry
with more than 5,000 vertices. I am looking to add THREE.Points
to the scene for only 3 specific vertices of the mesh within the geometry. My goal is to achieve a similar outcome as shown in this example:
https://i.sstatic.net/o97yd.png
To accomplish this, I selected the 3 vertices from the first face of the existing geometry and incorporated them into the vertices of a new geometry that should contain these 3 points. I experimented with using both THREE.Points
along with THREE.PointsMaterial
, and also with THREE.LineSegments
paired with
THREE.LineBasicMaterial</code, producing similar results (except lines instead of points).</p>
<pre><code>var vertices = [
mesh.geometry.faces[0].a,
mesh.geometry.faces[0].b,
mesh.geometry.faces[0].c
];
vertices.forEach( function(vId,i){
vertices[i].index = i;
vertices[i] = mesh.geometry.vertices[vId].clone();
vertices[i].l2w = mesh.localToWorld(vertices[i].clone());
vertices[i].id = vId;
vertices[i].distance = vertices[i].l2w.distanceTo(camera.position);
})
var plane_geom = new THREE.Geometry();
plane_geom.vertices.push(vertices[0]);
plane_geom.vertices.push(vertices[1]);
plane_geom.vertices.push(vertices[2]);
plane_geom.verticesNeedUpdate = true;
plane_geom.elementsNeedUpdate = true;
plane_geom.computeVertexNormals();
var pointsMaterial2 = new THREE.PointsMaterial({
size: 2,
color: "red"
});
var plane_mesh = new THREE.Points( plane_geom, pointsMaterial2 );
scene.add( plane_mesh );
mesh.geometry.dispose();
mesh.material.dispose();
scene.remove( mesh);
The initial geometry is globally defined as the geometry of the loaded STL-object and belongs to type THREE.Geometry
. The mesh with this geometry is added to the scene in the init function. The geometry object has the following structure:
__directGeometry: Object { vertices: (30006) […], normals: (30006) […],
colors: (30006) […], … }
__bufferGeometry: Object { uuid: "10EE834D-B19E-4C27-B831-F484D908DB06",
name: "", type: "BufferGeometry", … }
_listeners: Object { dispose: (1) […] }
boundingBox: Object { min: {…}, max: {…} }
boundingSphere: Object { center: {…}, radius: 135.73491999459804 }
colors: Array []
colorsNeedUpdate: false
elementsNeedUpdate: false
faceVertexUvs: Array [ [] ]
faces: Array(10002) [ {…}, {…}, {…}, … ]
groupsNeedUpdate: false
id: 2
lineDistances: Array []
lineDistancesNeedUpdate: false
morphNormals: Array []
morphTargets: Array []
name: ""
normalsNeedUpdate: false
skinIndices: Array []
skinWeights: Array []
type: "Geometry"
uuid: "0EB01FF3-E9BF-4CAD-AA97-5EC2933F0D9C"
uvsNeedUpdate: false
vertices: Array(5003) [ {…}, {…}, {…}, … ]
verticesNeedUpdate: false
Upon adding the new mesh plane_mesh
with the updated geometry to the scene, all the points (representing each vertex) are displayed (exceeding 5,000 points). However, upon removing the initial mesh from the scene, only the 3 specified points appear visible. When examining plane_mesh
, everything appears normal and the mesh contains just the 3 vertices...
After several attempts, it became evident that all operations were affecting the initial mesh. Only after disposing of the mesh, was plane_mesh
successfully integrated into the scene.
If you have any insights or solutions, they would be greatly appreciated!