Permalink
Browse files

Patch of sortFacesByMaterial for master branch.

See #2638
  • Loading branch information...
1 parent 888042b commit 941046566e46fbdf87583202609dc93f0af73baa @alteredq alteredq committed Nov 16, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/renderers/WebGLRenderer.js
@@ -4196,7 +4196,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// Geometry splitting
- function sortFacesByMaterial ( geometry ) {
+ function sortFacesByMaterial ( geometry, material ) {
var f, fl, face, materialIndex, vertices,
materialHash, groupHash,
@@ -4205,12 +4205,14 @@ THREE.WebGLRenderer = function ( parameters ) {
var numMorphTargets = geometry.morphTargets.length;
var numMorphNormals = geometry.morphNormals.length;
+ var usesFaceMaterial = material instanceof THREE.MeshFaceMaterial;
+
geometry.geometryGroups = {};
for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
face = geometry.faces[ f ];
- materialIndex = face.materialIndex;
+ materialIndex = usesFaceMaterial ? face.materialIndex : undefined;
materialHash = ( materialIndex !== undefined ) ? materialIndex : -1;
@@ -4310,7 +4312,7 @@ THREE.WebGLRenderer = function ( parameters ) {
function addObject ( object, scene ) {
- var g, geometry, geometryGroup;
+ var g, geometry, material, geometryGroup;
if ( ! object.__webglInit ) {
@@ -4322,12 +4324,13 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( object instanceof THREE.Mesh ) {
geometry = object.geometry;
+ material = object.material;
if ( geometry instanceof THREE.Geometry ) {
if ( geometry.geometryGroups === undefined ) {
- sortFacesByMaterial( geometry );
+ sortFacesByMaterial( geometry, material );
}

0 comments on commit 9410465

Please sign in to comment.