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

Place media frame content in world space coordinates #4279

Merged
merged 2 commits into from
May 26, 2021

Conversation

keianhzo
Copy link
Contributor

@keianhzo keianhzo commented May 21, 2021

We are currently placing elements in media-frames based on local coordinates so nested media-frames don't place them correctly.

Test scene: https://hubs.mozilla.com/scenes/4zXCrZE

Copy link
Contributor

@netpro2k netpro2k left a 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.

@@ -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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

this.el.object3D.getWorldPosition(worldPosition);
capturedEl.object3D.position.copy(worldPosition);
const worldQuat = new THREE.Quaternion();
this.el.object3D.updateWorldMatrix(true);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -250,8 +250,13 @@ AFRAME.registerComponent("media-frame", {

snapObject(capturedEl) {
// TODO this assumes media frames are all in world space
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@keianhzo
Copy link
Contributor Author

@netpro2k Updated.

@keianhzo keianhzo requested a review from netpro2k May 25, 2021 11:37
@keianhzo keianhzo merged commit a18235b into master May 26, 2021
@keianhzo keianhzo deleted the media-frame-world-space branch May 26, 2021 22:04
@camelgod
Copy link

Will this affect these issues at all?

#4102
#4089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants