Transforming Geometry to BufferGeometry
Asked Answered
M

1

29

As I understand it, Geometry stores a javascript object structure of the vertices and faces and BufferGeometry just stores the raw gl data via Float32Arrays, etc.

Is there any way to turn standard Geometry into BufferGeometry, which is a lot more memory compact with less objects? For example if I create a new SphereGeometry, is there a way to easily transform that to a BufferGeometry?

Myeshamyhre answered 15/8, 2013 at 22:21 Comment(0)
C
42

This answer only applies to versions of three.js prior to r.125.

The Legacy Geometry class has been removed.


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

three.js r.124

Chabot answered 15/8, 2013 at 22:48 Comment(6)
I just tried using this (brand spanking new, huh) but the faces don't port over. I've tried setting the nonexistant faces property on the buffer geometry to that on the old geometry, but no dice.Myeshamyhre
Works for me. Quad faces are not supported in r.60, only tris. Step through the code with the debugger. You can probably figure out what the problem is.Chabot
Ah, yeah I saw that and made something based on that code. Thanks! Ported my spheres to BufferGeometry: i.imgur.com/UCB1f61.pngMyeshamyhre
After converting your geometry to a buffergeometry, is there a way to save it and load it later from a file? Currently I'm loading a large model from a .ply and I'm looking for a performance improvement.Hopping
@Hopping You need to make a new post if you have a question.Chabot
I seems that fromGeometry() is no longer a method of BufferGeometry.Mackenzie

© 2022 - 2024 — McMap. All rights reserved.