提交 73673e91 编写于 作者: M Mr.doob

Merge pull request #5463 from vincent/dev.missingloadmanagers

Adds missing LoadingManager in some loaders
......@@ -5,7 +5,11 @@
* @author angelxuanchang
*/
THREE.OBJMTLLoader = function () {};
THREE.OBJMTLLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.OBJMTLLoader.prototype = {
......@@ -147,7 +151,7 @@ THREE.OBJMTLLoader.prototype = {
}
}
function add_uvs( a, b, c ) {
geometry.faceVertexUvs[ 0 ].push( [
......@@ -157,19 +161,19 @@ THREE.OBJMTLLoader.prototype = {
] );
}
function handle_face_line(faces, uvs, normals_inds) {
if ( faces[ 3 ] === undefined ) {
add_face( faces[ 0 ], faces[ 1 ], faces[ 2 ], normals_inds );
if (!(uvs === undefined) && uvs.length > 0) {
add_uvs( uvs[ 0 ], uvs[ 1 ], uvs[ 2 ] );
}
} else {
if (!(normals_inds === undefined) && normals_inds.length > 0) {
add_face( faces[ 0 ], faces[ 1 ], faces[ 3 ], [ normals_inds[ 0 ], normals_inds[ 1 ], normals_inds[ 3 ] ]);
......@@ -181,7 +185,7 @@ THREE.OBJMTLLoader.prototype = {
add_face( faces[ 1 ], faces[ 2 ], faces[ 3 ]);
}
if (!(uvs === undefined) && uvs.length > 0) {
add_uvs( uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] );
......@@ -190,7 +194,7 @@ THREE.OBJMTLLoader.prototype = {
}
}
}
......@@ -218,7 +222,7 @@ THREE.OBJMTLLoader.prototype = {
var face_pattern3 = /f( +(\d+)\/(\d+)\/(\d+))( +(\d+)\/(\d+)\/(\d+))( +(\d+)\/(\d+)\/(\d+))( +(\d+)\/(\d+)\/(\d+))?/;
// f vertex//normal vertex//normal vertex//normal ...
// f vertex//normal vertex//normal vertex//normal ...
var face_pattern4 = /f( +(\d+)\/\/(\d+))( +(\d+)\/\/(\d+))( +(\d+)\/\/(\d+))( +(\d+)\/\/(\d+))?/
......@@ -275,7 +279,7 @@ THREE.OBJMTLLoader.prototype = {
} else if ( ( result = face_pattern2.exec( line ) ) !== null ) {
// ["f 1/1 2/2 3/3", " 1/1", "1", "1", " 2/2", "2", "2", " 3/3", "3", "3", undefined, undefined, undefined]
handle_face_line(
[ result[ 2 ], result[ 5 ], result[ 8 ], result[ 11 ] ], //faces
[ result[ 3 ], result[ 6 ], result[ 9 ], result[ 12 ] ] //uv
......@@ -304,7 +308,7 @@ THREE.OBJMTLLoader.prototype = {
} else if ( /^o /.test( line ) ) {
// object
meshN();
face_offset = face_offset + vertices.length;
vertices = [];
......@@ -350,7 +354,7 @@ THREE.OBJMTLLoader.prototype = {
//Add last object
meshN(undefined, undefined);
return group;
}
......
......@@ -2,7 +2,7 @@
* @author alteredq / http://alteredqualia.com/
*/
THREE.SceneLoader = function () {
THREE.SceneLoader = function ( manager ) {
this.onLoadStart = function () {};
this.onLoadProgress = function() {};
......@@ -16,6 +16,8 @@ THREE.SceneLoader = function () {
this.addGeometryHandler( "ascii", THREE.JSONLoader );
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.SceneLoader.prototype = {
......@@ -449,7 +451,7 @@ THREE.SceneLoader.prototype = {
camera.lookAt( new THREE.Vector3().fromArray( objJSON.target ) );
}
}
parent.add( camera );
......@@ -989,7 +991,7 @@ THREE.SceneLoader.prototype = {
texture = new THREE.Texture();
loader = new THREE.ImageLoader();
( function ( texture ) {
loader.load( fullUrl, function ( image ) {
......@@ -1000,9 +1002,9 @@ THREE.SceneLoader.prototype = {
textureCallback();
} );
} )( texture )
}
......
......@@ -3,19 +3,23 @@
* @author mrdoob / http://mrdoob.com/
*/
THREE.TGALoader = function () {};
THREE.TGALoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.TGALoader.prototype = {
constructor: THREE.TGALoader,
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var texture = new THREE.DataTexture();
var loader = new THREE.XHRLoader();
var loader = new THREE.XHRLoader( scope.manager );
loader.setResponseType( 'arraybuffer' );
loader.load( url, function ( buffer ) {
......@@ -32,7 +36,7 @@ THREE.TGALoader.prototype = {
// reference from vthibault, https://github.com/vthibault/roBrowser/blob/master/src/Loaders/Targa.js
parse: function ( buffer ) {
// TGA Constants
var TGA_TYPE_NO_DATA = 0,
TGA_TYPE_INDEXED = 1,
......@@ -49,14 +53,14 @@ THREE.TGALoader.prototype = {
TGA_ORIGIN_UL = 0x02,
TGA_ORIGIN_UR = 0x03;
if ( buffer.length < 19 )
console.error( 'THREE.TGALoader.parse: Not enough data to contain header.' );
var content = new Uint8Array( buffer ),
offset = 0,
header = {
id_length: content[ offset ++ ],
id_length: content[ offset ++ ],
colormap_type: content[ offset ++ ],
image_type: content[ offset ++ ],
colormap_index: content[ offset ++ ] | content[ offset ++ ] << 8,
......@@ -72,7 +76,7 @@ THREE.TGALoader.prototype = {
pixel_size: content[ offset ++ ],
flags: content[ offset ++ ]
};
function tgaCheckHeader( header ) {
switch( header.image_type ) {
......@@ -110,7 +114,7 @@ THREE.TGALoader.prototype = {
console.error( 'THREE.TGALoader.parse.tgaCheckHeader: Invalid image size' );
}
// Check image pixel size
// Check image pixel size
if (header.pixel_size !== 8 &&
header.pixel_size !== 16 &&
header.pixel_size !== 24 &&
......@@ -131,10 +135,10 @@ THREE.TGALoader.prototype = {
offset += header.id_length;
// Get targa information about RLE compression and palette
var use_rle = false,
use_pal = false,
var use_rle = false,
use_pal = false,
use_grey = false;
switch ( header.image_type ) {
case TGA_TYPE_RLE_INDEXED:
......@@ -145,7 +149,7 @@ THREE.TGALoader.prototype = {
case TGA_TYPE_INDEXED:
use_pal = true;
break;
case TGA_TYPE_RLE_RGB:
use_rle = true;
break;
......@@ -163,27 +167,27 @@ THREE.TGALoader.prototype = {
break;
}
// Parse tga image buffer
function tgaParse( use_rle, use_pal, header, offset, data ) {
var pixel_data,
pixel_size,
pixel_total,
palettes;
pixel_size = header.pixel_size >> 3;
pixel_total = header.width * header.height * pixel_size;
// Read palettes
if ( use_pal ) {
palettes = data.subarray( offset, offset += header.colormap_length * ( header.colormap_size >> 3 ) );
}
// Read RLE
if ( use_rle ) {
pixel_data = new Uint8Array(pixel_total);
var c, count, i;
var shift = 0;
var pixels = new Uint8Array(pixel_size);
......@@ -221,19 +225,19 @@ THREE.TGALoader.prototype = {
offset, offset += (use_pal ? header.width * header.height : pixel_total)
);
}
return {
pixel_data: pixel_data,
palettes: palettes
return {
pixel_data: pixel_data,
palettes: palettes
};
}
function tgaGetImageData8bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image, palettes) {
var colormap = palettes;
var color, i = 0, x, y;
var width = header.width;
for (y = y_start; y !== y_end; y += y_step) {
for (x = x_start; x !== x_end; x += x_step, i++) {
color = image[i];
......@@ -284,8 +288,8 @@ THREE.TGALoader.prototype = {
return imageData;
};
function tgaGetImageData32bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
function tgaGetImageData32bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
var i = 0, x, y;
var width = header.width;
......@@ -322,7 +326,7 @@ THREE.TGALoader.prototype = {
};
function tgaGetImageDataGrey16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
function tgaGetImageDataGrey16bits(imageData, y_start, y_step, y_end, x_start, x_step, x_end, image) {
var i = 0, x, y;
var width = header.width;
......@@ -339,7 +343,7 @@ THREE.TGALoader.prototype = {
return imageData;
};
function getTgaRGBA( width, height, image, palette ) {
var x_start,
......@@ -347,9 +351,9 @@ THREE.TGALoader.prototype = {
x_step,
y_step,
x_end,
y_end,
y_end,
data = new Uint8Array(width * height * 4);
switch( (header.flags & TGA_ORIGIN_MASK) >> TGA_ORIGIN_SHIFT ) {
default:
case TGA_ORIGIN_UL:
......@@ -360,7 +364,7 @@ THREE.TGALoader.prototype = {
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BL:
x_start = 0;
x_step = 1;
......@@ -369,7 +373,7 @@ THREE.TGALoader.prototype = {
y_step = -1;
y_end = -1;
break;
case TGA_ORIGIN_UR:
x_start = width - 1;
x_step = -1;
......@@ -378,7 +382,7 @@ THREE.TGALoader.prototype = {
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BR:
x_start = width - 1;
x_step = -1;
......@@ -388,10 +392,10 @@ THREE.TGALoader.prototype = {
y_end = -1;
break;
}
}
if ( use_grey ) {
switch( header.pixel_size ) {
case 8:
tgaGetImageDataGrey8bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
......@@ -403,18 +407,18 @@ THREE.TGALoader.prototype = {
console.error( 'THREE.TGALoader.parse.getTgaRGBA: not support this format' );
break;
}
} else {
switch( header.pixel_size ) {
case 8:
tgaGetImageData8bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image, palette );
break;
case 16:
tgaGetImageData16bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
case 24:
tgaGetImageData24bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
......@@ -422,10 +426,10 @@ THREE.TGALoader.prototype = {
case 32:
tgaGetImageData32bits( data, y_start, y_step, y_end, x_start, x_step, x_end, image );
break;
default:
console.error( 'THREE.TGALoader.parse.getTgaRGBA: not support this format' );
break;
break;
}
}
......@@ -436,10 +440,10 @@ THREE.TGALoader.prototype = {
return data;
}
var result = tgaParse( use_rle, use_pal, header, offset, content );
var rgbaData = getTgaRGBA( header.width, header.height, result.pixel_data, result.palettes );
return {
width: header.width,
height: header.height,
......@@ -448,4 +452,4 @@ THREE.TGALoader.prototype = {
}
};
\ No newline at end of file
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册