Skip to content

Commit

Permalink
Removing MeshFaceMaterial.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Apr 5, 2015
1 parent b4242d0 commit 03b8391
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 165 deletions.
9 changes: 0 additions & 9 deletions examples/canvas_materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@

];

for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) {

var face = geometry.faces[ i ];
if ( Math.random() > 0.5 ) face.materialIndex = Math.floor( Math.random() * materials.length );

}

materials.push( new THREE.MeshFaceMaterial( materials ) );

objects = [];

for ( var i = 0, l = materials.length; i < l; i ++ ) {
Expand Down
13 changes: 3 additions & 10 deletions examples/js/loaders/AssimpJSONLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,8 @@ THREE.AssimpJSONLoader.prototype = {
// read faces
var cnt = 0;
for (in_data = json.faces, i = 0, e = in_data.length; i < e; ++ i) {
face = new THREE.Face3();
src = in_data[i];
face.a = src[0];
face.b = src[1];
face.c = src[2];

face.materialIndex = 0; //json.materialindex;
face = new THREE.Face3(src[0],src[1],src[2]);
geometry.faces.push(face);
}

Expand Down Expand Up @@ -189,7 +184,7 @@ THREE.AssimpJSONLoader.prototype = {
},

parseMaterial : function(json) {
var mat = null,
var mat = null,
scope = this, i, prop, has_textures = [],

init_props = {
Expand Down Expand Up @@ -286,7 +281,7 @@ THREE.AssimpJSONLoader.prototype = {
init_props[has_textures[i]] = defaultTexture();
}
}

mat = new THREE.MeshPhongMaterial( init_props );
return mat;
},
Expand All @@ -313,5 +308,3 @@ THREE.AssimpJSONLoader.prototype = {
return obj;
},
};


12 changes: 6 additions & 6 deletions examples/js/loaders/BinaryLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture

m = materialIndexBuffer[ i ];

scope.faces.push( new THREE.Face3( a, b, c, null, null, m ) );
scope.faces.push( new THREE.Face3( a, b, c ) );

}

Expand All @@ -510,8 +510,8 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture

m = materialIndexBuffer[ i ];

scope.faces.push( new THREE.Face3( a, b, d, null, null, m ) );
scope.faces.push( new THREE.Face3( b, c, d, null, null, m ) );
scope.faces.push( new THREE.Face3( a, b, d ) );
scope.faces.push( new THREE.Face3( b, c, d ) );

}

Expand Down Expand Up @@ -554,7 +554,7 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
new THREE.Vector3( nax, nay, naz ),
new THREE.Vector3( nbx, nby, nbz ),
new THREE.Vector3( ncx, ncy, ncz )
], null, m ) );
] ) );

}

Expand Down Expand Up @@ -603,13 +603,13 @@ THREE.BinaryLoader.prototype.createBinModel = function ( data, callback, texture
new THREE.Vector3( nax, nay, naz ),
new THREE.Vector3( nbx, nby, nbz ),
new THREE.Vector3( ndx, ndy, ndz )
], null, m ) );
] ) );

scope.faces.push( new THREE.Face3( b, c, d, [
new THREE.Vector3( nbx, nby, nbz ),
new THREE.Vector3( ncx, ncy, ncz ),
new THREE.Vector3( ndx, ndy, ndz )
], null, m ) );
] ) );

}

Expand Down
7 changes: 0 additions & 7 deletions examples/js/loaders/ColladaLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,13 +1179,6 @@ THREE.ColladaLoader = function () {

material = new THREE.MeshFaceMaterial( used_materials_array );

for ( j = 0; j < geom.faces.length; j ++ ) {

var face = geom.faces[ j ];
face.materialIndex = used_materials[ face.daeMaterial ]

}

}

