USD import: add support for displayColor on non-Mesh USD shape prims #120236

Merged
Jesse Yurkovich merged 5 commits from wave/blender_wave_Apple:matt/displayColor_for_shapes_v3 into main 2024-04-24 20:59:09 +02:00

Blender USD import already supports the displayColor primvar, when it is specified on Mesh prims. These colors are visible in the viewport when the viewport shading color type is set to Attribute.

This PR extends this displayColor primvar support to also work with the various shape prims, such as Box, Sphere, etc.

The original displayColor support was implemented in USDMeshReader. Because USDShapeReader is a sibling to to USDMeshReader, and USDShapeReader first converts shapes to a Mesh, we have factored out the mutually beneficial code from usd_reader_mesh.cc into a new usd_mesh_utils.cc.

For now only the displayColor primvar is supported on shapes, but this could be easily extended in a future PR.

Authored by Apple: Matt McLin

Blender USD import already supports the displayColor primvar, when it is specified on Mesh prims. These colors are visible in the viewport when the viewport shading color type is set to Attribute. This PR extends this displayColor primvar support to also work with the various shape prims, such as Box, Sphere, etc. The original displayColor support was implemented in USDMeshReader. Because USDShapeReader is a sibling to to USDMeshReader, and USDShapeReader first converts shapes to a Mesh, we have factored out the mutually beneficial code from usd_reader_mesh.cc into a new usd_mesh_utils.cc. For now only the displayColor primvar is supported on shapes, but this could be easily extended in a future PR. Authored by Apple: Matt McLin
Michael B Johnson added 1 commit 2024-04-04 01:45:49 +02:00
Michael B Johnson requested review from Michael Kowalski 2024-04-04 01:46:25 +02:00
Michael B Johnson requested review from Jesse Yurkovich 2024-04-04 01:47:10 +02:00
Michael B Johnson added this to the USD project 2024-04-04 01:47:27 +02:00

I've attached a shapes_with_colors.usda file generated from Houdini containing various shape types with different colors that I'm using for testing. The colors come through as expected in Blender, as shown in the attached screenshot. Nice work!

I might have additional comments when I complete my review.

I've attached a `shapes_with_colors.usda` file generated from Houdini containing various shape types with different colors that I'm using for testing. The colors come through as expected in Blender, as shown in the attached screenshot. Nice work! I might have additional comments when I complete my review.
Jesse Yurkovich requested changes 2024-04-09 23:04:04 +02:00
Dismissed
Jesse Yurkovich left a comment
Member

Things look alright from my side save for a few nits. Things seem fine otherwise. I can clean the nits up shortly after this is checked in. Or, if you want, you can address them now.

There are clang-format issues that should be fixed before commit though. A make format should auto fix them for you I think. Requesting changes just for this one mainly.

Things look alright from my side save for a few nits. Things seem fine otherwise. I can clean the nits up shortly after this is checked in. Or, if you want, you can address them now. There are clang-format issues that should be fixed before commit though. A `make format` should auto fix them for you I think. Requesting changes just for this one mainly.
@ -0,0 +8,4 @@
#include "BKE_attribute.hh"
#include "BLI_color.hh"
#include "BLI_span.hh"

Nit: To go along with the other #include change, add the following 2 headers:
#include "BKE_report.hh" and #include "DNA_mesh_types.h"

