Reputation: 11
I am having trouble accessing the .attributes.position for any sort of geometry in THREE.js. Basically, the console error is 'Uncaught TypeError: Cannot read properties of undefined (reading 'position')'.
const cylinderGeometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
const position = cylinderGeometry.attributes.position;
const vertex = new THREE.Vector3();
For reference, the snippet is taken from https://threejs.org/docs/#api/en/objects/SkinnedMesh.
Any idea why this might happen? Could it be related to the THREE.js version I am using?
Upvotes: 1
Views: 401
Reputation: 28482
If you're using Three.js version r125 or later, you should be able to get the position attribute of any geometry with the .getAttribute()
method.:
const cylinderGeometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 );
const posAttribute = cylinderGeometry.getAttribute("position");
const posArray = posAttribute.array;
If you're using version r124 or earlier, then the Geometry generated used to be structured differently. This approach is now deprecated, so it's recommended you update to a newer version.
Upvotes: 0