maya-usd icon indicating copy to clipboard operation
maya-usd copied to clipboard

Maya instances of mayaUsdProxyShape do not render in Viewport 2.0

Open radon199 opened this issue 1 year ago • 2 comments

Describe the bug When using Maya instancing of a object with a mayaUsdProxyShape, we don't get any instances of that shape drawing in the viewport except the first one.

Using renderers other than Viewport 2.0 such as Arnold will render the instances as expected.

Screen Shot 2025-01-15 at 3 41 40 PM

We have an existing workflow that involves instancing in Maya assets that we would like to keep, and this is preventing that from being possible.

Steps to reproduce Steps to reproduce the behavior:

  1. Import a file as a mayaUsdProxyShape
  2. In the Edit dropdown select Duplicate Special
  3. In the Duplicate Special UI, toggle the Geometry Type to Instance
  4. Move the instance in the viewport and see that nothing is drawn.
  5. Also see that there are no UFE objects in the outliner.

Expected behavior Maya instances of mayaUsdProxyShape should draw in the viewport.

Specs (if applicable):

  • OS & version : Windows 10
  • Maya version : 2022, 2024
  • Maya USD : 0.30.0

radon199 avatar Jan 15 '25 23:01 radon199

Hello @radon199, I took a look at the issue and unfortunately this isn't a workflow that we currently support. USD has its own instancing were a particular prim can be copied and instanced. The following python code will create an anonymous stage, Create a Sphere and then create instances of that sphere:

from pxr import Usd, UsdGeom
import mayaUsd.lib as mayaUsdLib
import maya.cmds as cmds

# Create a new proxy shape node
proxy_shape = cmds.createNode("mayaUsdProxyShape", name="USD_InMemory")

# Get the full path to the proxy shape in Maya
stage_path = cmds.ls(proxy_shape, long=True)[0]

# Get the USD stage from the proxy shape
usd_stage = mayaUsdLib.GetPrim(stage_path).GetStage()

# Define the original object
original = UsdGeom.Xform.Define(usd_stage, "/Original")
sphere = UsdGeom.Sphere.Define(usd_stage, "/Original/Sphere")

# Create instances using references
instance1 = UsdGeom.Xform.Define(usd_stage, "/Instance1")
instance1.GetPrim().GetReferences().AddReference("", "/Original")

instance2 = UsdGeom.Xform.Define(usd_stage, "/Instance2")
instance2.GetPrim().GetReferences().AddReference("", "/Original")

instance3 = UsdGeom.Xform.Define(usd_stage, "/Instance3")
instance3.GetPrim().GetReferences().AddReference("", "/Original")

# Ensure instances are marked as instanceable
instance1.GetPrim().SetInstanceable(True)
instance2.GetPrim().SetInstanceable(True)
instance3.GetPrim().SetInstanceable(True)

# Move instances
UsdGeom.Xformable(instance1).AddTranslateOp().Set((5, 0, 0))
UsdGeom.Xformable(instance2).AddTranslateOp().Set((-5, 0, 0))
UsdGeom.Xformable(instance3).AddTranslateOp().Set((10, 0, 0))

Notice that if the original sphere is scaled or moved the others will also do the same.

https://github.com/user-attachments/assets/f3d99579-66ec-4c84-a2c0-ca8fb6f8c4a6

santosd avatar Feb 12 '25 17:02 santosd

Hello @radon199, I took a look at the issue and unfortunately this isn't a workflow that we currently support. USD has its own instancing were a particular prim can be copied and instanced.

Hi @santosd,

Yes, we are aware of how USD instancing works internally within the mayaUsdProxyShape. Arnold supports instances of the mayaUsdProxyShape but it appears that Viewport2.0 does not.

We still have a desire to use Maya instancing with the mayaUsdProxyShape over building it all internally within UFE as we have existing importing and layout tools within Maya we want to use and don't want to move to a 100% maya-usd workflow.

I did actually do some experiments modifying maya-usd and was able to get both Maya instancing and USD instancing working at the same time by modifying the VP2 proxyRenderDelegate mesh class to insert a VP2 instance for each USD instance inside of the proxy (as it currently does), but also extra instances for each Maya instance of that parent mayaUsdProxyShape.

This worked and proved that it is possible for VP2 (there are issues around how to make selection work properly ) but we didn't get much farther than a proof of concept as we didn't want to have to support so much patching on top of the pubic repo.

We also encountered bugs with the mayaUsdProxyShape within references. It is a shame the core Maya workflows like instancing and referencing that have been in Maya for more than 15 years are not supported by maya-usd.

So far we have moved to using copies instead of instances to support our workflows, even if that has performance implications.

radon199 avatar Feb 12 '25 18:02 radon199