@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 1.68 kB
JavaScript
import{platform as t}from"../../core/platform.js";import{Mat4 as i}from"../../core/math/mat4.js";import{Quat as r}from"../../core/math/quat.js";import{Vec3 as o}from"../../core/math/vec3.js";const s=t.browser&&window.XRHand?["thumb-tip","index-finger-tip","middle-finger-tip","ring-finger-tip","pinky-finger-tip"]:[],n={};for(let t=0;t<s.length;t++)n[s[t]]=!0;class a{constructor(t,s,a,h=null){this._index=void 0,this._id=void 0,this._hand=void 0,this._finger=void 0,this._wrist=void 0,this._tip=void 0,this._radius=null,this._localTransform=new i,this._worldTransform=new i,this._localPosition=new o,this._localRotation=new r,this._position=new o,this._rotation=new r,this._dirtyLocal=!0,this._index=t,this._id=s,this._hand=a,this._finger=h,this._wrist="wrist"===s,this._tip=this._finger&&!!n[s]}update(t){this._dirtyLocal=!0,this._radius=t.radius,this._localPosition.copy(t.transform.position),this._localRotation.copy(t.transform.orientation)}_updateTransforms(){this._dirtyLocal&&(this._dirtyLocal=!1,this._localTransform.setTRS(this._localPosition,this._localRotation,o.ONE));const t=this._hand._manager.camera.parent;t?this._worldTransform.mul2(t.getWorldTransform(),this._localTransform):this._worldTransform.copy(this._localTransform)}getPosition(){return this._updateTransforms(),this._worldTransform.getTranslation(this._position),this._position}getRotation(){return this._updateTransforms(),this._rotation.setFromMat4(this._worldTransform),this._rotation}get index(){return this._index}get hand(){return this._hand}get finger(){return this._finger}get wrist(){return this._wrist}get tip(){return this._tip}get radius(){return this._radius||.005}}export{a as XrJoint};