Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferGeometry #2300

Closed
oal opened this issue Aug 8, 2012 · 4 comments
Closed

BufferGeometry #2300

oal opened this issue Aug 8, 2012 · 4 comments
Labels

Comments

@oal
Copy link
Contributor

oal commented Aug 8, 2012

Hi!

I'm generating some pretty big models, and the creation of Vector3s, Face3s etc. is simply too slow. Even if I let a WebWorker to most of the job, the creation of the THREE-classes still has to happen in the main thread. @jeromeetienne pointed out that there's something called BufferGeometry, but we're having a hard time getting it to work.

I tried looking at the CTMLoader, but no success so far. Would it be possible to get a small introduction/example on how it works?

I have populated the buffers, but apparently, I can't just throw the BufferGeometry into a Mesh, as it complains about geometryGroups offsets.

Thanks,
Olav.

@jeromeetienne
Copy link
Contributor

i am definitly interested in making one example work using this. it got advantages all over the places.

  • able to download vertices in binary to save time while parsing mesh
  • able to generate vertices in webworker and share them back with the main thread with nocopy (transferable object)

@oal
Copy link
Contributor Author

oal commented Aug 9, 2012

I got it working on 50dev. http://jsfiddle.net/jakLs/

It's written in CoffeeScript, but shouldn't be hard to understand.

@alteredq
Copy link
Contributor

alteredq commented Aug 9, 2012

If you want to understand how BufferGeometry is organized, the best place to check is probably BufferGeometry.computeVertexNormals:

https://github.com/mrdoob/three.js/blob/dev/src/extras/core/BufferGeometry.js#L160

The only tricky part should be getting proper indices - in the original CTM format index buffer can have 32-bit integers so for all practical purposes you can have as big geometries as you need.

But in WebGL element indices can be only 16-bit, so in one draw call you can address just up to 65,536 unique vertices. You can have as many triangles as you want, but they all must use just these vertices, so for example for our "classic" Geometry which uses 3 unique vertices per triangle you get up to ~21K faces per chunk (each chunk has own separate index buffer and separate attribute buffers).

Now in BufferGeometry this indexing problem for large number of vertices is handled in a different way - there is just one huge index buffer and several huge per-attribute buffers shared by all chunks and metadata about how are chunks organized is stored in offsets array.

Draw call for each chunk is sending count indices starting from start offset (from the beginning of index buffer) and these indices are interpreted as being themselves offset by index number of vertices in corresponding attribute buffers (thus you can address vertices with indices larger than 65,535):

https://github.com/mrdoob/three.js/blob/dev/src/renderers/WebGLRenderer.js#L3235

Please note that when creating buffers, you need to take care that in each chunk only up to 65,536 vertices will be addressed (so for example you can't have triangle using vertices (0,1,100000)).

@SimonVZ
Copy link
Contributor

SimonVZ commented Aug 23, 2013

The "chunking" approach will not work if any of triangles has vertices with indices more than 65,535 apart. CTMLoader goes into an infinite loop in this case. See issue Issue #3524.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants