-
Notifications
You must be signed in to change notification settings - Fork 295
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
Less confusing doc with the new introduced networked-hand-controls #362
Changes from 3 commits
74e3689
e03f895
7f1ddcd
7052160
bf872d5
15b7a4d
a88029a
8d0624d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,20 +20,20 @@ function addHandTemplate(hand) { | |
let templateOuter = document.createElement('template'); | ||
let templateInner = document.createElement('a-entity'); | ||
|
||
templateOuter.id = `${hand}-hand-template`; | ||
templateInner.setAttribute('networked-hand-controls',`hand: ${hand}`); | ||
templateOuter.id = `${hand}-hand-default-template`; | ||
templateInner.setAttribute('networked-hand-controls', `hand: ${hand}`); | ||
|
||
templateOuter.appendChild(templateInner); | ||
|
||
NAF.schemas.schemaDict[`#${hand}-hand-template`] = { | ||
template: `#${hand}-hand-template`, | ||
NAF.schemas.schemaDict[`#${hand}-hand-default-template`] = { | ||
template: `#${hand}-hand-default-template`, | ||
components: [ | ||
'position', | ||
'rotation', | ||
'networked-hand-controls', | ||
] | ||
}; | ||
NAF.schemas.templateCache[`#${hand}-hand-template`] = templateOuter; | ||
NAF.schemas.templateCache[`#${hand}-hand-default-template`] = templateOuter; | ||
} | ||
["left","right"].forEach(addHandTemplate); | ||
|
||
|
@@ -68,39 +68,39 @@ AFRAME.registerComponent('networked-hand-controls', { | |
|
||
init() { | ||
this.setup(); | ||
this.el.setAttribute('networked', 'template', `#${this.data.hand}-hand-template`); | ||
this.el.setAttribute('networked', 'attachTemplateToLocal', true); | ||
|
||
this.local = this.el.components.networked.createdByMe(); | ||
|
||
if (this.local) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by removing this condition, we do the binding unnecessarily for networked entities that don't respond to events. not a huge deal, but it's an unnecessary inefficiency. Since you moved/improved the this.local detection, you could move these method bindings to be async / done after line 91. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
for (const evtName in this.buttonEventMap) { | ||
this.eventFunctionMap[this.data.hand][evtName] = this.handleButton.bind(this, ...this.buttonEventMap[evtName]); | ||
} | ||
for (const evtName in this.visibleListeners) { | ||
this.eventFunctionMap[this.data.hand][evtName] = this.visibleListeners[evtName].bind(this); | ||
} | ||
for (const evtName in this.buttonEventMap) { | ||
this.eventFunctionMap[this.data.hand][evtName] = this.handleButton.bind(this, ...this.buttonEventMap[evtName]); | ||
} | ||
else { | ||
this.el.classList.add('naf-remote-hand'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can I ask why we remove this? this makes it easier to view in the a-frame inspector at a glance, if nothing else. I am a fan of things getting classes and IDs where possible to make things more viewable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see it used anywhere so I removed it. I almost never use the aframe inspector, so I didn't see the value of it, but you make a good point. I'll put it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
for (const evtName in this.visibleListeners) { | ||
this.eventFunctionMap[this.data.hand][evtName] = this.visibleListeners[evtName].bind(this); | ||
} | ||
|
||
if (this.data.handModelStyle !== "controller") { | ||
this.addHandModel(); | ||
} | ||
if (this.local) { | ||
this.addControllerComponents(this.data.handModelStyle == "controller"); | ||
} | ||
|
||
NAF.utils.getNetworkedEntity(this.el).then((networkedEl) => { | ||
// Here networkedEl may be different than this.el if we don't use nested | ||
// networked components for hands. | ||
this.local = networkedEl.components.networked.createdByMe(); | ||
}).catch(() => { | ||
this.local = true; | ||
}).then(() => { | ||
if (this.local) { | ||
this.addControllerComponents(this.data.handModelStyle === "controller"); | ||
} | ||
}); | ||
}, | ||
|
||
play() { | ||
if (this.local) { | ||
this.addEventListeners(); | ||
this.addEventListeners(); | ||
} | ||
}, | ||
|
||
pause() { | ||
if (this.local) { | ||
if (this.local) { | ||
this.removeEventListeners(); | ||
} | ||
}, | ||
|
@@ -119,7 +119,7 @@ AFRAME.registerComponent('networked-hand-controls', { | |
oldData.handModelStyle !== this.data.handModelStyle | ||
) { | ||
// first, remove old model | ||
this.el.removeObject3D(this.str.mesh); | ||
if (this.getMesh()) this.el.removeObject3D(this.str.mesh); | ||
['gltf-model','obj-model'].forEach(modelComponent => { | ||
if (this.el.components[modelComponent]) { | ||
this.el.removeAttribute(modelComponent); | ||
|
@@ -134,12 +134,14 @@ AFRAME.registerComponent('networked-hand-controls', { | |
// this.el.setAttribute(this.data.controllerComponent, 'model', true) | ||
|
||
// so we first remove the controller component | ||
if (this.el.components[this.data.controllerComponent]) { | ||
if (this.data.controllerComponent && this.el.components[this.data.controllerComponent]) { | ||
this.el.removeAttribute(this.data.controllerComponent); | ||
} | ||
|
||
if (!this.local) { | ||
this.injectRemoteControllerModel(); | ||
if (!this.injectedController && this.data.controllerComponent && this.data.webxrControllerProfiles[0]) { | ||
this.injectRemoteControllerModel(); | ||
} | ||
} | ||
else { | ||
this.addControllerComponents(true); | ||
|
@@ -201,17 +203,19 @@ AFRAME.registerComponent('networked-hand-controls', { | |
this.el.setObject3D(this.str.mesh, newMesh); | ||
|
||
const handMaterial = newMesh.children[1].material; | ||
handMaterial.color = new THREE.Color(this.data.handColor); | ||
handMaterial.color = new THREE.Color(this.data.color); | ||
this.el.sceneEl.systems.renderer.applyColorCorrection(handMaterial.color); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why duplicate this code instead of calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have the handMaterial variable here and we set the color already, calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I defined |
||
newMesh.position.set(0, 0, 0); | ||
newMesh.rotation.set(0, 0, handModelOrientation); | ||
|
||
this.updateHandMeshColor(); | ||
}); | ||
}, | ||
|
||
updateHandMeshColor() { | ||
this.getMesh().children[1].material.color.set(this.data.color); | ||
this.el.sceneEl.systems.renderer.applyColorCorrection(this.getMesh().children[1].material.color); | ||
const mesh = this.getMesh(); | ||
if (!mesh) return; | ||
const handMaterial = mesh.children[1].material; | ||
handMaterial.color.set(this.data.color); | ||
this.el.sceneEl.systems.renderer.applyColorCorrection(handMaterial.color); | ||
}, | ||
|
||
controllerComponents: [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have done this, but good to fix now: this should probably be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I introduced
and used it everywhere.