Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 58 additions & 18 deletions examples/js/loaders/TDSLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ THREE.TDSLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype

} else if ( next === MAT_SHININESS ) {

var shininess = this.readWord( data );
material.shininess = shininess;
var shininess = this.readPercentage( data );
material.shininess = shininess * 100;
this.debugMessage( ' Shininess : ' + shininess );

} else if ( next === MAT_TRANSPARENCY ) {

var opacity = this.readWord( data );
material.opacity = opacity * 0.01;
this.debugMessage( ' Opacity : ' + opacity );
material.transparent = opacity < 100 ? true : false;
var transparency = this.readPercentage( data );
material.opacity = 1 - transparency;
this.debugMessage( ' Transparency : ' + transparency );
material.transparent = material.opacity < 1 ? true : false;

} else if ( next === MAT_TEXMAP ) {

Expand Down Expand Up @@ -494,42 +494,49 @@ THREE.TDSLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype

//The rest of the FACE_ARRAY chunk is subchunks

var materialIndex = 0;
var start = 0;

while ( this.position < chunk.end ) {

var chunk = this.readChunk( data );
var subchunk = this.readChunk( data );

if ( chunk.id === MSH_MAT_GROUP ) {
if ( subchunk.id === MSH_MAT_GROUP ) {

this.debugMessage( ' Material Group' );

this.resetPosition( data );

var group = this.readMaterialGroup( data );
var count = group.index.length * 3; // assuming successive indices

var material = this.materials[ group.name ];
mesh.geometry.addGroup( start, count, materialIndex );

if ( material !== undefined ) {
start += count;
materialIndex ++;

mesh.material = material;
var material = this.materials[ group.name ];

if ( material.name === '' ) {
if ( Array.isArray( mesh.material ) === false ) mesh.material = [];

material.name = mesh.name;
if ( material !== undefined ) {

}
mesh.material.push( material );

}

} else {

this.debugMessage( ' Unknown face array chunk: ' + chunk.toString( 16 ) );
this.debugMessage( ' Unknown face array chunk: ' + subchunk.toString( 16 ) );

}

this.endChunk( chunk );
this.endChunk( subchunk );

}

if ( mesh.material.length === 1 ) mesh.material = mesh.material[ 0 ]; // for backwards compatibility

this.endChunk( chunk );

},
Expand Down Expand Up @@ -869,6 +876,39 @@ THREE.TDSLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype

},

/**
* Read percentage value.
*
* @method readPercentage
* @param {DataView} data Dataview to read data from.
* @return {Number} Data read from the dataview.
*/
readPercentage: function ( data ) {

var chunk = this.readChunk( data );
var value;

switch ( chunk.id ) {

case INT_PERCENTAGE:
value = ( this.readShort( data ) / 100 );
break;

case FLOAT_PERCENTAGE:
value = this.readFloat( data );
break;

default:
this.debugMessage( ' Unknown percentage chunk: ' + chunk.toString( 16 ) );

}

this.endChunk( chunk );

return value;

},

/**
* Print debug message to the console.
*
Expand Down Expand Up @@ -902,8 +942,8 @@ var COLOR_F = 0x0010;
var COLOR_24 = 0x0011;
var LIN_COLOR_24 = 0x0012;
var LIN_COLOR_F = 0x0013;
// var INT_PERCENTAGE = 0x0030;
// var FLOAT_PERCENTAGE = 0x0031;
var INT_PERCENTAGE = 0x0030;
var FLOAT_PERCENTAGE = 0x0031;
var MDATA = 0x3D3D;
var MESH_VERSION = 0x3D3E;
var MASTER_SCALE = 0x0100;
Expand Down
76 changes: 58 additions & 18 deletions examples/jsm/loaders/TDSLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ TDSLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

} else if ( next === MAT_SHININESS ) {

var shininess = this.readWord( data );
material.shininess = shininess;
var shininess = this.readPercentage( data );
material.shininess = shininess * 100;
this.debugMessage( ' Shininess : ' + shininess );

} else if ( next === MAT_TRANSPARENCY ) {

var opacity = this.readWord( data );
material.opacity = opacity * 0.01;
this.debugMessage( ' Opacity : ' + opacity );
material.transparent = opacity < 100 ? true : false;
var transparency = this.readPercentage( data );
material.opacity = 1 - transparency;
this.debugMessage( ' Transparency : ' + transparency );
material.transparent = material.opacity < 1 ? true : false;

} else if ( next === MAT_TEXMAP ) {

Expand Down Expand Up @@ -510,42 +510,49 @@ TDSLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

//The rest of the FACE_ARRAY chunk is subchunks

var materialIndex = 0;
var start = 0;

while ( this.position < chunk.end ) {

var chunk = this.readChunk( data );
var subchunk = this.readChunk( data );

if ( chunk.id === MSH_MAT_GROUP ) {
if ( subchunk.id === MSH_MAT_GROUP ) {

this.debugMessage( ' Material Group' );

this.resetPosition( data );

var group = this.readMaterialGroup( data );
var count = group.index.length * 3; // assuming successive indices

var material = this.materials[ group.name ];
mesh.geometry.addGroup( start, count, materialIndex );

if ( material !== undefined ) {
start += count;
materialIndex ++;

mesh.material = material;
var material = this.materials[ group.name ];

if ( material.name === '' ) {
if ( Array.isArray( mesh.material ) === false ) mesh.material = [];

material.name = mesh.name;
if ( material !== undefined ) {

}
mesh.material.push( material );

}

} else {

this.debugMessage( ' Unknown face array chunk: ' + chunk.toString( 16 ) );
this.debugMessage( ' Unknown face array chunk: ' + subchunk.toString( 16 ) );

}

this.endChunk( chunk );
this.endChunk( subchunk );

}

if ( mesh.material.length === 1 ) mesh.material = mesh.material[ 0 ]; // for backwards compatibility

this.endChunk( chunk );

},
Expand Down Expand Up @@ -885,6 +892,39 @@ TDSLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

},

/**
* Read percentage value.
*
* @method readPercentage
* @param {DataView} data Dataview to read data from.
* @return {Number} Data read from the dataview.
*/
readPercentage: function ( data ) {

var chunk = this.readChunk( data );
var value;

switch ( chunk.id ) {

case INT_PERCENTAGE:
value = ( this.readShort( data ) / 100 );
break;

case FLOAT_PERCENTAGE:
value = this.readFloat( data );
break;

default:
this.debugMessage( ' Unknown percentage chunk: ' + chunk.toString( 16 ) );

}

this.endChunk( chunk );

return value;

},

/**
* Print debug message to the console.
*
Expand Down Expand Up @@ -918,8 +958,8 @@ var COLOR_F = 0x0010;
var COLOR_24 = 0x0011;
var LIN_COLOR_24 = 0x0012;
var LIN_COLOR_F = 0x0013;
// var INT_PERCENTAGE = 0x0030;
// var FLOAT_PERCENTAGE = 0x0031;
var INT_PERCENTAGE = 0x0030;
var FLOAT_PERCENTAGE = 0x0031;
var MDATA = 0x3D3D;
var MESH_VERSION = 0x3D3E;
var MASTER_SCALE = 0x0100;
Expand Down