Nit: To go along with the other #include change, add the following 2 headers: `#include "BKE_report.hh"` and `#include "DNA_mesh_types.h"`
makowalski marked this conversation as resolved
@ -0,0 +92,4 @@
if (!primvar.ComputeFlattened(&primvar_val, motionSampleTime)) {
BKE_reportf(reports,
RPT_WARNING,
"Unable to get array values for primvar %s",

Nit: Surround the %s with single quotes to match the other report below this one: '%s' and change this message to begin with "USD Import: "

Nit: Surround the %s with single quotes to match the other report below this one: `'%s'` and change this message to begin with "USD Import: "
makowalski marked this conversation as resolved
@ -0,0 +11,4 @@
#include "usd_reader_geom.hh"
#include <pxr/usd/sdf/types.h>
#include <pxr/usd/usdGeom/mesh.h>

Nit: Replace all of the #includes above with the following to more accurately reflect what's actually necessary:

#include "DNA_customdata_types.h"

#include <pxr/base/vt/array.h>
#include <pxr/usd/sdf/valueTypeName.h>
#include <pxr/usd/usdGeom/primvar.h>

#include <optional>

struct Mesh;
struct ReportList;
Nit: Replace all of the #includes above with the following to more accurately reflect what's actually necessary: ``` #include "DNA_customdata_types.h" #include <pxr/base/vt/array.h> #include <pxr/usd/sdf/valueTypeName.h> #include <pxr/usd/usdGeom/primvar.h> #include <optional> struct Mesh; struct ReportList; ```
makowalski marked this conversation as resolved

The changes look good! Splitting out the shared attribute import functionality to usd_mesh_utils.cc is welcome, because I believe the attribute conversion functions can also be used in the Point Cloud import PR #120060.

I was wondering if we want support for animated attributes through the mesh sequence cache modifier. I've attached capsule_with_animating_color.usda that can be played in USDView, where the capsule displayColor animates from red to blue.

@Matt-McLin @deadpin Is this something we want to add? I personally think this would be helpful, but I would also be fine with adding support for this later.

Based on the mesh conversion code, I wrote a very quick prototype for supporting animated attributes for shapes, just as an example to start the discussion. It appears to work in my test.

a8ad8d1bf1

The scope of the required changes includes

  • Keep track of which primvars are time varying in a new primvar_time_varying_map_ member
  • Update USDShapeReader::is_time_varying() to return true if any color primvars are time varying
  • Move the call to apply_primvars_to_mesh() inside mesh_from_prim(), so primvars are read when the points are updated

Just a suggestion. As I said, I'm fine deferring this till later or taking a different approach to implement this.

The changes look good! Splitting out the shared attribute import functionality to `usd_mesh_utils.cc` is welcome, because I believe the attribute conversion functions can also be used in the Point Cloud import PR https://projects.blender.org/blender/blender/pulls/120060. I was wondering if we want support for animated attributes through the mesh sequence cache modifier. I've attached `capsule_with_animating_color.usda` that can be played in `USDView`, where the capsule `displayColor` animates from red to blue. @Matt-McLin @deadpin Is this something we want to add? I personally think this would be helpful, but I would also be fine with adding support for this later. Based on the mesh conversion code, I wrote a very quick prototype for supporting animated attributes for shapes, just as an example to start the discussion. It appears to work in my test. https://projects.blender.org/makowalski/blender/commit/a8ad8d1bf1403815d202c49a8efb19a225cd3df1 The scope of the required changes includes - Keep track of which primvars are time varying in a new `primvar_time_varying_map_` member - Update `USDShapeReader::is_time_varying()` to return true if any color primvars are time varying - Move the call to `apply_primvars_to_mesh()` inside `mesh_from_prim()`, so primvars are read when the points are updated Just a suggestion. As I said, I'm fine deferring this till later or taking a different approach to implement this.
BTW, this is the branch with the example code: https://projects.blender.org/makowalski/blender/src/branch/displayColor_for_shapes_with_anim
Member

Thank you @deadpin and @makowalski !

Michael, this is great point about animated displayColor attribute, thank you for adding this. I think it would be great to include here.
Jesse, your changes make sense, thanks for sharing the details.

I am happy to make the requested changes and incorporate Michael's commit, but am busy this week so may take some time.

If either of you would like to make the changes directly here sooner and push it through, that is fine for us.

Thank you @deadpin and @makowalski ! Michael, this is great point about animated displayColor attribute, thank you for adding this. I think it would be great to include here. Jesse, your changes make sense, thanks for sharing the details. I am happy to make the requested changes and incorporate Michael's commit, but am busy this week so may take some time. If either of you would like to make the changes directly here sooner and push it through, that is fine for us.

@Matt-McLin @deadpin I can probably merge in my proposed changes for the animating attributes into this PR this week. I'll add a comment here when I've started working on this, so we don't accidentally duplicate each other's work.

@Matt-McLin @deadpin I can probably merge in my proposed changes for the animating attributes into this PR this week. I'll add a comment here when I've started working on this, so we don't accidentally duplicate each other's work.

FYI, I will work on merging in the animation-related changes today. Will also try to address the comments by @deadpin today.

FYI, I will work on merging in the animation-related changes today. Will also try to address the comments by @deadpin today.
Michael Kowalski reviewed 2024-04-19 21:42:52 +02:00
@ -32,6 +32,8 @@ class USDShapeReader : public USDGeomReader {
pxr::VtIntArray &face_indices,
pxr::VtIntArray &face_counts) const;
void apply_primvars_to_mesh(Mesh *mesh, const double motionSampleTime);

I think const is necessary in the function definition but not the declaration, as per this guideline:

https://developer.blender.org/docs/handbook/guidelines/c_cpp/#const

I'll remove it from the declaration when I merge in the animation changes.

I think `const` is necessary in the function definition but not the declaration, as per this guideline: https://developer.blender.org/docs/handbook/guidelines/c_cpp/#const I'll remove it from the declaration when I merge in the animation changes.
makowalski marked this conversation as resolved
Michael Kowalski added 4 commits 2024-04-20 03:44:09 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
1a9d9d7b06
USD: remove duplicate include

@blender-bot build

@blender-bot build
Michael Kowalski approved these changes 2024-04-20 04:06:51 +02:00
Michael Kowalski left a comment
Member

I committed the animation changes and also addressed the comments by @deadpin.

Since I will be out all of next week, I will go ahead and approve this pull request.

@Matt-McLin @deadpin Please review my additional changes when you have a chance. Thanks!

I committed the animation changes and also addressed the comments by @deadpin. Since I will be out all of next week, I will go ahead and approve this pull request. @Matt-McLin @deadpin Please review my additional changes when you have a chance. Thanks!
Member

@makowalski Your updates look good to me, and I confirmed it works for the couple of test files.

@makowalski Your updates look good to me, and I confirmed it works for the couple of test files.
Matt McLin requested review from Jesse Yurkovich 2024-04-24 18:09:02 +02:00
Jesse Yurkovich approved these changes 2024-04-24 20:10:28 +02:00
Jesse Yurkovich merged commit f91b23ef2d into main 2024-04-24 20:59:09 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
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, Assets & 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
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
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
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
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#120236
No description provided.