if ( skinController !== undefined ) {
Expand Down
19 changes: 3 additions & 16 deletions examples/webgl_materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@

var geometry_smooth = new THREE.SphereGeometry( 70, 32, 16 );
var geometry_flat = new THREE.SphereGeometry( 70, 32, 16 );
var geometry_pieces = new THREE.SphereGeometry( 70, 32, 16 ); // Extra geometry to be broken down for MeshFaceMaterial

for ( var i = 0, l = geometry_pieces.faces.length; i < l; i ++ ) {

var face = geometry_pieces.faces[ i ];
face.materialIndex = Math.floor( Math.random() * materials.length );

}

geometry_pieces.materials = materials;

materials.push( new THREE.MeshFaceMaterial( materials ) );

objects = [];

Expand All @@ -112,8 +100,7 @@

material = materials[ i ];

geometry = material instanceof THREE.MeshFaceMaterial ? geometry_pieces :
( material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth );
geometry = material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth;

sphere = new THREE.Mesh( geometry, material );

Expand Down Expand Up @@ -238,8 +225,8 @@

}

materials[ materials.length - 3 ].emissive.setHSL( 0.54, 1, 0.35 * ( 0.5 + 0.5 * Math.sin( 35 * timer ) ) );
materials[ materials.length - 4 ].emissive.setHSL( 0.04, 1, 0.35 * ( 0.5 + 0.5 * Math.cos( 35 * timer ) ) );
materials[ materials.length - 2 ].emissive.setHSL( 0.54, 1, 0.35 * ( 0.5 + 0.5 * Math.sin( 35 * timer ) ) );
materials[ materials.length - 3 ].emissive.setHSL( 0.04, 1, 0.35 * ( 0.5 + 0.5 * Math.cos( 35 * timer ) ) );

particleLight.position.x = Math.sin( timer * 7 ) * 300;
particleLight.position.y = Math.cos( timer * 5 ) * 400;
Expand Down
38 changes: 19 additions & 19 deletions examples/webgl_mirror.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@
function fillScene() {

var planeGeo = new THREE.PlaneBufferGeometry( 100.1, 100.1 );

// MIRROR planes
groundMirror = new THREE.Mirror( renderer, camera, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT, color: 0x777777 } );

var mirrorMesh = new THREE.Mesh( planeGeo, groundMirror.material );
mirrorMesh.add( groundMirror );
mirrorMesh.rotateX( - Math.PI / 2 );
scene.add( mirrorMesh );

verticalMirror = new THREE.Mirror( renderer, camera, { clipBias: 0.003, textureWidth: WIDTH, textureHeight: HEIGHT, color:0x889999 } );

var verticalMirrorMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 60, 60 ), verticalMirror.material );
verticalMirrorMesh.add( verticalMirror );
verticalMirrorMesh.position.y = 35;
Expand All @@ -110,50 +110,50 @@
var sphereCap = new THREE.Mesh( geometry, material );
sphereCap.position.y = -15 * Math.sin( Math.PI / 180 * 30 ) - 0.05;
sphereCap.rotateX(-Math.PI);

var geometry = new THREE.SphereGeometry( 15, 24, 24, Math.PI / 2, Math.PI * 2, 0, Math.PI / 180 * 120 );
var halfSphere = new THREE.Mesh( geometry, material );
halfSphere.add( sphereCap );
halfSphere.rotateX( - Math.PI / 180 * 135 );
halfSphere.rotateZ( - Math.PI / 180 * 20 );
halfSphere.rotateX( - Math.PI / 180 * 135 );
halfSphere.rotateZ( - Math.PI / 180 * 20 );
halfSphere.position.y = 7.5 + 15 * Math.sin( Math.PI / 180 * 30 );

sphereGroup.add( halfSphere );

var geometry = new THREE.IcosahedronGeometry( 5, 0 );
var material = new THREE.MeshLambertMaterial( { color: 0xffffff, emissive: 0x333333, shading: THREE.FlatShading } );
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, emissive: 0x333333, shading: THREE.FlatShading } );
smallSphere = new THREE.Mesh( geometry, material );
scene.add(smallSphere);
scene.add(smallSphere);

// walls
var planeTop = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xffffff } ) );
planeTop.position.y = 100;
planeTop.rotateX( Math.PI / 2 );
scene.add( planeTop );

var planeBack = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xffffff } ) );
planeBack.position.z = -50;
planeBack.position.y = 50;
scene.add( planeBack );

