GLTFLoader BufferAttribute unable to reference directly in THREE.BufferGeometry.attributes[x] (Suggested Fix)
See original GitHub issueGLTF Loaders BufferAttribute cannot directly be used as references for THREE.BufferGeometry.attributes[x] such as position or THREE.BufferGeometry.index
Three.BufferGeometry requires attributes to be typed for example as Float32BufferAttribute or Uint16BufferAttribute
The fix is quite easy.
- add a new Mapping dict for Buffers ( which currently doesn’t exist it seems this is old and hardcoded):
const WEBGL_COMPONENT_TYPES_BUFFER_ATTRIBUTE_MAPPING = {
5120: THREE.Int8BufferAttribute,
5121: THREE.Uint8BufferAttribute,
5122: THREE.Int16BufferAttribute,
5123: THREE.Uint16BufferAttribute,
5125: THREE.Uint32BufferAttribute,
5126: THREE.Float32BufferAttribute,
};
- later in the GLTFLoader code replace the buffer attribute line with the following:
const bufferTypeLookUp = WEBGL_COMPONENT_TYPES_BUFFER_ATTRIBUTE_MAPPING [accessorDef.componentType];
bufferAttribute = new bufferTypeLookUp( array, itemSize, normalized );
// bufferAttribute = new THREE.BufferAttribute( array, itemSize, normalized );
//some ifs bellow
const bufferTypeLookUp2 = WEBGL_COMPONENT_TYPES_BUFFER_MAPPING[accessorDef.sparse.indices.componentType];
// bufferAttribute = new THREE.BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
bufferAttribute = new bufferTypeLookUp2( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
could probably reuse the same lookup for both attribute constructions.
doing a proper commit and pull request would take me too much time so I just write it here for the dedicated developer to pick it up 😃
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5
Top Results From Across the Web
BufferGeometry – three.js docs
A representation of mesh, line, or point geometry. Includes vertex positions, face indices, normals, colors, UVs, and custom attributes within buffers, reducing ...
Read more >Three.js BufferGeometry Vertices Not Updating - Stack Overflow
Instead of changing the value inside geometry.attributes.position directly, try using the .setAttribute() method. The docs state that using .
Read more >Managing References - Ex Libris Knowledge Center
Edit the reference to correct and complete the information. If you drag and drop multiple files at one time, a reference is created...
Read more >10 most popular FAQs - Sciwheel
A more in-depth overview of the features and benefits of the Sciwheel platform for writing papers. Importing references. A quick guide to importing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Most three.js contributors are not dedicated maintainers. With very few exceptions, we are doing this for free on our own time. If you are not comfortable making pull requests that’s OK, but please respect our time in addition to your own.
There may be a misunderstanding here — perhaps you’re using TypeScript and it’s giving warnings and errors in some particular situation? See https://github.com/three-types/three-ts-types if so. But in any case, there is no requirement to use Float32BufferAttribute etc. We can’t see these errors, but if they’re coming from three.js itself we can fix them. Please share details full details to reproduce the issue (as in the issue report template) if that’s the case.
There is no such requirement – using a generic THREE.BufferAttribute with a typed array is normal. Are you seeing some particular error or warning that you’re trying to fix?