* Setups the skeleton by the given JSON and bones. * * @param {Object} json - The skeleton as serialized JSON. * @param {Object } bones - An array of bones. * @return {Skeleton} A reference of this instance.
( json, bones )
| 315 | * @return {Skeleton} A reference of this instance. |
| 316 | */ |
| 317 | fromJSON( json, bones ) { |
| 318 | |
| 319 | this.uuid = json.uuid; |
| 320 | |
| 321 | for ( let i = 0, l = json.bones.length; i < l; i ++ ) { |
| 322 | |
| 323 | const uuid = json.bones[ i ]; |
| 324 | let bone = bones[ uuid ]; |
| 325 | |
| 326 | if ( bone === undefined ) { |
| 327 | |
| 328 | warn( 'Skeleton: No bone found with UUID:', uuid ); |
| 329 | bone = new Bone(); |
| 330 | |
| 331 | } |
| 332 | |
| 333 | this.bones.push( bone ); |
| 334 | this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) ); |
| 335 | |
| 336 | } |
| 337 | |
| 338 | this.init(); |
| 339 | |
| 340 | return this; |
| 341 | |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Serializes the skeleton into JSON. |