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

Move to current viewport transform when updating scene #263

Merged
merged 5 commits into from
Feb 13, 2024

Conversation

keianhzo
Copy link
Contributor

@keianhzo keianhzo commented Jan 9, 2024

This PR adds support for scene update moving the avatar to the same position as the current Blender 3D view transform so you can focus on specific details of the scene without needing to move there after the scene is updated.

This does not change the head orientation, that will stay the same as it was before, it only moves the avatar to the same position as the 3D viewport camera.

@keianhzo keianhzo changed the title Move to current viewport transform Move to current viewport transform when updating scene Jan 11, 2024
@keianhzo keianhzo requested a review from Exairnous January 15, 2024 09:55
Copy link
Contributor

@Exairnous Exairnous left a comment

Choose a reason for hiding this comment

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

This looks pretty good. I've mentioned a couple things in inline comments, but overall it's quite nice!
Note: the changes requested status is for the hard coded stuff.

Comment on lines +72 to +76
from mathutils import Matrix, Vector, Euler
from math import radians
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these imports mixed into the code here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know of any reason why locally imported modules are bad (if there is any let me know). I usally import globally for modules that are widely used and locally for modules that are specific to a function. There are quite a lot of cases of this throught the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Locally imported modules aren't bad per se, but (in my opinion) keeping imports at the top makes it easier to see what a file depends on, gives a consistent spot to look for this information, and prevents duplication. Sometimes they have to be imported in the middle of code to resolve dependency issues or other bugs and that's what I thought was usually the reason they had been added throughout the code (and that's the main reason I asked, because I wondered if you were working around a bug). In certain cases they may cause a slowdown in the middle of execution instead of at the beginning (but that's likely not an issue here). Also, PEP8 does specify for imports to be placed at the top: https://peps.python.org/pep-0008/#imports
This page also gives some reasons for placing them at the top: https://www.quora.com/Should-import-be-above-all-from-statements-in-Python-If-yes-why

bpy.ops.object.empty_add(location=final_loc, rotation=(euler.x, euler.y, euler.z), type="ARROWS")
viewpoint = bpy.context.object
viewpoint.name = "__scene_debugger_viewpoint"
from .components.utils import add_component
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, why is this import mixed into the code here?

Copy link
Contributor Author

@keianhzo keianhzo Feb 13, 2024

Choose a reason for hiding this comment

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

Same as above. Also for imports among our own file I try to do local importas to avoid circular dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

final_loc = loc + Vector((0, 0, -1.6))
rot_offset = Matrix.Rotation(radians(180), 4, 'Z').to_4x4()
final_rot = rot.to_matrix().to_4x4() @ rot_offset
euler: Euler = final_rot.to_euler()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this annotated? (Nothing else is annotated here)

Copy link
Contributor Author

@keianhzo keianhzo Feb 13, 2024

Choose a reason for hiding this comment

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

Yeah we don't really do that a lot, i can remove it although I don't think it hurts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. And yeah, it doesn't hurt, but I don't think it adds anything here either and it's inconsistent.

Comment on lines +97 to +101
hubs_session.move_to_waypoint("__scene_debugger_viewpoint")
ob = bpy.context.scene.objects["__scene_debugger_viewpoint"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should use viewpoint.name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I follow. We are checking if the object in line 65 exists or not, if we check for the attribute that will throw an exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry. I wasn't clear. I wasn't talking about the if check, I was referring to the two lines below it that use the hard coded version of viewpoint.name ("__scene_debugger_viewpoint"), if you use viewpoint.name as the arguments then if that ever needs changing there's only one spot to change it.

return {'FINISHED'}
except Exception as err:
print(err)
bpy.ops.wm.hubs_report_viewer('INVOKE_DEFAULT', title="Hubs scene debugger report", report_string='\n\n'.join(
["The scene export has failed", "Check the export logs or quit the browser instance and try again", f'{err}']))

if viewpoint:
ob = bpy.context.scene.objects["__scene_debugger_viewpoint"]
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, I think this should use viewpoint.name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor

Choose a reason for hiding this comment

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

See above.

Comment on lines +362 to +366
row = box.row()
row.prop(context.scene.hubs_scene_debugger_room_export_prefs, "avatar_to_viewport")
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to not do anything when spawning as an object (which is what I'd expect), so what do you think about greying it out?

if "debugLocalScene" not in hubs_session.room_params:
            row.active = False

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!. I'll add that.

try {
setTimeout(() => {
window.location = `${window.location.href}#${arguments[0]}`;
const mat = APP.world.scene.getObjectByName("__scene_debugger_viewpoint").matrixWorld;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should also use ${arguments[0] instead of hard coding __scene_debugger_viewpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good call. Updated.

@@ -175,3 +175,14 @@ def load_prefs(context):
new_room = prefs.hubs_rooms.add()
new_room.name = room["name"]
new_room.url = room["url"]


def find_area():
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should take the area type and would make a good generic function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Added.

This PR adds support for scene update moving the avatar to the same position as the current Blender 3D view transform so you can focus on specific details of the scene without needing to move there after the scene is updated.

This does not change the head orientation, that will stay the same as it was before, it only moves the avatar to the same position as the 3D viewport camera.
@keianhzo keianhzo force-pushed the spawn-on-viewport-transform branch from 5f8b227 to efbe8fd Compare February 13, 2024 11:13
@keianhzo keianhzo merged commit 28cb741 into master Feb 13, 2024
6 checks passed
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.

2 participants