0

We recently switched to r68 and are moving all our geometries to THREE.BufferGeometry.

We were using THREE.MeshFaceMaterial in a lot of places and according to BufferGeometry faces materials THREE.BufferGeometry does not support it. The solution seems to be to create multiple meshes, I tried this but it doesn't seem to work and I don't get any errors.

My approach is as follows:

var oldGeometry = ... // THREE.Geometry from our loader
var materials = ... // Material array from our loader, uses lightmaps, normalmaps etc.
var bufferGeometry = new THREE.BufferGeometry();
var geometry = bufferGeometry.fromGeometry(oldGeometry);

var group = new THREE.Object3D();

materials.forEach(function(material){
  group.add(new THREE.Mesh(geometry, material));
});

geometry.attributes.uv = geometry.attributes.uvs;

This works fine without errors, but when rendered, all the lightmaps etc don't seem to work, the geometry looks fine but has just one color.

Any hints on how to implement this properly?

Edit:

UV issue: https://github.com/mrdoob/three.js/issues/5118

Edit 2:

After digging through the WebGLRenderer Source Code, I think implementing this is a lot more work then it's worth it right now. We will stick with the old geometry for now, but I'm still open for suggestions ;)

Edit 3: A basic way to to do this yourself can be found here: https://github.com/mrdoob/three.js/issues/5268

There is work being done here https://github.com/mrdoob/three.js/issues/5417 to improve the three.js exporter, e.g. exporting buffergeometries with multiple materials.

Community
  • 1
  • 1
rawphl
  • 331
  • 2
  • 8

1 Answers1

2

There is a bug in bufferGeometry.fromGeometry() when handling the uvs in r68.

Try this workaround:

bufferGeometry.attributes.uv = bufferGeometry.attributes.uvs;
mrdoob
  • 19,334
  • 4
  • 63
  • 62
  • Unfortunately, this did not really help. If I separate the different meshes (different positions), I can see that every mesh has it's own material, but when combined, only one is visible. I tried creating the meshes with maps first, like suggested here https://github.com/mrdoob/three.js/issues/4751, but that also didn't help. Are there any working examples for BufferGeometry with multiple materials or can you point me to the uv issue? – rawphl Sep 02 '14 at 13:08
  • I just realised that the materials get applied to the whole geometry, so if I have a material with a texture, it looks very funny. I guess I have to split my geometry, which makes this a lot harder^^ – rawphl Sep 02 '14 at 15:32