提交 20b77b27 编写于 作者: M Mr.doob

Reverting MeshFaceMaterial removal.

上级 d2fb8f23
......@@ -80,6 +80,15 @@
];
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 ++ ) {
......
......@@ -232,7 +232,7 @@ THREE.BinaryLoader.prototype = {
+ metaData.nquad_smooth_uv * ( metaData.vertex_index_bytes*4 + metaData.material_index_bytes + metaData.normal_index_bytes*4 + metaData.uv_index_bytes*4 );
console.log( "total bytes: " + total );
*/
return metaData;
}
......@@ -429,7 +429,7 @@ THREE.BinaryLoader.prototype = {
m = materialIndexBuffer[ i ];
scope.faces.push( new THREE.Face3( a, b, c ) );
scope.faces.push( new THREE.Face3( a, b, c, null, null, m ) );
}
......@@ -451,8 +451,8 @@ THREE.BinaryLoader.prototype = {
m = materialIndexBuffer[ i ];
scope.faces.push( new THREE.Face3( a, b, d ) );
scope.faces.push( new THREE.Face3( b, c, d ) );
scope.faces.push( new THREE.Face3( a, b, d, null, null, m ) );
scope.faces.push( new THREE.Face3( b, c, d, null, null, m ) );
}
......@@ -495,7 +495,7 @@ THREE.BinaryLoader.prototype = {
new THREE.Vector3( nax, nay, naz ),
new THREE.Vector3( nbx, nby, nbz ),
new THREE.Vector3( ncx, ncy, ncz )
] ) );
], null, m ) );
}
......@@ -544,13 +544,13 @@ THREE.BinaryLoader.prototype = {
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 ) );
}
......
......@@ -517,7 +517,7 @@ THREE.Projector = function () {
var face = faces[ f ];
material = isFaceMaterial === true
? objectMaterials.materials[ 0 ] // objectMaterials.materials[ face.materialIndex ]
? objectMaterials.materials[ face.materialIndex ]
: object.material;
if ( material === undefined ) continue;
......
......@@ -91,6 +91,18 @@
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 = [];
......@@ -100,7 +112,8 @@
material = materials[ i ];
geometry = material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth;
geometry = material instanceof THREE.MeshFaceMaterial ? geometry_pieces :
( material.shading == THREE.FlatShading ? geometry_flat : geometry_smooth );
sphere = new THREE.Mesh( geometry, material );
......@@ -225,8 +238,8 @@
}
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 ) ) );
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 ) ) );
particleLight.position.x = Math.sin( timer * 7 ) * 300;
particleLight.position.y = Math.cos( timer * 5 ) * 400;
......
......@@ -3,7 +3,7 @@
* @author alteredq / http://alteredqualia.com/
*/
THREE.Face3 = function ( a, b, c, normal, color ) {
THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
this.a = a;
this.b = b;
......@@ -17,6 +17,8 @@ THREE.Face3 = function ( a, b, c, normal, color ) {
this.vertexTangents = [];
this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
};
THREE.Face3.prototype = {
......@@ -32,6 +34,8 @@ THREE.Face3.prototype = {
this.normal.copy( source.normal );
this.color.copy( source.color );
this.materialIndex = source.materialIndex;
for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
......
......@@ -645,7 +645,7 @@ THREE.Geometry.prototype = {
},
merge: function ( geometry, matrix ) {
merge: function ( geometry, matrix, materialIndexOffset ) {
if ( geometry instanceof THREE.Geometry === false ) {
......@@ -663,6 +663,8 @@ 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 );
......@@ -723,6 +725,8 @@ THREE.Geometry.prototype = {
}
faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
faces1.push( faceCopy );
}
......
......@@ -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 ); // 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
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
function buildPlane( u, v, udir, vdir, width, height, depth ) {
function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
var w, ix, iy,
gridX = scope.widthSegments,
......@@ -100,6 +100,7 @@ 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 ] );
......@@ -107,6 +108,7 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
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() ] );
......
......@@ -91,7 +91,7 @@ THREE.JSONLoader.prototype = {
offset, zLength,
colorIndex, normalIndex, uvIndex,
colorIndex, normalIndex, uvIndex, materialIndex,
type,
isQuad,
......@@ -178,7 +178,9 @@ THREE.JSONLoader.prototype = {
if ( hasMaterial ) {
offset ++;
materialIndex = faces[ offset ++ ];
faceA.materialIndex = materialIndex;
faceB.materialIndex = materialIndex;
}
......@@ -285,7 +287,8 @@ THREE.JSONLoader.prototype = {
if ( hasMaterial ) {
offset ++;
materialIndex = faces[ offset ++ ];
face.materialIndex = materialIndex;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册