pmndrs / drei-vanilla

🍦 drei-inspired helpers for threejs
https://pmndrs.github.io/drei-vanilla/
MIT License
448 stars 17 forks source link

Include uniform types on shaderMaterial's returned class type #23

Closed mattrossman closed 1 year ago

mattrossman commented 1 year ago

Describe the feature you'd like:

shaderMaterial() has trouble with TypeScript. The storybook example has several type errors because custom uniforms don't exist on the resulting class type.

image

In the main drei project, they work around this by specifying the types when extending the JSX namespace.

https://github.com/pmndrs/drei/blob/f5354c4cc5349e048c00d5ad2b8c839cde5bd132/.storybook/stories/shaderMaterial.stories.tsx#L58-L69

This adds friction and duplication in userland though. I would like shaderMaterial to automaticallly wire up these uniform types to its resulting class type. Uniform types can be inferred from the function arguments or provided by the user through generics.

Suggested implementation:

See implementation with generics here: TypeScript Playground

image

This resolves the type errors in the storybook example.

I can make a PR for this.

mattrossman commented 1 year ago

Updated implementation with uniform types for .setValues()

Playground Link

vis-prime commented 1 year ago

Oh yes ! , many effects use shaderMaterial and they all have this problem , would be great to have a proper solution

if you can, do make the PR ❤

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: