From 1147f6d1d57d1357d4fc04a26b6bfecc2f18c3cb Mon Sep 17 00:00:00 2001 From: -=ybafelo Date: Tue, 1 May 2018 07:46:39 +0200 Subject: [PATCH] better skeleton and bone creation --- src/r3-d3-mesh-0.js | 11 ++++++----- src/r3-d3-skeleton.js | 14 ++++++-------- src/r3-d3-vertex.js | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/r3-d3-mesh-0.js b/src/r3-d3-mesh-0.js index bbd2708..e6eba13 100644 --- a/src/r3-d3-mesh-0.js +++ b/src/r3-d3-mesh-0.js @@ -60,11 +60,12 @@ R3.D3.Mesh = function ( }.bind(this) ); - if (this.skeleton) { - this.skeleton = new R3.D3.Skeleton( - this.graphics, - this.skeleton - ); + if ( + R3.Utils.Defined(this.skeleton) && + R3.Utils.Defined(this.skeleton.componentType) && + !(this.skeleton instanceof R3.D3.Skeleton) + ) { + this.skeleton = R3.Component.ConstructFromObject(this.skeleton); } this.cloneDirection = new R3.Vector3( diff --git a/src/r3-d3-skeleton.js b/src/r3-d3-skeleton.js index 0a7769c..223f186 100644 --- a/src/r3-d3-skeleton.js +++ b/src/r3-d3-skeleton.js @@ -29,17 +29,15 @@ R3.D3.Skeleton = function Skeleton( apiSkeleton.parentEntity ); + this.bones = this.bones.map( function(apiBone) { - if (apiBone instanceof R3.D3.API.Bone) { - return new R3.D3.Bone( - this.graphics, - apiBone - ) - } else { - console.warn('apiBone not an instance of API.Bone'); - throw new Error('apiBone not an instance of API.Bone'); + if ( + R3.Utils.Defined(apiBone.componentType) && + !(apiBone instanceof R3.D3.Bone) + ) { + return R3.Component.ConstructFromObject(apiBone); } }.bind(this) diff --git a/src/r3-d3-vertex.js b/src/r3-d3-vertex.js index 18912ac..a709b10 100644 --- a/src/r3-d3-vertex.js +++ b/src/r3-d3-vertex.js @@ -30,10 +30,10 @@ R3.D3.Vertex = function Vertex( this.boneWeights = this.boneWeights.map( function(boneWeight) { return new R3.Vector4( - this.graphics, + this.implementation, boneWeight ) - } + }.bind(this) ); };