提交 b2fa718d 编写于 作者: M Mikael Emtinger

Unmergable: commited to be able to merge with alterq.

上级 29d45e6d
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -14,7 +14,7 @@ THREE.Geometry = function () {
this.uvs = [];
this.uvs2 = [];
this.colors = [];
this.vertexKeys = [];
this.morphTargets = [];
this.skinWeights = [];
this.skinIndices = [];
......
......@@ -808,47 +808,32 @@ THREE.Loader.prototype = {
// normal vertices
if( data.vertices !== undefined ) {
for( i = 0, l = data.vertices.length; i < l; i += 3 ) {
for( i = 0, l = data.vertices.length; i < l; i += 3 ) {
x = data.vertices[ i ];
y = data.vertices[ i + 1 ];
z = data.vertices[ i + 2 ];
THREE.Loader.prototype.v( scope, x, y, z );
}
x = data.vertices[ i ];
y = data.vertices[ i + 1 ];
z = data.vertices[ i + 2 ];
THREE.Loader.prototype.v( scope, x, y, z );
}
// vertex animation
} else {
if( data.morphTargets !== undefined ) {
for( i = 0, l = data.vertexKeys.length; i < l; i++ ) {
for( i = 0, l = data.morphTargets.length; i < l; i++ ) {
scope.vertexKeys[ i ] = {};
scope.vertexKeys[ i ].time = data.vertexKeys[ i ].t;
scope.vertexKeys[ i ].vertices = [];
scope.morphTargets[ i ] = {};
scope.morphTargets[ i ].name = data.morphTargets[ i ].name;
scope.morphTargets[ i ].vertices = [];
dstVertices = scope.vertexKeys[ i ].vertices;
srcVertices = data.vertexKeys[ i ].v;
dstVertices = scope.morphTargets[ i ].vertices;
srcVertices = data.morphTargets [ i ].vertices;
// also add first frame to .vertices (so many things depends on vertices.length)
if( i === 0 ) {
for( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
scope.vertices.push( new THREE.Vertex( new THREE.Vector3( srcVertices[ v ], srcVertices[ v + 1 ], srcVertices[ v + 2 ] ) ) );
}
}
for( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
dstVertices.push( new THREE.Vertex( new THREE.Vector3( srcVertices[ v ], srcVertices[ v + 1 ], srcVertices[ v + 2 ] ) ) );
dstVertices.push( new THREE.Vertex( new THREE.Vector3( srcVertices[ v ], srcVertices[ v + 1 ], srcVertices[ v + 2 ] )));
}
......
......@@ -54,7 +54,7 @@ THREE.MeshBasicMaterial = function ( parameters ) {
this.vertexColors = false;
this.skinning = false;
this.vertexAnimated = false;
this.morphTargets = false;
if ( parameters ) {
......@@ -82,7 +82,7 @@ THREE.MeshBasicMaterial = function ( parameters ) {
if ( parameters.vertexColors !== undefined ) this.vertexColors = parameters.vertexColors;
if ( parameters.skinning !== undefined ) this.skinning = parameters.skinning;
if ( parameters.vertexAnimated !== undefined ) this.vertexAnimated = parameters.vertexAnimated;
if ( parameters.morphTargets !== undefined ) this.morphTargets = parameters.morphTargets;
}
......
......@@ -54,7 +54,7 @@ THREE.MeshLambertMaterial = function ( parameters ) {
this.vertexColors = false;
this.skinning = false;
this.vertexAnimated = false;
this.morphTargets = false;
if ( parameters ) {
......@@ -82,7 +82,7 @@ THREE.MeshLambertMaterial = function ( parameters ) {
if ( parameters.vertexColors !== undefined ) this.vertexColors = parameters.vertexColors;
if ( parameters.skinning !== undefined ) this.skinning = parameters.skinning;
if ( parameters.vertexAnimated !== undefined ) this.vertexAnimated = parameters.vertexAnimated;
if ( parameters.morphTargets !== undefined ) this.morphTargets = parameters.morphTargets;
}
......
......@@ -62,7 +62,7 @@ THREE.MeshPhongMaterial = function ( parameters ) {
this.vertexColors = false;
this.skinning = false;
this.vertexAnimated = false;
this.morphTargets = false;
if ( parameters ) {
......@@ -94,7 +94,7 @@ THREE.MeshPhongMaterial = function ( parameters ) {
if ( parameters.vertexColors !== undefined ) this.vertexColors = parameters.vertexColors;
if ( parameters.skinning !== undefined ) this.skinning = parameters.skinning;
if ( parameters.vertexAnimated !== undefined ) this.vertexAnimated = parameters.vertexAnimated;
if ( parameters.morphTargets !== undefined ) this.morphTargets = parameters.morphTargets;
}
......
......@@ -40,7 +40,7 @@ THREE.MeshShaderMaterial = function ( parameters ) {
this.vertexColors = false; // must set this if shader wants to use "color" attribute stream
this.skinning = false; // must set this is shader wants to use skinning attribute streams
this.vertexAnimated = false;
this.morphTargets = false;
if ( parameters ) {
......@@ -62,7 +62,7 @@ THREE.MeshShaderMaterial = function ( parameters ) {
if ( parameters.vertexColors !== undefined ) this.vertexColors = parameters.vertexColors;
if ( parameters.skinning !== undefined ) this.skinning = parameters.skinning;
if ( parameters.vertexAnimated !== undefined ) this.vertexAnimated = parameters.vertexAnimated;
if ( parameters.morphTargets !== undefined ) this.morphTargets = parameters.morphTargets;
}
......
......@@ -16,10 +16,11 @@ THREE.Mesh = function ( geometry, materials ) {
this.overdraw = false; // TODO: Move to material?
// calc bound radius
if ( this.geometry ) {
// calc bound radius
if( !this.geometry.boundingSphere ) {
this.geometry.computeBoundingSphere();
......@@ -28,6 +29,21 @@ THREE.Mesh = function ( geometry, materials ) {
this.boundRadius = geometry.boundingSphere.radius;
// setup morph targets
if( this.geometry.morphTargets.length ) {
this.morphTargetBase = 0;
this.morphTargetInfluences = [];
for( var m = 0; m < this.geometry.morphTargets.length; m++ ) {
this.morphTargetInfluences.push( 0 );
}
}
}
}
......
......@@ -79,6 +79,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
this.maxMorphTargets = 8;
this.domElement = _canvas;
this.autoClear = true;
this.sortObjects = true;
......@@ -269,14 +270,14 @@ THREE.WebGLRenderer = function ( parameters ) {
geometryGroup.__webGLLineBuffer = _gl.createBuffer();
if( geometryGroup.numberVertexKeys ) {
if( geometryGroup.numMorphTargets ) {
var k, kl;
geometryGroup.__webGLVertexKeysBuffers = [];
var m, ml;
geometryGroup.__webGLMorphTargetsBuffers = [];
for( k = 0, kl = geometryGroup.numberVertexKeys; k < kl; k++ ) {
for( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m++ ) {
geometryGroup.__webGLVertexKeysBuffers.push( _gl.createBuffer());
geometryGroup.__webGLMorphTargetsBuffers.push( _gl.createBuffer());
}
}
......@@ -367,19 +368,18 @@ THREE.WebGLRenderer = function ( parameters ) {
geometryGroup.__webGLFaceCount = ntris * 3;
geometryGroup.__webGLLineCount = nlines * 2;
if( geometryGroup.numberVertexKeys ) {
if( geometryGroup.numMorphTargets ) {
var k, kl;
geometryGroup.__vertexKeysArrays = [];
var m, ml;
geometryGroup.__morphTargetsArrays = [];
for( k = 0, kl = geometryGroup.numberVertexKeys; k < kl; k++ ) {
for( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m++ ) {
geometryGroup.__vertexKeysArrays.push( new Float32Array( nvertices * 3 ));
geometryGroup.__morphTargetsArrays.push( new Float32Array( nvertices * 3 ));
}
}
};
function setMeshBuffers ( geometryGroup, object, hint ) {
......@@ -398,7 +398,6 @@ THREE.WebGLRenderer = function ( parameters ) {
vertexIndex = 0,
offset = 0,
offsetVertexKey = 0,
offset_uv = 0,
offset_uv2 = 0,
offset_face = 0,
......@@ -407,9 +406,9 @@ THREE.WebGLRenderer = function ( parameters ) {
offset_line = 0,
offset_color = 0,
offset_skin = 0,
offset_morphTarget = 0,
vertexArray = geometryGroup.__vertexArray,
vertexKeysArrays = geometryGroup.__vertexKeysArrays,
uvArray = geometryGroup.__uvArray,
uv2Array = geometryGroup.__uv2Array,
normalArray = geometryGroup.__normalArray,
......@@ -421,6 +420,8 @@ THREE.WebGLRenderer = function ( parameters ) {
skinIndexArray = geometryGroup.__skinIndexArray,
skinWeightArray = geometryGroup.__skinWeightArray,
morphTargetsArrays = geometryGroup.__morphTargetsArrays,
faceArray = geometryGroup.__faceArray,
lineArray = geometryGroup.__lineArray,
......@@ -429,15 +430,14 @@ THREE.WebGLRenderer = function ( parameters ) {
geometry = object.geometry, // this is shared for all chunks
dirtyVertices = geometry.__dirtyVertices,
dirtyVertexKeys = geometry.__dirtyVertexKeys,
dirtyElements = geometry.__dirtyElements,
dirtyUvs = geometry.__dirtyUvs,
dirtyNormals = geometry.__dirtyNormals,
dirtyTangents = geometry.__dirtyTangents,
dirtyColors = geometry.__dirtyColors,
dirtyMorphTargets = geometry.__dirtyMorphTargets,
vertices = geometry.vertices,
vertexKeys = geometry.vertexKeys,
chunk_faces = geometryGroup.faces,
obj_faces = geometry.faces,
obj_uvs = geometry.uvs,
......@@ -447,7 +447,10 @@ THREE.WebGLRenderer = function ( parameters ) {
obj_skinVerticesA = geometry.skinVerticesA,
obj_skinVerticesB = geometry.skinVerticesB,
obj_skinIndices = geometry.skinIndices,
obj_skinWeights = geometry.skinWeights;
obj_skinWeights = geometry.skinWeights,
morphTargets = geometry.morphTargets;
for ( f = 0, fl = chunk_faces.length; f < fl; f++ ) {
......@@ -483,30 +486,30 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( dirtyVertexKeys ) {
if ( dirtyMorphTargets ) {
for( vk = 0, vkl = vertexKeys.length; vk < vkl; vk++ ) {
for( vk = 0, vkl = morphTargets.length; vk < vkl; vk++ ) {
v1 = vertexKeys[ vk ].vertices[ face.a ].position;
v2 = vertexKeys[ vk ].vertices[ face.b ].position;
v3 = vertexKeys[ vk ].vertices[ face.c ].position;
v1 = morphTargets[ vk ].vertices[ face.a ].position;
v2 = morphTargets[ vk ].vertices[ face.b ].position;
v3 = morphTargets[ vk ].vertices[ face.c ].position;
vka = vertexKeysArrays[ vk ];
vka = morphTargetsArrays[ vk ];
vka[ offsetVertexKey + 0 ] = v1.x;
vka[ offsetVertexKey + 1 ] = v1.y;
vka[ offsetVertexKey + 2 ] = v1.z;
vka[ offset_morphTarget + 0 ] = v1.x;
vka[ offset_morphTarget + 1 ] = v1.y;
vka[ offset_morphTarget + 2 ] = v1.z;
vka[ offsetVertexKey + 3 ] = v2.x;
vka[ offsetVertexKey + 4 ] = v2.y;
vka[ offsetVertexKey + 5 ] = v2.z;
vka[ offset_morphTarget + 3 ] = v2.x;
vka[ offset_morphTarget + 4 ] = v2.y;
vka[ offset_morphTarget + 5 ] = v2.z;
vka[ offsetVertexKey + 6 ] = v3.x;
vka[ offsetVertexKey + 7 ] = v3.y;
vka[ offsetVertexKey + 8 ] = v3.z;
vka[ offset_morphTarget + 6 ] = v3.x;
vka[ offset_morphTarget + 7 ] = v3.y;
vka[ offset_morphTarget + 8 ] = v3.z;
}
offsetVertexKey += 9;
offset_morphTarget += 9;
}
......@@ -762,35 +765,35 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( dirtyVertexKeys ) {
if ( dirtyMorphTargets ) {
for( vk = 0, vkl = vertexKeys.length; vk < vkl; vk++ ) {
for( vk = 0, vkl = morphTargets.length; vk < vkl; vk++ ) {
v1 = vertexKeys[ vk ].vertices[ face.a ].position;
v2 = vertexKeys[ vk ].vertices[ face.b ].position;
v3 = vertexKeys[ vk ].vertices[ face.c ].position;
v4 = vertexKeys[ vk ].vertices[ face.d ].position;
v1 = morphTargets[ vk ].vertices[ face.a ].position;
v2 = morphTargets[ vk ].vertices[ face.b ].position;
v3 = morphTargets[ vk ].vertices[ face.c ].position;
v4 = morphTargets[ vk ].vertices[ face.d ].position;
vka = vertexKeysArrays[ vk ];
vka = morphTargetsArrays[ vk ];
vka[ offsetVertexKey + 0 ] = v1.x;
vka[ offsetVertexKey + 1 ] = v1.y;
vka[ offsetVertexKey + 2 ] = v1.z;
vka[ offset_morphTarget + 0 ] = v1.x;
vka[ offset_morphTarget + 1 ] = v1.y;
vka[ offset_morphTarget + 2 ] = v1.z;
vka[ offsetVertexKey + 3 ] = v2.x;
vka[ offsetVertexKey + 4 ] = v2.y;
vka[ offsetVertexKey + 5 ] = v2.z;
vka[ offset_morphTarget + 3 ] = v2.x;
vka[ offset_morphTarget + 4 ] = v2.y;
vka[ offset_morphTarget + 5 ] = v2.z;
vka[ offsetVertexKey + 6 ] = v3.x;
vka[ offsetVertexKey + 7 ] = v3.y;
vka[ offsetVertexKey + 8 ] = v3.z;
vka[ offset_morphTarget + 6 ] = v3.x;
vka[ offset_morphTarget + 7 ] = v3.y;
vka[ offset_morphTarget + 8 ] = v3.z;
vka[ offsetVertexKey + 9 ] = v4.x;
vka[ offsetVertexKey + 10 ] = v4.y;
vka[ offsetVertexKey + 11 ] = v4.z;
vka[ offset_morphTarget + 9 ] = v4.x;
vka[ offset_morphTarget + 10 ] = v4.y;
vka[ offset_morphTarget + 11 ] = v4.z;
}
offsetVertexKey += 12;
offset_morphTarget += 12;
}
......@@ -1069,12 +1072,12 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( dirtyVertexKeys ) {
if ( dirtyMorphTargets ) {
for( vk = 0, vkl = vertexKeys.length; vk < vkl; vk++ ) {
for( vk = 0, vkl = morphTargets.length; vk < vkl; vk++ ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLVertexKeysBuffers[ vk ] );
_gl.bufferData( _gl.ARRAY_BUFFER, vertexKeysArrays[ vk ], hint );
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLMorphTargetsBuffers[ vk ] );
_gl.bufferData( _gl.ARRAY_BUFFER, morphTargetsArrays[ vk ], hint );
}
}
......@@ -1448,7 +1451,7 @@ THREE.WebGLRenderer = function ( parameters ) {
this.initMaterial = function ( material, lights, fog, object ) {
var u, identifiers, parameters, maxLightCount, maxBones;
var u, identifiers, i, parameters, maxLightCount, maxBones;
if ( material instanceof THREE.MeshDepthMaterial ) {
......@@ -1489,14 +1492,14 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters = { fog: fog, map: material.map, envMap: material.envMap, lightMap: material.lightMap, vertexColors: material.vertexColors,
skinning: material.skinning,
vertexAnimated: material.vertexAnimated,
morphTargets: material.morphTargets, maxMorphTargets: 1,
maxDirLights: maxLightCount.directional, maxPointLights: maxLightCount.point,
maxBones: maxBones };
material.program = buildProgram( material.fragmentShader, material.vertexShader, parameters );
identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
'cameraInverseMatrix', 'boneGlobalMatrices', 'positionInterpolation'
'cameraInverseMatrix', 'boneGlobalMatrices', 'morphTargetInfluences'
];
for( u in material.uniforms ) {
......@@ -1506,8 +1509,18 @@ THREE.WebGLRenderer = function ( parameters ) {
}
cacheUniformLocations( material.program, identifiers );
cacheAttributeLocations( material.program, [ "position", "positionNextKey", "normal", "uv", "uv2", "tangent", "color",
"skinVertexA", "skinVertexB", "skinIndex", "skinWeight" ] );
identifiers = [ "position", "normal", "uv", "uv2", "tangent", "color",
"skinVertexA", "skinVertexB", "skinIndex", "skinWeight" ];
for( i = 0; i < this.maxMorphTargets; i++ ) {
identifiers.push( "morphTarget" + i );
}
cacheAttributeLocations( material.program, identifiers );
var attributes = material.program.attributes;
......@@ -1528,11 +1541,27 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( material.vertexAnimated &&
attributes.positionNextKey >= 0 ) {
_gl.enableVertexAttribArray( attributes.positionNextKey );
if ( material.morphTargets ) {
material.numSupportedMorphTargets = 0;
if( attributes.morphTarget0 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget0 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget1 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget1 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget2 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget2 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget3 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget3 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget4 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget4 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget5 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget5 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget6 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget6 ); material.numSupportedMorphTargets++ }
if( attributes.morphTarget7 >= 0 ) { _gl.enableVertexAttribArray( attributes.morphTarget7 ); material.numSupportedMorphTargets++ }
object.__webGLMorphTargetInfluences = new Float32Array( this.maxMorphTargets );
for( var i = 0; i < this.maxMorphTargets; i++ ) {
object.__webGLMorphTargetInfluences[ i ] = 0;
}
}
};
......@@ -1649,11 +1678,6 @@ THREE.WebGLRenderer = function ( parameters ) {
}
if ( material.vertexAnimated ) {
loadUniformsVertexAnimated( p_uniforms, object );
}
return program;
};
......@@ -1668,18 +1692,56 @@ THREE.WebGLRenderer = function ( parameters ) {
// vertices
if ( !material.vertexAnimated ) {
if ( !material.morphTargets ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLVertexBuffer );
_gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
} else {
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLVertexKeysBuffers[ object.keyA ] );
// set base
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLMorphTargetsBuffers[ object.morphTargetBase ] );
_gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLVertexKeysBuffers[ object.keyB ] );
_gl.vertexAttribPointer( attributes.positionNextKey, 3, _gl.FLOAT, false, 0, 0 );
// find most influencing
var used = [];
var candidateInfluence = -1;
var candidate = 0;
var influences = object.morphTargetInfluences;
var i, il = influences.length;
var m = 0;
used[ object.morphTargetBase ] = 1;
while( m < material.numSupportedMorphTargets ) {
for( i = 0; i < il; i++ ) {
if( !used[ i ] && candidateInfluence < influences[ i ] ) {
candidate = i;
candidateInfluence = influences[ candidate ];
}
}
_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webGLMorphTargetsBuffers[ candidate ] );
_gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
object.__webGLMorphTargetInfluences[ m ] = candidateInfluence;
used[ candidate ] = 1;
candidateInfluence = -1;
m++;
}
// load updated influences uniform
_gl.uniform1fv( material.program.uniforms.morphTargetInfluences, object.__webGLMorphTargetInfluences );
}
......@@ -2326,7 +2388,7 @@ THREE.WebGLRenderer = function ( parameters ) {
initMeshBuffers( geometryGroup, object );
geometry.__dirtyVertices = true;
geometry.__dirtyVertexKeys = true;
geometry.__dirtyMorphTargets = true;
geometry.__dirtyElements = true;
geometry.__dirtyUvs = true;
geometry.__dirtyNormals = true;
......@@ -2413,7 +2475,7 @@ THREE.WebGLRenderer = function ( parameters ) {
geometryGroup = geometry.geometryGroups[ g ];
if ( geometry.__dirtyVertices || geometry.__dirtyVertexKeys || geometry.__dirtyElements ||
if ( geometry.__dirtyVertices || geometry.__dirtyMorphTargets || geometry.__dirtyElements ||
geometry.__dirtyUvs || geometry.__dirtyNormals ||
geometry.__dirtyColors || geometry.__dirtyTangents ) {
......@@ -2424,7 +2486,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
geometry.__dirtyVertices = false;
geometry.__dirtyVertexKeys = false;
geometry.__dirtyMorphTargets = false;
geometry.__dirtyElements = false;
geometry.__dirtyUvs = false;
geometry.__dirtyNormals = false;
......@@ -2506,7 +2568,7 @@ THREE.WebGLRenderer = function ( parameters ) {
// in its separate VBO
var i, l, f, fl, face, material, materials, vertices, mhash, ghash, hash_map = {};
var numberVertexKeys = geometry.vertexKeys !== undefined ? geometry.vertexKeys.length : 0;
var numMorphTargets = geometry.morphTargets !== undefined ? geometry.morphTargets.length : 0;
geometry.geometryGroups = {};
......@@ -2549,7 +2611,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( geometry.geometryGroups[ ghash ] == undefined ) {
geometry.geometryGroups[ ghash ] = { 'faces': [], 'materials': materials, 'vertices': 0, 'numberVertexKeys': numberVertexKeys };
geometry.geometryGroups[ ghash ] = { 'faces': [], 'materials': materials, 'vertices': 0, 'numMorphTargets': numMorphTargets };
}
......@@ -2562,7 +2624,7 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( geometry.geometryGroups[ ghash ] == undefined ) {
geometry.geometryGroups[ ghash ] = { 'faces': [], 'materials': materials, 'vertices': 0, 'numberVertexKeys': numberVertexKeys };
geometry.geometryGroups[ ghash ] = { 'faces': [], 'materials': materials, 'vertices': 0, 'numMorphTargets': numMorphTargets };
}
......@@ -2715,7 +2777,7 @@ THREE.WebGLRenderer = function ( parameters ) {
parameters.lightMap ? "#define USE_LIGHTMAP" : "",
parameters.vertexColors ? "#define USE_COLOR" : "",
parameters.skinning ? "#define USE_SKINNING" : "",
parameters.vertexAnimated ? "#define USE_VERTEXANIMATION" : "",
parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
"uniform mat4 objectMatrix;",
......@@ -2728,7 +2790,14 @@ THREE.WebGLRenderer = function ( parameters ) {
"uniform mat4 cameraInverseMatrix;",
"attribute vec3 position;",
"attribute vec3 positionNextKey;",
"attribute vec3 morphTarget0;",
"attribute vec3 morphTarget1;",
"attribute vec3 morphTarget2;",
"attribute vec3 morphTarget3;",
"attribute vec3 morphTarget4;",
"attribute vec3 morphTarget5;",
"attribute vec3 morphTarget6;",
"attribute vec3 morphTarget7;",
"attribute vec3 normal;",
"attribute vec3 color;",
"attribute vec2 uv;",
......@@ -2772,11 +2841,7 @@ THREE.WebGLRenderer = function ( parameters ) {
_gl.uniformMatrix4fv( uniforms.boneGlobalMatrices, false, object.boneMatrices );
};
function loadUniformsVertexAnimated ( uniforms, object ) {
_gl.uniform1f( uniforms.positionInterpolation, object.keyInterpolation );
}
function loadUniformsMatrices ( uniforms, object ) {
......@@ -3773,21 +3838,29 @@ THREE.Snippets = {
// vertex animation
vertexanimated_pars_vertex: [
// vertexanimated_pars_vertex: [
morphtarget_pars_vertex: [
"#ifdef USE_VERTEXANIMATION",
"#ifdef USE_MORPHTARGETS",
"uniform float positionInterpolation;",
"uniform float morphTargetInfluences[8];",
"#endif"
].join("\n"),
vertexanimated_vertex: [
morphtarget_vertex: [
"#ifdef USE_VERTEXANIMATION",
"#ifdef USE_MORPHTARGETS",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( mix( position, positionNextKey, positionInterpolation ), 1.0 );",
"vec3 morphed = vec3( 0, 0, 0 );",
"morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];",
"morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];",
"morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];",
"morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];",
"morphed *= 0.25;",
"morphed += position;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( morphed, 1.0 );",
"#else",
......@@ -3820,7 +3893,7 @@ THREE.UniformsLib = {
"fogFar" : { type: "f", value: 2000 },
"fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) },
"positionInterpolation" : { type: "f", value: 0 }
"morphTargetInfluences" : { type: "f", value: 0 }
},
......@@ -3958,7 +4031,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "envmap_pars_vertex" ],
THREE.Snippets[ "color_pars_vertex" ],
THREE.Snippets[ "skinning_pars_vertex" ],
THREE.Snippets[ "vertexanimated_pars_vertex" ],
THREE.Snippets[ "morphtarget_pars_vertex" ],
"void main() {",
......@@ -3969,7 +4042,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "envmap_vertex" ],
THREE.Snippets[ "color_vertex" ],
THREE.Snippets[ "skinning_vertex" ],
THREE.Snippets[ "vertexanimated_vertex" ],
THREE.Snippets[ "morphtarget_vertex" ],
"}"
......@@ -4020,7 +4093,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "lights_pars_vertex" ],
THREE.Snippets[ "color_pars_vertex" ],
THREE.Snippets[ "skinning_pars_vertex" ],
THREE.Snippets[ "vertexanimated_pars_vertex" ],
THREE.Snippets[ "morphtarget_pars_vertex" ],
"void main() {",
......@@ -4035,7 +4108,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "lights_vertex" ],
THREE.Snippets[ "skinning_vertex" ],
THREE.Snippets[ "vertexanimated_vertex" ],
THREE.Snippets[ "morphtarget_vertex" ],
"}"
......@@ -4102,7 +4175,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "lights_pars_vertex" ],
THREE.Snippets[ "color_pars_vertex" ],
THREE.Snippets[ "skinning_pars_vertex" ],
THREE.Snippets[ "vertexanimated_pars_vertex" ],
THREE.Snippets[ "morphtarget_pars_vertex" ],
"void main() {",
......@@ -4124,7 +4197,7 @@ THREE.ShaderLib = {
THREE.Snippets[ "lights_vertex" ],
THREE.Snippets[ "skinning_vertex" ],
THREE.Snippets[ "vertexanimated_vertex" ],
THREE.Snippets[ "morphtarget_vertex" ],
"}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册