3

I am loading a glb-File using GLTFLoader in Three.js: Before I was using the JSONLoader. Accessing the vertices of the loaded mesh was easy:

meh.geometry.vertices

But when looking at the mesh loaded with GLTFloader, I just can not find, where the vertices are?

I need to manipulate each single vertex for some particle animation.

Thanks

  • 3
    You have to look at the children of the loaded object. They should be of `THREE.Mesh()` with `THREE.BufferGeometry()`, thus their vertices are stored in a buffer attribute, for example `object.geometry.attributes.position`. – prisoner849 Sep 29 '18 at 15:22
  • Thanks for the quick reply. Is there a way to work with this "positions" as a vector3? Before I could just multiply, add and subtract vectors to the single vertices. Now it seems I have to first separate the array in groups of three, then create a vector3 from that separations, then multiply, add, subtract ect., then write the values back to the array. Im am pretty sure, I am overseeing something here .. sorry if the question is stupid :) – Paul Hoepner Sep 29 '18 at 15:56
  • 1
    [Vector3.fromBufferAttribute](https://threejs.org/docs/index.html#api/en/math/Vector3.fromBufferAttribute) is a valuable method when working with `BufferAttribute`'s. It automatically extracts the vector components from the given `BufferAttribute` and index. In general, it's a little bit harder to work with `BufferGeometry` than with `Geometry` but it is the more efficient representation of geometric data. It pays off to use it. – Mugen87 Sep 29 '18 at 18:51
  • Perfect, thats the solution! Thanks a lot! – Paul Hoepner Sep 29 '18 at 19:49

1 Answers1

2

Use console.log(gltf)- To view the JSON file, then you will find everything in Scenes. To access the mesh use gltf.scene.traverse( function ( child ) {if ( child.isMesh ){ child.geometries.attributes...}}