@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) • 12.1 kB
JavaScript
import{bu as t,M as e,aS as i,Q as o,V as s,aY as n}from"./index-Bw2N6w1y.esm.min.js";class r 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._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._absoluteMatrix}getAbsoluteTransform(){return this._absoluteMatrix}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 a=this.getLocalMatrix();if(0==i)n?(a.addAtIndex(12,t.x),a.addAtIndex(13,t.y),a.addAtIndex(14,t.z)):a.setTranslationFromFloats(t.x,t.y,t.z);else{let i=null;o&&(i=o.getWorldMatrix()),this._skeleton.computeAbsoluteMatrices();const l=r._TmpMats[0],h=r._TmpVecs[0];this.parent?o&&i?(l.copyFrom(this.parent.getAbsoluteMatrix()),l.multiplyToRef(i,l)):l.copyFrom(this.parent.getAbsoluteMatrix()):e.IdentityToRef(l),n&&l.setTranslationFromFloats(0,0,0),l.invert(),s.TransformCoordinatesToRef(t,l,h),n?(a.addAtIndex(12,h.x),a.addAtIndex(13,h.y),a.addAtIndex(14,h.z)):a.setTranslationFromFloats(h.x,h.y,h.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(),a=r._TmpMats[0];e.ScalingToRef(t,i,o,a),a.multiplyToRef(n,n),a.invert();for(const e of this.children){const s=e.getLocalMatrix();s.multiplyToRef(a,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,a){if(0===n){const e=r._TmpQuat;return o.RotationYawPitchRollToRef(t,i,s,e),void this.setRotationQuaternion(e,n,a)}const l=r._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(l,a))return;const h=r._TmpMats[1];e.RotationYawPitchRollToRef(t,i,s,h),l.multiplyToRef(h,h),this._rotateWithMatrix(h,n,a)}rotate(t,i,o=0,s){const n=r._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=r._TmpQuat;return o.RotationAxisToRef(t,i,e),void this.setRotationQuaternion(e,s,n)}const a=r._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(a,n))return;const l=r._TmpMats[1];e.RotationAxisToRef(t,i,l),a.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=r._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(s,o))return;const n=r._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=r._TmpQuat;return o.FromRotationMatrixToRef(t,s),void this.setRotationQuaternion(s,e,i)}const s=r._TmpMats[0];if(!this._getAbsoluteInverseMatrixUnscaledToRef(s,i))return;const n=r._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],a=o.m[14],l=this.getParent(),h=r._TmpMats[3],c=r._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,a),this.computeAbsoluteMatrices(),this._markAsDirtyAndDecompose()}_getAbsoluteInverseMatrixUnscaledToRef(t,i){const o=r._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{let t=null;e&&(t=e.getWorldMatrix()),this._skeleton.computeAbsoluteMatrices();let o=r._TmpMats[0];e&&t?(o.copyFrom(this.getAbsoluteMatrix()),o.multiplyToRef(t,o)):o=this.getAbsoluteMatrix(),i.x=o.m[12],i.y=o.m[13],i.z=o.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){let o=null;e&&(o=e.getWorldMatrix()),this._skeleton.computeAbsoluteMatrices();const n=r._TmpMats[0];n.copyFrom(this.getAbsoluteMatrix()),e&&o&&n.multiplyToRef(o,n),s.TransformNormalToRef(t,n,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=r._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=r._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=r._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){let o=null;e&&(o=e.getWorldMatrix()),this._skeleton.computeAbsoluteMatrices();const n=r._TmpMats[0];n.copyFrom(this.getAbsoluteMatrix()),e&&o&&n.multiplyToRef(o,n),s.TransformCoordinatesToRef(t,n,i)}getLocalPositionFromAbsolute(t,e=null){const i=s.Zero();return this.getLocalPositionFromAbsoluteToRef(t,e,i),i}getLocalPositionFromAbsoluteToRef(t,e=null,i){let o=null;e&&(o=e.getWorldMatrix()),this._skeleton.computeAbsoluteMatrices();const n=r._TmpMats[0];n.copyFrom(this.getAbsoluteMatrix()),e&&o&&n.multiplyToRef(o,n),n.invert(),s.TransformCoordinatesToRef(t,n,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()}}r._TmpVecs=n(2,s.Zero),r._TmpQuat=o.Identity(),r._TmpMats=n(5,e.Identity);export{r as B};
//# sourceMappingURL=bone-BwMp7T0B.esm.min.js.map