Skip to content

Commit

Permalink
[XR] Failproof the snippet reference in NearInteraction
Browse files Browse the repository at this point in the history
  • Loading branch information
RaananW committed May 8, 2024
1 parent ad08fb3 commit fb055eb
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions packages/dev/core/src/XR/features/WebXRNearInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Animation } from "../../Animations/animation";
import { QuadraticEase, EasingFunction } from "../../Animations/easing";
// side effects
import "../../Meshes/subMesh.project";
import { Logger } from "core/Misc/logger";

type ControllerData = {
xrController?: WebXRInputSource;
Expand Down Expand Up @@ -132,6 +133,13 @@ export interface IWebXRNearInteractionOptions {
* Optional material for the motion controller orb, if enabled
*/
motionControllerOrbMaterial?: Material;

/**
* If provided, this URL will be used by Node Material to generate the material for the motion controller orb
* If not provided, a snippet will be downloaded from the Babylon.js snippet server CDN.
* The NME JSON file can be found here - https://github.com/BabylonJS/Assets/blob/master/nme/nearInteractionTouchMaterial.json
*/
motionControllerTouchMaterialSnippetUrl?: string;
}

/**
Expand Down Expand Up @@ -842,9 +850,19 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
if (this._options.motionControllerOrbMaterial) {
touchCollisionMesh.material = this._options.motionControllerOrbMaterial;
} else {
NodeMaterial.ParseFromSnippetAsync("8RUNKL#3", meshCreationScene).then((nodeMaterial) => {
touchCollisionMesh.material = nodeMaterial;
});
let parsePromise: Promise<NodeMaterial>;
if (this._options.motionControllerTouchMaterialSnippetUrl) {
parsePromise = NodeMaterial.ParseFromFileAsync("motionControllerTouchMaterial", this._options.motionControllerTouchMaterialSnippetUrl, meshCreationScene);
} else {
parsePromise = NodeMaterial.ParseFromSnippetAsync("8RUNKL#3", meshCreationScene);
}
parsePromise
.then((mat) => {
touchCollisionMesh.material = mat;
})
.catch((err) => {
Logger.Warn(`Error creating touch material in WebXRNearInteraction: ${err}`);
});
}

const easingFunction = new QuadraticEase();
Expand Down

0 comments on commit fb055eb

Please sign in to comment.