Advertisement
thureinfree

copy attr

Nov 6th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. from pxr import Usd, UsdShade
  2.  
  3. # Assume stage is your loaded USD stage
  4. # Replace '/LightPrimPath' and '/ShadingPrimPath' with the actual paths of the light and shading prims
  5. stage = Usd.Stage.Open("path_to_your_stage.usda")
  6. light_path = "/LightPrimPath"
  7. shading_path = "/ShadingPrimPath"
  8.  
  9. # Fetch the light prim and the shading prim
  10. light_prim = stage.GetPrimAtPath(light_path)
  11. shading_prim = stage.GetPrimAtPath(shading_path)
  12.  
  13. # Check if the light prim has the 'inputs:texture:file' attribute
  14. light_texture_attr = light_prim.GetAttribute("inputs:texture:file")
  15. if light_texture_attr:
  16. # Get the value of the attribute
  17. texture_file = light_texture_attr.Get()
  18.  
  19. # Fetch or create the shading prim's 'inputs:file' attribute
  20. shading_shader = UsdShade.Shader(shading_prim)
  21. file_attr = shading_shader.CreateInput("file", Sdf.ValueTypeNames.Asset)
  22.  
  23. # Apply the texture file path to the 'inputs:file' attribute on the shading prim
  24. file_attr.Set(texture_file)
  25. print(f"Applied texture file '{texture_file}' from light prim to shading prim.")
  26.  
  27. else:
  28. print("The light prim does not have an 'inputs:texture:file' attribute.")
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement