@@ -1296,9 +1296,11 @@ THREE.SEA3D.Mesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype
12961296// Skinning
12971297//
12981298
1299- THREE . SEA3D . SkinnedMesh = function ( geometry , material , useVertexTexture ) {
1299+ THREE . SEA3D . SkinnedMesh = function ( geometry , material ) {
13001300
1301- THREE . SkinnedMesh . call ( this , geometry , material , useVertexTexture ) ;
1301+ THREE . SkinnedMesh . call ( this , geometry , material ) ;
1302+
1303+ this . bind ( new THREE . Skeleton ( this . initBones ( ) ) , this . matrixWorld ) ;
13021304
13031305 this . updateAnimations ( geometry . animations , new THREE . AnimationMixer ( this ) ) ;
13041306
@@ -1308,6 +1310,66 @@ THREE.SEA3D.SkinnedMesh.prototype = Object.assign( Object.create( THREE.SkinnedM
13081310
13091311 constructor : THREE . SEA3D . SkinnedMesh ,
13101312
1313+ initBones : function ( ) {
1314+
1315+ var bones = [ ] , bone , gbone ;
1316+ var i , il ;
1317+
1318+ if ( this . geometry && this . geometry . bones !== undefined ) {
1319+
1320+ // first, create array of 'Bone' objects from geometry data
1321+
1322+ for ( i = 0 , il = this . geometry . bones . length ; i < il ; i ++ ) {
1323+
1324+ gbone = this . geometry . bones [ i ] ;
1325+
1326+ // create new 'Bone' object
1327+
1328+ bone = new THREE . Bone ( ) ;
1329+ bones . push ( bone ) ;
1330+
1331+ // apply values
1332+
1333+ bone . name = gbone . name ;
1334+ bone . position . fromArray ( gbone . pos ) ;
1335+ bone . quaternion . fromArray ( gbone . rotq ) ;
1336+ if ( gbone . scl !== undefined ) bone . scale . fromArray ( gbone . scl ) ;
1337+
1338+ }
1339+
1340+ // second, create bone hierarchy
1341+
1342+ for ( i = 0 , il = this . geometry . bones . length ; i < il ; i ++ ) {
1343+
1344+ gbone = this . geometry . bones [ i ] ;
1345+
1346+ if ( ( gbone . parent !== - 1 ) && ( gbone . parent !== null ) && ( bones [ gbone . parent ] !== undefined ) ) {
1347+
1348+ // subsequent bones in the hierarchy
1349+
1350+ bones [ gbone . parent ] . add ( bones [ i ] ) ;
1351+
1352+ } else {
1353+
1354+ // topmost bone, immediate child of the skinned mesh
1355+
1356+ this . add ( bones [ i ] ) ;
1357+
1358+ }
1359+
1360+ }
1361+
1362+ }
1363+
1364+ // now the bones are part of the scene graph and children of the skinned mesh.
1365+ // let's update the corresponding matrices
1366+
1367+ this . updateMatrixWorld ( true ) ;
1368+
1369+ return bones ;
1370+
1371+ } ,
1372+
13111373 boneByName : function ( name ) {
13121374
13131375 var bones = this . skeleton . bones ;
0 commit comments