| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 | 
							- import Matrix4 from "../../Core/Matrix4.js";
 
- import Check from "../../Core/Check.js";
 
- import defaultValue from "../../Core/defaultValue.js";
 
- /**
 
-  * An in-memory representation of a skin that affects nodes in the {@link ModelExperimentalSceneGraph}.
 
-  * Skins should only be initialized after all of the {@link ModelExperimentalNode}s have been instantiated
 
-  * by the scene graph.
 
-  *
 
-  * @param {Object} options An object containing the following options:
 
-  * @param {ModelComponents.Skin} options.skin The corresponding skin components from the 3D model
 
-  * @param {ModelExperimentalSceneGraph} options.sceneGraph The scene graph this skin belongs to.
 
-  *
 
-  * @alias ModelExperimentalSkin
 
-  * @constructor
 
-  *
 
-  * @private
 
-  */
 
- export default function ModelExperimentalSkin(options) {
 
-   options = defaultValue(options, defaultValue.EMPTY_OBJECT);
 
-   //>>includeStart('debug', pragmas.debug);
 
-   Check.typeOf.object("options.skin", options.skin);
 
-   Check.typeOf.object("options.sceneGraph", options.sceneGraph);
 
-   //>>includeEnd('debug');
 
-   this._sceneGraph = options.sceneGraph;
 
-   const skin = options.skin;
 
-   this._skin = skin;
 
-   this._inverseBindMatrices = undefined;
 
-   this._joints = [];
 
-   this._jointMatrices = [];
 
-   initialize(this);
 
- }
 
- Object.defineProperties(ModelExperimentalSkin.prototype, {
 
-   /**
 
-    * The internal skin this runtime skin represents.
 
-    *
 
-    * @memberof ModelExperimentalSkin.prototype
 
-    * @type {ModelComponents.Skin}
 
-    * @readonly
 
-    *
 
-    * @private
 
-    */
 
-   skin: {
 
-     get: function () {
 
-       return this._skin;
 
-     },
 
-   },
 
-   /**
 
-    * The scene graph this skin belongs to.
 
-    *
 
-    * @type {ModelExperimentalSceneGraph}
 
-    * @readonly
 
-    *
 
-    * @private
 
-    */
 
-   sceneGraph: {
 
-     get: function () {
 
-       return this._sceneGraph;
 
-     },
 
-   },
 
-   /**
 
-    * The inverse bind matrices of the skin.
 
-    *
 
-    * @memberof ModelExperimentalSkin.prototype
 
-    * @type {Matrix4[]}
 
-    * @readonly
 
-    *
 
-    * @private
 
-    */
 
-   inverseBindMatrices: {
 
-     get: function () {
 
-       return this._inverseBindMatrices;
 
-     },
 
-   },
 
-   /**
 
-    * The joints of the skin.
 
-    *
 
-    * @memberof ModelExperimentalSkin.prototype
 
-    * @type {ModelExperimentalNode[]}
 
-    * @readonly
 
-    *
 
-    * @private
 
-    */
 
-   joints: {
 
-     get: function () {
 
-       return this._joints;
 
-     },
 
-   },
 
-   /**
 
-    * The joint matrices for the skin, where each joint matrix is computed as
 
-    * jointMatrix = jointWorldTransform * inverseBindMatrix.
 
-    *
 
-    * Each node that references this skin is responsible for pre-multiplying its inverse
 
-    * world transform to the joint matrices for its own use.
 
-    *
 
-    * @memberof ModelExperimentalSkin.prototype
 
-    * @type {Matrix4[]}
 
-    * @readonly
 
-    *
 
-    * @private
 
-    */
 
-   jointMatrices: {
 
-     get: function () {
 
-       return this._jointMatrices;
 
-     },
 
-   },
 
- });
 
- function initialize(runtimeSkin) {
 
-   const skin = runtimeSkin.skin;
 
-   const inverseBindMatrices = skin.inverseBindMatrices;
 
-   runtimeSkin._inverseBindMatrices = inverseBindMatrices;
 
-   const joints = skin.joints;
 
-   const length = joints.length;
 
-   const runtimeNodes = runtimeSkin.sceneGraph._runtimeNodes;
 
-   const runtimeJoints = runtimeSkin.joints;
 
-   const runtimeJointMatrices = runtimeSkin._jointMatrices;
 
-   for (let i = 0; i < length; i++) {
 
-     const jointIndex = joints[i].index;
 
-     const runtimeNode = runtimeNodes[jointIndex];
 
-     runtimeJoints.push(runtimeNode);
 
-     const inverseBindMatrix = inverseBindMatrices[i];
 
-     const jointMatrix = computeJointMatrix(
 
-       runtimeNode,
 
-       inverseBindMatrix,
 
-       new Matrix4()
 
-     );
 
-     runtimeJointMatrices.push(jointMatrix);
 
-   }
 
- }
 
- function computeJointMatrix(joint, inverseBindMatrix, result) {
 
-   const jointWorldTransform = Matrix4.multiplyTransformation(
 
-     joint.transformToRoot,
 
-     joint.transform,
 
-     result
 
-   );
 
-   result = Matrix4.multiplyTransformation(
 
-     jointWorldTransform,
 
-     inverseBindMatrix,
 
-     result
 
-   );
 
-   return result;
 
- }
 
- /**
 
-  * Updates the joint matrices for the skin.
 
-  *
 
-  * @private
 
-  */
 
- ModelExperimentalSkin.prototype.updateJointMatrices = function () {
 
-   const jointMatrices = this._jointMatrices;
 
-   const length = jointMatrices.length;
 
-   for (let i = 0; i < length; i++) {
 
-     const joint = this.joints[i];
 
-     const inverseBindMatrix = this.inverseBindMatrices[i];
 
-     jointMatrices[i] = computeJointMatrix(
 
-       joint,
 
-       inverseBindMatrix,
 
-       jointMatrices[i]
 
-     );
 
-   }
 
- };
 
 
  |