Skip to content

Commit

Permalink
WebXR: optional onLoad callback when loading hands or controllers (m…
Browse files Browse the repository at this point in the history
…rdoob#27544)

* WebXR: add onLoad callback for XRHandMeshModel

* add onLoad for XRControllerModelFactory
  • Loading branch information
hybridherbst authored and AdaRoseCannon committed Jan 15, 2024
1 parent 7769afd commit 0923b39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/jsm/webxr/XRControllerModelFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ function addAssetSceneToControllerModel( controllerModel, scene ) {

class XRControllerModelFactory {

constructor( gltfLoader = null ) {
constructor( gltfLoader = null, onLoad = null ) {

this.gltfLoader = gltfLoader;
this.path = DEFAULT_PROFILES_PATH;
this._assetCache = {};
this.onLoad = onLoad;

// If a GLTFLoader wasn't supplied to the constructor create a new one.
if ( ! this.gltfLoader ) {
Expand Down Expand Up @@ -247,6 +248,8 @@ class XRControllerModelFactory {

addAssetSceneToControllerModel( controllerModel, scene );

if ( this.onLoad ) this.onLoad( scene );

} else {

if ( ! this.gltfLoader ) {
Expand All @@ -264,6 +267,8 @@ class XRControllerModelFactory {

addAssetSceneToControllerModel( controllerModel, scene );

if ( this.onLoad ) this.onLoad( scene );

},
null,
() => {
Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/webxr/XRHandMeshModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const DEFAULT_HAND_PROFILE_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-pro

class XRHandMeshModel {

constructor( handModel, controller, path, handedness, loader = null ) {
constructor( handModel, controller, path, handedness, loader = null, onLoad = null ) {

this.controller = controller;
this.handModel = handModel;
Expand Down Expand Up @@ -74,6 +74,8 @@ class XRHandMeshModel {

} );

if ( onLoad ) onLoad( object );

} );

}
Expand Down

0 comments on commit 0923b39

Please sign in to comment.