-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good :)
src/core/abstractions/useFBO.ts
Outdated
} & WebGLRenderTargetOptions | ||
|
||
export function useFBO( | ||
width?: number | FBOSettings, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Width could be FBOSettings ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/core/staging/Sky.vue
Outdated
: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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't blame me, I simply ran pnpm lint --fix
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know heheh this was an issue in others PRs too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
src/core/abstractions/useFBO.ts
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make it works and then we see if we can clean something :)
Now we have something 🥸 fbo.mp4 |
4a632f0
to
f3a00a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/core/abstractions/useFBO.ts
Outdated
settings?: WebGLRenderTargetOptions | ||
} | ||
|
||
export const UseFBO = defineComponent<UseFboProps>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaimeTorrealba how would it look if done via slots for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been a difficult one :D. But great work.
I'll not merge until @alvarosabu check this one but see everything fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brilliant work @kekkorider @JaimeTorrealba
<TresBoxGeometry :args="[1, 1, 1]" /> | ||
<TresMeshBasicMaterial | ||
:color="0xff8833" | ||
:map="fboRef?.texture || null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-fbo
the 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