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

feat: add <Fbo /> abstraction #228

Merged
merged 28 commits into from
Oct 7, 2023
Merged

feat: add <Fbo /> abstraction #228

merged 28 commits into from
Oct 7, 2023

Conversation

kekkorider
Copy link
Collaborator

@kekkorider kekkorider commented Sep 21, 2023

This is basically copypasted from Drei 😀

At the moment, when you head over /abstractions/use-fbo the console shows this error:

Screenshot 2023-09-21 alle 21 39 35

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

@netlify
Copy link

netlify bot commented Sep 21, 2023

Deploy Preview for cientos-tresjs ready!

Name Link
🔨 Latest commit 54b3730
🔍 Latest deploy log https://app.netlify.com/sites/cientos-tresjs/deploys/652165692da6af00087fa9ed
😎 Deploy Preview https://deploy-preview-228--cientos-tresjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@kekkorider kekkorider changed the title Add useFBO() abstraction feat: add useFBO() abstraction Sep 21, 2023
@JaimeTorrealba
Copy link
Member

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
You can base on the StatsGL component, for example.

Copy link
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good :)

} & WebGLRenderTargetOptions

export function useFBO(
width?: number | FBOSettings,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Width could be FBOSettings ?

Copy link
Collaborator Author

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.

:material-uniforms-mieCoefficient-value="props.mieCoefficient"
:material-uniforms-mieDirectionalG-value="props.mieDirectionalG"
:material-uniforms-sunPosition-value="sunPosition"
:material-uniforms-mie-coefficient-value="props.mieCoefficient"
Copy link
Member

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??

Copy link
Collaborator Author

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 😄

Copy link
Member

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

Copy link
Member

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"
  />

Copy link
Collaborator Author

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.

// const viewport = useThree((state) => state.viewport)
const viewport = { dpr: 1.5 }

const _width = typeof width === 'number' ? width : size.width * viewport.dpr
Copy link
Member

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 :)

Copy link
Collaborator Author

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.

Copy link
Member

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 :)

@kekkorider
Copy link
Collaborator Author

Now we have something 🥸

fbo.mp4

Copy link
Member

@alvarosabu alvarosabu left a 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

settings?: WebGLRenderTargetOptions
}

export const UseFBO = defineComponent<UseFboProps>({
Copy link
Member

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"
Copy link
Member

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?

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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>

@kekkorider
Copy link
Collaborator Author

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).
I'm logging the UUID of the FBO texture in the browser console and it stays the same no matter what.

@kekkorider kekkorider changed the title feat: add useFBO() abstraction feat: add <Fbo /> abstraction Sep 26, 2023
Copy link
Member

@JaimeTorrealba JaimeTorrealba left a 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

@alvarosabu
Copy link
Member

alvarosabu commented Sep 28, 2023

@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)

@kekkorider
Copy link
Collaborator Author

@alvarosabu awesome! I will work on it next week. 🍻

@kekkorider kekkorider marked this pull request as ready for review October 5, 2023 12:44
@kekkorider
Copy link
Collaborator Author

@alvarosabu @JaimeTorrealba I guess we're there 🥳

@alvarosabu
Copy link
Member

Hey @kekkorider amazing job! There seem to be some conflicts with main, could you please check it?

@kekkorider
Copy link
Collaborator Author

Hey @kekkorider amazing job! There seem to be some conflicts with main, could you please check it?

@alvarosabu I just rebased and removed the conflicts 🙌

Copy link
Member

@JaimeTorrealba JaimeTorrealba left a 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

docs/guide/abstractions/fbo.md Outdated Show resolved Hide resolved
docs/guide/abstractions/fbo.md Outdated Show resolved Hide resolved
docs/guide/abstractions/fbo.md Outdated Show resolved Hide resolved
docs/components.d.ts Outdated Show resolved Hide resolved
@kekkorider
Copy link
Collaborator Author

@JaimeTorrealba I just fixed everything you asked 🙌

Copy link
Member

@JaimeTorrealba JaimeTorrealba left a 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

Copy link
Member

@alvarosabu alvarosabu left a 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"
Copy link
Member

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>

docs/components.d.ts Outdated Show resolved Hide resolved
docs/guide/abstractions/use-fbo.md Show resolved Hide resolved
@alvarosabu alvarosabu merged commit 6efc076 into main Oct 7, 2023
6 checks passed
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

Successfully merging this pull request may close these issues.

useFBO abstraction
3 participants