Cannot access to .obj vertices

Hello guys

I try to manipulate a .obj file and visualise a music throught it. I canno’t apply transformation of the obj with the function that I use. It work with a sphere but not with the obj. I maybe miss something realy easy :slight_smile: .

My obj load function :

    loader.load(
        // resource URL
        "./skullHead.obj",
        // called when resource is loaded
        function(object) {
          var self = this;
          object.scale.set(7, 7, 7);
          object.position.set(0, 0, 0);
          let man = object;
          vmLoader.mesh = {};
          const vmLoaderFunction = vmLoader;
          man.traverse(function(child) {
            //give color to the obj
            if (child instanceof THREE.Mesh) {
              child.material = new THREE.MeshPhongMaterial(pinkMat);
              const geometry = new THREE.BufferGeometry();

              const dataBuffer =
                object.children[0].geometry.attributes.position;
              geometry.setAttribute(
                "position",
                new THREE.BufferAttribute(dataBuffer, 3)
              );
              // let pos = geometry.attributes.position;
              let pos = geometry.attributes.position.array;
              console.log("pos", pos);

              let vertex = new THREE.Vector3(
                pos.getX(0),
                pos.getY(0),
                pos.getZ(0)
              );
              console.log("vertex", vertex);
            
              console.log(vmLoaderFunction.mesh);
              group.add(vmLoaderFunction.mesh);
        },
        // called when loading is in progresses
        function(xhr) {
          console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
        }
      );

My audio change function :

      function makeRoughBall(mesh, bassFr, treFr, item) {
        console.log(item, mesh);
        mesh.geometry.attributes.position.array.forEach(function(vertex, i) {
          var offset = mesh.geometry.parameters.radius;
          var amp = 7;
          var time = window.performance.now();
          vertex.normalize();
          var rf = 0.00001;
          var distance =
            offset +
            bassFr +
            noise.noise3D(
              vertex.x + time * rf * 7,
              vertex.y + time * rf * 8,
              vertex.z + time * rf * 9
            ) *
              amp *
              treFr;
          vertex.multiplyScalar(distance);
        });
        mesh.geometry.verticesNeedUpdate = true;
        mesh.geometry.normalsNeedUpdate = true;
        mesh.geometry.computeVertexNormals();
        mesh.geometry.computeFaceNormals();
        
      }

This looks wrong. You probably want to do this:

const dataBuffer = child.geometry.attributes.position;

The line after that makes no sense to me. Why do you recreate the position buffer attribute? The parameterization of this line is definitely wrong. The ctor of BufferAttribute does not support a buffer attribute itself.

These flags belong to the deprecated Geometry class. They do not exists for BufferGeometry.

This call has no effect for BufferGeometry since the class has no concept of face normals. It’s best to remove the line.

You probably want to study the BufferGeometry class in more detail. The implementation errors should then disappear automatically.

Thanks for your quick reply !

Do you know if from bufferGeometr i can generate a vertices (vector data) array ?

Thanks