@@ -127,6 +127,13 @@ protected Object loadFromStream(AssetInfo assetInfo, InputStream stream) throws
127127
128128 rootNode = customContentManager .readExtensionAndExtras ("root" , docRoot , rootNode );
129129
130+ //Loading animations
131+ if (animations != null ) {
132+ for (int i = 0 ; i < animations .size (); i ++) {
133+ readAnimation (i );
134+ }
135+ }
136+
130137 setupControls ();
131138
132139 //only one scene let's not return the root.
@@ -177,13 +184,6 @@ public void readScenes(JsonPrimitive defaultScene, Node rootNode) throws IOExcep
177184
178185 }
179186
180- //Loading animations
181- if (animations != null ) {
182- for (int i = 0 ; i < animations .size (); i ++) {
183- readAnimation (i );
184- }
185- }
186-
187187 //Setting the default scene cul hint to inherit.
188188 int activeChild = 0 ;
189189 if (defaultScene != null ) {
@@ -278,7 +278,10 @@ private void readChild(Spatial parent, JsonElement nodeIndex) throws IOException
278278 BoneWrapper bw = (BoneWrapper ) loaded ;
279279 bw .isRoot = true ;
280280 SkinData skinData = fetchFromCache ("skins" , bw .skinIndex , SkinData .class );
281- skinData .armatureTransforms = parent .getLocalTransform ();
281+ if (skinData == null ) {
282+ return ;
283+ }
284+ skinData .parent = parent ;
282285 }
283286
284287 }
@@ -1086,15 +1089,13 @@ private void findChildren(int nodeIndex) throws IOException {
10861089 private void setupControls () {
10871090 for (SkinData skinData : skinnedSpatials .keySet ()) {
10881091 List <Spatial > spatials = skinnedSpatials .get (skinData );
1089- Spatial spatial ;
10901092 if (spatials .isEmpty ()) {
10911093 //can happen when a file contains a skin that is not used by any mesh...
10921094 continue ;
10931095 }
1096+ Spatial spatial = skinData .parent ;
10941097 if (spatials .size () >= 1 ) {
10951098 spatial = findCommonAncestor (spatials );
1096- } else {
1097- spatial = spatials .get (0 );
10981099 }
10991100
11001101 AnimControl animControl = spatial .getControl (AnimControl .class );
@@ -1220,7 +1221,7 @@ public void update(TrackData data) {
12201221 Transform t = new Transform (translation , rotation , scale );
12211222 if (isRoot ) {
12221223 //Apply the armature transforms to the root bone anim track.
1223- t .combineWithParent (skinData .armatureTransforms );
1224+ t .combineWithParent (skinData .parent . getLocalTransform () );
12241225 }
12251226
12261227 reverseBlendAnimTransforms (t , bindTransforms );
@@ -1285,50 +1286,11 @@ private Vector3f getScale(TrackData data, int i) {
12851286 private class SkinData {
12861287 SkeletonControl skeletonControl ;
12871288 AnimControl animControl ;
1288- Transform armatureTransforms ;
1289+ Spatial parent ;
12891290 Bone [] bones ;
12901291 boolean used = false ;
12911292 }
12921293
1293- private class PartialTransforms {
1294- Vector3f translation ;
1295- Quaternion rotation ;
1296- Vector3f scale ;
1297- Transform transform ;
1298-
1299- Transform getTransforms () {
1300- if (transform == null ) {
1301- if (translation == null ) {
1302- translation = new Vector3f ();
1303- }
1304- if (rotation == null ) {
1305- rotation = new Quaternion ();
1306- }
1307- if (scale == null ) {
1308- scale = new Vector3f (1 , 1 , 1 );
1309- }
1310- transform = new Transform (translation , rotation , scale );
1311- }
1312- return transform ;
1313- }
1314-
1315- Transform getTransforms (Transform bindTransforms ) {
1316- if (transform == null ) {
1317- if (translation == null ) {
1318- translation = bindTransforms .getTranslation ();
1319- }
1320- if (rotation == null ) {
1321- rotation = bindTransforms .getRotation ();
1322- }
1323- if (scale == null ) {
1324- scale = bindTransforms .getScale ();
1325- }
1326- transform = new Transform (translation , rotation , scale );
1327- }
1328- return transform ;
1329- }
1330- }
1331-
13321294 public static class SkinBuffers {
13331295 short [] joints ;
13341296 float [] weights ;
@@ -1343,10 +1305,6 @@ public SkinBuffers() {
13431305 }
13441306 }
13451307
1346- private class TextureData {
1347- byte [] data ;
1348- }
1349-
13501308 private interface Populator <T > {
13511309 T populate (Integer bufferViewIndex , int componentType , String type , int count , int byteOffset , boolean normalized ) throws IOException ;
13521310 }
0 commit comments