USD: Adding an option to convert the scene's meters per unit value #122804

Open
Charles Wardlaw wants to merge 2 commits from CharlesWardlaw/blender:feature/usd_convert_to_cm into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

This rescales the whole scene by its root transform to match the same visual size while not forcing the user to wait for scale to be applied to each object.

This is requested by studios whose main applications / USD scenes are in CM, because referencing and payloading scenes from disparate scales can cause issues at resolution time.

This rescales the whole scene by its root transform to match the same visual size while not forcing the user to wait for scale to be applied to each object. This is requested by studios whose main applications / USD scenes are in CM, because referencing and payloading scenes from disparate scales can cause issues at resolution time.
Charles Wardlaw added 1 commit 2024-06-05 22:17:33 +02:00
Charles Wardlaw requested review from Michael Kowalski 2024-06-05 22:41:50 +02:00
Charles Wardlaw requested review from Jesse Yurkovich 2024-06-05 22:42:02 +02:00

Thanks for porting this @CharlesWardlaw ! I was thinking that the unit conversion should be made more generic to handle arbitrary unit scaling, not just centimeters. The initial USD branch implementation supported centimeters only, but I always felt that this prototype is too limited in that regard. It shouldn't be hard to extend this to handle other units. What do you think?

Thanks for porting this @CharlesWardlaw ! I was thinking that the unit conversion should be made more generic to handle arbitrary unit scaling, not just centimeters. The initial USD branch implementation supported centimeters only, but I always felt that this prototype is too limited in that regard. It shouldn't be hard to extend this to handle other units. What do you think?
First-time contributor

I agree that the functionality would be useful (even though we prefer meters ourselves).

However, I think this might be better served as a dropdown enum choice of common units? With a default of Meters, and any other unit sizes as options (could just be meters and centimetres to start). In fact, I'd recommend that the input to the operator itself actually be a float that defaults to 1 (metersPerUnit=1.0) and the dropdown just be a UI set of preset values.

That way it's generalizable and easy to add more unit sizes in the future, since some studios use imperial units. By generalizing it to a scalar , that enum just needs to change the scalar without modifying the rest of the code.

This is generally how I implemented it in other DCCs and our internal pipeline as well.

I agree that the functionality would be useful (even though we prefer meters ourselves). However, I think this might be better served as a dropdown enum choice of common units? With a default of Meters, and any other unit sizes as options (could just be meters and centimetres to start). In fact, I'd recommend that the input to the operator itself actually be a float that defaults to 1 (metersPerUnit=1.0) and the dropdown just be a UI set of preset values. That way it's generalizable and easy to add more unit sizes in the future, since some studios use imperial units. By generalizing it to a scalar , that enum just needs to change the scalar without modifying the rest of the code. This is generally how I implemented it in other DCCs and our internal pipeline as well.
Author
Member

It's easy enough to add-- I'll send a follow up in a few.

It's easy enough to add-- I'll send a follow up in a few.
Charles Wardlaw added 1 commit 2024-06-06 20:45:10 +02:00
Author
Member

I think this is correct, but I'm going to do a bunch more tests first. 🤣

I think this is correct, but I'm going to do a bunch more tests first. 🤣
Charles Wardlaw changed title from USD: Adding a Convert to Centimeters option to USD: Adding an option to convert the scene's meters per unit value 2024-06-06 20:48:17 +02:00
Charles Wardlaw added this to the USD project 2024-07-11 23:15:35 +02:00
Michael Kowalski reviewed 2024-07-12 20:23:55 +02:00
@ -159,0 +164,4 @@
{USD_SCENE_UNITS_INCHES, "INCHES", 0, "Inches", "Scene scale of 0.0254"},
{USD_SCENE_UNITS_FEET, "FEET", 0, "Feet", "Scene scale of 0.3048"},
{USD_SCENE_UNITS_YARDS, "YARDS", 0, "Yards", "Scene scale of 0.9144"},
{USD_SCENE_UNITS_CUSTOM, "CUSTOM", 0, "Custom", "Specify a custom scene scale value"},

Minor point: the help for the Custom option is "Specify a custom scene scale value". However, the custom value is actually in meters-per-unit. Would it be better to be consistent? I.e., either have the help for all the menu items be in meters-per-unit, or have the Custom option be a scene scale? The former option (using meters-per-unit for all items) would probably be less work and might fit better with the USD conventions. Again, this might not be an important issue.

Minor point: the help for the `Custom` option is "Specify a custom scene scale value". However, the custom value is actually in meters-per-unit. Would it be better to be consistent? I.e., either have the help for all the menu items be in meters-per-unit, or have the `Custom` option be a scene scale? The former option (using meters-per-unit for all items) would probably be less work and might fit better with the USD conventions. Again, this might not be an important issue.
Michael Kowalski reviewed 2024-07-12 22:29:37 +02:00
@ -45,1 +45,3 @@
if (!usd_export_context_.export_params.convert_orientation) {
if ((!usd_export_context_.export_params.convert_orientation ||
usd_export_context_.export_params.convert_scene_units))
{

I think this conditional should be

 if (!(usd_export_context_.export_params.convert_orientation ||
       usd_export_context_.export_params.convert_scene_units))

Note the ! is outside the innermost parentheses. Without this change, no transform is applied to root prims if the Root Prim export param is empty. To reproduce, export the default cube to USDA with an empty Root Prim path with Convert Scene Units set to something other than meters. Note that the prims don't have the scaling set.

I think this conditional should be ``` if (!(usd_export_context_.export_params.convert_orientation || usd_export_context_.export_params.convert_scene_units)) ``` Note the `!` is outside the innermost parentheses. Without this change, no transform is applied to root prims if the `Root Prim` export param is empty. To reproduce, export the default cube to USDA with an empty `Root Prim` path with `Convert Scene Units` set to something other than meters. Note that the prims don't have the scaling set.
Michael Kowalski reviewed 2024-07-12 23:01:11 +02:00
@ -135,2 +145,3 @@
bool allow_unicode = false;
eUSDSceneUnits convert_scene_units = eUSDSceneUnits::USD_SCENE_UNITS_METERS;
float meters_per_unit = 1.0f;

Just a question that occurred to me: is convert_scene_units redundant in this case? I.e., would it be sufficient to just have meters_per_unit set appropriately in io_usd.cc and use that to compute the scale? I know this would change some of the logic elsewhere to determine whether to apply scaling by checking if meters_per_unit is close to 1.0, so there are tradeoffs with either approach.

Just a question that occurred to me: is `convert_scene_units` redundant in this case? I.e., would it be sufficient to just have `meters_per_unit` set appropriately in `io_usd.cc` and use that to compute the scale? I know this would change some of the logic elsewhere to determine whether to apply scaling by checking if `meters_per_unit` is close to 1.0, so there are tradeoffs with either approach.

This whole units thing reminded me of #128337 which also attempts to add units dropdown to another I/O type. Maybe it would be good to unify that across various I/O types and use shared code?

This whole units thing reminded me of https://projects.blender.org/blender/blender/pulls/128337 which also attempts to add units dropdown to another I/O type. Maybe it would be good to unify that across various I/O types and use shared code?
This pull request has changes conflicting with the target branch.
  • source/blender/editors/io/io_usd.cc
  • source/blender/io/usd/intern/usd_writer_camera.cc
  • source/blender/io/usd/usd.hh

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/usd_convert_to_cm:CharlesWardlaw-feature/usd_convert_to_cm
git checkout CharlesWardlaw-feature/usd_convert_to_cm
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#122804
No description provided.