var planeFront = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0x7f7fff } ) );
planeFront.position.z = 50;
planeFront.position.y = 50;
planeFront.rotateY( Math.PI );
scene.add( planeFront );

var planeRight = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0x00ff00 } ) );
planeRight.position.x = 50;
planeRight.position.y = 50;
planeRight.rotateY( - Math.PI / 2 );
scene.add( planeRight );

var planeLeft = new THREE.Mesh( planeGeo, new THREE.MeshPhongMaterial( { color: 0xff0000 } ) );
planeLeft.position.x = -50;
planeLeft.position.y = 50;
planeLeft.rotateY( Math.PI / 2 );
scene.add( planeLeft );

// lights
var mainLight = new THREE.PointLight( 0xcccccc, 1.5, 250 );
mainLight.position.y = 60;
Expand All @@ -178,13 +178,13 @@
// render (update) the mirrors
groundMirror.renderWithMirror( verticalMirror );
verticalMirror.renderWithMirror( groundMirror );

renderer.render(scene, camera);

}

function update() {

requestAnimationFrame( update );

var timer = Date.now() * 0.01;
Expand All @@ -200,7 +200,7 @@
smallSphere.rotation.z = timer * 0.8;

cameraControls.update();

render();
}

Expand Down
6 changes: 1 addition & 5 deletions src/core/Face3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author alteredq / http://alteredqualia.com/
*/

THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
THREE.Face3 = function ( a, b, c, normal, color ) {

this.a = a;
this.b = b;
Expand All @@ -17,8 +17,6 @@ THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {

this.vertexTangents = [];

this.materialIndex = materialIndex !== undefined ? materialIndex : 0;

};

THREE.Face3.prototype = {
Expand All @@ -32,8 +30,6 @@ THREE.Face3.prototype = {
face.normal.copy( this.normal );
face.color.copy( this.color );

face.materialIndex = this.materialIndex;

for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {

face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
Expand Down
15 changes: 1 addition & 14 deletions src/core/Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ THREE.Geometry.prototype = {

},

merge: function ( geometry, matrix, materialIndexOffset ) {
merge: function ( geometry, matrix ) {

if ( geometry instanceof THREE.Geometry === false ) {

Expand All @@ -601,8 +601,6 @@ THREE.Geometry.prototype = {
uvs1 = this.faceVertexUvs[ 0 ],
uvs2 = geometry.faceVertexUvs[ 0 ];

if ( materialIndexOffset === undefined ) materialIndexOffset = 0;

if ( matrix !== undefined ) {

normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
Expand Down Expand Up @@ -663,8 +661,6 @@ THREE.Geometry.prototype = {

}

faceCopy.materialIndex = face.materialIndex + materialIndexOffset;

faces1.push( faceCopy );

}
Expand Down Expand Up @@ -872,15 +868,6 @@ THREE.Geometry.prototype = {
faces.push( faceType );
faces.push( face.a, face.b, face.c );


/*
if ( hasMaterial ) {
faces.push( face.materialIndex );
}
*/

if ( hasFaceVertexUv ) {

var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
Expand Down
16 changes: 7 additions & 9 deletions src/extras/geometries/BoxGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
var height_half = height / 2;
var depth_half = depth / 2;

buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half ); // nx
buildPlane( 'x', 'z', 1, 1, width, depth, height_half ); // py
buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half ); // ny
buildPlane( 'x', 'y', 1, - 1, width, height, depth_half ); // pz
buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz

function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
function buildPlane( u, v, udir, vdir, width, height, depth ) {

var w, ix, iy,
gridX = scope.widthSegments,
Expand Down Expand Up @@ -100,15 +100,13 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
var face = new THREE.Face3( a + offset, b + offset, d + offset );
face.normal.copy( normal );
face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
face.materialIndex = materialIndex;

scope.faces.push( face );
scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );

face = new THREE.Face3( b + offset, c + offset, d + offset );
face.normal.copy( normal );
face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
face.materialIndex = materialIndex;

scope.faces.push( face );
scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
Expand Down
Loading

0 comments on commit 03b8391

Please sign in to comment.