USD: Add an option to convert the scene's meters per unit value #122804
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
BlendFile
Interest
Blender Asset Bundle
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
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
USD
Interest
UV Editing
Interest
Undo
Interest
User Interface
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest
glTF
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
Windows
Platform
macOS
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
5 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#122804
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "CharlesWardlaw/blender:feature/usd_convert_to_cm"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
If "Apply Unit Scale Conversion" is unchecked on import, the user now has the ability to bring the objects in with a scale factor of 1.0, so that the objects may be edited as if Blender's scene units matches the imported stage's.
At export time, a "Stage Meters Per Unit" value can be chosen from a list of common measurements, as well as setting a custom value.
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?
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.
It's easy enough to add-- I'll send a follow up in a few.
I think this is correct, but I'm going to do a bunch more tests first. 🤣
USD: Adding a Convert to Centimeters optionto USD: Adding an option to convert the scene's meters per unit value@ -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 theCustom
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.Good point-- I've reworked the math to make those numbers make sense as meters per unit values, and changed the Custom values to be in meters per unit. Benefit of this is it made me rethink some terrible floating point conversions. 🤦
@ -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
Note the
!
is outside the innermost parentheses. Without this change, no transform is applied to root prims if theRoot Prim
export param is empty. To reproduce, export the default cube to USDA with an emptyRoot Prim
path withConvert Scene Units
set to something other than meters. Note that the prims don't have the scaling set.I moved it outside. I'm not entirely clear on the difference so I'd appreciate more folks checking.
@ -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 havemeters_per_unit
set appropriately inio_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 ifmeters_per_unit
is close to 1.0, so there are tradeoffs with either approach.I'd prefer to leave it as is only because the enum makes it evident what was being done in other places.
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?
make format
74c173b422USD: Adding an option to convert the scene's meters per unit valueto USD: Add an option to convert the scene's meters per unit value@ -860,0 +898,4 @@
"convert_scene_units",
rna_enum_usd_convert_scene_units_items,
eUSDSceneUnits::USD_SCENE_UNITS_METERS,
"t",
It looks like the UI label is a typo. Perhaps "t" should be "Units"?
This looks good! I had just a couple of comments.
Also, I think for both camera import and camera export we should apply scaling to the near and far clipping planes and the focal distance.
BTW, I'm available to help make these changes if you don't have time.
These are all the comments I have. @deadpin I'd love to get your opinion as well, when you have a chance to look at this.
@ -1364,1 +1430,4 @@
namespace blender::io::usd {
double get_scene_scale_from_export_params(const struct USDExportParams *params)
I think it might be clearer to name this function
get_meters_per_unit()
because in the code you use the inverse of the returned value for the scale. But I don't feel strongly about this.Additionally, this can be defined inside usd_capi_export probably. No need to have it all the way over in editors/io.
@ -58,6 +58,9 @@ static void camera_sensor_size_for_render(const Camera *camera,
void USDCameraWriter::do_write(HierarchyContext &context)
{
const float unit_scale = float(
As per the previous comment about naming this function, maybe
unit_scale
should be renamedmeters_per_unit
:You can keep this variable as double precision too.
@ -76,3 +79,3 @@
* = 100 * stage_meters_per_unit
*/
const float tenth_unit_to_mm = 100.0f * scene->unit.scale_length;
const float tenth_unit_to_mm = float(unit_scale * 100.0);
Maybe to be compatible with the previous scaling behavior and not break existing scenes we should keep the original
scene->unit.scale_length
factor as well, i.e.,(assuming we renamed the
unit_scale
variable above.@ -292,0 +291,4 @@
const double stage_meters_per_unit = UsdGeomGetStageMetersPerUnit(stage);
data->settings.stage_meters_per_unit = stage_meters_per_unit;
if (data->params.apply_unit_conversion_scale) {
The code relating to
stage_meters_per_unit
is now inside theUSDStageReader
ctor and the adjustment to params.scale can happen inside there now.@ -154,6 +155,10 @@ static void ensure_root_prim(pxr::UsdStageRefPtr stage, const USDExportParams &p
return;
}
if (!(params.convert_orientation || params.convert_scene_units)) {
This conditional should be removed because it causes the root prim to be an undefined prim when the
convert_scene_units
andconvert_orientation
export options are both off.Checkout
From your project repository, check out a new branch and test the changes.