Hello
I have an issue when I get the vertex from a face of a gltf model with three.js. I noticed that most of the faces have stored wrong normal and vertex values and I need the correct normal to write a function
In the image you can see that the model is correct but for the point that it’s in the origin of the axis says that the vertex of the face are those three spheres.
I don’t know exactly what’s happening because the model is loaded well but vertex are different.
Any help will be welcome
Thanks
Geometry data like vertices are always expressed in local space. As soon as you apply a transformation to the mesh object (e.g. by modulating mesh.position) or its parent objects, you have to respect the world matrix of the mesh. The code for this looks like so:
mesh.position.set( 1, 1, 1 ); // change position of mesh
mesh.updateMatrixWorld(); // ensure world matrix is up-to-date
vertex.applyMatrix4( mesh.matrixWorld ); // transform the vertex from local to world space
var vA = new THREE.Vector3();
var vB = new THREE.Vector3();
var vC = new THREE.Vector3();
var face = elemento.face;
var geometry = elemento.object.geometry;
var posicion = geometry.attributes.position;
vA.fromBufferAttribute( posicion, face.a );
vB.fromBufferAttribute( posicion, face.b );
vC.fromBufferAttribute( posicion, face.c );
console.log(vA,vB,vC);
var object3d=elemento.object.parent.parent.parent;
object3d.updateMatrixWorld();
var vA_global=object3d.localToWorld(vA.clone());
var vB_global=object3d.localToWorld(vB.clone());
var vC_global=object3d.localToWorld(vC.clone());
console.log(vA_global,vB_global,vC_global);
var plano=new THREE.Plane();
console.log(plano);
plano.setFromCoplanarPoints(vA_global,vB_global,vC_global);
var geometry = new THREE.SphereBufferGeometry( 0.4, 10, 10 );
var material = new THREE.MeshLambertMaterial({
flatShading: THREE.SmoothShading,
color: 0xca4fb2,
depthTest: false,
depthWrite: false
});
this.esfera = new THREE.Mesh( geometry, material );
this.esfera2 = new THREE.Mesh( geometry, material );
this.esfera3 = new THREE.Mesh( geometry, material );
this.esfera.position.copy(vA_global);
scope.visor.viewer.scene.scene.add( this.esfera );
this.esfera2.position.copy(vB_global);
scope.visor.viewer.scene.scene.add( this.esfera2 );
this.esfera3.position.copy(vC_global);
scope.visor.viewer.scene.scene.add( this.esfera3 );