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.

Three drops indices when converting from a Geometry > BufferGeometry

See original GitHub issue
Description of the problem

Every face in a Geometry has a materialIndex. When Three converts from a Geometry to a BufferGeometry…

var bufferGeometry = THREE.BufferGeometry.new().fromGeometry(geometry);

…there’s an intermediary step where a DirectGeometry is used

fromGeometry: function ( geometry ) {
    geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );

Note that a DirectGeometry defines an indices array, then does nothing with it.

So it’s not surprising when BufferGeometry checks the intermediary directGeometry.indices.length, it won’t ever be populated.

When the BufferGeometry comes out the other end, it has no indices. bufferGeometry.getIndex() is null.

It looks like DirectGeometry’s ability to handle indices was removed two years ago.

Here’s a CodePen demonstrating the problem. Check the logs. The merged geometry should have indices returned, but it doesn’t. https://codepen.io/andrewray/pen/gRyrzR?editors=0010

Three.js version
  • Dev
  • r85
Browser
  • All of them
OS
  • All of them

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
WestLangleycommented, Jul 17, 2017

@Bryce-Summers If you mean the option to return indexed BufferGeometry, no, because in most cases it is not reasonable, and it adds a lot of additional logic to the loader.

BTW, would returning non-indexed BufferGeoemtry and simply adding an attribute originalIndex solve your problem?

1reaction
mrdoobcommented, Jul 16, 2017

Every face in a Geometry has a materialIndex. When Three converts from a Geometry to a BufferGeometry…

materialIndex and indices are different things though. materialIndex refers to multi-materials. indices refer to attribute indices.

Note that a DirectGeometry defines an indices array, then does nothing with it.

Good catch!

It looks like DirectGeometry’s ability to handle indices was removed two years ago.

It was also added some weeks before that. Basically, I was trying to keep indices somehow but it was not really possible so I removed it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

update indices of a bufferGeometry in three.js - Stack Overflow
You want to update the indices of your indexed- BufferGeometry after the geometry has been rendered. To do so, you cannot reassign a...
Read more >
3d - Which provides better intuition: THREE.Geometry or ...
Note that BufferGeometry still supports both indexed and non-indexed meshes. It contains arrays of vertex attributes and indices, and works ...
Read more >
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 >
Tips & Tricks for speeding up Three.js - Attacking Pixels
BufferGeometry is an efficient representation of mesh, line, or point geometry. Includes vertex positions, face indices, normals, colours, UVs, ...
Read more >
[Solved]-THREE.BufferGeometry - accessing face indices and ...
SphereGeometry , derived from BufferGeometry , is of the indexed type. You can access the face normals in the geometry data structure like...
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