question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GLTFLoader BufferAttribute unable to reference directly in THREE.BufferGeometry.attributes[x] (Suggested Fix)

See original GitHub issue

GLTF 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.

  1. 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,
	};
  1. 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

3reactions
donmccurdycommented, Apr 7, 2022

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.

3reactions
donmccurdycommented, Apr 5, 2022

Three.BufferGeometry requires attributes to be typed for example as Float32BufferAttribute or Uint16BufferAttribute

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found