Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebXR: optional onLoad callback when loading hands or controllers #27544

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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