@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 11.8 kB
JavaScript
import{aC as t,M as e,T as i,aD as o,V as s,B as n,aE as r}from"./index-BPURObVq.esm.min.js";class a extends t{get _matrix(){return this._compose(),this._localMatrix}set _matrix(t){(t.updateFlag!==this._localMatrix.updateFlag||this._needToCompose)&&(this._needToCompose=!1,this._localMatrix.copyFrom(t),this._markAsDirtyAndDecompose())}constructor(t,i,o=null,s=null,n=null,r=null,a=null){super(t,i.getScene(),!1),this.name=t,this.children=[],this.animations=[],this._index=null,this._scalingDeterminant=1,this._needToDecompose=!0,this._needToCompose=!1,this._linkedTransformNode=null,this._waitingTransformNodeId=null,this._waitingTransformNodeUniqueId=null,this._skeleton=i,this._localMatrix=s?.clone()??e.Identity(),this._restMatrix=n??this._localMatrix.clone(),this._bindMatrix=r??this._localMatrix.clone(),this._index=a,this._absoluteMatrix=new e,this._absoluteBindMatrix=new e,this._absoluteInverseBindMatrix=new e,this._finalMatrix=new e,i.bones.push(this),this.setParent(o,!1),this._updateAbsoluteBindMatrices()}getClassName(){return"Bone"}getSkeleton(){return this._skeleton}get parent(){return this._parentNode}getParent(){return this.parent}getChildren(){return this.children}getIndex(){return null===this._index?this.getSkeleton().bones.indexOf(this):this._index}set parent(t){this.setParent(t)}setParent(t,e=!0){if(this.parent!==t){if(this.parent){const t=this.parent.children.indexOf(this);-1!==t&&this.parent.children.splice(t,1)}this._parentNode=t,this.parent&&this.parent.children.push(this),e&&this._updateAbsoluteBindMatrices(),this.markAsDirty()}}getLocalMatrix(){return this._compose(),this._localMatrix}getBindMatrix(){return this._bindMatrix}getBaseMatrix(){return this.getBindMatrix()}getRestMatrix(){return this._restMatrix}getRestPose(){return this.getRestMatrix()}setRestMatrix(t){this._restMatrix.copyFrom(t)}setRestPose(t){this.setRestMatrix(t)}getBindPose(){return this.getBindMatrix()}setBindMatrix(t){this.updateMatrix(t)}setBindPose(t){this.setBindMatrix(t)}getFinalMatrix(){return this._finalMatrix}getWorldMatrix(){return this.getFinalMatrix()}returnToRest(){if(this._linkedTransformNode){const t=i.Vector3[0],e=i.Quaternion[0],s=i.Vector3[1];this.getRestMatrix().decompose(t,e,s),this._linkedTransformNode.position.copyFrom(s),this._linkedTransformNode.rotationQuaternion=this._linkedTransformNode.rotationQuaternion??o.Identity(),this._linkedTransformNode.rotationQuaternion.copyFrom(e),this._linkedTransformNode.scaling.copyFrom(t)}else this._matrix=this._restMatrix}getAbsoluteInverseBindMatrix(){return this._absoluteInverseBindMatrix}getInvertedAbsoluteTransform(){return this.getAbsoluteInverseBindMatrix()}getAbsoluteMatrix(){return this._skeleton.computeAbsoluteMatrices(),this._absoluteMatrix}getAbsoluteTransform(){return this.getAbsoluteMatrix()}linkTransformNode(t){this._linkedTransformNode&&this._skeleton._numBonesWithLinkedTransformNode--,this._linkedTransformNode=t,this._linkedTransformNode&&this._skeleton._numBonesWithLinkedTransformNode++}getTransformNode(){return this._linkedTransformNode}get position(){return this._decompose(),this._localPosition}set position(t){this._decompose(),this._localPosition.copyFrom(t),this._markAsDirtyAndCompose()}get rotation(){return this.getRotation()}set rotation(t){this.setRotation(t)}get rotationQuaternion(){return this._decompose(),this._localRotation}set rotationQuaternion(t){this.setRotationQuaternion(t)}get scaling(){return this.getScale()}set scaling(t){this.setScale(t)}get animationPropertiesOverride(){return this._skeleton.animationPropertiesOverride}_decompose(){this._needToDecompose&&(this._needToDecompose=!1,this._localScaling||(this._localScaling=s.Zero(),this._localRotation=o.Zero(),this._localPosition=s.Zero()),this._localMatrix.decompose(this._localScaling,this._localRotation,this._localPosition))}_compose(){this._needToCompose&&(this._localScaling?(this._needToCompose=!1,e.ComposeToRef(this._localScaling,this._localRotation,this._localPosition,this._localMatrix)):this._needToCompose=!1)}updateMatrix(t,e=!0,i=!0){this._bindMatrix.copyFrom(t),e&&this._updateAbsoluteBindMatrices(),i?this._matrix=t:this.markAsDirty()}_updateAbsoluteBindMatrices(t,e=!0){if(t||(t=this._bindMatrix),this.parent?t.multiplyToRef(this.parent._absoluteBindMatrix,this._absoluteBindMatrix):this._absoluteBindMatrix.copyFrom(t),this._absoluteBindMatrix.invertToRef(this._absoluteInverseBindMatrix),e)for(let t=0;t<this.children.length;t++)this.children[t]._updateAbsoluteBindMatrices();this._scalingDeterminant=this._absoluteBindMatrix.determinant()<0?-1:1}markAsDirty(){return this._currentRenderId++,this._childUpdateId++,this._skeleton._markAsDirty(),this}_markAsDirtyAndCompose(){this.markAsDirty(),this._needToCompose=!0}_markAsDirtyAndDecompose(){this.markAsDirty(),this._needToDecompose=!0}_updatePosition(t,i=0,o,n=!0){const r=this.getLocalMatrix();if(0==i)n?(r.addAtIndex(12,t.x),r.addAtIndex(13,t.y),r.addAtIndex(14,t.z)):r.setTranslationFromFloats(t.x,t.y,t.z);else{const i=a._TmpMats[0],l=a._TmpVecs[0];this.parent?(i.copyFrom(this.parent.getAbsoluteMatrix()),o&&i.multiplyToRef(o.getWorldMatrix(),i)):e.IdentityToRef(i),n&&i.setTranslationFromFloats(0,0,0),i.invert(),s.TransformCoordinatesToRef(t,i,l),n?(r.addAtIndex(12,l.x),r.addAtIndex(13,l.y),r.addAtIndex(14,l.z)):r.setTranslationFromFloats(l.x,l.y,l.z)}this._markAsDirtyAndDecompose()}translate(t,e=0,i){this._updatePosition(t,e,i,!0)}setPosition(t,e=0,i){this._updatePosition(t,e,i,!1)}setAbsolutePosition(t,e){this.setPosition(t,1,e)}scale(t,i,o,s=!1){const n=this.getLocalMatrix(),r=a._TmpMats[0];e.ScalingToRef(t,i,o,r),r.multiplyToRef(n,n),r.invert();for(const e of this.children){const s=e.getLocalMatrix();s.multiplyToRef(r,s),s.multiplyAtIndex(12,t),s.multiplyAtIndex(13,i),s.multiplyAtIndex(14,o),e._markAsDirtyAndDecompose()}if(this._markAsDirtyAndDecompose(),s)for(const e of this.children)e.scale(t,i,o,s)}setScale(t){this._decompose(),this._localScaling.copyFrom(t),this._markAsDirtyAndCompose()}getScale(){return this._decompose(),this._localScaling}getScaleToRef(t){this._decompose(),t.copyFrom(this._localScaling)}setYawPitchRoll(t,i,s,n=0,r){if(0===n){const e=a._TmpQuat;return o.RotationYawPitchRollToRef(t,i,s,e),void this.setRotationQuaternion(e,n,r)}const l=a._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(l,r))return;const h=a._TmpMats[1];e.RotationYawPitchRollToRef(t,i,s,h),l.multiplyToRef(h,h),this._rotateWithMatrix(h,n,r)}rotate(t,i,o=0,s){const n=a._TmpMats[0];n.setTranslationFromFloats(0,0,0),e.RotationAxisToRef(t,i,n),this._rotateWithMatrix(n,o,s)}setAxisAngle(t,i,s=0,n){if(0===s){const e=a._TmpQuat;return o.RotationAxisToRef(t,i,e),void this.setRotationQuaternion(e,s,n)}const r=a._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(r,n))return;const l=a._TmpMats[1];e.RotationAxisToRef(t,i,l),r.multiplyToRef(l,l),this._rotateWithMatrix(l,s,n)}setRotation(t,e=0,i){this.setYawPitchRoll(t.y,t.x,t.z,e,i)}setRotationQuaternion(t,i=0,o){if(0===i)return this._decompose(),this._localRotation.copyFrom(t),void this._markAsDirtyAndCompose();const s=a._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(s,o))return;const n=a._TmpMats[1];e.FromQuaternionToRef(t,n),s.multiplyToRef(n,n),this._rotateWithMatrix(n,i,o)}setRotationMatrix(t,e=0,i){if(0===e){const s=a._TmpQuat;return o.FromRotationMatrixToRef(t,s),void this.setRotationQuaternion(s,e,i)}const s=a._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(s,i))return;const n=a._TmpMats[1];n.copyFrom(t),s.multiplyToRef(t,n),this._rotateWithMatrix(n,e,i)}_rotateWithMatrix(t,e=0,i){const o=this.getLocalMatrix(),s=o.m[12],n=o.m[13],r=o.m[14],l=this.getParent(),h=a._TmpMats[3],c=a._TmpMats[4];l&&1==e?(i?(h.copyFrom(i.getWorldMatrix()),l.getAbsoluteMatrix().multiplyToRef(h,h)):h.copyFrom(l.getAbsoluteMatrix()),c.copyFrom(h),c.invert(),o.multiplyToRef(h,o),o.multiplyToRef(t,o),o.multiplyToRef(c,o)):1==e&&i?(h.copyFrom(i.getWorldMatrix()),c.copyFrom(h),c.invert(),o.multiplyToRef(h,o),o.multiplyToRef(t,o),o.multiplyToRef(c,o)):o.multiplyToRef(t,o),o.setTranslationFromFloats(s,n,r),this._markAsDirtyAndDecompose()}_getAbsoluteInverseMatrixUnscaledToRef(t,i){const o=a._TmpMats[2];return t.copyFrom(this.getAbsoluteMatrix()),i?(t.multiplyToRef(i.getWorldMatrix(),t),e.ScalingToRef(i.scaling.x,i.scaling.y,i.scaling.z,o)):e.IdentityToRef(o),t.invert(),!isNaN(t.m[0])&&(o.multiplyAtIndex(0,this._scalingDeterminant),t.multiplyToRef(o,t),!0)}getPosition(t=0,e=null){const i=s.Zero();return this.getPositionToRef(t,e,i),i}getPositionToRef(t=0,e,i){if(0==t){const t=this.getLocalMatrix();i.x=t.m[12],i.y=t.m[13],i.z=t.m[14]}else{const t=a._TmpMats[0].copyFrom(this.getAbsoluteMatrix());e&&t.multiplyToRef(e.getWorldMatrix(),t),i.x=t.m[12],i.y=t.m[13],i.z=t.m[14]}}getAbsolutePosition(t=null){const e=s.Zero();return this.getPositionToRef(1,t,e),e}getAbsolutePositionToRef(t,e){this.getPositionToRef(1,t,e)}computeAbsoluteMatrices(){if(this._compose(),this.parent)this._localMatrix.multiplyToRef(this.parent._absoluteMatrix,this._absoluteMatrix);else{this._absoluteMatrix.copyFrom(this._localMatrix);const t=this._skeleton.getPoseMatrix();t&&this._absoluteMatrix.multiplyToRef(t,this._absoluteMatrix)}const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].computeAbsoluteMatrices()}computeAbsoluteTransforms(){this.computeAbsoluteMatrices()}getDirection(t,e=null){const i=s.Zero();return this.getDirectionToRef(t,e,i),i}getDirectionToRef(t,e=null,i){const o=a._TmpMats[0].copyFrom(this.getAbsoluteMatrix());e&&o.multiplyToRef(e.getWorldMatrix(),o),s.TransformNormalToRef(t,o,i),i.normalize()}getRotation(t=0,e=null){const i=s.Zero();return this.getRotationToRef(t,e,i),i}getRotationToRef(t=0,e=null,i){const o=a._TmpQuat;this.getRotationQuaternionToRef(t,e,o),o.toEulerAnglesToRef(i)}getRotationQuaternion(t=0,e=null){const i=o.Identity();return this.getRotationQuaternionToRef(t,e,i),i}getRotationQuaternionToRef(t=0,e=null,i){if(0==t)this._decompose(),i.copyFrom(this._localRotation);else{const t=a._TmpMats[0],o=this.getAbsoluteMatrix();e?o.multiplyToRef(e.getWorldMatrix(),t):t.copyFrom(o),t.multiplyAtIndex(0,this._scalingDeterminant),t.multiplyAtIndex(1,this._scalingDeterminant),t.multiplyAtIndex(2,this._scalingDeterminant),t.decompose(void 0,i,void 0)}}getRotationMatrix(t=0,i){const o=e.Identity();return this.getRotationMatrixToRef(t,i,o),o}getRotationMatrixToRef(t=0,e,i){if(0==t)this.getLocalMatrix().getRotationMatrixToRef(i);else{const t=a._TmpMats[0],o=this.getAbsoluteMatrix();e?o.multiplyToRef(e.getWorldMatrix(),t):t.copyFrom(o),t.multiplyAtIndex(0,this._scalingDeterminant),t.multiplyAtIndex(1,this._scalingDeterminant),t.multiplyAtIndex(2,this._scalingDeterminant),t.getRotationMatrixToRef(i)}}getAbsolutePositionFromLocal(t,e=null){const i=s.Zero();return this.getAbsolutePositionFromLocalToRef(t,e,i),i}getAbsolutePositionFromLocalToRef(t,e=null,i){const o=a._TmpMats[0].copyFrom(this.getAbsoluteMatrix());e&&o.multiplyToRef(e.getWorldMatrix(),o),s.TransformCoordinatesToRef(t,o,i)}getLocalPositionFromAbsolute(t,e=null){const i=s.Zero();return this.getLocalPositionFromAbsoluteToRef(t,e,i),i}getLocalPositionFromAbsoluteToRef(t,e=null,i){const o=a._TmpMats[0].copyFrom(this.getAbsoluteMatrix());e&&o.multiplyToRef(e.getWorldMatrix(),o),o.invert(),s.TransformCoordinatesToRef(t,o,i)}setCurrentPoseAsRest(){this.setRestMatrix(this.getLocalMatrix())}dispose(){this._linkedTransformNode=null;const t=this._skeleton.bones.indexOf(this);if(-1!==t&&this._skeleton.bones.splice(t,1),this._parentNode&&this._parentNode.children){const t=this._parentNode.children,e=t.indexOf(this);-1!==e&&t.splice(e,1)}super.dispose()}}a._TmpVecs=n(2,s.Zero),a._TmpQuat=o.Identity(),a._TmpMats=n(5,e.Identity),a.prototype.copyAnimationRange??=r("Bone","copyAnimationRange");export{a as B};
//# sourceMappingURL=bone.pure-BcPT5kCP.esm.min.js.map