Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating colors programatically without using state? #58

Open
ggomaeng opened this issue Sep 26, 2023 · 1 comment
Open

Updating colors programatically without using state? #58

ggomaeng opened this issue Sep 26, 2023 · 1 comment

Comments

@ggomaeng
Copy link

ggomaeng commented Sep 26, 2023

I am trying to update the colors programatically frame by frame without using state for performance reasons, and it seems like I can't access uniforms of the material. It seems like I can't access the getters and setters of the shaderMaterial as well.

https://github.com/ruucm/shadergradient/blob/650f8e14581bbbc69171333af01a165ee477ddaa/packages/shadergradient/src/Gradient/comps/Mesh/shaderMaterial.ts#L70C5-L70C5

Any pointers would be greatly appreciated!

Here are my efforts below without any luck

three.current?.scene.traverse(function (object) {
  if (
    object instanceof Mesh &&
    object.material instanceof MeshPhysicalMaterial
  ) {
    object.material.userData.colors = ["#0000FF", "#00FF00", "#000000"];
    object.material.needsUpdate = true;
    const shaderMaterial =
      object.material as unknown as ShaderMaterial & {
        colors: Color[];
      };

    console.log(shaderMaterial);
    console.log(shaderMaterial.colors); // this throws an error
    console.log(shaderMaterial.uniforms); // this throws an error
  }
});
@ruucm
Copy link
Owner

ruucm commented Dec 11, 2023

hello @ggomaeng I've exported r3f hooks to use it outside from v1.2.5. (like useFrame or useThree)

here is an example to change the userData outside of the package.

https://codesandbox.io/p/sandbox/github/ruucm/shadergradient/tree/main/apps/example-cra?file=%2Fsrc%2FApp.tsx

but I think there will be more modifications needed to update the colors in this hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants