Hi Shapespark community,
I’m working on a project where I need to dynamically modify materials in Shapespark and later restore them to their original state using a reset button. This includes both materials with solid colors and those with textures assigned to baseColorTexture
.
To achieve this, I am storing the initial properties of each material, including:
- HSL values (hue, saturation, lightness) using
baseColor.getHSL()
- Texture reference by capturing
material.baseColorTexture
- Texture ID by accessing
material._correctedBaseColorTexture.texture.id
(for materials with textures)
Issue Encountered
While the approach works well for materials without textures, I am having trouble restoring textures correctly after applying changes.
- When I store
material.baseColorTexture
, it seems like I cannot directly reassign it later. - I tried using
material.baseColorTexture = storedTexture;
but it does not revert correctly. - I also tried tracking the texture ID (
material._correctedBaseColorTexture.texture.id
), but I could not find a method in the API to retrieve a texture by ID.
My Questions:
- How can I properly restore a material’s original texture once it has been modified?
- Is there an API method to retrieve a texture using its stored ID?
- Is there a recommended way to store and reapply
baseColorTexture
for materials that have it?
I would appreciate any insights or recommendations from the community. Thank you for your help!
Best regards,
Angel Castro