-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Camera focus and tracking #725
Conversation
src/components/camera-tool.js
Outdated
if (track) { | ||
this.trackTarget = el; | ||
|
||
this.trackTarget.addEventListener("componentremoved", e => { |
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.
Is there a better way to do this? Trying to detect removal of the element.
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.
The "correct" way is probably using a MutationObserver but in this case I would probably just check for this.trackTarget && !this.trackTarget.parrentNode
in tick
.
|
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.
Nice little feature. We should definitely rename the camera
system, surprised this didn't cause major issues since it should shadow the built in camera
system in aframe. I would also get rid of the Vector3 allocation in lookAt, the other suggestions are up to you.
src/systems/cameras.js
Outdated
@@ -0,0 +1,28 @@ | |||
// Used for tracking and managing camera tools in the scene | |||
AFRAME.registerSystem("cameras", { |
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.
ooh, while reading all the rest of the code I was assuming this was the system for the build in aframe camera
component (which is also called camera
so I am surprised this didn't break everything). We should call this camera-tool
, it also then gets automatically bound in camera-tool
component as this.system
src/systems/cameras.js
Outdated
this.currentCamera = null; | ||
}, | ||
|
||
getCurrent() { |
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.
What does it mean for a camera to be "current", maybe this should be `getMyCamera"
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.
haha I called it that originally but had a flashback to Windows 95 and reverted it. I think its better though, you're right.
src/components/camera-tool.js
Outdated
@@ -88,6 +88,12 @@ AFRAME.registerComponent("camera-tool", { | |||
selfieScreen.scale.set(-2, 2, 2); | |||
this.el.setObject3D("selfieScreen", selfieScreen); | |||
|
|||
this.cameraSystem = this.el.sceneEl.systems.cameras; | |||
|
|||
if (this.cameraSystem) { |
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 would ditch this defensive if, if the system doesn't exist something bad has happened, and this if would just put us in a weird state where this camera inst registered instead of complaining loudly.
src/components/camera-tool.js
Outdated
if (track) { | ||
this.trackTarget = el; | ||
|
||
this.trackTarget.addEventListener("componentremoved", e => { |
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.
The "correct" way is probably using a MutationObserver but in this case I would probably just check for this.trackTarget && !this.trackTarget.parrentNode
in tick
.
}, | ||
|
||
lookAt(el) { | ||
const targetPos = new THREE.Vector3(); |
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.
You are creating a new THREE.Vector3
every tick here, I would rewrite this as:
lookAt: (function() {
const targetPos = new THREE.Vector3();
return function(el) {
this.el.object3D.lookAt(targetPos.setFromMatrixPosition(el.object3D.matrixWorld));
}
})(),
}); | ||
|
||
this.onClick = () => { | ||
if (!this.cameraSystem) return; |
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 would get rid of all these defensive checks for camera system existence.
const shouldBeVisible = !!(this.cameraSystem && this.cameraSystem.getCurrent()); | ||
|
||
if (isVisible !== shouldBeVisible) { | ||
this.el.setAttribute("visible", shouldBeVisible); |
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.
Would rewrite this to use threejs visibility directly this.el.object3D.visible = shouldBeVisible
Adds the ability to focus and track objects on your current camera.
Note this feature isn't going to be very useful until we fix the pause menu on avatars, which seems broken. Once fixed, we should add "focus" and "track" buttons to avatars as well.