提交 22e84234 编写于 作者: A alteredq

Fixed class hierarchy for BinaryLoader and UTF8Loader.

Also tried to clean whitespace for ColladaLoader. This thing is so massive.
上级 e459fc92
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -405,4 +405,4 @@ THREE.JSONLoader.prototype.createModel = function ( json, callback, texture_path
callback( geometry );
}
};
......@@ -55,7 +55,7 @@ THREE.Loader.prototype = {
},
extractUrlbase: function( url ) {
extractUrlbase: function ( url ) {
var chunks = url.split( "/" );
chunks.pop();
......@@ -63,11 +63,11 @@ THREE.Loader.prototype = {
},
init_materials: function( scope, materials, texture_path ) {
init_materials: function ( scope, materials, texture_path ) {
scope.materials = [];
for ( var i = 0; i < materials.length; ++i ) {
for ( var i = 0; i < materials.length; ++ i ) {
scope.materials[ i ] = [ THREE.Loader.prototype.createMaterial( materials[ i ], texture_path ) ];
......@@ -75,7 +75,7 @@ THREE.Loader.prototype = {
},
hasNormals: function( scope ) {
hasNormals: function ( scope ) {
var m, i, il = scope.materials.length;
......@@ -136,7 +136,7 @@ THREE.Loader.prototype = {
}
function create_texture( where, name, sourceFile, repeat, offset, wrap ) {
function create_texture ( where, name, sourceFile, repeat, offset, wrap ) {
var texture = document.createElement( 'canvas' );
......@@ -174,7 +174,7 @@ THREE.Loader.prototype = {
}
function rgb2hex( rgb ) {
function rgb2hex ( rgb ) {
return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
......@@ -367,7 +367,7 @@ THREE.Loader.prototype = {
return material;
},
constructor : THREE.Loader
};
......@@ -21,297 +21,287 @@ THREE.UTF8Loader.prototype = new THREE.UTF8Loader();
THREE.UTF8Loader.prototype.constructor = THREE.UTF8Loader;
THREE.UTF8Loader.prototype = {
// Load UTF8 compressed models generated by objcompress
// - parameters
// - model (required)
// - callback (required)
// Load UTF8 compressed models generated by objcompress
// - parameters
// - model (required)
// - callback (required)
THREE.UTF8Loader.prototype.load = function( parameters ) {
load: function( parameters ) {
var xhr = new XMLHttpRequest(),
url = parameters.model,
var xhr = new XMLHttpRequest(),
url = parameters.model,
callback = parameters.callback,
callback_progress = null,
callback = parameters.callback,
callback_progress = null,
scale = parameters.scale !== undefined ? parameters.scale : 1,
offsetX = parameters.offsetX !== undefined ? parameters.offsetX : 0,
offsetY = parameters.offsetY !== undefined ? parameters.offsetY : 0,
offsetZ = parameters.offsetZ !== undefined ? parameters.offsetZ : 0;
scale = parameters.scale !== undefined ? parameters.scale : 1,
offsetX = parameters.offsetX !== undefined ? parameters.offsetX : 0,
offsetY = parameters.offsetY !== undefined ? parameters.offsetY : 0,
offsetZ = parameters.offsetZ !== undefined ? parameters.offsetZ : 0;
var length = 0;
var length = 0;
xhr.onreadystatechange = function() {
xhr.onreadystatechange = function() {
if ( xhr.readyState == 4 ) {
if ( xhr.readyState == 4 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
if ( xhr.status == 200 || xhr.status == 0 ) {
THREE.UTF8Loader.prototype.createModel( xhr.responseText, callback, scale, offsetX, offsetY, offsetZ );
THREE.UTF8Loader.prototype.createModel( xhr.responseText, callback, scale, offsetX, offsetY, offsetZ );
} else {
} else {
alert( "Couldn't load [" + url + "] [" + xhr.status + "]" );
alert( "Couldn't load [" + url + "] [" + xhr.status + "]" );
}
} else if ( xhr.readyState == 3 ) {
if ( callback_progress ) {
}
if ( length == 0 ) {
} else if ( xhr.readyState == 3 ) {
length = xhr.getResponseHeader( "Content-Length" );
if ( callback_progress ) {
}
if ( length == 0 ) {
callback_progress( { total: length, loaded: xhr.responseText.length } );
length = xhr.getResponseHeader( "Content-Length" );
}
} else if ( xhr.readyState == 2 ) {
length = xhr.getResponseHeader( "Content-Length" );
callback_progress( { total: length, loaded: xhr.responseText.length } );
}
}
} else if ( xhr.readyState == 2 ) {
xhr.open( "GET", url, true );
xhr.send( null );
length = xhr.getResponseHeader( "Content-Length" );
},
}
// UTF-8 decoder from webgl-loader
// http://code.google.com/p/webgl-loader/
}
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You
// may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
xhr.open( "GET", url, true );
xhr.send( null );
decompressMesh: function ( str ) {
};
var num_verts = str.charCodeAt( 0 );
// UTF-8 decoder from webgl-loader
// http://code.google.com/p/webgl-loader/
if ( num_verts >= 0xE000 ) {
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You
// may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
num_verts -= 0x0800;
THREE.UTF8Loader.prototype.decompressMesh = function ( str ) {
}
var num_verts = str.charCodeAt( 0 );
num_verts ++;
if ( num_verts >= 0xE000 ) {
var attribs_out = new Float32Array( 8 * num_verts );
num_verts -= 0x0800;
var offset = 1;
}
for ( var i = 0; i < 8; i ++ ) {
num_verts ++;
var prev_attrib = 0;
var attribs_out = new Float32Array( 8 * num_verts );
for ( var j = 0; j < num_verts; ++ j ) {
var offset = 1;
var code = str.charCodeAt( j + offset );
for ( var i = 0; i < 8; i ++ ) {
prev_attrib += ( code >> 1 ) ^ ( - ( code & 1 ) );
var prev_attrib = 0;
attribs_out[ 8 * j + i ] = prev_attrib;
for ( var j = 0; j < num_verts; ++ j ) {
}
var code = str.charCodeAt( j + offset );
prev_attrib += ( code >> 1 ) ^ ( - ( code & 1 ) );
offset += num_verts;
attribs_out[ 8 * j + i ] = prev_attrib;
}
var num_indices = str.length - offset;
offset += num_verts;
var indices_out = new Uint16Array( num_indices );
}
var index_high_water_mark = 0;
var num_indices = str.length - offset;
for ( var i = 0; i < num_indices; i ++ ) {
var indices_out = new Uint16Array( num_indices );
var code = str.charCodeAt( i + offset );
var index_high_water_mark = 0;
indices_out[ i ] = index_high_water_mark - code;
for ( var i = 0; i < num_indices; i ++ ) {
if ( code == 0 ) {
var code = str.charCodeAt( i + offset );
index_high_water_mark ++;
indices_out[ i ] = index_high_water_mark - code;
}
if ( code == 0 ) {
index_high_water_mark ++;
}
return [ attribs_out, indices_out ];
}
},
return [ attribs_out, indices_out ];
createModel: function ( data, callback, scale, offsetX, offsetY, offsetZ ) {
};
var Model = function ( texture_path ) {
THREE.UTF8Loader.prototype.createModel = function ( data, callback, scale, offsetX, offsetY, offsetZ ) {
//var s = (new Date).getTime();
var Model = function ( texture_path ) {
var scope = this;
//var s = (new Date).getTime();
scope.materials = [];
var scope = this;
THREE.Geometry.call( this );
scope.materials = [];
var buffers = THREE.UTF8Loader.prototype.decompressMesh( data );
THREE.Geometry.call( this );
var normals = [],
uvs = [];
var buffers = THREE.UTF8Loader.prototype.decompressMesh( data );
init_vertices( buffers[ 0 ], 8, 0 );
init_uvs( buffers[ 0 ], 8, 3 );
init_normals( buffers[ 0 ], 8, 5 );
var normals = [],
uvs = [];
init_faces( buffers[ 1 ] );
init_vertices( buffers[ 0 ], 8, 0 );
init_uvs( buffers[ 0 ], 8, 3 );
init_normals( buffers[ 0 ], 8, 5 );
this.computeCentroids();
this.computeFaceNormals();
//this.computeTangents();
init_faces( buffers[ 1 ] );
//var e = (new Date).getTime();
this.computeCentroids();
this.computeFaceNormals();
//this.computeTangents();
//console.log( "utf8 data parse time: " + (e-s) + " ms" );
//var e = (new Date).getTime();
function init_vertices( data, stride, offset ) {
//console.log( "utf8 data parse time: " + (e-s) + " ms" );
var i, x, y, z,
end = data.length;
function init_vertices( data, stride, offset ) {
for( i = offset; i < end; i += stride ) {
var i, x, y, z,
end = data.length;
x = data[ i ];
y = data[ i + 1 ];
z = data[ i + 2 ];
for( i = offset; i < end; i += stride ) {
// fix scale and offsets
x = data[ i ];
y = data[ i + 1 ];
z = data[ i + 2 ];
x = ( x / 16383 ) * scale;
y = ( y / 16383 ) * scale;
z = ( z / 16383 ) * scale;
// fix scale and offsets
x += offsetX;
y += offsetY;
z += offsetZ;
x = ( x / 16383 ) * scale;
y = ( y / 16383 ) * scale;
z = ( z / 16383 ) * scale;
THREE.UTF8Loader.prototype.v( scope, x, y, z );
x += offsetX;
y += offsetY;
z += offsetZ;
}
vertex( scope, x, y, z );
}
function init_normals( data, stride, offset ) {
};
var i, x, y, z,
end = data.length;
function init_normals( data, stride, offset ) {
for( i = offset; i < end; i += stride ) {
var i, x, y, z,
end = data.length;
x = data[ i ];
y = data[ i + 1 ];
z = data[ i + 2 ];
for( i = offset; i < end; i += stride ) {
// normalize to <-1,1>
x = data[ i ];
y = data[ i + 1 ];
z = data[ i + 2 ];
x = ( x - 512 ) / 511;
y = ( y - 512 ) / 511;
z = ( z - 512 ) / 511;
// normalize to <-1,1>
normals.push( x, y, z );
x = ( x - 512 ) / 511;
y = ( y - 512 ) / 511;
z = ( z - 512 ) / 511;
}
normals.push( x, y, z );
}
function init_uvs( data, stride, offset ) {
};
var i, u, v,
end = data.length;
function init_uvs( data, stride, offset ) {
for( i = offset; i < end; i += stride ) {
var i, u, v,
end = data.length;
u = data[ i ];
v = data[ i + 1 ];
for( i = offset; i < end; i += stride ) {
// normalize to <0,1>
u = data[ i ];
v = data[ i + 1 ];
u /= 1023;
v /= 1023;
// normalize to <0,1>
uvs.push( u, v );
u /= 1023;
v /= 1023;
}
uvs.push( u, v );
}
function init_faces( indices ) {
var i,
a, b, c,
u1, v1, u2, v2, u3, v3,
m,
end = indices.length;
};
m = 0; // all faces defaulting to material 0
function init_faces( indices ) {
for( i = 0; i < end; i += 3 ) {
var i,
a, b, c,
u1, v1, u2, v2, u3, v3,
m,
end = indices.length;
a = indices[ i ];
b = indices[ i + 1 ];
c = indices[ i + 2 ];
m = 0; // all faces defaulting to material 0
THREE.UTF8Loader.prototype.f3n( scope, normals, a, b, c, m, a, b, c );
for( i = 0; i < end; i += 3 ) {
u1 = uvs[ a * 2 ];
v1 = uvs[ a * 2 + 1 ];
a = indices[ i ];
b = indices[ i + 1 ];
c = indices[ i + 2 ];
u2 = uvs[ b * 2 ];
v2 = uvs[ b * 2 + 1 ];
f3n( scope, normals, a, b, c, m, a, b, c );
u3 = uvs[ c * 2 ];
v3 = uvs[ c * 2 + 1 ];
u1 = uvs[ a * 2 ];
v1 = uvs[ a * 2 + 1 ];
THREE.UTF8Loader.prototype.uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
u2 = uvs[ b * 2 ];
v2 = uvs[ b * 2 + 1 ];
}
u3 = uvs[ c * 2 ];
v3 = uvs[ c * 2 + 1 ];
uv3( scope.faceVertexUvs[ 0 ], u1, v1, u2, v2, u3, v3 );
}
}
Model.prototype = new THREE.Geometry();
Model.prototype.constructor = Model;
callback( new Model() );
},
}
};
v: function( scope, x, y, z ) {
function vertex ( scope, x, y, z ) {
scope.vertices.push( new THREE.Vertex( new THREE.Vector3( x, y, z ) ) );
},
};
f3n: function( scope, normals, a, b, c, mi, na, nb, nc ) {
function f3n ( scope, normals, a, b, c, mi, na, nb, nc ) {
var material = scope.materials[ mi ],
......@@ -333,9 +323,9 @@ THREE.UTF8Loader.prototype = {
scope.faces.push( new THREE.Face3( a, b, c, [ na, nb, nc ], null, material ) );
},
};
uv3: function( where, u1, v1, u2, v2, u3, v3 ) {
function uv3 ( where, u1, v1, u2, v2, u3, v3 ) {
var uv = [];
uv.push( new THREE.UV( u1, v1 ) );
......@@ -343,8 +333,12 @@ THREE.UTF8Loader.prototype = {
uv.push( new THREE.UV( u3, v3 ) );
where.push( uv );
},
};
Model.prototype = new THREE.Geometry();
Model.prototype.constructor = Model;
constructor : THREE.UTF8Loader
callback( new Model() );
};
......@@ -290,7 +290,7 @@ THREE.WebGLRenderer = function ( parameters ) {
};
this.getContext = function() {
this.getContext = function () {
return _gl;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册