Comments (7)
let's add it!
from drei.
users should be able to do:
useHelper<SpotLightHelper>(ref, SpotLightHelper, color)
function useHelper<T>(
ref: React.MutableRefObject<Object3D>,
proto: T,
...args: ConstructorParameters<T>
) {
from drei.
that's fine, thats how i do it as well most of the time, eventually it will annoy someone and they fix it ;-)
from drei.
Alright, I've made some progress, I'll share here before a pr as I'm not sure about some details.
https://codesandbox.io/s/r3f-use-helper-bm2qu?file=/src/use-helper.tsx
- I'm not sure how to type the arguments to the hook, the second one should be an helper constructor but I can't seem to find any type in threejs that could work for all helpers
- the rest of the arguments would be passed to the constructor, don't know if is the correct way to do it
from drei.
So, I updated the sandbox with your suggestions, still:
useHelper<BoxHelper>(mesh, BoxHelper, "cyan");
gives me a type error "Argument of type 'typeof BoxHelper' is not assignable to parameter of type 'BoxHelper'."
This is fixed using useHelper<typeof BoxHelper>(...)
( and I'm not sure if this is desirable)
in the hook I get these type errors:
Type 'T' does not satisfy the constraint 'new (...args: any) => any'
and
This expression is not constructable.
when I try to create the new helper instance.
I'm not sure if there is a simpler approach or I'm missing some piece of ts knowledge to make this work
from drei.
i dont know TS myself, but in reactthreefiber they have solved args in /src/three-types.ts maybe you find something over there
from drei.
I fixed the warning but I think that made everything too "any"ish, maybe I'll just PR now and open an issue later to have somebody more expert with TS check the typings
from drei.
Related Issues (20)
- Expose MeshPortalMaterial RenderTarget
- R3F how can I get the camera controls through the hook get()
- Bounds Ignores Group Scale HOT 1
- Three.js outlinePass add-on not working when implemented with R3F
- Edges don't work when negative scaling is used (works in Drei <=0.101.0)
- Strange issues with MeshReflectorMaterial and GLB geometries HOT 1
- Float does not work with on demand rendering HOT 1
- e2e playright + docker support
- The reason for the very low performance of R3F with instances ?
- Billboard does not respect position after updating three to 0.166 HOT 2
- Using Outlines in React Native HOT 1
- MeshTransmissionMaterial heats up my macbook air m2
- The grass (instances) example in the readme / documentation should be updated. HOT 1
- Unsupported GPOS/GSUB table LookupType with <Text> HOT 2
- AdaptiveDpr min/max settings
- iOS production build crash: Calling the 'readAsStringAsync' function has failed in the latest react-native version
- iOS production build crash: Calling the 'readAsStringAsync' function has failed in the latest react-native version HOT 1
- Environment "encoding" out of date
- Error: R3F: P is not part of the THREE namespace! Did you forget to extend? See: https://docs.pmnd.rs/react-three-fiber/api/objects#using-3rd-party-objects-declaratively HOT 1
- Environment component cause white square
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drei.