28

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?

Wilt
  • 41,477
  • 12
  • 152
  • 203
Axiverse
  • 1,589
  • 3
  • 14
  • 30

1 Answers1

41

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

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • 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. – Axiverse Aug 16 '13 at 02:29
  • 1
    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. – WestLangley Aug 16 '13 at 03:08
  • Ah, yeah I saw that and made something based on that code. Thanks! Ported my spheres to BufferGeometry: http://i.imgur.com/UCB1f61.png – Axiverse Aug 16 '13 at 04:37
  • 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. – foobarbecue Jun 03 '14 at 21:56
  • @foobarbecue You need to make a new post if you have a question. – WestLangley Jun 03 '14 at 23:31
  • 2
    I seems that `fromGeometry()` is no longer a method of [`BufferGeometry`](https://threejs.org/docs/?q=buffergeo#api/en/core/BufferGeometry). – alexis_thual Jan 30 '23 at 11:29