feat: add <Fbo /> abstraction#228
Conversation
✅ Deploy Preview for cientos-tresjs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
Since useTresContextProvider() is a provide/inject value, I believe you can't use outside setup context Maybe we can convert this one into a renderlessComponent |
| } & WebGLRenderTargetOptions | ||
|
|
||
| export function useFBO( | ||
| width?: number | FBOSettings, |
There was a problem hiding this comment.
Width could be FBOSettings ?
There was a problem hiding this comment.
That comes from Drei.
IMHO this is in case you do not specify the size (i.e. fullscreen) and you provide the settings object as first parameter.
| :material-uniforms-mieCoefficient-value="props.mieCoefficient" | ||
| :material-uniforms-mieDirectionalG-value="props.mieDirectionalG" | ||
| :material-uniforms-sunPosition-value="sunPosition" | ||
| :material-uniforms-mie-coefficient-value="props.mieCoefficient" |
There was a problem hiding this comment.
This will break this abstraction @alvarosabu, what is needed here to use the linter propertly? a git pull??
There was a problem hiding this comment.
Don't blame me, I simply ran pnpm lint --fix 😄
There was a problem hiding this comment.
I know heheh this was an issue in others PRs too
There was a problem hiding this comment.
@kekkorider please merge last main with the eslint over-rule and set the tmeplate of this file to:
<primitive
:object="skyImpl"
:material-uniforms-turbidity-value="props.turbidity"
:material-uniforms-rayleigh-value="props.rayleigh"
:material-uniforms-mieCoefficient-value="props.mieCoefficient"
:material-uniforms-mieDirectionalG-value="props.mieDirectionalG"
:material-uniforms-sunPosition-value="sunPosition"
:scale="props.distance"
/>
There was a problem hiding this comment.
@alvarosabu I just rebased and force-pushed (I'm used to work this way instead merging main).
After running pnpm lint --fix everything was ok as expected.
| // const viewport = useThree((state) => state.viewport) | ||
| const viewport = { dpr: 1.5 } | ||
|
|
||
| const _width = typeof width === 'number' ? width : size.width * viewport.dpr |
There was a problem hiding this comment.
We could pass default values in the props or in the parameters,
but these types of validations (for type) are not necessary, for that is typescript :)
There was a problem hiding this comment.
Yeah I was thinking the same thing, but I was having a lot of errors in the editor (despite everything was working).
So I copypasted this stuff as-is from Drei.
There was a problem hiding this comment.
Let's make it works and then we see if we can clean something :)
|
Now we have something 🥸 fbo.mp4 |
4a632f0 to
f3a00a1
Compare
alvarosabu
left a comment
There was a problem hiding this comment.
Excellent first contribution @kekkorider 👏🏻
Just change the naming convention to Fbo rather than useFbo since is not composable and change the file from a ts to a vue component to ensure better reactivity
| settings?: WebGLRenderTargetOptions | ||
| } | ||
|
|
||
| export const UseFBO = defineComponent<UseFboProps>({ |
There was a problem hiding this comment.
Since this is a component rather than a composable I would probably avoid using use prefix and turn this file into a SFC vue component called <Fbo /> rather than a ts component.
This will make things easier for the props.
Also is not reactive, if any of the props change the target is not disposed and created again.
@kekkorider take a look at this component https://github.com/Tresjs/cientos/blob/main/src/core/staging/ContactShadows.vue let me know if you need help.
| <TresBoxGeometry :args="[1, 1, 1]" /> | ||
| <TresMeshBasicMaterial | ||
| :color="0xff8833" | ||
| :map="fboRef?.texture || null" |
There was a problem hiding this comment.
Question, this way of using is good, but it feels a little odd...
Since it is useful to use a renderless component, could this be made with slots?
Something like:
Is that possible, did you find comfortable? The FBO is use only in :map property?
What do you think, guys?
There was a problem hiding this comment.
@JaimeTorrealba how would it look if done via slots for example?
There was a problem hiding this comment.
In the code could be something like:
const slots = useSlots()
const material = slot.default()[0].children.material // and here you access the material of the slot component
//and you can assign the "texture" created directly, obviously some validations are needed first
Just by the record, I'm not demanding a change, you did this abstraction @alvarosabu you know what is better, is just I feel this way of usage a little weird, you don't. Other solutions are considered too
There was a problem hiding this comment.
That's not what I mean actually, you mention passing the fboRef as a map it's odd. What would be the alternative?
const slots = useSlots()
const material = slot.default()[0].children.material
Here you are mentioning the possible implementation, what I mean is how would this look in the template? Like this?
<Fbo>
<TresMesh>
<TresBoxGeometry :args="[1, 1, 1]" />
</TresMesh>
</Fbo>
|
I refactored everything to make it a renderless component following the new naming convention as @alvarosabu requested. Basically it works, but whenever I change a prop the box turns black (no map set). |
useFBO() abstraction<Fbo /> abstraction
JaimeTorrealba
left a comment
There was a problem hiding this comment.
@alvarosabu when you have time please check this one, when the components have WebGlRenders I couldn't make then reactive... Example of that is the Reflector, so please if you know a way to achieve this, comment us
|
@kekkorider only missing the docs and add the composable as well in them (the composable needs to be used inside of a child component since it needs the context of TresCanvas) |
|
@alvarosabu awesome! I will work on it next week. 🍻 |
c17039a to
023422b
Compare
|
@alvarosabu @JaimeTorrealba I guess we're there 🥳 |
|
Hey @kekkorider amazing job! There seem to be some conflicts with |
48749bd to
81acaed
Compare
@alvarosabu I just rebased and removed the conflicts 🙌 |
JaimeTorrealba
left a comment
There was a problem hiding this comment.
Great work man, the component looks nice, I'll include it for the next v3.5 of cientos
Thanks you
I've just some little changes, docs related, and one question
|
@JaimeTorrealba I just fixed everything you asked 🙌 |
JaimeTorrealba
left a comment
There was a problem hiding this comment.
It has been a difficult one :D. But great work.
I'll not merge until @alvarosabu check this one but see everything fine
alvarosabu
left a comment
There was a problem hiding this comment.
Brilliant work @kekkorider @JaimeTorrealba
| <TresBoxGeometry :args="[1, 1, 1]" /> | ||
| <TresMeshBasicMaterial | ||
| :color="0xff8833" | ||
| :map="fboRef?.texture || null" |
There was a problem hiding this comment.
That's not what I mean actually, you mention passing the fboRef as a map it's odd. What would be the alternative?
const slots = useSlots()
const material = slot.default()[0].children.material
Here you are mentioning the possible implementation, what I mean is how would this look in the template? Like this?
<Fbo>
<TresMesh>
<TresBoxGeometry :args="[1, 1, 1]" />
</TresMesh>
</Fbo>
This is basically copypasted from Drei 😀
At the moment, when you head over
/abstractions/use-fbothe console shows this error:That's because here I'm using
useTresContext()to get info about the size and viewport.Any help on how to use
useTresContextProvider()would be much appreciated 🥸Closes #149