@vladkrutenyuk/three-kvy-core
Version:
Everything you need to create any-complexity 3D apps with Three.js. Empower Three.js with a modular, lifecycle-managed context that seamlessly propagates through objects via reusable features providing structured logic.
3 lines (2 loc) • 1.09 kB
JavaScript
import{utils as e}from"@vladkrutenyuk/three-kvy-core";import{RapierPhysics as i}from"./RapierPhysics.js";import{Rigidbody as o}from"./Rigidbody.js";const{defineProps:t,readOnly:s}=e.props,n=Object.freeze({None:0,Obj2Body:2,Body2Obj:4});class r extends o{constructor(e,i){super(e),this.isRigidbodyKinematic=!0,this._syncMode=0,t(this,{isRigidbodyKinematic:s(!0)}),this.setSyncMode((null==i?void 0:i.syncMode)||0)}useCtx(e){console.log("RigidbodyKinematic useCtx");const o=i.findInCtx(e);if(!o)throw new Error("'RapierPhysics' is not found in context");const t=o.world,s=o.api,n=this.getObjWorldPos(),r=this.getObjWorldQuat(),d=s.RigidBodyDesc.kinematicPositionBased().setTranslation(n.x,n.y,n.z).setRotation(r),c=t.createRigidBody(d);return this._rb=c,()=>{t.removeRigidBody(c),this._rb=void 0}}getSyncMode(){return this._syncMode}setSyncMode(e){return this._syncMode=e,this}onBeforeRender(){switch(this._syncMode){case 2:this.syncObjectToBody();break;case 4:this.syncBodyToObjectKinematically()}}}export{r as RigidbodyKinematic,n as SyncMode};
//# sourceMappingURL=RigidbodyKinematic.js.map