three-stdlib 2.26.5 → 2.26.6
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/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
@@ -2789,7 +2789,7 @@ _loadNodeShallow(nodeIndex){const json=this.json;const extensions=this.extension
|
|
2789
2789
|
* Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
2790
2790
|
* @param {number} sceneIndex
|
2791
2791
|
* @return {Promise<Group>}
|
2792
|
-
*/loadScene(sceneIndex){const extensions=this.extensions;const sceneDef=this.json.scenes[sceneIndex];const parser=this;const scene=new Group();if(sceneDef.name)scene.name=parser.createUniqueName(sceneDef.name);assignExtrasToUserData(scene,sceneDef);if(sceneDef.extensions)addUnknownExtensionsToUserData(extensions,scene,sceneDef);const nodeIds=sceneDef.nodes||[];const pending=[];for(let i2=0,il=nodeIds.length;i2<il;i2++){pending.push(parser.getDependency("node",nodeIds[i2]));}return Promise.all(pending).then(function(nodes){for(let i2=0,il=nodes.length;i2<il;i2++){scene.add(nodes[i2]);}const reduceAssociations=node=>{const reducedAssociations=/* @__PURE__ */new Map();for(const[key,value]of parser.associations){if(key instanceof Material||key instanceof Texture){reducedAssociations.set(key,value);}}node.traverse(node2=>{const mappings=parser.associations.get(node2);if(mappings!=null){reducedAssociations.set(node2,mappings);}});return reducedAssociations;};parser.associations=reduceAssociations(scene);return scene;});}}function computeBounds(geometry2,primitiveDef,parser){const attributes=primitiveDef.attributes;const box=new Box3();if(attributes.POSITION!==void 0){const accessor=parser.json.accessors[attributes.POSITION];const min=accessor.min;const max=accessor.max;if(min!==void 0&&max!==void 0){box.set(new Vector3(min[0],min[1],min[2]),new Vector3(max[0],max[1],max[2]));if(accessor.normalized){const boxScale=getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);box.min.multiplyScalar(boxScale);box.max.multiplyScalar(boxScale);}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return;}}else{return;}const targets=primitiveDef.targets;if(targets!==void 0){const maxDisplacement=new Vector3();const vector=new Vector3();for(let i2=0,il=targets.length;i2<il;i2++){const target=targets[i2];if(target.POSITION!==void 0){const accessor=parser.json.accessors[target.POSITION];const min=accessor.min;const max=accessor.max;if(min!==void 0&&max!==void 0){vector.setX(Math.max(Math.abs(min[0]),Math.abs(max[0])));vector.setY(Math.max(Math.abs(min[1]),Math.abs(max[1])));vector.setZ(Math.max(Math.abs(min[2]),Math.abs(max[2])));if(accessor.normalized){const boxScale=getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);vector.multiplyScalar(boxScale);}maxDisplacement.max(vector);}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");}}}box.expandByVector(maxDisplacement);}geometry2.boundingBox=box;const sphere=new Sphere();box.getCenter(sphere.center);sphere.radius=box.min.distanceTo(box.max)/2;geometry2.boundingSphere=sphere;}function addPrimitiveAttributes(geometry2,primitiveDef,parser){const attributes=primitiveDef.attributes;const pending=[];function assignAttributeAccessor(accessorIndex,attributeName){return parser.getDependency("accessor",accessorIndex).then(function(accessor){geometry2.setAttribute(attributeName,accessor);});}for(const gltfAttributeName in attributes){const threeAttributeName=ATTRIBUTES[gltfAttributeName]||gltfAttributeName.toLowerCase();if(threeAttributeName in geometry2.attributes)continue;pending.push(assignAttributeAccessor(attributes[gltfAttributeName],threeAttributeName));}if(primitiveDef.indices!==void 0&&!geometry2.index){const accessor=parser.getDependency("accessor",primitiveDef.indices).then(function(accessor2){geometry2.setIndex(accessor2);});pending.push(accessor);}assignExtrasToUserData(geometry2,primitiveDef);computeBounds(geometry2,primitiveDef,parser);return Promise.all(pending).then(function(){return primitiveDef.targets!==void 0?addMorphTargets(geometry2,primitiveDef.targets,parser):geometry2;});}const DEFAULT_HAND_PROFILE_PATH="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/";class XRHandMeshModel{constructor(handModel,controller,path=DEFAULT_HAND_PROFILE_PATH,handedness,customModelPath){__publicField(this,"controller");__publicField(this,"handModel");__publicField(this,"bones");this.controller=controller;this.handModel=handModel;this.bones=[];const loader=new GLTFLoader();if(!customModelPath)loader.setPath(path);loader.load(customModelPath!=null?customModelPath:`${handedness}.glb`,gltf=>{const object=gltf.scene.children[0];this.handModel.add(object);const mesh=object.getObjectByProperty("type","SkinnedMesh");mesh.frustumCulled=false;mesh.castShadow=true;mesh.receiveShadow=true;const joints=["wrist","thumb-metacarpal","thumb-phalanx-proximal","thumb-phalanx-distal","thumb-tip","index-finger-metacarpal","index-finger-phalanx-proximal","index-finger-phalanx-intermediate","index-finger-phalanx-distal","index-finger-tip","middle-finger-metacarpal","middle-finger-phalanx-proximal","middle-finger-phalanx-intermediate","middle-finger-phalanx-distal","middle-finger-tip","ring-finger-metacarpal","ring-finger-phalanx-proximal","ring-finger-phalanx-intermediate","ring-finger-phalanx-distal","ring-finger-tip","pinky-finger-metacarpal","pinky-finger-phalanx-proximal","pinky-finger-phalanx-intermediate","pinky-finger-phalanx-distal","pinky-finger-tip"];joints.forEach(jointName=>{const bone=object.getObjectByName(jointName);if(bone!==void 0){bone.jointName=jointName;}else{console.warn(`Couldn't find ${jointName} in ${handedness} hand mesh`);}this.bones.push(bone);});});}updateMesh(){const XRJoints=this.controller.joints;for(let i2=0;i2<this.bones.length;i2++){const bone=this.bones[i2];if(bone){const XRJoint=XRJoints[bone.jointName];if(XRJoint.visible){const position=XRJoint.position;bone.position.copy(position);bone.quaternion.copy(XRJoint.quaternion);}}}}}const TOUCH_RADIUS=0.01;const POINTING_JOINT="index-finger-tip";class OculusHandModel extends Object3D{constructor(controller,leftModelPath,rightModelPath){super();__publicField(this,"controller");__publicField(this,"motionController");__publicField(this,"envMap");__publicField(this,"mesh");__publicField(this,"xrInputSource");this.controller=controller;this.motionController=null;this.envMap=null;this.mesh=null;this.xrInputSource=null;controller.addEventListener("connected",event=>{const xrInputSource=event.data;if(xrInputSource.hand&&!this.motionController){this.xrInputSource=xrInputSource;this.motionController=new XRHandMeshModel(this,controller,void 0,xrInputSource.handedness,xrInputSource.handedness==="left"?leftModelPath:rightModelPath);}});controller.addEventListener("disconnected",()=>{this.dispose();});}updateMatrixWorld(force){super.updateMatrixWorld(force);if(this.motionController){this.motionController.updateMesh();}}getPointerPosition(){const indexFingerTip=this.controller.joints[POINTING_JOINT];if(indexFingerTip){return indexFingerTip.position;}else{return null;}}intersectBoxObject(boxObject){const pointerPosition=this.getPointerPosition();if(pointerPosition){const indexSphere=new Sphere(pointerPosition,TOUCH_RADIUS);const box=new Box3().setFromObject(boxObject);return indexSphere.intersectsBox(box);}else{return false;}}checkButton(button){if(this.intersectBoxObject(button)){button.onPress();}else{button.onClear();}if(button.isPressed()){button.whilePressed();}}dispose(){this.clear();this.motionController=null;}}const PINCH_MAX=0.05;const PINCH_THRESHOLD=0.02;const PINCH_MIN=0.01;const POINTER_ADVANCE_MAX=0.02;const POINTER_OPACITY_MAX=1;const POINTER_OPACITY_MIN=0.4;const POINTER_FRONT_RADIUS=2e-3;const POINTER_REAR_RADIUS=0.01;const POINTER_REAR_RADIUS_MIN=3e-3;const POINTER_LENGTH=0.035;const POINTER_SEGMENTS=16;const POINTER_RINGS=12;const POINTER_HEMISPHERE_ANGLE=110;const YAXIS=/*@__PURE__*/new THREE.Vector3(0,1,0);const ZAXIS=/*@__PURE__*/new THREE.Vector3(0,0,1);const CURSOR_RADIUS=0.02;const CURSOR_MAX_DISTANCE=1.5;class OculusHandPointerModel extends THREE.Object3D{constructor(hand,controller){super();this.hand=hand;this.controller=controller;this.motionController=null;this.envMap=null;this.mesh=null;this.pointerGeometry=null;this.pointerMesh=null;this.pointerObject=null;this.pinched=false;this.attached=false;this.cursorObject=null;this.raycaster=null;this._onConnected=this._onConnected.bind(this);this._onDisconnected=this._onDisconnected.bind(this);this.hand.addEventListener("connected",this._onConnected);this.hand.addEventListener("disconnected",this._onDisconnected);}_onConnected(event){const xrInputSource=event.data;if(xrInputSource.hand){this.visible=true;this.xrInputSource=xrInputSource;this.createPointer();}}_onDisconnected(){var _a2,_b2;this.visible=false;this.xrInputSource=null;(_a2=this.pointerGeometry)==null?void 0:_a2.dispose();(_b2=this.pointerMesh)==null?void 0:_b2.material.dispose();this.clear();}_drawVerticesRing(vertices,baseVector,ringIndex){const segmentVector=baseVector.clone();for(var i2=0;i2<POINTER_SEGMENTS;i2++){segmentVector.applyAxisAngle(ZAXIS,Math.PI*2/POINTER_SEGMENTS);const vid=ringIndex*POINTER_SEGMENTS+i2;vertices[3*vid]=segmentVector.x;vertices[3*vid+1]=segmentVector.y;vertices[3*vid+2]=segmentVector.z;}}_updatePointerVertices(rearRadius){const vertices=this.pointerGeometry.attributes.position.array;const frontFaceBase=new THREE.Vector3(POINTER_FRONT_RADIUS,0,-1*(POINTER_LENGTH-rearRadius));this._drawVerticesRing(vertices,frontFaceBase,0);const rearBase=new THREE.Vector3(Math.sin(Math.PI*POINTER_HEMISPHERE_ANGLE/180)*rearRadius,Math.cos(Math.PI*POINTER_HEMISPHERE_ANGLE/180)*rearRadius,0);for(var i2=0;i2<POINTER_RINGS;i2++){this._drawVerticesRing(vertices,rearBase,i2+1);rearBase.applyAxisAngle(YAXIS,Math.PI*POINTER_HEMISPHERE_ANGLE/180/(POINTER_RINGS*-2));}const frontCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS);const rearCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS)+1;const frontCenter=new THREE.Vector3(0,0,-1*(POINTER_LENGTH-rearRadius));vertices[frontCenterIndex*3]=frontCenter.x;vertices[frontCenterIndex*3+1]=frontCenter.y;vertices[frontCenterIndex*3+2]=frontCenter.z;const rearCenter=new THREE.Vector3(0,0,rearRadius);vertices[rearCenterIndex*3]=rearCenter.x;vertices[rearCenterIndex*3+1]=rearCenter.y;vertices[rearCenterIndex*3+2]=rearCenter.z;this.pointerGeometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3));}createPointer(){var i2,j;const vertices=new Array(((POINTER_RINGS+1)*POINTER_SEGMENTS+2)*3).fill(0);const indices=[];this.pointerGeometry=new THREE.BufferGeometry();this.pointerGeometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3));this._updatePointerVertices(POINTER_REAR_RADIUS);for(i2=0;i2<POINTER_RINGS;i2++){for(j=0;j<POINTER_SEGMENTS-1;j++){indices.push(i2*POINTER_SEGMENTS+j,i2*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j);indices.push(i2*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j);}indices.push((i2+1)*POINTER_SEGMENTS-1,i2*POINTER_SEGMENTS,(i2+2)*POINTER_SEGMENTS-1);indices.push(i2*POINTER_SEGMENTS,(i2+1)*POINTER_SEGMENTS,(i2+2)*POINTER_SEGMENTS-1);}const frontCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS);const rearCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS)+1;for(i2=0;i2<POINTER_SEGMENTS-1;i2++){indices.push(frontCenterIndex,i2+1,i2);indices.push(rearCenterIndex,i2+POINTER_SEGMENTS*POINTER_RINGS,i2+POINTER_SEGMENTS*POINTER_RINGS+1);}indices.push(frontCenterIndex,0,POINTER_SEGMENTS-1);indices.push(rearCenterIndex,POINTER_SEGMENTS*(POINTER_RINGS+1)-1,POINTER_SEGMENTS*POINTER_RINGS);const material2=new THREE.MeshBasicMaterial();material2.transparent=true;material2.opacity=POINTER_OPACITY_MIN;this.pointerGeometry.setIndex(indices);this.pointerMesh=new THREE.Mesh(this.pointerGeometry,material2);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS);this.pointerObject=new THREE.Object3D();this.pointerObject.add(this.pointerMesh);this.raycaster=new THREE.Raycaster();const cursorGeometry=new THREE.SphereGeometry(CURSOR_RADIUS,10,10);const cursorMaterial=new THREE.MeshBasicMaterial();cursorMaterial.transparent=true;cursorMaterial.opacity=POINTER_OPACITY_MIN;this.cursorObject=new THREE.Mesh(cursorGeometry,cursorMaterial);this.pointerObject.add(this.cursorObject);this.add(this.pointerObject);}_updateRaycaster(){if(this.raycaster){const pointerMatrix=this.pointerObject.matrixWorld;const tempMatrix=new THREE.Matrix4();tempMatrix.identity().extractRotation(pointerMatrix);this.raycaster.ray.origin.setFromMatrixPosition(pointerMatrix);this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(tempMatrix);}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const indexTip=this.hand.joints["index-finger-tip"];const thumbTip=this.hand.joints["thumb-tip"];const distance=indexTip.position.distanceTo(thumbTip.position);const position=indexTip.position.clone().add(thumbTip.position).multiplyScalar(0.5);this.pointerObject.position.copy(position);this.pointerObject.quaternion.copy(this.controller.quaternion);this.pinched=distance<=PINCH_THRESHOLD;const pinchScale=(distance-PINCH_MIN)/(PINCH_MAX-PINCH_MIN);const focusScale=(distance-PINCH_MIN)/(PINCH_THRESHOLD-PINCH_MIN);if(pinchScale>1){this._updatePointerVertices(POINTER_REAR_RADIUS);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN;}else if(pinchScale>0){const rearRadius=(POINTER_REAR_RADIUS-POINTER_REAR_RADIUS_MIN)*pinchScale+POINTER_REAR_RADIUS_MIN;this._updatePointerVertices(rearRadius);if(focusScale<1){this.pointerMesh.position.set(0,0,-1*rearRadius-(1-focusScale)*POINTER_ADVANCE_MAX);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN+(1-focusScale)*(POINTER_OPACITY_MAX-POINTER_OPACITY_MIN);}else{this.pointerMesh.position.set(0,0,-1*rearRadius);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN;}}else{this._updatePointerVertices(POINTER_REAR_RADIUS_MIN);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS_MIN-POINTER_ADVANCE_MAX);this.pointerMesh.material.opacity=POINTER_OPACITY_MAX;}this.cursorObject.material.opacity=this.pointerMesh.material.opacity;}updateMatrixWorld(force){super.updateMatrixWorld(force);if(this.pointerGeometry){this._updatePointer();this._updateRaycaster();}}isPinched(){return this.pinched;}setAttached(attached){this.attached=attached;}isAttached(){return this.attached;}intersectObject(object,recursive=true){if(this.raycaster){return this.raycaster.intersectObject(object,recursive);}}intersectObjects(objects,recursive=true){if(this.raycaster){return this.raycaster.intersectObjects(objects,recursive);}}checkIntersections(objects,recursive=false){if(this.raycaster&&!this.attached){const intersections=this.raycaster.intersectObjects(objects,recursive);const direction=new THREE.Vector3(0,0,-1);if(intersections.length>0){const intersection=intersections[0];const distance=intersection.distance;this.cursorObject.position.copy(direction.multiplyScalar(distance));}else{this.cursorObject.position.copy(direction.multiplyScalar(CURSOR_MAX_DISTANCE));}}}setCursor(distance){const direction=new THREE.Vector3(0,0,-1);if(this.raycaster&&!this.attached){this.cursorObject.position.copy(direction.multiplyScalar(distance));}}dispose(){this._onDisconnected();this.hand.removeEventListener("connected",this._onConnected);this.hand.removeEventListener("disconnected",this._onDisconnected);}}function createText(message,height){const canvas=document.createElement("canvas");const context=canvas.getContext("2d");let metrics=null;const textHeight=100;context.font="normal "+textHeight+"px Arial";metrics=context.measureText(message);const textWidth=metrics.width;canvas.width=textWidth;canvas.height=textHeight;context.font="normal "+textHeight+"px Arial";context.textAlign="center";context.textBaseline="middle";context.fillStyle="#ffffff";context.fillText(message,textWidth/2,textHeight/2);const texture=new THREE.Texture(canvas);texture.needsUpdate=true;const material2=new THREE.MeshBasicMaterial({color:16777215,side:THREE.DoubleSide,map:texture,transparent:true});const geometry2=new THREE.PlaneGeometry(height*textWidth/textHeight,height);const plane=new THREE.Mesh(geometry2,material2);return plane;}const _VRButton=class{static createButton(renderer,sessionInit={}){const button=document.createElement("button");function showEnterVR(){let currentSession=null;async function onSessionStarted(session){session.addEventListener("end",onSessionEnded);await renderer.xr.setSession(session);button.textContent="EXIT VR";currentSession=session;}function onSessionEnded(){currentSession.removeEventListener("end",onSessionEnded);button.textContent="ENTER VR";currentSession=null;}button.style.display="";button.style.cursor="pointer";button.style.left="calc(50% - 50px)";button.style.width="100px";button.textContent="ENTER VR";button.onmouseenter=()=>{button.style.opacity="1.0";};button.onmouseleave=()=>{button.style.opacity="0.5";};button.onclick=()=>{var _a2;if(currentSession===null){const optionalFeatures=[sessionInit.optionalFeatures,"local-floor","bounded-floor","hand-tracking"].flat().filter(Boolean);(_a2=navigator.xr)==null?void 0:_a2.requestSession("immersive-vr",{...sessionInit,optionalFeatures}).then(onSessionStarted);}else{currentSession.end();}};}function disableButton(){button.style.display="";button.style.cursor="auto";button.style.left="calc(50% - 75px)";button.style.width="150px";button.onmouseenter=null;button.onmouseleave=null;button.onclick=null;}function showWebXRNotFound(){disableButton();button.textContent="VR NOT SUPPORTED";}function stylizeElement(element){element.style.position="absolute";element.style.bottom="20px";element.style.padding="12px 6px";element.style.border="1px solid #fff";element.style.borderRadius="4px";element.style.background="rgba(0,0,0,0.1)";element.style.color="#fff";element.style.font="normal 13px sans-serif";element.style.textAlign="center";element.style.opacity="0.5";element.style.outline="none";element.style.zIndex="999";}if("xr"in navigator){stylizeElement(button);button.id="VRButton";button.style.display="none";navigator.xr.isSessionSupported("immersive-vr").then(supported=>{supported?showEnterVR():showWebXRNotFound();if(supported&&_VRButton.xrSessionIsGranted){button.click();}});return button;}else{const message=document.createElement("a");if(window.isSecureContext===false){message.href=document.location.href.replace(/^http:/,"https:");message.innerHTML="WEBXR NEEDS HTTPS";}else{message.href="https://immersiveweb.dev/";message.innerHTML="WEBXR NOT AVAILABLE";}message.style.left="calc(50% - 90px)";message.style.width="180px";message.style.textDecoration="none";stylizeElement(message);return message;}}static registerSessionGrantedListener(){if("xr"in navigator){navigator.xr.addEventListener("sessiongranted",()=>{_VRButton.xrSessionIsGranted=true;});}}};let VRButton=_VRButton;/*@__PURE__*/__publicField(VRButton,"xrSessionIsGranted",false);/*@__PURE__*/VRButton.registerSessionGrantedListener();const MotionControllerConstants={Handedness:{NONE:"none",LEFT:"left",RIGHT:"right"},ComponentState:{DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"},ComponentProperty:{BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"},ComponentType:{TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"},ButtonTouchThreshold:0.05,AxisTouchThreshold:0.1,VisualResponseProperty:{TRANSFORM:"transform",VISIBILITY:"visibility"}};async function fetchJsonFile(path){const response=await fetch(path);if(!response.ok){throw new Error(response.statusText);}else{return response.json();}}async function fetchProfilesList(basePath){if(!basePath){throw new Error("No basePath supplied");}const profileListFileName="profilesList.json";const profilesList=await fetchJsonFile(`${basePath}/${profileListFileName}`);return profilesList;}async function fetchProfile(xrInputSource,basePath,defaultProfile=null,getAssetPath=true){if(!xrInputSource){throw new Error("No xrInputSource supplied");}if(!basePath){throw new Error("No basePath supplied");}const supportedProfilesList=await fetchProfilesList(basePath);let match=void 0;xrInputSource.profiles.some(profileId=>{const supportedProfile=supportedProfilesList[profileId];if(supportedProfile){match={profileId,profilePath:`${basePath}/${supportedProfile.path}`,deprecated:!!supportedProfile.deprecated};}return!!match;});if(!match){if(!defaultProfile){throw new Error("No matching profile name found");}const supportedProfile=supportedProfilesList[defaultProfile];if(!supportedProfile){throw new Error(`No matching profile name found and default profile "${defaultProfile}" missing.`);}match={profileId:defaultProfile,profilePath:`${basePath}/${supportedProfile.path}`,deprecated:!!supportedProfile.deprecated};}const profile=await fetchJsonFile(match.profilePath);let assetPath=void 0;if(getAssetPath){let layout;if(xrInputSource.handedness==="any"){layout=profile.layouts[Object.keys(profile.layouts)[0]];}else{layout=profile.layouts[xrInputSource.handedness];}if(!layout){throw new Error(`No matching handedness, ${xrInputSource.handedness}, in profile ${match.profileId}`);}if(layout.assetPath){assetPath=match.profilePath.replace("profile.json",layout.assetPath);}}return{profile,assetPath};}const defaultComponentValues={xAxis:0,yAxis:0,button:0,state:MotionControllerConstants.ComponentState.DEFAULT};function normalizeAxes(x=0,y=0){let xAxis2=x;let yAxis2=y;const hypotenuse=Math.sqrt(x*x+y*y);if(hypotenuse>1){const theta=Math.atan2(y,x);xAxis2=Math.cos(theta);yAxis2=Math.sin(theta);}const result={normalizedXAxis:xAxis2*0.5+0.5,normalizedYAxis:yAxis2*0.5+0.5};return result;}class VisualResponse{constructor(visualResponseDescription){__publicField(this,"value");__publicField(this,"componentProperty");__publicField(this,"states");__publicField(this,"valueNodeName");__publicField(this,"valueNodeProperty");__publicField(this,"minNodeName");__publicField(this,"maxNodeName");__publicField(this,"valueNode");__publicField(this,"minNode");__publicField(this,"maxNode");this.componentProperty=visualResponseDescription.componentProperty;this.states=visualResponseDescription.states;this.valueNodeName=visualResponseDescription.valueNodeName;this.valueNodeProperty=visualResponseDescription.valueNodeProperty;if(this.valueNodeProperty===MotionControllerConstants.VisualResponseProperty.TRANSFORM){this.minNodeName=visualResponseDescription.minNodeName;this.maxNodeName=visualResponseDescription.maxNodeName;}this.value=0;this.updateFromComponent(defaultComponentValues);}/**
|
2792
|
+
*/loadScene(sceneIndex){const extensions=this.extensions;const sceneDef=this.json.scenes[sceneIndex];const parser=this;const scene=new Group();if(sceneDef.name)scene.name=parser.createUniqueName(sceneDef.name);assignExtrasToUserData(scene,sceneDef);if(sceneDef.extensions)addUnknownExtensionsToUserData(extensions,scene,sceneDef);const nodeIds=sceneDef.nodes||[];const pending=[];for(let i2=0,il=nodeIds.length;i2<il;i2++){pending.push(parser.getDependency("node",nodeIds[i2]));}return Promise.all(pending).then(function(nodes){for(let i2=0,il=nodes.length;i2<il;i2++){scene.add(nodes[i2]);}const reduceAssociations=node=>{const reducedAssociations=/* @__PURE__ */new Map();for(const[key,value]of parser.associations){if(key instanceof Material||key instanceof Texture){reducedAssociations.set(key,value);}}node.traverse(node2=>{const mappings=parser.associations.get(node2);if(mappings!=null){reducedAssociations.set(node2,mappings);}});return reducedAssociations;};parser.associations=reduceAssociations(scene);return scene;});}}function computeBounds(geometry2,primitiveDef,parser){const attributes=primitiveDef.attributes;const box=new Box3();if(attributes.POSITION!==void 0){const accessor=parser.json.accessors[attributes.POSITION];const min=accessor.min;const max=accessor.max;if(min!==void 0&&max!==void 0){box.set(new Vector3(min[0],min[1],min[2]),new Vector3(max[0],max[1],max[2]));if(accessor.normalized){const boxScale=getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);box.min.multiplyScalar(boxScale);box.max.multiplyScalar(boxScale);}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return;}}else{return;}const targets=primitiveDef.targets;if(targets!==void 0){const maxDisplacement=new Vector3();const vector=new Vector3();for(let i2=0,il=targets.length;i2<il;i2++){const target=targets[i2];if(target.POSITION!==void 0){const accessor=parser.json.accessors[target.POSITION];const min=accessor.min;const max=accessor.max;if(min!==void 0&&max!==void 0){vector.setX(Math.max(Math.abs(min[0]),Math.abs(max[0])));vector.setY(Math.max(Math.abs(min[1]),Math.abs(max[1])));vector.setZ(Math.max(Math.abs(min[2]),Math.abs(max[2])));if(accessor.normalized){const boxScale=getNormalizedComponentScale(WEBGL_COMPONENT_TYPES[accessor.componentType]);vector.multiplyScalar(boxScale);}maxDisplacement.max(vector);}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");}}}box.expandByVector(maxDisplacement);}geometry2.boundingBox=box;const sphere=new Sphere();box.getCenter(sphere.center);sphere.radius=box.min.distanceTo(box.max)/2;geometry2.boundingSphere=sphere;}function addPrimitiveAttributes(geometry2,primitiveDef,parser){const attributes=primitiveDef.attributes;const pending=[];function assignAttributeAccessor(accessorIndex,attributeName){return parser.getDependency("accessor",accessorIndex).then(function(accessor){geometry2.setAttribute(attributeName,accessor);});}for(const gltfAttributeName in attributes){const threeAttributeName=ATTRIBUTES[gltfAttributeName]||gltfAttributeName.toLowerCase();if(threeAttributeName in geometry2.attributes)continue;pending.push(assignAttributeAccessor(attributes[gltfAttributeName],threeAttributeName));}if(primitiveDef.indices!==void 0&&!geometry2.index){const accessor=parser.getDependency("accessor",primitiveDef.indices).then(function(accessor2){geometry2.setIndex(accessor2);});pending.push(accessor);}assignExtrasToUserData(geometry2,primitiveDef);computeBounds(geometry2,primitiveDef,parser);return Promise.all(pending).then(function(){return primitiveDef.targets!==void 0?addMorphTargets(geometry2,primitiveDef.targets,parser):geometry2;});}const DEFAULT_HAND_PROFILE_PATH="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/";class XRHandMeshModel{constructor(handModel,controller,path=DEFAULT_HAND_PROFILE_PATH,handedness,customModelPath){__publicField(this,"controller");__publicField(this,"handModel");__publicField(this,"bones");this.controller=controller;this.handModel=handModel;this.bones=[];const loader=new GLTFLoader();if(!customModelPath)loader.setPath(path);loader.load(customModelPath!=null?customModelPath:`${handedness}.glb`,gltf=>{const object=gltf.scene.children[0];this.handModel.add(object);const mesh=object.getObjectByProperty("type","SkinnedMesh");mesh.frustumCulled=false;mesh.castShadow=true;mesh.receiveShadow=true;const joints=["wrist","thumb-metacarpal","thumb-phalanx-proximal","thumb-phalanx-distal","thumb-tip","index-finger-metacarpal","index-finger-phalanx-proximal","index-finger-phalanx-intermediate","index-finger-phalanx-distal","index-finger-tip","middle-finger-metacarpal","middle-finger-phalanx-proximal","middle-finger-phalanx-intermediate","middle-finger-phalanx-distal","middle-finger-tip","ring-finger-metacarpal","ring-finger-phalanx-proximal","ring-finger-phalanx-intermediate","ring-finger-phalanx-distal","ring-finger-tip","pinky-finger-metacarpal","pinky-finger-phalanx-proximal","pinky-finger-phalanx-intermediate","pinky-finger-phalanx-distal","pinky-finger-tip"];joints.forEach(jointName=>{const bone=object.getObjectByName(jointName);if(bone!==void 0){bone.jointName=jointName;}else{console.warn(`Couldn't find ${jointName} in ${handedness} hand mesh`);}this.bones.push(bone);});});}updateMesh(){const XRJoints=this.controller.joints;for(let i2=0;i2<this.bones.length;i2++){const bone=this.bones[i2];if(bone){const XRJoint=XRJoints[bone.jointName];if(XRJoint.visible){const position=XRJoint.position;bone.position.copy(position);bone.quaternion.copy(XRJoint.quaternion);}}}}}const TOUCH_RADIUS=0.01;const POINTING_JOINT="index-finger-tip";class OculusHandModel extends Object3D{constructor(controller,leftModelPath,rightModelPath){super();__publicField(this,"controller");__publicField(this,"motionController");__publicField(this,"envMap");__publicField(this,"mesh");__publicField(this,"xrInputSource");this.controller=controller;this.motionController=null;this.envMap=null;this.mesh=null;this.xrInputSource=null;controller.addEventListener("connected",event=>{const xrInputSource=event.data;if(xrInputSource.hand&&!this.motionController){this.xrInputSource=xrInputSource;this.motionController=new XRHandMeshModel(this,controller,void 0,xrInputSource.handedness,xrInputSource.handedness==="left"?leftModelPath:rightModelPath);}});controller.addEventListener("disconnected",()=>{this.dispose();});}updateMatrixWorld(force){super.updateMatrixWorld(force);if(this.motionController){this.motionController.updateMesh();}}getPointerPosition(){const indexFingerTip=this.controller.joints[POINTING_JOINT];if(indexFingerTip){return indexFingerTip.position;}else{return null;}}intersectBoxObject(boxObject){const pointerPosition=this.getPointerPosition();if(pointerPosition){const indexSphere=new Sphere(pointerPosition,TOUCH_RADIUS);const box=new Box3().setFromObject(boxObject);return indexSphere.intersectsBox(box);}else{return false;}}checkButton(button){if(this.intersectBoxObject(button)){button.onPress();}else{button.onClear();}if(button.isPressed()){button.whilePressed();}}dispose(){this.clear();this.motionController=null;}}const PINCH_MAX=0.05;const PINCH_THRESHOLD=0.02;const PINCH_MIN=0.01;const POINTER_ADVANCE_MAX=0.02;const POINTER_OPACITY_MAX=1;const POINTER_OPACITY_MIN=0.4;const POINTER_FRONT_RADIUS=2e-3;const POINTER_REAR_RADIUS=0.01;const POINTER_REAR_RADIUS_MIN=3e-3;const POINTER_LENGTH=0.035;const POINTER_SEGMENTS=16;const POINTER_RINGS=12;const POINTER_HEMISPHERE_ANGLE=110;const YAXIS=/*@__PURE__*/new THREE.Vector3(0,1,0);const ZAXIS=/*@__PURE__*/new THREE.Vector3(0,0,1);const CURSOR_RADIUS=0.02;const CURSOR_MAX_DISTANCE=1.5;class OculusHandPointerModel extends THREE.Object3D{constructor(hand,controller){super();this.hand=hand;this.controller=controller;this.motionController=null;this.envMap=null;this.mesh=null;this.pointerGeometry=null;this.pointerMesh=null;this.pointerObject=null;this.pinched=false;this.attached=false;this.cursorObject=null;this.raycaster=null;this._onConnected=this._onConnected.bind(this);this._onDisconnected=this._onDisconnected.bind(this);this.hand.addEventListener("connected",this._onConnected);this.hand.addEventListener("disconnected",this._onDisconnected);}_onConnected(event){const xrInputSource=event.data;if(xrInputSource.hand){this.visible=true;this.xrInputSource=xrInputSource;this.createPointer();}}_onDisconnected(){var _a2,_b2;this.visible=false;this.xrInputSource=null;(_a2=this.pointerGeometry)==null?void 0:_a2.dispose();(_b2=this.pointerMesh)==null?void 0:_b2.material.dispose();this.clear();}_drawVerticesRing(vertices,baseVector,ringIndex){const segmentVector=baseVector.clone();for(var i2=0;i2<POINTER_SEGMENTS;i2++){segmentVector.applyAxisAngle(ZAXIS,Math.PI*2/POINTER_SEGMENTS);const vid=ringIndex*POINTER_SEGMENTS+i2;vertices[3*vid]=segmentVector.x;vertices[3*vid+1]=segmentVector.y;vertices[3*vid+2]=segmentVector.z;}}_updatePointerVertices(rearRadius){const vertices=this.pointerGeometry.attributes.position.array;const frontFaceBase=new THREE.Vector3(POINTER_FRONT_RADIUS,0,-1*(POINTER_LENGTH-rearRadius));this._drawVerticesRing(vertices,frontFaceBase,0);const rearBase=new THREE.Vector3(Math.sin(Math.PI*POINTER_HEMISPHERE_ANGLE/180)*rearRadius,Math.cos(Math.PI*POINTER_HEMISPHERE_ANGLE/180)*rearRadius,0);for(var i2=0;i2<POINTER_RINGS;i2++){this._drawVerticesRing(vertices,rearBase,i2+1);rearBase.applyAxisAngle(YAXIS,Math.PI*POINTER_HEMISPHERE_ANGLE/180/(POINTER_RINGS*-2));}const frontCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS);const rearCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS)+1;const frontCenter=new THREE.Vector3(0,0,-1*(POINTER_LENGTH-rearRadius));vertices[frontCenterIndex*3]=frontCenter.x;vertices[frontCenterIndex*3+1]=frontCenter.y;vertices[frontCenterIndex*3+2]=frontCenter.z;const rearCenter=new THREE.Vector3(0,0,rearRadius);vertices[rearCenterIndex*3]=rearCenter.x;vertices[rearCenterIndex*3+1]=rearCenter.y;vertices[rearCenterIndex*3+2]=rearCenter.z;this.pointerGeometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3));}createPointer(){var i2,j;const vertices=new Array(((POINTER_RINGS+1)*POINTER_SEGMENTS+2)*3).fill(0);const indices=[];this.pointerGeometry=new THREE.BufferGeometry();this.pointerGeometry.setAttribute("position",new THREE.Float32BufferAttribute(vertices,3));this._updatePointerVertices(POINTER_REAR_RADIUS);for(i2=0;i2<POINTER_RINGS;i2++){for(j=0;j<POINTER_SEGMENTS-1;j++){indices.push(i2*POINTER_SEGMENTS+j,i2*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j);indices.push(i2*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j+1,(i2+1)*POINTER_SEGMENTS+j);}indices.push((i2+1)*POINTER_SEGMENTS-1,i2*POINTER_SEGMENTS,(i2+2)*POINTER_SEGMENTS-1);indices.push(i2*POINTER_SEGMENTS,(i2+1)*POINTER_SEGMENTS,(i2+2)*POINTER_SEGMENTS-1);}const frontCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS);const rearCenterIndex=POINTER_SEGMENTS*(1+POINTER_RINGS)+1;for(i2=0;i2<POINTER_SEGMENTS-1;i2++){indices.push(frontCenterIndex,i2+1,i2);indices.push(rearCenterIndex,i2+POINTER_SEGMENTS*POINTER_RINGS,i2+POINTER_SEGMENTS*POINTER_RINGS+1);}indices.push(frontCenterIndex,0,POINTER_SEGMENTS-1);indices.push(rearCenterIndex,POINTER_SEGMENTS*(POINTER_RINGS+1)-1,POINTER_SEGMENTS*POINTER_RINGS);const material2=new THREE.MeshBasicMaterial();material2.transparent=true;material2.opacity=POINTER_OPACITY_MIN;this.pointerGeometry.setIndex(indices);this.pointerMesh=new THREE.Mesh(this.pointerGeometry,material2);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS);this.pointerObject=new THREE.Object3D();this.pointerObject.add(this.pointerMesh);this.raycaster=new THREE.Raycaster();const cursorGeometry=new THREE.SphereGeometry(CURSOR_RADIUS,10,10);const cursorMaterial=new THREE.MeshBasicMaterial();cursorMaterial.transparent=true;cursorMaterial.opacity=POINTER_OPACITY_MIN;this.cursorObject=new THREE.Mesh(cursorGeometry,cursorMaterial);this.pointerObject.add(this.cursorObject);this.add(this.pointerObject);}_updateRaycaster(){if(this.raycaster){const pointerMatrix=this.pointerObject.matrixWorld;const tempMatrix=new THREE.Matrix4();tempMatrix.identity().extractRotation(pointerMatrix);this.raycaster.ray.origin.setFromMatrixPosition(pointerMatrix);this.raycaster.ray.direction.set(0,0,-1).applyMatrix4(tempMatrix);}}_updatePointer(){this.pointerObject.visible=this.controller.visible;const indexTip=this.hand.joints["index-finger-tip"];const thumbTip=this.hand.joints["thumb-tip"];const distance=indexTip.position.distanceTo(thumbTip.position);const position=indexTip.position.clone().add(thumbTip.position).multiplyScalar(0.5);this.pointerObject.position.copy(position);this.pointerObject.quaternion.copy(this.controller.quaternion);this.pinched=distance<=PINCH_THRESHOLD;const pinchScale=(distance-PINCH_MIN)/(PINCH_MAX-PINCH_MIN);const focusScale=(distance-PINCH_MIN)/(PINCH_THRESHOLD-PINCH_MIN);if(pinchScale>1){this._updatePointerVertices(POINTER_REAR_RADIUS);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN;}else if(pinchScale>0){const rearRadius=(POINTER_REAR_RADIUS-POINTER_REAR_RADIUS_MIN)*pinchScale+POINTER_REAR_RADIUS_MIN;this._updatePointerVertices(rearRadius);if(focusScale<1){this.pointerMesh.position.set(0,0,-1*rearRadius-(1-focusScale)*POINTER_ADVANCE_MAX);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN+(1-focusScale)*(POINTER_OPACITY_MAX-POINTER_OPACITY_MIN);}else{this.pointerMesh.position.set(0,0,-1*rearRadius);this.pointerMesh.material.opacity=POINTER_OPACITY_MIN;}}else{this._updatePointerVertices(POINTER_REAR_RADIUS_MIN);this.pointerMesh.position.set(0,0,-1*POINTER_REAR_RADIUS_MIN-POINTER_ADVANCE_MAX);this.pointerMesh.material.opacity=POINTER_OPACITY_MAX;}this.cursorObject.material.opacity=this.pointerMesh.material.opacity;}updateMatrixWorld(force){super.updateMatrixWorld(force);if(this.pointerGeometry){this._updatePointer();this._updateRaycaster();}}isPinched(){return this.pinched;}setAttached(attached){this.attached=attached;}isAttached(){return this.attached;}intersectObject(object,recursive=true){if(this.raycaster){return this.raycaster.intersectObject(object,recursive);}}intersectObjects(objects,recursive=true){if(this.raycaster){return this.raycaster.intersectObjects(objects,recursive);}}checkIntersections(objects,recursive=false){if(this.raycaster&&!this.attached){const intersections=this.raycaster.intersectObjects(objects,recursive);const direction=new THREE.Vector3(0,0,-1);if(intersections.length>0){const intersection=intersections[0];const distance=intersection.distance;this.cursorObject.position.copy(direction.multiplyScalar(distance));}else{this.cursorObject.position.copy(direction.multiplyScalar(CURSOR_MAX_DISTANCE));}}}setCursor(distance){const direction=new THREE.Vector3(0,0,-1);if(this.raycaster&&!this.attached){this.cursorObject.position.copy(direction.multiplyScalar(distance));}}dispose(){this._onDisconnected();this.hand.removeEventListener("connected",this._onConnected);this.hand.removeEventListener("disconnected",this._onDisconnected);}}function createText(message,height){const canvas=document.createElement("canvas");const context=canvas.getContext("2d");let metrics=null;const textHeight=100;context.font="normal "+textHeight+"px Arial";metrics=context.measureText(message);const textWidth=metrics.width;canvas.width=textWidth;canvas.height=textHeight;context.font="normal "+textHeight+"px Arial";context.textAlign="center";context.textBaseline="middle";context.fillStyle="#ffffff";context.fillText(message,textWidth/2,textHeight/2);const texture=new THREE.Texture(canvas);texture.needsUpdate=true;const material2=new THREE.MeshBasicMaterial({color:16777215,side:THREE.DoubleSide,map:texture,transparent:true});const geometry2=new THREE.PlaneGeometry(height*textWidth/textHeight,height);const plane=new THREE.Mesh(geometry2,material2);return plane;}const _VRButton=class{static createButton(renderer,sessionInit={}){const button=document.createElement("button");function showEnterVR(){let currentSession=null;async function onSessionStarted(session){session.addEventListener("end",onSessionEnded);await renderer.xr.setSession(session);button.textContent="EXIT VR";currentSession=session;}function onSessionEnded(){currentSession.removeEventListener("end",onSessionEnded);button.textContent="ENTER VR";currentSession=null;}button.style.display="";button.style.cursor="pointer";button.style.left="calc(50% - 50px)";button.style.width="100px";button.textContent="ENTER VR";button.onmouseenter=()=>{button.style.opacity="1.0";};button.onmouseleave=()=>{button.style.opacity="0.5";};button.onclick=()=>{var _a2;if(currentSession===null){const optionalFeatures=[sessionInit.optionalFeatures,"local-floor","bounded-floor","hand-tracking"].flat().filter(Boolean);(_a2=navigator.xr)==null?void 0:_a2.requestSession("immersive-vr",{...sessionInit,optionalFeatures}).then(onSessionStarted);}else{currentSession.end();}};}function disableButton(){button.style.display="";button.style.cursor="auto";button.style.left="calc(50% - 75px)";button.style.width="150px";button.onmouseenter=null;button.onmouseleave=null;button.onclick=null;}function showWebXRNotFound(){disableButton();button.textContent="VR NOT SUPPORTED";}function stylizeElement(element){element.style.position="absolute";element.style.bottom="20px";element.style.padding="12px 6px";element.style.border="1px solid #fff";element.style.borderRadius="4px";element.style.background="rgba(0,0,0,0.1)";element.style.color="#fff";element.style.font="normal 13px sans-serif";element.style.textAlign="center";element.style.opacity="0.5";element.style.outline="none";element.style.zIndex="999";}if("xr"in navigator){stylizeElement(button);button.id="VRButton";button.style.display="none";navigator.xr.isSessionSupported("immersive-vr").then(supported=>{supported?showEnterVR():showWebXRNotFound();if(supported&&_VRButton.xrSessionIsGranted){button.click();}});return button;}else{const message=document.createElement("a");if(window.isSecureContext===false){message.href=document.location.href.replace(/^http:/,"https:");message.innerHTML="WEBXR NEEDS HTTPS";}else{message.href="https://immersiveweb.dev/";message.innerHTML="WEBXR NOT AVAILABLE";}message.style.left="calc(50% - 90px)";message.style.width="180px";message.style.textDecoration="none";stylizeElement(message);return message;}}static registerSessionGrantedListener(){if(typeof navigator!=="undefined"&&"xr"in navigator){navigator.xr.addEventListener("sessiongranted",()=>{_VRButton.xrSessionIsGranted=true;});}}};let VRButton=_VRButton;/*@__PURE__*/__publicField(VRButton,"xrSessionIsGranted",false);/*@__PURE__*/VRButton.registerSessionGrantedListener();const MotionControllerConstants={Handedness:{NONE:"none",LEFT:"left",RIGHT:"right"},ComponentState:{DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"},ComponentProperty:{BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"},ComponentType:{TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"},ButtonTouchThreshold:0.05,AxisTouchThreshold:0.1,VisualResponseProperty:{TRANSFORM:"transform",VISIBILITY:"visibility"}};async function fetchJsonFile(path){const response=await fetch(path);if(!response.ok){throw new Error(response.statusText);}else{return response.json();}}async function fetchProfilesList(basePath){if(!basePath){throw new Error("No basePath supplied");}const profileListFileName="profilesList.json";const profilesList=await fetchJsonFile(`${basePath}/${profileListFileName}`);return profilesList;}async function fetchProfile(xrInputSource,basePath,defaultProfile=null,getAssetPath=true){if(!xrInputSource){throw new Error("No xrInputSource supplied");}if(!basePath){throw new Error("No basePath supplied");}const supportedProfilesList=await fetchProfilesList(basePath);let match=void 0;xrInputSource.profiles.some(profileId=>{const supportedProfile=supportedProfilesList[profileId];if(supportedProfile){match={profileId,profilePath:`${basePath}/${supportedProfile.path}`,deprecated:!!supportedProfile.deprecated};}return!!match;});if(!match){if(!defaultProfile){throw new Error("No matching profile name found");}const supportedProfile=supportedProfilesList[defaultProfile];if(!supportedProfile){throw new Error(`No matching profile name found and default profile "${defaultProfile}" missing.`);}match={profileId:defaultProfile,profilePath:`${basePath}/${supportedProfile.path}`,deprecated:!!supportedProfile.deprecated};}const profile=await fetchJsonFile(match.profilePath);let assetPath=void 0;if(getAssetPath){let layout;if(xrInputSource.handedness==="any"){layout=profile.layouts[Object.keys(profile.layouts)[0]];}else{layout=profile.layouts[xrInputSource.handedness];}if(!layout){throw new Error(`No matching handedness, ${xrInputSource.handedness}, in profile ${match.profileId}`);}if(layout.assetPath){assetPath=match.profilePath.replace("profile.json",layout.assetPath);}}return{profile,assetPath};}const defaultComponentValues={xAxis:0,yAxis:0,button:0,state:MotionControllerConstants.ComponentState.DEFAULT};function normalizeAxes(x=0,y=0){let xAxis2=x;let yAxis2=y;const hypotenuse=Math.sqrt(x*x+y*y);if(hypotenuse>1){const theta=Math.atan2(y,x);xAxis2=Math.cos(theta);yAxis2=Math.sin(theta);}const result={normalizedXAxis:xAxis2*0.5+0.5,normalizedYAxis:yAxis2*0.5+0.5};return result;}class VisualResponse{constructor(visualResponseDescription){__publicField(this,"value");__publicField(this,"componentProperty");__publicField(this,"states");__publicField(this,"valueNodeName");__publicField(this,"valueNodeProperty");__publicField(this,"minNodeName");__publicField(this,"maxNodeName");__publicField(this,"valueNode");__publicField(this,"minNode");__publicField(this,"maxNode");this.componentProperty=visualResponseDescription.componentProperty;this.states=visualResponseDescription.states;this.valueNodeName=visualResponseDescription.valueNodeName;this.valueNodeProperty=visualResponseDescription.valueNodeProperty;if(this.valueNodeProperty===MotionControllerConstants.VisualResponseProperty.TRANSFORM){this.minNodeName=visualResponseDescription.minNodeName;this.maxNodeName=visualResponseDescription.maxNodeName;}this.value=0;this.updateFromComponent(defaultComponentValues);}/**
|
2793
2793
|
* Computes the visual response's interpolation weight based on component state
|
2794
2794
|
* @param {Object} componentValues - The component from which to update
|
2795
2795
|
* @param {number | undefined} xAxis - The reported X axis value of the component
|