DAZ Studio 6 SDK: Safe way to duplicate and assign DzUberIrayMaterial to another DzShape?

In DAZ Studio 6 / 2026 SDK, what is the supported way to duplicate a DzUberIrayMaterial and assign it to another DzShape with addMaterial() or replaceMaterial() so the shader network is preserved and ownership/lifetime is safe?

  • DzElement::doDuplicateElement() returns DzElementPtr, and script replacement fails with DzTSharedPointer<DzElement> ... to DzMaterial*.
  • DzMaterial::duplicateOrDefaultMaterial() returns DzMaterialHandle; calling it from C++ and using handle.get() crashed inside cloneMaterialPreserveNameCxx.
  • Manual DzDefaultMaterial copying works structurally but loses Iray glass shader fidelity.

Comments

  • umblefuglyumblefugly Posts: 131

    I figured it out and ill leave this summary for anyone else having the issue migrating from DS 4.24.x.x to DS 2026:
     

    1. C++ creates DzFacetShape for each shard.

    2. C++ adds initial materials with shape->addMaterial(...):

      • slot 0: outside fallback material
      • slot 1: inside material
      • slots 2+: placeholder copies for each source material
    3. While emitting shard facets, C++ activates material indices directly:

      • inside faces use material slot 1
      • source-mapped outside faces use sourceMaterialIdBase + sourceMaterialIndex
      • sourceMaterialIdBase is 2
    4. After scene nodes are created, C++ calls the embedded DAZ Script material pass.

    5. Script resolves the original source node by label and gets:
      srcShape.getMaterial(mi)

    6. For each source material, script creates a DAZ6 material duplicate with:
      srcMat.duplicateOrDefaultMaterial(ctx)

    7. Script finalizes the DzElementDuplicateContext:
      createAlaises/createAliases, createERC, doResolve, doFinalize

    8. Script gets the shard placeholder material at:
      shardShape.getMaterial(mi + 2)

    9. Script replaces it:
      shardShape.replaceMaterial(oldMat, duplicatedMat)

    The critical DAZ6 change is using duplicateOrDefaultMaterial() instead of doDuplicateElement() or manual DzDefaultMaterial property copying. That preserves DzUberIrayMaterial instead of downgrading to DzDefaultMaterial.

    Some wording is specific to my plugin, but hopefully you get the gist :D

    Example.PNG
    1920 x 1080 - 3M
Sign In or Register to comment.