提交 1d439d02 编写于 作者: M Michael Guerrero

Merge branch 'dev' of https://github.com/mrdoob/three.js into blending-take2

......@@ -4133,23 +4133,26 @@ THREE.Matrix3.prototype = {
var v1 = new THREE.Vector3();
return function ( a ) {
return function ( array, offset, length ) {
for ( var i = 0, il = a.length; i < il; i += 3 ) {
if ( offset === undefined ) offset = 0;
if ( length === undefined ) length = array.length;
v1.x = a[ i ];
v1.y = a[ i + 1 ];
v1.z = a[ i + 2 ];
for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
v1.x = array[ j ];
v1.y = array[ j + 1 ];
v1.z = array[ j + 2 ];
v1.applyMatrix3( this );
a[ i ] = v1.x;
a[ i + 1 ] = v1.y;
a[ i + 2 ] = v1.z;
array[ j ] = v1.x;
array[ j + 1 ] = v1.y;
array[ j + 2 ] = v1.z;
}
return a;
return array;
};
......@@ -4763,23 +4766,26 @@ THREE.Matrix4.prototype = {
var v1 = new THREE.Vector3();
return function ( a ) {
return function ( array, offset, length ) {
if ( offset === undefined ) offset = 0;
if ( length === undefined ) length = array.length;
for ( var i = 0, il = a.length; i < il; i += 3 ) {
for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
v1.x = a[ i ];
v1.y = a[ i + 1 ];
v1.z = a[ i + 2 ];
v1.x = array[ j ];
v1.y = array[ j + 1 ];
v1.z = array[ j + 2 ];
v1.applyMatrix4( this );
a[ i ] = v1.x;
a[ i + 1 ] = v1.y;
a[ i + 2 ] = v1.z;
array[ j ] = v1.x;
array[ j + 1 ] = v1.y;
array[ j + 2 ] = v1.z;
}
return a;
return array;
};
......@@ -9495,28 +9501,6 @@ THREE.BufferGeometry.prototype = {
},
normalizeNormals: function () {
var normals = this.attributes[ "normal" ].array;
var x, y, z, n;
for ( var i = 0, il = normals.length; i < il; i += 3 ) {
x = normals[ i ];
y = normals[ i + 1 ];
z = normals[ i + 2 ];
n = 1.0 / Math.sqrt( x * x + y * y + z * z );
normals[ i ] *= n;
normals[ i + 1 ] *= n;
normals[ i + 2 ] *= n;
}
},
computeTangents: function () {
// based on http://www.terathon.com/code/tangent.html
......@@ -9827,6 +9811,34 @@ THREE.BufferGeometry.prototype = {
return offsets;
},
merge: function () {
console.log( 'BufferGeometry.merge(): TODO' );
},
normalizeNormals: function () {
var normals = this.attributes[ "normal" ].array;
var x, y, z, n;
for ( var i = 0, il = normals.length; i < il; i += 3 ) {
x = normals[ i ];
y = normals[ i + 1 ];
z = normals[ i + 2 ];
n = 1.0 / Math.sqrt( x * x + y * y + z * z );
normals[ i ] *= n;
normals[ i + 1 ] *= n;
normals[ i + 2 ] *= n;
}
},
/*
reoderBuffers:
Reorder attributes based on a new indexBuffer and indexMap.
......@@ -9943,34 +9955,150 @@ THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
* @author mrdoob / http://mrdoob.com/
*/
THREE.Geometry2 = function ( vertices, normals, uvs ) {
THREE.Geometry2 = function ( size ) {
THREE.BufferGeometry.call( this );
if ( size !== undefined ) {
this.vertices = new Float32Array( size * 3 * 3 );
this.normals = new Float32Array( size * 3 * 3 );
this.uvs = new Float32Array( size * 3 * 2 );
this.attributes[ 'position' ] = { array: this.vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: this.normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: this.uvs, itemSize: 2 };
}
};
THREE.Geometry2.prototype = Object.create( THREE.BufferGeometry.prototype );
THREE.Geometry2.prototype.setArrays = function ( vertices, normals, uvs ) {
this.vertices = vertices;
this.normals = normals;
this.uvs = uvs;
this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
return this;
};
THREE.Geometry2.prototype = Object.create( THREE.BufferGeometry.prototype );
THREE.Geometry2.prototype.merge = ( function () {
var offset = 0;
var normalMatrix = new THREE.Matrix3();
return function ( geometry, matrix, startOffset ) {
if ( startOffset !== undefined ) offset = startOffset;
var offset2 = offset * 2;
var offset3 = offset * 3;
var vertices = this.attributes[ 'position' ].array;
var normals = this.attributes[ 'normal' ].array;
var uvs = this.attributes[ 'uv' ].array;
if ( geometry instanceof THREE.Geometry2 ) {
var vertices2 = geometry.attributes[ 'position' ].array;
var normals2 = geometry.attributes[ 'normal' ].array;
var uvs2 = geometry.attributes[ 'uv' ].array;
for ( var i = 0, l = vertices2.length; i < l; i += 3 ) {
vertices[ i + offset3 ] = vertices2[ i ];
vertices[ i + offset3 + 1 ] = vertices2[ i + 1 ];
vertices[ i + offset3 + 2 ] = vertices2[ i + 2 ];
normals[ i + offset3 ] = normals2[ i ];
normals[ i + offset3 + 1 ] = normals2[ i + 1 ];
normals[ i + offset3 + 2 ] = normals2[ i + 2 ];
uvs[ i + offset2 ] = uvs2[ i ];
uvs[ i + offset2 + 1 ] = uvs2[ i + 1 ];
}
} else if ( geometry instanceof THREE.IndexedGeometry2 ) {
var indices2 = geometry.attributes[ 'index' ].array;
var vertices2 = geometry.attributes[ 'position' ].array;
var normals2 = geometry.attributes[ 'normal' ].array;
var uvs2 = geometry.attributes[ 'uv' ].array;
for ( var i = 0, l = indices2.length; i < l; i ++ ) {
var index = indices2[ i ];
var index3 = index * 3;
var i3 = i * 3;
vertices[ i3 + offset3 ] = vertices2[ index3 ];
vertices[ i3 + offset3 + 1 ] = vertices2[ index3 + 1 ];
vertices[ i3 + offset3 + 2 ] = vertices2[ index3 + 2 ];
normals[ i3 + offset3 ] = normals2[ index3 ];
normals[ i3 + offset3 + 1 ] = normals2[ index3 + 1 ];
normals[ i3 + offset3 + 2 ] = normals2[ index3 + 2 ];
var index2 = index * 2;
var i2 = i * 2;
uvs[ i2 + offset2 ] = uvs2[ index2 ];
uvs[ i2 + offset2 + 1 ] = uvs2[ index2 + 1 ];
}
if ( matrix !== undefined ) {
matrix.applyToVector3Array( vertices, offset3, indices2.length * 3 );
normalMatrix.getNormalMatrix( matrix );
normalMatrix.applyToVector3Array( normals, offset3, indices2.length * 3 );
}
offset += indices2.length;
}
};
} )();
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.IndexedGeometry2 = function ( indices, vertices, normals, uvs ) {
THREE.IndexedGeometry2 = function () {
THREE.BufferGeometry.call( this );
};
THREE.IndexedGeometry2.prototype = Object.create( THREE.BufferGeometry.prototype );
THREE.IndexedGeometry2.prototype.setArrays = function ( indices, vertices, normals, uvs ) {
this.indices = indices;
this.vertices = vertices;
this.normals = normals;
this.uvs = uvs;
this.attributes[ 'index' ] = { array: indices, itemSize: 1 };
this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
};
THREE.IndexedGeometry2.prototype = Object.create( THREE.BufferGeometry.prototype );
return this;
};
/**
* @author mrdoob / http://mrdoob.com/
* @author kile / http://kile.stravaganza.org/
......@@ -10223,8 +10351,6 @@ THREE.Geometry.prototype = {
for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
face = this.faces[ f ];
faceNormal = new THREE.Vector3();
vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
......@@ -28539,6 +28665,9 @@ THREE.WebGLShader = ( function () {
}
// --enable-privileged-webgl-extension
// console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
return shader;
};
......@@ -33866,7 +33995,9 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
}
THREE.IndexedGeometry2.call( this, indices, vertices, normals, uvs );
THREE.IndexedGeometry2.call( this );
this.setArrays( indices, vertices, normals, uvs );
this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
......@@ -35068,7 +35199,10 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
}
THREE.IndexedGeometry2.call( this, indices, vertices, normals, uvs );
THREE.IndexedGeometry2.call( this );
this.setArrays( indices, vertices, normals, uvs );
this.computeBoundingSphere();
};
......@@ -38458,6 +38592,8 @@ THREE.ShadowMapPlugin = function () {
}
_renderer.setMaterialFaces( objectMaterial );
if ( buffer instanceof THREE.BufferGeometry ) {
_renderer.renderBufferDirect( shadowCamera, scene.__lights, fog, material, buffer, object );
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -106,12 +106,10 @@ THREE.STLLoader.prototype.parseBinary = function ( data ) {
var dataOffset = 84;
var faceLength = 12 * 4 + 2;
var vertices = new Float32Array( faces * 3 * 3 );
var normals = new Float32Array( faces * 3 * 3 );
var uvs = new Float32Array( faces * 3 * 2 );
var offset = 0;
var geometry = new THREE.Geometry2( faces );
for ( var face = 0; face < faces; face ++ ) {
var start = dataOffset + face * faceLength;
......@@ -120,13 +118,13 @@ THREE.STLLoader.prototype.parseBinary = function ( data ) {
var vertexstart = start + i * 12;
vertices[ offset ] = reader.getFloat32( vertexstart, true );
vertices[ offset + 1 ] = reader.getFloat32( vertexstart + 4, true );
vertices[ offset + 2 ] = reader.getFloat32( vertexstart + 8, true );
geometry.vertices[ offset ] = reader.getFloat32( vertexstart, true );
geometry.vertices[ offset + 1 ] = reader.getFloat32( vertexstart + 4, true );
geometry.vertices[ offset + 2 ] = reader.getFloat32( vertexstart + 8, true );
normals[ offset ] = reader.getFloat32( start , true );
normals[ offset + 1 ] = reader.getFloat32( start + 4, true );
normals[ offset + 2 ] = reader.getFloat32( start + 8, true );
geometry.normals[ offset ] = reader.getFloat32( start , true );
geometry.normals[ offset + 1 ] = reader.getFloat32( start + 4, true );
geometry.normals[ offset + 2 ] = reader.getFloat32( start + 8, true );
offset += 3;
......@@ -134,7 +132,7 @@ THREE.STLLoader.prototype.parseBinary = function ( data ) {
}
return new THREE.Geometry2( vertices, normals, uvs );
return geometry;
};
......
......@@ -107,8 +107,8 @@
nxGeometry.applyMatrix( matrix.makeTranslation( - 50, 0, 0 ) );
var pyGeometry = new THREE.PlaneGeometry( 100, 100 );
pyGeometry.attributes.uv.array[ 5 ] = 0.5;
pyGeometry.attributes.uv.array[ 7 ] = 0.5;
pyGeometry.uvs[ 5 ] = 0.5;
pyGeometry.uvs[ 7 ] = 0.5;
// pyGeometry.faceVertexUvs[ 0 ][ 0 ][ 1 ].y = 0.5;
// pyGeometry.faceVertexUvs[ 0 ][ 1 ][ 0 ].y = 0.5;
// pyGeometry.faceVertexUvs[ 0 ][ 1 ][ 1 ].y = 0.5;
......
......@@ -8,13 +8,13 @@ THREE.Geometry2 = function ( size ) {
if ( size !== undefined ) {
var vertices = new Float32Array( size * 3 * 3 );
var normals = new Float32Array( size * 3 * 3 );
var uvs = new Float32Array( size * 3 * 2 );
this.vertices = new Float32Array( size * 3 * 3 );
this.normals = new Float32Array( size * 3 * 3 );
this.uvs = new Float32Array( size * 3 * 2 );
this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
this.attributes[ 'position' ] = { array: this.vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: this.normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: this.uvs, itemSize: 2 };
}
......@@ -24,6 +24,10 @@ THREE.Geometry2.prototype = Object.create( THREE.BufferGeometry.prototype );
THREE.Geometry2.prototype.setArrays = function ( vertices, normals, uvs ) {
this.vertices = vertices;
this.normals = normals;
this.uvs = uvs;
this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
this.attributes[ 'uv' ] = { array: uvs, itemSize: 2 };
......
......@@ -12,6 +12,11 @@ THREE.IndexedGeometry2.prototype = Object.create( THREE.BufferGeometry.prototype
THREE.IndexedGeometry2.prototype.setArrays = function ( indices, vertices, normals, uvs ) {
this.indices = indices;
this.vertices = vertices;
this.normals = normals;
this.uvs = uvs;
this.attributes[ 'index' ] = { array: indices, itemSize: 1 };
this.attributes[ 'position' ] = { array: vertices, itemSize: 3 };
this.attributes[ 'normal' ] = { array: normals, itemSize: 3 };
......
......@@ -64,7 +64,9 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
}
THREE.IndexedGeometry2.call( this, indices, vertices, normals, uvs );
THREE.IndexedGeometry2.call( this );
this.setArrays( indices, vertices, normals, uvs );
this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
......
......@@ -298,6 +298,8 @@ THREE.ShadowMapPlugin = function () {
}
_renderer.setMaterialFaces( objectMaterial );
if ( buffer instanceof THREE.BufferGeometry ) {
_renderer.renderBufferDirect( shadowCamera, scene.__lights, fog, material, buffer, object );
......
......@@ -34,6 +34,9 @@ THREE.WebGLShader = ( function () {
}
// --enable-privileged-webgl-extension
// console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
return shader;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册