-
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
Place media frame content in world space coordinates #4279
Conversation
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.
lgtm, some minor comments. I probably should have just done this originally instead of making a TODO heh. If I remember correctly I was fighting some annoying physics system bugs at the time so was trying to keep things as simple as possible.
src/systems/media-frames.js
Outdated
@@ -250,8 +250,13 @@ AFRAME.registerComponent("media-frame", { | |||
|
|||
snapObject(capturedEl) { | |||
// TODO this assumes media frames are all in world space | |||
capturedEl.object3D.position.copy(this.el.object3D.position); | |||
capturedEl.object3D.rotation.copy(this.el.object3D.rotation); | |||
const worldPosition = 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.
Not so bad since this isn't run every frame but we should avoid allocating these vectors every time, either by just pulling it out into the root of the file, or in a closure for this function alone. I will often just create a const tmpWorldPos = new THREE.Vector3()
in a file to use for this sort of thing.
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.
Yeah, I thought that being non a tick function would be fine but it makes sense to avoid instancing if possible. Updated.
src/systems/media-frames.js
Outdated
this.el.object3D.getWorldPosition(worldPosition); | ||
capturedEl.object3D.position.copy(worldPosition); | ||
const worldQuat = new THREE.Quaternion(); | ||
this.el.object3D.updateWorldMatrix(true); |
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 should not need to manually call this, and in fact we don't want to because it will cause extra work. See https://github.com/mozilla/hubs/blob/master/src/utils/threejs-world-update.js#L22. Also worth reading through these rules and this file in general if you havent yet. Not following these rules is source of most of our hubs-specific threejs issues... I do hope we can get rid of it some day, but when we implemented it there was a big performance win, especially due to all the extra Object3Ds aframe introduces into the scene graph.
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.
Humm, I didn't know about that file. I've remove the updateWorldMatrix
call.
src/systems/media-frames.js
Outdated
@@ -250,8 +250,13 @@ AFRAME.registerComponent("media-frame", { | |||
|
|||
snapObject(capturedEl) { | |||
// TODO this assumes media frames are all in world space |
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.
This PR fixes this todo so we should remove it.
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.
Updated.
@netpro2k Updated. |
We are currently placing elements in
media-frame
s based on local coordinates so nestedmedia-frame
s don't place them correctly.Test scene: https://hubs.mozilla.com/scenes/4zXCrZE