Create a simplex noise for gltf model

Hi have a nice day , i try to make a simplex noise to gltf model (create it in blender) ,
The first problem is i cannot access to vertices so i found a way, no error but nothing happen
that’s my code

 var k = 1.9;
 let update = () => {
   var time = performance.now() * 0.0009;
   var vertex = new THREE.Vector3();
   var positionAttribute = mesh.geometry.getAttribute('position');

   for (var i = 0; i < positionAttribute.count; i++) {
     vertex.fromBufferAttribute(positionAttribute, i);
     let p = vertex;
     p.normalize().multiplyScalar(1 + 0.09 * simplex.noise3D(p.x * k, p.y * k, p.z * k + time));
   }
   mesh.geometry.computeVertexNormals();
   mesh.geometry.normalsNeedUpdate = true;
   mesh.geometry.verticesNeedUpdate = true;

 }

Not sure, but shouldn’t you set the changed values back to the buffer?

mesh.geometry.attributes.position.setXYZ(i, p.x, p.y, p.z);

Hi!

Try to use this instead:

mesh.geometry.attributes.position.needsUpdate = true;
mesh.geometry.attributes.normal.needsUpdate = true;

I try that but not working Unfortunately

not working Unfortunately

Without a glitch it is difficult to see what might be wrong. I use something similar on a gltf model, so it can work. Do you perhaps have multiple meshes, and only address one (just guessing now)?.

No i use just one mesh

This part needs one more line at the end:
positionAttribute.setXYZ(i, p.x, p.y, p.z);
As you’re reading the data from attribute, putting it in vertex, then compuing the values with noise, but not changing values of the attribute.
And after all you need to set .needsUpdate to true for attributes of positions and normals.

thank you for replay but when i add this the mesh disappear

   for (var i = 0; i < positionAttribute.count; i++) {
      vertex.fromBufferAttribute(positionAttribute, i);
      let p = vertex;
      p.normalize().multiplyScalar(1 + 0.09 * simplex.noise3D(p.x * k, p.y * k, p.z * k + time));
      positionAttribute.setXYZ(i, p.x, p.y, p.z);

    }
    mesh.geometry.normalsNeedUpdate = true;
    mesh.geometry.verticesNeedUpdate = true;
  }

Can it be that you should not use i++, but every third position i=i+3?

Buffer attributes have their x, y z positions in sequences (see Three.js Custom BufferGeometry (threejsfundamentals.org))

.fromBufferAttribute() internally uses .getX() (and .getY(), .getZ()) method, that takes in count attribute’s item size.

These properties are useless, if you use a buffer geometry.
With that type of geometry you have to use those ones, that applied to geometry’s attributes:

Also, is it possible to provide an editable example, that demonstrates the issue? jsfiddle, codepen etc.

Thank you ,now it’s working !!!