提交 afbace28 编写于 作者: A alteredq

Cleaning up to make it pass through Closure compiler.

We have been very lucky - setters / getters were not supported till just 2 hours ago (so fresh, I had to build Closure myself from their repo ;).

http://code.google.com/p/closure-compiler/issues/detail?id=249

Also some refactoring plus added hackish animation offset feature.
上级 a3cdbf66
因为 它太大了无法显示 source diff 。你可以改为 查看blob
因为 它太大了无法显示 source diff 。你可以改为 查看blob
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -11,6 +11,8 @@ THREE.Animation = function( root, data ) {
this.startTime = 0;
this.isPlaying = false;
this.loop = true;
this.offset = 0;
// need to initialize data?
......@@ -25,6 +27,7 @@ THREE.Animation = function( root, data ) {
for( var b = 0; b < this.root.bones.length; b++ )
this.hierarchy.push( this.root.bones[ b ] );
}
else {
......@@ -57,6 +60,7 @@ THREE.Animation.prototype.play = function( loop ) {
this.hierarchy[ h ].prevKey = { pos: 0, rot: 0, scl: 0 };
this.hierarchy[ h ].nextKey = { pos: 0, rot: 0, scl: 0 };
}
this.hierarchy[ h ].prevKey.pos = this.data.hierarchy[ h ].keys[ 0 ];
......@@ -127,7 +131,7 @@ THREE.Animation.prototype.update = function( time ) {
// update
var currentTime = new Date().getTime() * 0.001 - this.startTime;
var currentTime = new Date().getTime() * 0.001 - this.startTime + this.offset;
var unloopedCurrentTime = currentTime;
......@@ -140,6 +144,7 @@ THREE.Animation.prototype.update = function( time ) {
this.startTime = new Date().getTime() * 0.001 - currentTime;
currentTime = new Date().getTime() * 0.001 - this.startTime;
}
frame = Math.min( parseInt( currentTime * this.data.fps ), parseInt( this.data.length * this.data.fps ));
......@@ -157,10 +162,8 @@ THREE.Animation.prototype.update = function( time ) {
object.autoUpdateMatrix = false;
object.matrixNeedsToUpdate = false;
this.root.boneMatrices[ h ] = object.skinMatrix.flatten32;
//object.skinMatrix.flattenToArray( this.root.boneMatrices[ h ] );
//object.skinMatrix.flattenToArrayOffset( this.root.boneMatrices, h * 16 );
object.skinMatrix.flattenToArrayOffset( this.root.boneMatrices, h * 16 );
}
else {
......@@ -185,14 +188,15 @@ THREE.Animation.prototype.update = function( time ) {
prevKey = this.data.hierarchy[ h ].keys[ 0 ];
nextKey = this.getNextKeyWith( type, h, 1 );
}
else {
} else {
this.stop();
return;
}
}
else {
} else {
do {
......@@ -204,6 +208,7 @@ THREE.Animation.prototype.update = function( time ) {
object.prevKey[ type ] = prevKey;
object.nextKey[ type ] = nextKey;
}
......@@ -239,7 +244,7 @@ THREE.Animation.prototype.update = function( time ) {
vector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
}
}
}
}
}
......
......@@ -22,7 +22,8 @@ THREE.Quaternion = function( _x, _y, _z, _w ) {
set x( value ) { this.that.x = value; this.isDirty = true; },
set y( value ) { this.that.y = value; this.isDirty = true; },
set z( value ) { this.that.z = value; this.isDirty = true; },
set w( value ) { this.that.w = value; this.isDirty = true; },
set w( value ) { this.that.w = value; this.isDirty = true; }
};
this.api.__proto__ = THREE.Quaternion.prototype;
......
......@@ -22,7 +22,8 @@ THREE.Vector3 = function ( _x, _y, _z ) {
set x( value ) { this.that.x = value; this.isDirty = true; },
set y( value ) { this.that.y = value; this.isDirty = true; },
set z( value ) { this.that.z = value; this.isDirty = true; },
set z( value ) { this.that.z = value; this.isDirty = true; }
};
this.api.__proto__ = THREE.Vector3.prototype;
......
......@@ -431,10 +431,10 @@ var ShaderUtils = {
"uniform bool grayscale;",
// noise effect intensity value (0 = no effect, 1 = full effect)
"const float fNintensity = 0.35;",
"const float fNintensity = 0.5;",
// scanlines effect intensity value (0 = no effect, 1 = full effect)
"const float fSintensity = 0.35;",
"const float fSintensity = 0.05;",
// scanlines effect count value (0 = no effect, 4096 = full effect)
"const float fScount = 4096.0;",
......
......@@ -50,7 +50,7 @@ THREE.SkinnedMesh = function( geometry, materials ) {
this.bones[ this.geometry.bones[ b ].parent ].addChild( this.bones[ b ] );
}
//this.boneMatrices = new Float32Array( 16 * this.bones.length );
this.boneMatrices = new Float32Array( 16 * this.bones.length );
this.pose();
......@@ -154,22 +154,18 @@ THREE.SkinnedMesh.prototype.pose = function() {
var bim, bone,
boneInverses = [];
for( var b = 0; b < this.bones.length; b++ ) {
boneInverses.push( THREE.Matrix4.makeInvert( this.bones[ b ].skinMatrix, new THREE.Matrix4() ) );
this.boneMatrices.push( this.bones[ b ].skinMatrix.flatten32 );
/*
for( var b = 0; b < this.bones.length; b++ ) {
bone = this.bones[ b ];
boneInverses.push( THREE.Matrix4.makeInvert( bone.skinMatrix ) );
bim = new Float32Array( 16 );
bone.skinMatrix.flattenToArray( bim );
this.boneMatrices.push( bim );
//bim = new Float32Array( 16 );
//bone.skinMatrix.flattenToArray( bim );
//this.boneMatrices.push( bim );
bone.skinMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
//bone.skinMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
*/
}
......
......@@ -1278,10 +1278,7 @@ THREE.WebGLRenderer = function ( parameters ) {
material.program = buildProgram( material.fragment_shader, material.vertex_shader, parameters );
identifiers = [ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'objectMatrix', 'cameraPosition',
'cameraInverseMatrix',
'uBoneGlobalMatrices[0]', 'uBoneGlobalMatrices[1]', 'uBoneGlobalMatrices[2]', 'uBoneGlobalMatrices[3]', 'uBoneGlobalMatrices[4]',
'uBoneGlobalMatrices[5]', 'uBoneGlobalMatrices[6]', 'uBoneGlobalMatrices[7]', 'uBoneGlobalMatrices[8]', 'uBoneGlobalMatrices[9]',
'uBoneGlobalMatrices[10]', 'uBoneGlobalMatrices[11]', 'uBoneGlobalMatrices[12]', 'uBoneGlobalMatrices[13]', 'uBoneGlobalMatrices[14]'
'cameraInverseMatrix', 'uBoneGlobalMatrices'
];
for( u in material.uniforms ) {
......@@ -1403,32 +1400,14 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( material.skinning ) {
_gl.uniformMatrix4fv( p_uniforms.cameraInverseMatrix, false, _cameraInverseMatrixArray );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[0]"], false, object.boneMatrices[0]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[1]"], false, object.boneMatrices[1]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[2]"], false, object.boneMatrices[2]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[3]"], false, object.boneMatrices[3]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[4]"], false, object.boneMatrices[4]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[5]"], false, object.boneMatrices[5]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[6]"], false, object.boneMatrices[6]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[7]"], false, object.boneMatrices[7]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[8]"], false, object.boneMatrices[8]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[9]"], false, object.boneMatrices[9]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[10]"], false, object.boneMatrices[10]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[11]"], false, object.boneMatrices[11]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[12]"], false, object.boneMatrices[12]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[13]"], false, object.boneMatrices[13]() );
_gl.uniformMatrix4fv( p_uniforms["uBoneGlobalMatrices[14]"], false, object.boneMatrices[14]() );
loadUniformsSkinning( p_uniforms, object );
}
return program;
};
this.renderBuffer = function ( camera, lights, fog, material, geometryChunk, object ) {
var program, attributes, linewidth, primitives;
......@@ -2376,6 +2355,24 @@ THREE.WebGLRenderer = function ( parameters ) {
};
function loadUniformsSkinning( uniforms, object ) {
_gl.uniformMatrix4fv( uniforms.cameraInverseMatrix, false, _cameraInverseMatrixArray );
/*
var i, l = object.boneMatrices.length;
for( i = 0; i < l; i++ ) {
//_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices[" + i + "]" ], false, object.boneMatrices[ i ]() );
_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices[" + i + "]" ], false, object.boneMatrices[ i ] );
}
*/
_gl.uniformMatrix4fv( uniforms[ "uBoneGlobalMatrices" ], false, object.boneMatrices );
};
function loadUniformsMatrices( uniforms, object ) {
_gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrixArray );
......
......@@ -21,21 +21,26 @@ COMMON_FILES = [
'core/Rectangle.js',
'core/Matrix3.js',
'core/Matrix4.js',
'core/Quaternion.js',
'core/Vertex.js',
'core/Face3.js',
'core/Face4.js',
'core/UV.js',
'core/Geometry.js',
'cameras/Camera.js',
'lights/Light.js',
'lights/AmbientLight.js',
'lights/DirectionalLight.js',
'lights/PointLight.js',
'objects/Object3D.js',
'objects/Particle.js',
'objects/ParticleSystem.js',
'objects/Line.js',
'objects/Mesh.js',
'objects/Bone.js',
'objects/SkinnedMesh.js',
'animation/AnimationHandler.js',
'animation/Animation.js',
'cameras/Camera.js',
'lights/Light.js',
'lights/AmbientLight.js',
'lights/DirectionalLight.js',
'lights/PointLight.js',
'materials/Material.js',
'materials/LineBasicMaterial.js',
'materials/MeshBasicMaterial.js',
......@@ -282,9 +287,15 @@ def compress(text):
with os.fdopen(in_tuple[0], 'w') as handle:
handle.write(text)
# uncomment to get concatenated JS if you can't figure out Closure compiler errors :|
#f = open( "debug.js" , "w" )
#f.write(text)
#f.close()
out_tuple = tempfile.mkstemp()
# os.system("java -jar yuicompressor-2.4.2.jar %s --type js -o %s --charset utf-8 -v" % (in_tuple[1], out_tuple[1]))
os.system("java -jar compiler.jar --js %s --js_output_file %s" % (in_tuple[1], out_tuple[1]))
os.system("java -jar compiler.jar --language_in=ECMASCRIPT5 --js %s --js_output_file %s" % (in_tuple[1], out_tuple[1]))
with os.fdopen(out_tuple[0], 'r') as handle:
compressed = handle.read()
......
无法预览此类型文件
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册