Skip to content

Commit ad47d7d

Browse files
takahiroxmrdoob
authored andcommitted
Fix PMX parse bug of MMDLoader (mrdoob#9127)
1 parent 6d62670 commit ad47d7d

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

examples/js/loaders/MMDLoader.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ THREE.MMDLoader.prototype.parsePmx = function ( buffer ) {
989989
var parseFace = function () {
990990

991991
var p = {};
992-
p.indices = dv.getIndexArray( metadata.vertexIndexSize, 3 );
992+
p.indices = dv.getIndexArray( metadata.vertexIndexSize, 3, true );
993993
return p;
994994

995995
};
@@ -1214,7 +1214,7 @@ THREE.MMDLoader.prototype.parsePmx = function ( buffer ) {
12141214
} else if ( p.type === 1 ) { // vertex morph
12151215

12161216
var m = {};
1217-
m.index = dv.getIndex( pmx.metadata.vertexIndexSize );
1217+
m.index = dv.getIndex( pmx.metadata.vertexIndexSize, true );
12181218
m.position = dv.getFloat32Array( 3 );
12191219
p.elements.push( m );
12201220

@@ -1229,7 +1229,7 @@ THREE.MMDLoader.prototype.parsePmx = function ( buffer ) {
12291229
} else if ( p.type === 3 ) { // uv morph
12301230

12311231
var m = {};
1232-
m.index = dv.getIndex( pmx.metadata.vertexIndexSize );
1232+
m.index = dv.getIndex( pmx.metadata.vertexIndexSize, true );
12331233
m.uv = dv.getFloat32Array( 4 );
12341234
p.elements.push( m );
12351235

@@ -1268,7 +1268,6 @@ THREE.MMDLoader.prototype.parsePmx = function ( buffer ) {
12681268

12691269
}
12701270

1271-
12721271
};
12731272

12741273
var parseFrames = function () {
@@ -3449,18 +3448,18 @@ THREE.MMDLoader.DataView.prototype = {
34493448

34503449
},
34513450

3452-
getIndex: function ( type ) {
3451+
getIndex: function ( type, isUnsigned ) {
34533452

34543453
switch ( type ) {
34553454

34563455
case 1:
3457-
return this.getInt8();
3456+
return ( isUnsigned === true ) ? this.getUint8() : this.getInt8();
34583457

34593458
case 2:
3460-
return this.getInt16();
3459+
return ( isUnsigned === true ) ? this.getUint16() : this.getInt16();
34613460

34623461
case 4:
3463-
return this.getInt32();
3462+
return this.getInt32(); // No Uint32
34643463

34653464
default:
34663465
throw 'unknown number type ' + type + ' exception.';
@@ -3469,13 +3468,13 @@ THREE.MMDLoader.DataView.prototype = {
34693468

34703469
},
34713470

3472-
getIndexArray: function ( type, size ) {
3471+
getIndexArray: function ( type, size, isUnsigned ) {
34733472

34743473
var a = [];
34753474

34763475
for ( var i = 0; i < size; i++ ) {
34773476

3478-
a.push( this.getIndex( type ) );
3477+
a.push( this.getIndex( type, isUnsigned ) );
34793478

34803479
}
34813480

0 commit comments

Comments
 (0)