@galacean/engine-physics-lite 0.9.21 → 0.9.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +1249 -1170
- package/dist/browser.min.js +1 -1
- package/dist/main.js +112 -37
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +32571 -31674
- package/dist/module.js +97 -15
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
package/dist/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@swc/helpers/src/_ts_decorate.mjs"),require("@swc/helpers/src/_inherits.mjs"),require("@swc/helpers/src/_create_class.mjs"),require("@swc/helpers/src/_instanceof.mjs"),require("@galacean/engine")):"function"==typeof define&&define.amd?define(["exports","@swc/helpers/src/_ts_decorate.mjs","@swc/helpers/src/_inherits.mjs","@swc/helpers/src/_create_class.mjs","@swc/helpers/src/_instanceof.mjs","@galacean/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).Galacean=t.Galacean||{},t.Galacean.PhysicsLite={}),t._ts_decorate,t._inherits,t._create_class,t._instanceof,t.Galacean)}(this,function(t,e,i,s,n,o){"use strict";function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a,h,l,c,u=r(e),d=r(i),_=r(s),p=r(n),f=function(){function t(t){void 0===t&&(t=[]),this._flags=t,this.flag=!0,this._flags.push(this)}return t.prototype.destroy=function(){(function(t,e){var i=t.indexOf(e);if(!(i<0)){var s=t.length-1;i!==s&&(t[i]=t[s]),t.length--}})(this._flags,this),this._flags=null},t}(),y=function(){function t(){this._updateFlags=[]}var e=t.prototype;return e.register=function(){return new f(this._updateFlags)},e.distribute=function(){for(var t=this._updateFlags,e=t.length-1;e>=0;e--)t[e].flag=!0},t}(),g=function(){function t(){this._transform=new m,this._invModelMatrix=new o.Matrix,this._transform.owner=this,this._inverseWorldMatFlag=this._transform.registerWorldChangeFlag()}var e=t.prototype;return e.setRotation=function(t){console.log("Physics-lite don't support setRotation. Use Physics-PhysX instead!")},e.setPosition=function(t){this._transform.setPosition(t.x,t.y,t.z)},e.setContactOffset=function(t){console.log("Physics-lite don't support setContactOffset. Use Physics-PhysX instead!")},e.setMaterial=function(t){console.log("Physics-lite don't support setMaterial. Use Physics-PhysX instead!")},e.setUniqueID=function(t){this._id=t},e.setIsTrigger=function(t){console.log("Physics-lite don't support setIsTrigger. Use Physics-PhysX instead!")},e.destroy=function(){},e._updateHitResult=function(e,i,s,n,r){void 0===r&&(r=!1);var a=t._tempPoint;e.getPoint(i,a),r||o.Vector3.transformCoordinate(a,this._transform.worldMatrix,a);var h=o.Vector3.distance(n,a);h<s.distance&&(s.point.copyFrom(a),s.distance=h,s.shapeID=this._id)},e._getLocalRay=function(e){var i=this._getInvModelMatrix(),s=t._ray;return o.Vector3.transformCoordinate(e.origin,i,s.origin),o.Vector3.transformNormal(e.direction,i,s.direction),s.direction.normalize(),s},e._getInvModelMatrix=function(){return this._inverseWorldMatFlag.flag&&(o.Matrix.invert(this._transform.worldMatrix,this._invModelMatrix),this._inverseWorldMatFlag.flag=!1),this._invModelMatrix},t}();g._ray=new o.Ray,g._tempPoint=new o.Vector3;var m=function(){function t(){this._position=new o.Vector3,this._rotation=new o.Vector3,this._rotationQuaternion=new o.Quaternion,this._scale=new o.Vector3(1,1,1),this._worldRotationQuaternion=new o.Quaternion,this._localMatrix=new o.Matrix,this._worldMatrix=new o.Matrix,this._updateFlagManager=new y,this._isParentDirty=!0,this._parentTransformCache=null,this._dirtyFlag=188}var e=t.prototype;return e.setPosition=function(t,e,i){this._position.set(t,e,i),this.position=this._position},e.setRotationQuaternion=function(t,e,i,s){this._rotationQuaternion.set(t,e,i,s),this.rotationQuaternion=this._rotationQuaternion},e.setScale=function(t,e,i){this._scale.set(t,e,i),this.scale=this._scale},e.registerWorldChangeFlag=function(){return this._updateFlagManager.register()},e._updateWorldPositionFlag=function(){if(!this._isContainDirtyFlags(132)&&(this._worldAssociatedChange(132),p.default(this._owner,P)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldPositionFlag()},e._updateWorldRotationFlag=function(){if(!this._isContainDirtyFlags(152)&&(this._worldAssociatedChange(152),p.default(this._owner,P)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldRotationFlag()},e._updateWorldScaleFlag=function(){if(!this._isContainDirtyFlags(160)&&(this._worldAssociatedChange(160),p.default(this._owner,P)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldScaleFlag()},e._updateAllWorldFlag=function(){if(!this._isContainDirtyFlags(188)&&(this._worldAssociatedChange(188),p.default(this._owner,P)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateAllWorldFlag()},e._getParentTransform=function(){if(!this._isParentDirty)return this._parentTransformCache;var t=null;return p.default(this._owner,g)&&(t=this._owner._collider._transform),this._parentTransformCache=t,this._isParentDirty=!1,t},e._isContainDirtyFlags=function(t){return(this._dirtyFlag&t)===t},e._isContainDirtyFlag=function(t){return(this._dirtyFlag&t)!=0},e._setDirtyFlagTrue=function(t){this._dirtyFlag|=t},e._setDirtyFlagFalse=function(t){this._dirtyFlag&=~t},e._worldAssociatedChange=function(t){this._dirtyFlag|=t,this._updateFlagManager.distribute()},_.default(t,[{key:"owner",set:function(t){this._owner=t}},{key:"position",get:function(){return this._position},set:function(t){this._position!==t&&this._position.copyFrom(t),this._setDirtyFlagTrue(64),this._updateWorldPositionFlag()}},{key:"rotationQuaternion",get:function(){return this._isContainDirtyFlag(2)&&(o.Quaternion.rotationEuler(o.MathUtil.degreeToRadian(this._rotation.x),o.MathUtil.degreeToRadian(this._rotation.y),o.MathUtil.degreeToRadian(this._rotation.z),this._rotationQuaternion),this._setDirtyFlagFalse(2)),this._rotationQuaternion},set:function(t){this._rotationQuaternion!==t&&this._rotationQuaternion.copyFrom(t),this._setDirtyFlagTrue(65),this._setDirtyFlagFalse(2),this._updateWorldRotationFlag()}},{key:"worldRotationQuaternion",get:function(){if(this._isContainDirtyFlag(16)){var t=this._getParentTransform();null!=t?o.Quaternion.multiply(t.worldRotationQuaternion,this.rotationQuaternion,this._worldRotationQuaternion):this._worldRotationQuaternion.copyFrom(this.rotationQuaternion),this._setDirtyFlagFalse(16)}return this._worldRotationQuaternion},set:function(e){this._worldRotationQuaternion!==e&&this._worldRotationQuaternion.copyFrom(e);var i=this._getParentTransform();i?(o.Quaternion.invert(i.worldRotationQuaternion,t._tempQuat0),o.Quaternion.multiply(e,t._tempQuat0,this._rotationQuaternion)):this._rotationQuaternion.copyFrom(e),this.rotationQuaternion=this._rotationQuaternion,this._setDirtyFlagFalse(16)}},{key:"scale",get:function(){return this._scale},set:function(t){this._scale!==t&&this._scale.copyFrom(t),this._setDirtyFlagTrue(64),this._updateWorldScaleFlag()}},{key:"localMatrix",get:function(){return this._isContainDirtyFlag(64)&&(o.Matrix.affineTransformation(this._scale,this.rotationQuaternion,this._position,this._localMatrix),this._setDirtyFlagFalse(64)),this._localMatrix},set:function(t){this._localMatrix!==t&&this._localMatrix.copyFrom(t),this._localMatrix.decompose(this._position,this._rotationQuaternion,this._scale),this._setDirtyFlagTrue(1),this._setDirtyFlagFalse(64),this._updateAllWorldFlag()}},{key:"worldMatrix",get:function(){if(this._isContainDirtyFlag(128)){var t=this._getParentTransform();t?o.Matrix.multiply(t.worldMatrix,this.localMatrix,this._worldMatrix):this._worldMatrix.copyFrom(this.localMatrix),this._setDirtyFlagFalse(128)}return this._worldMatrix},set:function(e){this._worldMatrix!==e&&this._worldMatrix.copyFrom(e);var i=this._getParentTransform();i?(o.Matrix.invert(i.worldMatrix,t._tempMat42),o.Matrix.multiply(t._tempMat42,e,this._localMatrix)):this._localMatrix.copyFrom(e),this.localMatrix=this._localMatrix,this._setDirtyFlagFalse(128)}}]),t}();m._tempQuat0=new o.Quaternion,m._tempMat42=new o.Matrix,(a=l||(l={}))[a.LocalEuler=1]="LocalEuler",a[a.LocalQuat=2]="LocalQuat",a[a.WorldPosition=4]="WorldPosition",a[a.WorldEuler=8]="WorldEuler",a[a.WorldQuat=16]="WorldQuat",a[a.WorldScale=32]="WorldScale",a[a.LocalMatrix=64]="LocalMatrix",a[a.WorldMatrix=128]="WorldMatrix",a[a.WmWp=132]="WmWp",a[a.WmWeWq=152]="WmWeWq",a[a.WmWpWeWq=156]="WmWpWeWq",a[a.WmWs=160]="WmWs",a[a.WmWpWs=164]="WmWpWs",a[a.WmWpWeWqWs=188]="WmWpWeWqWs";var P=function(){function t(){this._shapes=[],this._transform=new m,this._transform.owner=this}var e=t.prototype;return e.addShape=function(t){var e=t._collider;e!==this&&(e&&e.removeShape(t),this._shapes.push(t),t._collider=this)},e.removeShape=function(t){var e=this._shapes.indexOf(t);-1!==e&&(this._shapes.splice(e,1),t._collider=null)},e.setWorldTransform=function(t,e){this._transform.setPosition(t.x,t.y,t.z),this._transform.setRotationQuaternion(e.x,e.y,e.z,e.w)},e.getWorldTransform=function(t,e){var i=this._transform,s=i.position,n=i.rotationQuaternion;t.set(s.x,s.y,s.z),e.set(n.x,n.y,n.z,n.w)},e.destroy=function(){},e._raycast=function(t,e,i){i.distance=Number.MAX_VALUE;for(var s=this._shapes,n=0,o=s.length;n<o;n++){var r=s[n];e(r._id)&&r._raycast(t,i)}return i.distance!=Number.MAX_VALUE},t}(),x=function(t){function e(e,i){var s;return(s=t.call(this)||this)._transform.setPosition(e.x,e.y,e.z),s._transform.setRotationQuaternion(i.x,i.y,i.z,i.w),s}d.default(e,t);var i=e.prototype;return i.addForce=function(t){throw"Physics-lite don't support addForce. Use Physics-PhysX instead!"},i.addTorque=function(t){throw"Physics-lite don't support addTorque. Use Physics-PhysX instead!"},i.move=function(t,e){throw"Physics-lite don't support move. Use Physics-PhysX instead!"},i.sleep=function(){throw"Physics-lite don't support putToSleep. Use Physics-PhysX instead!"},i.setAngularDamping=function(t){throw"Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!"},i.setAngularVelocity=function(t){throw"Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!"},i.setCenterOfMass=function(t){throw"Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!"},i.setCollisionDetectionMode=function(t){throw"Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!"},i.setConstraints=function(t){throw"Physics-lite don't support setConstraints. Use Physics-PhysX instead!"},i.setInertiaTensor=function(t){throw"Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!"},i.setIsKinematic=function(t){throw"Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!"},i.setLinearDamping=function(t){throw"Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!"},i.setLinearVelocity=function(t){throw"Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!"},i.setMass=function(t){throw"Physics-lite don't support setMass. Use Physics-PhysX instead!"},i.setMaxAngularVelocity=function(t){throw"Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!"},i.setMaxDepenetrationVelocity=function(t){throw"Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!"},i.setSleepThreshold=function(t){throw"Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!"},i.setSolverIterations=function(t){throw"Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!"},i.wakeUp=function(){throw"Physics-lite don't support wakeUp. Use Physics-PhysX instead!"},e}(P),v=function(){function t(t){void 0===t&&(t=0),this.length=0,this._elements=Array(t)}var e=t.prototype;return e.add=function(t){this.length===this._elements.length?this._elements.push(t):this._elements[this.length]=t,this.length++},e.delete=function(t){var e=this._elements.indexOf(t);this.deleteByIndex(e)},e.get=function(t){if(t>=this.length)throw"Index is out of range.";return this._elements[t]},e.deleteByIndex=function(t){var e=this._elements,i=null,s=this.length-1;return t!==s&&(i=e[s],e[t]=i),this.length--,i},e.garbageCollection=function(){this._elements.length=this.length},t}(),w=function(){this.shapeID=-1,this.distance=0,this.point=new o.Vector3,this.normal=new o.Vector3},M=function(t){function e(e,i,s){var n;return(n=t.call(this)||this)._halfSize=new o.Vector3,n._scale=new o.Vector3(1,1,1),n._boxMin=new o.Vector3(-.5,-.5,-.5),n._boxMax=new o.Vector3(.5,.5,.5),n._id=e,n._halfSize.set(.5*i.x,.5*i.y,.5*i.z),n._setBondingBox(),n}d.default(e,t);var i=e.prototype;return i.setPosition=function(e){t.prototype.setPosition.call(this,e),this._setBondingBox()},i.setWorldScale=function(t){this._transform.position=this._transform.position.multiply(t),this._scale.copyFrom(t)},i.setSize=function(t){this._halfSize.set(.5*t.x,.5*t.y,.5*t.z),this._setBondingBox()},i._raycast=function(t,i){var s=this._getLocalRay(t),n=e._tempBox;n.min.set(-this._halfSize.x*this._scale.x,-this._halfSize.y*this._scale.y,-this._halfSize.z*this._scale.z),n.max.set(this._halfSize.x*this._scale.x,this._halfSize.y*this._scale.y,this._halfSize.z*this._scale.z);var o=s.intersectBox(n);return -1!==o&&(this._updateHitResult(s,o,i,t.origin),!0)},i._setBondingBox=function(){var t=this._transform.position,e=this._halfSize;o.Vector3.add(t,e,this._boxMax),o.Vector3.subtract(t,e,this._boxMin)},e}(g);M._tempBox=new o.BoundingBox;var F=function(t){function e(e,i,s){var n;return(n=t.call(this)||this)._radius=1,n._maxScale=1,n._radius=i,n._id=e,n}d.default(e,t);var i=e.prototype;return i.setRadius=function(t){this._radius=t},i.setWorldScale=function(t){this._maxScale=Math.max(t.x,Math.max(t.x,t.y))},i._raycast=function(t,i){var s=e._tempSphere;o.Vector3.transformCoordinate(this._transform.position,this._collider._transform.worldMatrix,s.center),s.radius=this.worldRadius;var n=t.intersectSphere(s);return -1!==n&&(this._updateHitResult(t,n,i,t.origin,!0),!0)},_.default(e,[{key:"worldRadius",get:function(){return this._radius*this._maxScale}}]),e}(g);F._tempSphere=new o.BoundingSphere;var C=function(){function t(t,e,i,s,n,r){this._colliders=[],this._sphere=new o.BoundingSphere,this._box=new o.BoundingBox,this._currentEvents=new v,this._eventMap={},this._eventPool=[],this._onContactEnter=t,this._onContactExit=e,this._onContactStay=i,this._onTriggerEnter=s,this._onTriggerExit=n,this._onTriggerStay=r}var e=t.prototype;return e.setGravity=function(t){console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!")},e.addColliderShape=function(t){this._eventMap[t._id]={}},e.removeColliderShape=function(t){for(var e=this._eventPool,i=this._currentEvents,s=t._id,n=i.length-1;n>=0;n--){var o=i.get(n);(o.index1==s||o.index2==s)&&(i.deleteByIndex(n),e.push(o))}delete this._eventMap[s]},e.addCollider=function(t){this._colliders.push(t)},e.removeCollider=function(t){var e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1)},e.update=function(t){for(var e=this._colliders,i=0,s=e.length;i<s;i++)this._collisionDetection(t,e[i]);this._fireEvent()},e.raycast=function(e,i,s,n){var o,r=this._colliders;n&&(o=t._hitResult);for(var a=!1,h=t._currentHit,l=0,c=r.length;l<c;l++)if(r[l]._raycast(e,s,h)&&(a=!0,h.distance<i)){if(!o)return!0;o.normal.copyFrom(h.normal),o.point.copyFrom(h.point),o.distance=h.distance,o.shapeID=h.shapeID,i=h.distance}return!a&&o?(o.shapeID=-1,o.distance=0,o.point.set(0,0,0),o.normal.set(0,0,0)):a&&o&&n(o.shapeID,o.distance,o.point,o.normal),a},e.addCharacterController=function(t){throw"Physics-lite don't support addCharacterController. Use Physics-PhysX instead!"},e.removeCharacterController=function(t){throw"Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!"},e._getTrigger=function(t,e){var i;return this._eventPool.length?((i=this._eventPool.pop()).index1=t,i.index2=e):i=new W(t,e),this._eventMap[t][e]=i,i},e._collisionDetection=function(e,i){for(var s=this._colliders,n=i._shapes,o=0,r=n.length;o<r;o++){var a=n[o];if(p.default(a,M)){t._updateWorldBox(a,this._box);for(var h=0,l=s.length;h<l;h++)for(var c=s[h]._shapes,u=0,d=c.length;u<d;u++){var _=c[u],f=_._id,y=a._id,g=f<y?this._eventMap[f][y]:this._eventMap[y][f];if((void 0===g||g.alreadyInvoked)&&_!=a&&this._boxCollision(_)){if(void 0===g){var m=f<y?this._getTrigger(f,y):this._getTrigger(y,f);m.state=0,m.alreadyInvoked=!1,this._currentEvents.add(m)}else 0===g.state?(g.state=1,g.alreadyInvoked=!1):1===g.state&&(g.alreadyInvoked=!1)}}}else if(p.default(a,F)){t._upWorldSphere(a,this._sphere);for(var P=0,x=s.length;P<x;P++)for(var v=s[P]._shapes,w=0,C=v.length;w<C;w++){var W=v[w],S=W._id,U=a._id,D=S<U?this._eventMap[S][U]:this._eventMap[U][S];if((void 0===D||D.alreadyInvoked)&&W!=a&&this._sphereCollision(W)){if(void 0===D){var Q=S<U?this._getTrigger(S,U):this._getTrigger(U,S);Q.state=0,Q.alreadyInvoked=!1,this._currentEvents.add(Q)}else 0===D.state?(D.state=1,D.alreadyInvoked=!1):1===D.state&&(D.alreadyInvoked=!1)}}}}},e._fireEvent=function(){for(var t=this._eventPool,e=this._currentEvents,i=e.length-1;i>=0;i--){var s=e.get(i);s.alreadyInvoked?(s.state=2,this._eventMap[s.index1][s.index2]=void 0,this._onTriggerExit(s.index1,s.index2),e.deleteByIndex(i),t.push(s)):0==s.state?(this._onTriggerEnter(s.index1,s.index2),s.alreadyInvoked=!0):1==s.state&&(this._onTriggerStay(s.index1,s.index2),s.alreadyInvoked=!0)}},e._boxCollision=function(e){if(p.default(e,M)){var i=t._tempBox;return t._updateWorldBox(e,i),o.CollisionUtil.intersectsBoxAndBox(i,this._box)}if(p.default(e,F)){var s=t._tempSphere;return t._upWorldSphere(e,s),o.CollisionUtil.intersectsSphereAndBox(s,this._box)}return!1},e._sphereCollision=function(e){if(p.default(e,M)){var i=t._tempBox;return t._updateWorldBox(e,i),o.CollisionUtil.intersectsSphereAndBox(this._sphere,i)}if(p.default(e,F)){var s=t._tempSphere;return t._upWorldSphere(e,s),o.CollisionUtil.intersectsSphereAndSphere(s,this._sphere)}return!1},t._updateWorldBox=function(t,e){var i=t._transform.worldMatrix;e.min.copyFrom(t._boxMin),e.max.copyFrom(t._boxMax),o.BoundingBox.transform(e,i,e)},t._upWorldSphere=function(t,e){o.Vector3.transformCoordinate(t._transform.position,t._transform.worldMatrix,e.center),e.radius=t.worldRadius},t}();C._tempSphere=new o.BoundingSphere,C._tempBox=new o.BoundingBox,C._currentHit=new w,C._hitResult=new w,(h=c||(c={}))[h.Enter=0]="Enter",h[h.Stay=1]="Stay",h[h.Exit=2]="Exit";var W=function(t,e){this.alreadyInvoked=!1,this.index1=t,this.index2=e},S=function(){function t(t,e,i,s,n){}var e=t.prototype;return e.setBounciness=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setDynamicFriction=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setStaticFriction=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setBounceCombine=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setFrictionCombine=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.destroy=function(){},t}(),U=function(t){function e(e,i){var s;return(s=t.call(this)||this)._transform.setPosition(e.x,e.y,e.z),s._transform.setRotationQuaternion(i.x,i.y,i.z,i.w),s}return d.default(e,t),e}(P);t.LitePhysics=function(){function t(){}return t.createPhysicsManager=function(t,e,i,s,n,o){return new C(t,e,i,s,n,o)},t.createStaticCollider=function(t,e){return new U(t,e)},t.createDynamicCollider=function(t,e){return new x(t,e)},t.createCharacterController=function(){throw"Physics-lite don't support createCharacterController. Use Physics-PhysX instead!"},t.createPhysicsMaterial=function(t,e,i,s,n){return new S(t,e,i,s,n)},t.createBoxColliderShape=function(t,e,i){return new M(t,e,i)},t.createSphereColliderShape=function(t,e,i){return new F(t,e,i)},t.createPlaneColliderShape=function(t,e){throw"Physics-lite don't support PlaneColliderShape. Use Physics-PhysX instead!"},t.createCapsuleColliderShape=function(t,e,i,s){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createFixedJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createHingeJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createSpringJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t}(),t.LitePhysics=u.default([function(t){}],t.LitePhysics),Object.defineProperty(t,"__esModule",{value:!0})});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@galacean/engine")):"function"==typeof define&&define.amd?define(["exports","@galacean/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).Galacean=t.Galacean||{},t.Galacean.PhysicsLite={}),t.Galacean)}(this,function(t,e){"use strict";function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function n(t,e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}function s(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e,i){return e&&s(t.prototype,e),i&&s(t,i),t}function r(t,e){return null!=e&&"undefined"!=typeof Symbol&&e[Symbol.hasInstance]?!!e[Symbol.hasInstance](t):t instanceof e}var a,h,l,c,u=function(){function t(t){void 0===t&&(t=[]),this._flags=t,this.flag=!0,this._flags.push(this)}return t.prototype.destroy=function(){(function(t,e){var i=t.indexOf(e);if(!(i<0)){var n=t.length-1;i!==n&&(t[i]=t[n]),t.length--}})(this._flags,this),this._flags=null},t}(),d=function(){function t(){this._updateFlags=[]}var e=t.prototype;return e.register=function(){return new u(this._updateFlags)},e.distribute=function(){for(var t=this._updateFlags,e=t.length-1;e>=0;e--)t[e].flag=!0},t}(),_=function(){function t(){this._transform=new p,this._invModelMatrix=new e.Matrix,this._transform.owner=this,this._inverseWorldMatFlag=this._transform.registerWorldChangeFlag()}var i=t.prototype;return i.setRotation=function(t){console.log("Physics-lite don't support setRotation. Use Physics-PhysX instead!")},i.setPosition=function(t){this._transform.setPosition(t.x,t.y,t.z)},i.setContactOffset=function(t){console.log("Physics-lite don't support setContactOffset. Use Physics-PhysX instead!")},i.setMaterial=function(t){console.log("Physics-lite don't support setMaterial. Use Physics-PhysX instead!")},i.setUniqueID=function(t){this._id=t},i.setIsTrigger=function(t){console.log("Physics-lite don't support setIsTrigger. Use Physics-PhysX instead!")},i.destroy=function(){},i._updateHitResult=function(i,n,s,o,r){void 0===r&&(r=!1);var a=t._tempPoint;i.getPoint(n,a),r||e.Vector3.transformCoordinate(a,this._transform.worldMatrix,a);var h=e.Vector3.distance(o,a);h<s.distance&&(s.point.copyFrom(a),s.distance=h,s.shapeID=this._id)},i._getLocalRay=function(i){var n=this._getInvModelMatrix(),s=t._ray;return e.Vector3.transformCoordinate(i.origin,n,s.origin),e.Vector3.transformNormal(i.direction,n,s.direction),s.direction.normalize(),s},i._getInvModelMatrix=function(){return this._inverseWorldMatFlag.flag&&(e.Matrix.invert(this._transform.worldMatrix,this._invModelMatrix),this._inverseWorldMatFlag.flag=!1),this._invModelMatrix},t}();_._ray=new e.Ray,_._tempPoint=new e.Vector3;var p=function(){function t(){this._position=new e.Vector3,this._rotation=new e.Vector3,this._rotationQuaternion=new e.Quaternion,this._scale=new e.Vector3(1,1,1),this._worldRotationQuaternion=new e.Quaternion,this._localMatrix=new e.Matrix,this._worldMatrix=new e.Matrix,this._updateFlagManager=new d,this._isParentDirty=!0,this._parentTransformCache=null,this._dirtyFlag=188}var i=t.prototype;return i.setPosition=function(t,e,i){this._position.set(t,e,i),this.position=this._position},i.setRotationQuaternion=function(t,e,i,n){this._rotationQuaternion.set(t,e,i,n),this.rotationQuaternion=this._rotationQuaternion},i.setScale=function(t,e,i){this._scale.set(t,e,i),this.scale=this._scale},i.registerWorldChangeFlag=function(){return this._updateFlagManager.register()},i._updateWorldPositionFlag=function(){if(!this._isContainDirtyFlags(132)&&(this._worldAssociatedChange(132),r(this._owner,f)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldPositionFlag()},i._updateWorldRotationFlag=function(){if(!this._isContainDirtyFlags(152)&&(this._worldAssociatedChange(152),r(this._owner,f)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldRotationFlag()},i._updateWorldScaleFlag=function(){if(!this._isContainDirtyFlags(160)&&(this._worldAssociatedChange(160),r(this._owner,f)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateWorldScaleFlag()},i._updateAllWorldFlag=function(){if(!this._isContainDirtyFlags(188)&&(this._worldAssociatedChange(188),r(this._owner,f)))for(var t=this._owner._shapes,e=0,i=t.length;e<i;e++)t[e]._transform._updateAllWorldFlag()},i._getParentTransform=function(){if(!this._isParentDirty)return this._parentTransformCache;var t=null;return r(this._owner,_)&&(t=this._owner._collider._transform),this._parentTransformCache=t,this._isParentDirty=!1,t},i._isContainDirtyFlags=function(t){return(this._dirtyFlag&t)===t},i._isContainDirtyFlag=function(t){return(this._dirtyFlag&t)!=0},i._setDirtyFlagTrue=function(t){this._dirtyFlag|=t},i._setDirtyFlagFalse=function(t){this._dirtyFlag&=~t},i._worldAssociatedChange=function(t){this._dirtyFlag|=t,this._updateFlagManager.distribute()},o(t,[{key:"owner",set:function(t){this._owner=t}},{key:"position",get:function(){return this._position},set:function(t){this._position!==t&&this._position.copyFrom(t),this._setDirtyFlagTrue(64),this._updateWorldPositionFlag()}},{key:"rotationQuaternion",get:function(){return this._isContainDirtyFlag(2)&&(e.Quaternion.rotationEuler(e.MathUtil.degreeToRadian(this._rotation.x),e.MathUtil.degreeToRadian(this._rotation.y),e.MathUtil.degreeToRadian(this._rotation.z),this._rotationQuaternion),this._setDirtyFlagFalse(2)),this._rotationQuaternion},set:function(t){this._rotationQuaternion!==t&&this._rotationQuaternion.copyFrom(t),this._setDirtyFlagTrue(65),this._setDirtyFlagFalse(2),this._updateWorldRotationFlag()}},{key:"worldRotationQuaternion",get:function(){if(this._isContainDirtyFlag(16)){var t=this._getParentTransform();null!=t?e.Quaternion.multiply(t.worldRotationQuaternion,this.rotationQuaternion,this._worldRotationQuaternion):this._worldRotationQuaternion.copyFrom(this.rotationQuaternion),this._setDirtyFlagFalse(16)}return this._worldRotationQuaternion},set:function(i){this._worldRotationQuaternion!==i&&this._worldRotationQuaternion.copyFrom(i);var n=this._getParentTransform();n?(e.Quaternion.invert(n.worldRotationQuaternion,t._tempQuat0),e.Quaternion.multiply(i,t._tempQuat0,this._rotationQuaternion)):this._rotationQuaternion.copyFrom(i),this.rotationQuaternion=this._rotationQuaternion,this._setDirtyFlagFalse(16)}},{key:"scale",get:function(){return this._scale},set:function(t){this._scale!==t&&this._scale.copyFrom(t),this._setDirtyFlagTrue(64),this._updateWorldScaleFlag()}},{key:"localMatrix",get:function(){return this._isContainDirtyFlag(64)&&(e.Matrix.affineTransformation(this._scale,this.rotationQuaternion,this._position,this._localMatrix),this._setDirtyFlagFalse(64)),this._localMatrix},set:function(t){this._localMatrix!==t&&this._localMatrix.copyFrom(t),this._localMatrix.decompose(this._position,this._rotationQuaternion,this._scale),this._setDirtyFlagTrue(1),this._setDirtyFlagFalse(64),this._updateAllWorldFlag()}},{key:"worldMatrix",get:function(){if(this._isContainDirtyFlag(128)){var t=this._getParentTransform();t?e.Matrix.multiply(t.worldMatrix,this.localMatrix,this._worldMatrix):this._worldMatrix.copyFrom(this.localMatrix),this._setDirtyFlagFalse(128)}return this._worldMatrix},set:function(i){this._worldMatrix!==i&&this._worldMatrix.copyFrom(i);var n=this._getParentTransform();n?(e.Matrix.invert(n.worldMatrix,t._tempMat42),e.Matrix.multiply(t._tempMat42,i,this._localMatrix)):this._localMatrix.copyFrom(i),this.localMatrix=this._localMatrix,this._setDirtyFlagFalse(128)}}]),t}();p._tempQuat0=new e.Quaternion,p._tempMat42=new e.Matrix,(a=l||(l={}))[a.LocalEuler=1]="LocalEuler",a[a.LocalQuat=2]="LocalQuat",a[a.WorldPosition=4]="WorldPosition",a[a.WorldEuler=8]="WorldEuler",a[a.WorldQuat=16]="WorldQuat",a[a.WorldScale=32]="WorldScale",a[a.LocalMatrix=64]="LocalMatrix",a[a.WorldMatrix=128]="WorldMatrix",a[a.WmWp=132]="WmWp",a[a.WmWeWq=152]="WmWeWq",a[a.WmWpWeWq=156]="WmWpWeWq",a[a.WmWs=160]="WmWs",a[a.WmWpWs=164]="WmWpWs",a[a.WmWpWeWqWs=188]="WmWpWeWqWs";var f=function(){function t(){this._shapes=[],this._transform=new p,this._transform.owner=this}var e=t.prototype;return e.addShape=function(t){var e=t._collider;e!==this&&(e&&e.removeShape(t),this._shapes.push(t),t._collider=this)},e.removeShape=function(t){var e=this._shapes.indexOf(t);-1!==e&&(this._shapes.splice(e,1),t._collider=null)},e.setWorldTransform=function(t,e){this._transform.setPosition(t.x,t.y,t.z),this._transform.setRotationQuaternion(e.x,e.y,e.z,e.w)},e.getWorldTransform=function(t,e){var i=this._transform,n=i.position,s=i.rotationQuaternion;t.set(n.x,n.y,n.z),e.set(s.x,s.y,s.z,s.w)},e.destroy=function(){},e._raycast=function(t,e,i){i.distance=Number.MAX_VALUE;for(var n=this._shapes,s=0,o=n.length;s<o;s++){var r=n[s];e(r._id)&&r._raycast(t,i)}return i.distance!=Number.MAX_VALUE},t}(),y=function(t){function e(e,i){var n;return(n=t.call(this)||this)._transform.setPosition(e.x,e.y,e.z),n._transform.setRotationQuaternion(i.x,i.y,i.z,i.w),n}n(e,t);var i=e.prototype;return i.addForce=function(t){throw"Physics-lite don't support addForce. Use Physics-PhysX instead!"},i.addTorque=function(t){throw"Physics-lite don't support addTorque. Use Physics-PhysX instead!"},i.move=function(t,e){throw"Physics-lite don't support move. Use Physics-PhysX instead!"},i.sleep=function(){throw"Physics-lite don't support putToSleep. Use Physics-PhysX instead!"},i.setAngularDamping=function(t){throw"Physics-lite don't support setAngularDamping. Use Physics-PhysX instead!"},i.setAngularVelocity=function(t){throw"Physics-lite don't support setAngularVelocity. Use Physics-PhysX instead!"},i.setCenterOfMass=function(t){throw"Physics-lite don't support setCenterOfMass. Use Physics-PhysX instead!"},i.setCollisionDetectionMode=function(t){throw"Physics-lite don't support setCollisionDetectionMode. Use Physics-PhysX instead!"},i.setConstraints=function(t){throw"Physics-lite don't support setConstraints. Use Physics-PhysX instead!"},i.setInertiaTensor=function(t){throw"Physics-lite don't support setInertiaTensor. Use Physics-PhysX instead!"},i.setIsKinematic=function(t){throw"Physics-lite don't support setIsKinematic. Use Physics-PhysX instead!"},i.setLinearDamping=function(t){throw"Physics-lite don't support setLinearDamping. Use Physics-PhysX instead!"},i.setLinearVelocity=function(t){throw"Physics-lite don't support setLinearVelocity. Use Physics-PhysX instead!"},i.setMass=function(t){throw"Physics-lite don't support setMass. Use Physics-PhysX instead!"},i.setMaxAngularVelocity=function(t){throw"Physics-lite don't support setMaxAngularVelocity. Use Physics-PhysX instead!"},i.setMaxDepenetrationVelocity=function(t){throw"Physics-lite don't support setMaxDepenetrationVelocity. Use Physics-PhysX instead!"},i.setSleepThreshold=function(t){throw"Physics-lite don't support setSleepThreshold. Use Physics-PhysX instead!"},i.setSolverIterations=function(t){throw"Physics-lite don't support setSolverIterations. Use Physics-PhysX instead!"},i.wakeUp=function(){throw"Physics-lite don't support wakeUp. Use Physics-PhysX instead!"},e}(f),g=function(){function t(t){void 0===t&&(t=0),this.length=0,this._elements=Array(t)}var e=t.prototype;return e.add=function(t){this.length===this._elements.length?this._elements.push(t):this._elements[this.length]=t,this.length++},e.delete=function(t){var e=this._elements.indexOf(t);this.deleteByIndex(e)},e.get=function(t){if(t>=this.length)throw"Index is out of range.";return this._elements[t]},e.deleteByIndex=function(t){var e=this._elements,i=null,n=this.length-1;return t!==n&&(i=e[n],e[t]=i),this.length--,i},e.garbageCollection=function(){this._elements.length=this.length},t}(),m=function(){this.shapeID=-1,this.distance=0,this.point=new e.Vector3,this.normal=new e.Vector3},P=function(t){function i(i,n,s){var o;return(o=t.call(this)||this)._halfSize=new e.Vector3,o._scale=new e.Vector3(1,1,1),o._boxMin=new e.Vector3(-.5,-.5,-.5),o._boxMax=new e.Vector3(.5,.5,.5),o._id=i,o._halfSize.set(.5*n.x,.5*n.y,.5*n.z),o._setBondingBox(),o}n(i,t);var s=i.prototype;return s.setPosition=function(e){t.prototype.setPosition.call(this,e),this._setBondingBox()},s.setWorldScale=function(t){this._transform.position=this._transform.position.multiply(t),this._scale.copyFrom(t)},s.setSize=function(t){this._halfSize.set(.5*t.x,.5*t.y,.5*t.z),this._setBondingBox()},s._raycast=function(t,e){var n=this._getLocalRay(t),s=i._tempBox;s.min.set(-this._halfSize.x*this._scale.x,-this._halfSize.y*this._scale.y,-this._halfSize.z*this._scale.z),s.max.set(this._halfSize.x*this._scale.x,this._halfSize.y*this._scale.y,this._halfSize.z*this._scale.z);var o=n.intersectBox(s);return -1!==o&&(this._updateHitResult(n,o,e,t.origin),!0)},s._setBondingBox=function(){var t=this._transform.position,i=this._halfSize;e.Vector3.add(t,i,this._boxMax),e.Vector3.subtract(t,i,this._boxMin)},i}(_);P._tempBox=new e.BoundingBox;var x=function(t){function i(e,i,n){var s;return(s=t.call(this)||this)._radius=1,s._maxScale=1,s._radius=i,s._id=e,s}n(i,t);var s=i.prototype;return s.setRadius=function(t){this._radius=t},s.setWorldScale=function(t){this._maxScale=Math.max(t.x,Math.max(t.x,t.y))},s._raycast=function(t,n){var s=i._tempSphere;e.Vector3.transformCoordinate(this._transform.position,this._collider._transform.worldMatrix,s.center),s.radius=this.worldRadius;var o=t.intersectSphere(s);return -1!==o&&(this._updateHitResult(t,o,n,t.origin,!0),!0)},o(i,[{key:"worldRadius",get:function(){return this._radius*this._maxScale}}]),i}(_);x._tempSphere=new e.BoundingSphere;var v=function(){function t(t,i,n,s,o,r){this._colliders=[],this._sphere=new e.BoundingSphere,this._box=new e.BoundingBox,this._currentEvents=new g,this._eventMap={},this._eventPool=[],this._onContactEnter=t,this._onContactExit=i,this._onContactStay=n,this._onTriggerEnter=s,this._onTriggerExit=o,this._onTriggerStay=r}var i=t.prototype;return i.setGravity=function(t){console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!")},i.addColliderShape=function(t){this._eventMap[t._id]={}},i.removeColliderShape=function(t){for(var e=this._eventPool,i=this._currentEvents,n=t._id,s=i.length-1;s>=0;s--){var o=i.get(s);(o.index1==n||o.index2==n)&&(i.deleteByIndex(s),e.push(o))}delete this._eventMap[n]},i.addCollider=function(t){this._colliders.push(t)},i.removeCollider=function(t){var e=this._colliders.indexOf(t);-1!==e&&this._colliders.splice(e,1)},i.update=function(t){for(var e=this._colliders,i=0,n=e.length;i<n;i++)this._collisionDetection(t,e[i]);this._fireEvent()},i.raycast=function(e,i,n,s){var o,r=this._colliders;s&&(o=t._hitResult);for(var a=!1,h=t._currentHit,l=0,c=r.length;l<c;l++)if(r[l]._raycast(e,n,h)&&(a=!0,h.distance<i)){if(!o)return!0;o.normal.copyFrom(h.normal),o.point.copyFrom(h.point),o.distance=h.distance,o.shapeID=h.shapeID,i=h.distance}return!a&&o?(o.shapeID=-1,o.distance=0,o.point.set(0,0,0),o.normal.set(0,0,0)):a&&o&&s(o.shapeID,o.distance,o.point,o.normal),a},i.addCharacterController=function(t){throw"Physics-lite don't support addCharacterController. Use Physics-PhysX instead!"},i.removeCharacterController=function(t){throw"Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!"},i._getTrigger=function(t,e){var i;return this._eventPool.length?((i=this._eventPool.pop()).index1=t,i.index2=e):i=new w(t,e),this._eventMap[t][e]=i,i},i._collisionDetection=function(e,i){for(var n=this._colliders,s=i._shapes,o=0,a=s.length;o<a;o++){var h=s[o];if(r(h,P)){t._updateWorldBox(h,this._box);for(var l=0,c=n.length;l<c;l++)for(var u=n[l]._shapes,d=0,_=u.length;d<_;d++){var p=u[d],f=p._id,y=h._id,g=f<y?this._eventMap[f][y]:this._eventMap[y][f];if((void 0===g||g.alreadyInvoked)&&p!=h&&this._boxCollision(p)){if(void 0===g){var m=f<y?this._getTrigger(f,y):this._getTrigger(y,f);m.state=0,m.alreadyInvoked=!1,this._currentEvents.add(m)}else 0===g.state?(g.state=1,g.alreadyInvoked=!1):1===g.state&&(g.alreadyInvoked=!1)}}}else if(r(h,x)){t._upWorldSphere(h,this._sphere);for(var v=0,w=n.length;v<w;v++)for(var M=n[v]._shapes,F=0,C=M.length;F<C;F++){var W=M[F],S=W._id,U=h._id,D=S<U?this._eventMap[S][U]:this._eventMap[U][S];if((void 0===D||D.alreadyInvoked)&&W!=h&&this._sphereCollision(W)){if(void 0===D){var Q=S<U?this._getTrigger(S,U):this._getTrigger(U,S);Q.state=0,Q.alreadyInvoked=!1,this._currentEvents.add(Q)}else 0===D.state?(D.state=1,D.alreadyInvoked=!1):1===D.state&&(D.alreadyInvoked=!1)}}}}},i._fireEvent=function(){for(var t=this._eventPool,e=this._currentEvents,i=e.length-1;i>=0;i--){var n=e.get(i);n.alreadyInvoked?(n.state=2,this._eventMap[n.index1][n.index2]=void 0,this._onTriggerExit(n.index1,n.index2),e.deleteByIndex(i),t.push(n)):0==n.state?(this._onTriggerEnter(n.index1,n.index2),n.alreadyInvoked=!0):1==n.state&&(this._onTriggerStay(n.index1,n.index2),n.alreadyInvoked=!0)}},i._boxCollision=function(i){if(r(i,P)){var n=t._tempBox;return t._updateWorldBox(i,n),e.CollisionUtil.intersectsBoxAndBox(n,this._box)}if(r(i,x)){var s=t._tempSphere;return t._upWorldSphere(i,s),e.CollisionUtil.intersectsSphereAndBox(s,this._box)}return!1},i._sphereCollision=function(i){if(r(i,P)){var n=t._tempBox;return t._updateWorldBox(i,n),e.CollisionUtil.intersectsSphereAndBox(this._sphere,n)}if(r(i,x)){var s=t._tempSphere;return t._upWorldSphere(i,s),e.CollisionUtil.intersectsSphereAndSphere(s,this._sphere)}return!1},t._updateWorldBox=function(t,i){var n=t._transform.worldMatrix;i.min.copyFrom(t._boxMin),i.max.copyFrom(t._boxMax),e.BoundingBox.transform(i,n,i)},t._upWorldSphere=function(t,i){e.Vector3.transformCoordinate(t._transform.position,t._transform.worldMatrix,i.center),i.radius=t.worldRadius},t}();v._tempSphere=new e.BoundingSphere,v._tempBox=new e.BoundingBox,v._currentHit=new m,v._hitResult=new m,(h=c||(c={}))[h.Enter=0]="Enter",h[h.Stay=1]="Stay",h[h.Exit=2]="Exit";var w=function(t,e){this.alreadyInvoked=!1,this.index1=t,this.index2=e},M=function(){function t(t,e,i,n,s){}var e=t.prototype;return e.setBounciness=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setDynamicFriction=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setStaticFriction=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setBounceCombine=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.setFrictionCombine=function(t){throw"Physics-lite don't support physics material. Use Physics-PhysX instead!"},e.destroy=function(){},t}(),F=function(t){function e(e,i){var n;return(n=t.call(this)||this)._transform.setPosition(e.x,e.y,e.z),n._transform.setRotationQuaternion(i.x,i.y,i.z,i.w),n}return n(e,t),e}(f);t.LitePhysics=function(){function t(){}return t.createPhysicsManager=function(t,e,i,n,s,o){return new v(t,e,i,n,s,o)},t.createStaticCollider=function(t,e){return new F(t,e)},t.createDynamicCollider=function(t,e){return new y(t,e)},t.createCharacterController=function(){throw"Physics-lite don't support createCharacterController. Use Physics-PhysX instead!"},t.createPhysicsMaterial=function(t,e,i,n,s){return new M(t,e,i,n,s)},t.createBoxColliderShape=function(t,e,i){return new P(t,e,i)},t.createSphereColliderShape=function(t,e,i){return new x(t,e,i)},t.createPlaneColliderShape=function(t,e){throw"Physics-lite don't support PlaneColliderShape. Use Physics-PhysX instead!"},t.createCapsuleColliderShape=function(t,e,i,n){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createFixedJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createHingeJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t.createSpringJoint=function(t){throw"Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!"},t}(),t.LitePhysics=function(t,e,i,n){var s,o=arguments.length,r=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(r=(o<3?s(r):o>3?s(e,i,r):s(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r}([function(t){}],t.LitePhysics),Object.defineProperty(t,"__esModule",{value:!0})});
|
package/dist/main.js
CHANGED
|
@@ -2,18 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _ts_decorate = require('@swc/helpers/src/_ts_decorate.mjs');
|
|
6
|
-
var _inherits = require('@swc/helpers/src/_inherits.mjs');
|
|
7
|
-
var _create_class = require('@swc/helpers/src/_create_class.mjs');
|
|
8
|
-
var _instanceof = require('@swc/helpers/src/_instanceof.mjs');
|
|
9
5
|
var engine = require('@galacean/engine');
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
|
|
22
|
+
function __decorate(decorators, target, key, desc) {
|
|
23
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _set_prototype_of(o, p) {
|
|
30
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
31
|
+
o.__proto__ = p;
|
|
32
|
+
|
|
33
|
+
return o;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return _set_prototype_of(o, p);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _inherits(subClass, superClass) {
|
|
40
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
41
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
42
|
+
}
|
|
12
43
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
44
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
|
|
45
|
+
|
|
46
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _defineProperties(target, props) {
|
|
50
|
+
for (var i = 0; i < props.length; i++) {
|
|
51
|
+
var descriptor = props[i];
|
|
52
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
53
|
+
descriptor.configurable = true;
|
|
54
|
+
|
|
55
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
56
|
+
|
|
57
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
61
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
62
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
63
|
+
|
|
64
|
+
return Constructor;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function _instanceof(left, right) {
|
|
68
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
69
|
+
return !!right[Symbol.hasInstance](left);
|
|
70
|
+
} else return left instanceof right;
|
|
71
|
+
}
|
|
17
72
|
|
|
18
73
|
/**
|
|
19
74
|
* Fastly remove an element from array.
|
|
@@ -143,8 +198,12 @@ var _instanceof__default = /*#__PURE__*/_interopDefaultLegacy(_instanceof);
|
|
|
143
198
|
};
|
|
144
199
|
return LiteColliderShape;
|
|
145
200
|
}();
|
|
146
|
-
|
|
147
|
-
LiteColliderShape.
|
|
201
|
+
(function() {
|
|
202
|
+
LiteColliderShape._ray = new engine.Ray();
|
|
203
|
+
})();
|
|
204
|
+
(function() {
|
|
205
|
+
LiteColliderShape._tempPoint = new engine.Vector3();
|
|
206
|
+
})();
|
|
148
207
|
|
|
149
208
|
/**
|
|
150
209
|
* Used to implement transformation related functions.
|
|
@@ -204,7 +263,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
204
263
|
*/ _proto._updateWorldPositionFlag = function _updateWorldPositionFlag() {
|
|
205
264
|
if (!this._isContainDirtyFlags(0x84)) {
|
|
206
265
|
this._worldAssociatedChange(0x84);
|
|
207
|
-
if (
|
|
266
|
+
if (_instanceof(this._owner, LiteCollider)) {
|
|
208
267
|
var shapes = this._owner._shapes;
|
|
209
268
|
for(var i = 0, n = shapes.length; i < n; i++){
|
|
210
269
|
shapes[i]._transform._updateWorldPositionFlag();
|
|
@@ -221,7 +280,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
221
280
|
*/ _proto._updateWorldRotationFlag = function _updateWorldRotationFlag() {
|
|
222
281
|
if (!this._isContainDirtyFlags(0x98)) {
|
|
223
282
|
this._worldAssociatedChange(0x98);
|
|
224
|
-
if (
|
|
283
|
+
if (_instanceof(this._owner, LiteCollider)) {
|
|
225
284
|
var shapes = this._owner._shapes;
|
|
226
285
|
for(var i = 0, n = shapes.length; i < n; i++){
|
|
227
286
|
shapes[i]._transform._updateWorldRotationFlag();
|
|
@@ -237,7 +296,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
237
296
|
*/ _proto._updateWorldScaleFlag = function _updateWorldScaleFlag() {
|
|
238
297
|
if (!this._isContainDirtyFlags(0xa0)) {
|
|
239
298
|
this._worldAssociatedChange(0xa0);
|
|
240
|
-
if (
|
|
299
|
+
if (_instanceof(this._owner, LiteCollider)) {
|
|
241
300
|
var shapes = this._owner._shapes;
|
|
242
301
|
for(var i = 0, n = shapes.length; i < n; i++){
|
|
243
302
|
shapes[i]._transform._updateWorldScaleFlag();
|
|
@@ -250,7 +309,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
250
309
|
*/ _proto._updateAllWorldFlag = function _updateAllWorldFlag() {
|
|
251
310
|
if (!this._isContainDirtyFlags(0xbc)) {
|
|
252
311
|
this._worldAssociatedChange(0xbc);
|
|
253
|
-
if (
|
|
312
|
+
if (_instanceof(this._owner, LiteCollider)) {
|
|
254
313
|
var shapes = this._owner._shapes;
|
|
255
314
|
for(var i = 0, n = shapes.length; i < n; i++){
|
|
256
315
|
shapes[i]._transform._updateAllWorldFlag();
|
|
@@ -263,7 +322,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
263
322
|
return this._parentTransformCache;
|
|
264
323
|
}
|
|
265
324
|
var parentCache = null;
|
|
266
|
-
if (
|
|
325
|
+
if (_instanceof(this._owner, LiteColliderShape)) {
|
|
267
326
|
var parent = this._owner._collider;
|
|
268
327
|
parentCache = parent._transform;
|
|
269
328
|
}
|
|
@@ -287,7 +346,7 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
287
346
|
this._dirtyFlag |= type;
|
|
288
347
|
this._updateFlagManager.distribute();
|
|
289
348
|
};
|
|
290
|
-
|
|
349
|
+
_create_class(LiteTransform, [
|
|
291
350
|
{
|
|
292
351
|
key: "owner",
|
|
293
352
|
set: function set(value) {
|
|
@@ -436,8 +495,12 @@ LiteColliderShape._tempPoint = new engine.Vector3();
|
|
|
436
495
|
]);
|
|
437
496
|
return LiteTransform;
|
|
438
497
|
}();
|
|
439
|
-
|
|
440
|
-
LiteTransform.
|
|
498
|
+
(function() {
|
|
499
|
+
LiteTransform._tempQuat0 = new engine.Quaternion();
|
|
500
|
+
})();
|
|
501
|
+
(function() {
|
|
502
|
+
LiteTransform._tempMat42 = new engine.Matrix();
|
|
503
|
+
})();
|
|
441
504
|
var /**
|
|
442
505
|
* Dirty flag of transform.
|
|
443
506
|
*/ TransformFlag;
|
|
@@ -521,7 +584,7 @@ var /**
|
|
|
521
584
|
/**
|
|
522
585
|
* A dynamic collider can act with self-defined movement or physical force
|
|
523
586
|
*/ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
524
|
-
|
|
587
|
+
_inherits(LiteDynamicCollider, LiteCollider);
|
|
525
588
|
function LiteDynamicCollider(position, rotation) {
|
|
526
589
|
var _this;
|
|
527
590
|
_this = LiteCollider.call(this) || this;
|
|
@@ -687,7 +750,7 @@ var /**
|
|
|
687
750
|
/**
|
|
688
751
|
* Box collider shape in Lite.
|
|
689
752
|
*/ var LiteBoxColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
|
|
690
|
-
|
|
753
|
+
_inherits(LiteBoxColliderShape, LiteColliderShape);
|
|
691
754
|
function LiteBoxColliderShape(uniqueID, size, material) {
|
|
692
755
|
var _this;
|
|
693
756
|
_this = LiteColliderShape.call(this) || this;
|
|
@@ -742,12 +805,14 @@ var /**
|
|
|
742
805
|
};
|
|
743
806
|
return LiteBoxColliderShape;
|
|
744
807
|
}(LiteColliderShape);
|
|
745
|
-
|
|
808
|
+
(function() {
|
|
809
|
+
LiteBoxColliderShape._tempBox = new engine.BoundingBox();
|
|
810
|
+
})();
|
|
746
811
|
|
|
747
812
|
/**
|
|
748
813
|
* Sphere collider shape in Lite.
|
|
749
814
|
*/ var LiteSphereColliderShape = /*#__PURE__*/ function(LiteColliderShape) {
|
|
750
|
-
|
|
815
|
+
_inherits(LiteSphereColliderShape, LiteColliderShape);
|
|
751
816
|
function LiteSphereColliderShape(uniqueID, radius, material) {
|
|
752
817
|
var _this;
|
|
753
818
|
_this = LiteColliderShape.call(this) || this;
|
|
@@ -782,7 +847,7 @@ LiteBoxColliderShape._tempBox = new engine.BoundingBox();
|
|
|
782
847
|
return false;
|
|
783
848
|
}
|
|
784
849
|
};
|
|
785
|
-
|
|
850
|
+
_create_class(LiteSphereColliderShape, [
|
|
786
851
|
{
|
|
787
852
|
key: "worldRadius",
|
|
788
853
|
get: function get() {
|
|
@@ -792,7 +857,9 @@ LiteBoxColliderShape._tempBox = new engine.BoundingBox();
|
|
|
792
857
|
]);
|
|
793
858
|
return LiteSphereColliderShape;
|
|
794
859
|
}(LiteColliderShape);
|
|
795
|
-
|
|
860
|
+
(function() {
|
|
861
|
+
LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
862
|
+
})();
|
|
796
863
|
|
|
797
864
|
/**
|
|
798
865
|
* A manager is a collection of colliders and constraints which can interact.
|
|
@@ -922,7 +989,7 @@ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
|
922
989
|
var myColliderShapes = myCollider._shapes;
|
|
923
990
|
for(var i = 0, len = myColliderShapes.length; i < len; i++){
|
|
924
991
|
var myShape = myColliderShapes[i];
|
|
925
|
-
if (
|
|
992
|
+
if (_instanceof(myShape, LiteBoxColliderShape)) {
|
|
926
993
|
LitePhysicsManager._updateWorldBox(myShape, this._box);
|
|
927
994
|
for(var j = 0, len1 = colliders.length; j < len1; j++){
|
|
928
995
|
var colliderShape = colliders[j]._shapes;
|
|
@@ -949,7 +1016,7 @@ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
|
949
1016
|
}
|
|
950
1017
|
}
|
|
951
1018
|
}
|
|
952
|
-
} else if (
|
|
1019
|
+
} else if (_instanceof(myShape, LiteSphereColliderShape)) {
|
|
953
1020
|
LitePhysicsManager._upWorldSphere(myShape, this._sphere);
|
|
954
1021
|
for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
|
|
955
1022
|
var colliderShape1 = colliders[j1]._shapes;
|
|
@@ -1001,11 +1068,11 @@ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
|
1001
1068
|
}
|
|
1002
1069
|
};
|
|
1003
1070
|
_proto._boxCollision = function _boxCollision(other) {
|
|
1004
|
-
if (
|
|
1071
|
+
if (_instanceof(other, LiteBoxColliderShape)) {
|
|
1005
1072
|
var box = LitePhysicsManager._tempBox;
|
|
1006
1073
|
LitePhysicsManager._updateWorldBox(other, box);
|
|
1007
1074
|
return engine.CollisionUtil.intersectsBoxAndBox(box, this._box);
|
|
1008
|
-
} else if (
|
|
1075
|
+
} else if (_instanceof(other, LiteSphereColliderShape)) {
|
|
1009
1076
|
var sphere = LitePhysicsManager._tempSphere;
|
|
1010
1077
|
LitePhysicsManager._upWorldSphere(other, sphere);
|
|
1011
1078
|
return engine.CollisionUtil.intersectsSphereAndBox(sphere, this._box);
|
|
@@ -1013,11 +1080,11 @@ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
|
1013
1080
|
return false;
|
|
1014
1081
|
};
|
|
1015
1082
|
_proto._sphereCollision = function _sphereCollision(other) {
|
|
1016
|
-
if (
|
|
1083
|
+
if (_instanceof(other, LiteBoxColliderShape)) {
|
|
1017
1084
|
var box = LitePhysicsManager._tempBox;
|
|
1018
1085
|
LitePhysicsManager._updateWorldBox(other, box);
|
|
1019
1086
|
return engine.CollisionUtil.intersectsSphereAndBox(this._sphere, box);
|
|
1020
|
-
} else if (
|
|
1087
|
+
} else if (_instanceof(other, LiteSphereColliderShape)) {
|
|
1021
1088
|
var sphere = LitePhysicsManager._tempSphere;
|
|
1022
1089
|
LitePhysicsManager._upWorldSphere(other, sphere);
|
|
1023
1090
|
return engine.CollisionUtil.intersectsSphereAndSphere(sphere, this._sphere);
|
|
@@ -1044,10 +1111,18 @@ LiteSphereColliderShape._tempSphere = new engine.BoundingSphere();
|
|
|
1044
1111
|
};
|
|
1045
1112
|
return LitePhysicsManager;
|
|
1046
1113
|
}();
|
|
1047
|
-
|
|
1048
|
-
LitePhysicsManager.
|
|
1049
|
-
|
|
1050
|
-
|
|
1114
|
+
(function() {
|
|
1115
|
+
LitePhysicsManager._tempSphere = new engine.BoundingSphere();
|
|
1116
|
+
})();
|
|
1117
|
+
(function() {
|
|
1118
|
+
LitePhysicsManager._tempBox = new engine.BoundingBox();
|
|
1119
|
+
})();
|
|
1120
|
+
(function() {
|
|
1121
|
+
LitePhysicsManager._currentHit = new LiteHitResult();
|
|
1122
|
+
})();
|
|
1123
|
+
(function() {
|
|
1124
|
+
LitePhysicsManager._hitResult = new LiteHitResult();
|
|
1125
|
+
})();
|
|
1051
1126
|
var /**
|
|
1052
1127
|
* Physics state
|
|
1053
1128
|
*/ TriggerEventState;
|
|
@@ -1104,7 +1179,7 @@ var /**
|
|
|
1104
1179
|
* A static collider component that will not move.
|
|
1105
1180
|
* @remarks Mostly used for object which always stays at the same place and never moves around.
|
|
1106
1181
|
*/ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
1107
|
-
|
|
1182
|
+
_inherits(LiteStaticCollider, LiteCollider);
|
|
1108
1183
|
function LiteStaticCollider(position, rotation) {
|
|
1109
1184
|
var _this;
|
|
1110
1185
|
_this = LiteCollider.call(this) || this;
|
|
@@ -1187,7 +1262,7 @@ exports.LitePhysics = /*#__PURE__*/ function() {
|
|
|
1187
1262
|
};
|
|
1188
1263
|
return LitePhysics;
|
|
1189
1264
|
}();
|
|
1190
|
-
exports.LitePhysics =
|
|
1265
|
+
exports.LitePhysics = __decorate([
|
|
1191
1266
|
StaticInterfaceImplement()
|
|
1192
1267
|
], exports.LitePhysics);
|
|
1193
1268
|
//# sourceMappingURL=main.js.map
|