Giter Site home page Giter Site logo

useRender not called about react-three-fiber HOT 4 CLOSED

pmndrs avatar pmndrs commented on May 12, 2024
useRender not called

from react-three-fiber.

Comments (4)

jean-noelp avatar jean-noelp commented on May 12, 2024 1

I found the solution!
I was not using references of my objects to update in render loop, so it was not able to update anything.

So, be carefull to follow these steps :

const geometriesRef = useRef(geometries);
geometriesRef.current = geometries;
useRender(() => {
    geometriesRef.current.map(model => {
        // update things on model
    });
});

So I think there is no bugs.

Thanks for your attention!

from react-three-fiber.

drcmda avatar drcmda commented on May 12, 2024

yes, use render should be called in the render loop. this is how this demo for instance is working: https://codesandbox.io/embed/9y8vkjykyy

useRender has to be in a child component of canvas though. Do you have a codesandbox i could expect?

from react-three-fiber.

jean-noelp avatar jean-noelp commented on May 12, 2024

Until I can isolate the relevant code, I purpose this workaround :

useEffect(() => {
        function tick() {
            // do some render stuff
        }

        if (delay !== null) {
            let id = setInterval(tick, delay);
            return () => clearInterval(id);
        }

    }, [delay]);

from react-three-fiber.

drcmda avatar drcmda commented on May 12, 2024

the problem with this is that you create two frames, one for three and another one, its unclear which runs first, and it will turn into a perf sink once you have many. useRender on the other just calls its subscribers smack in the middle of threes update loop, which is fast, but also leads to deterministic results. for instance here we're painting a scene with effects, and another as a heads up display without effects: https://codesandbox.io/embed/mo0xrqrj79 so basically render effects can be orchestrated.

And there's another thing, canvas can be used multiple times (https://codesandbox.io/s/3411q86j51). If useRender was just a global effect, that would cause some tear.

Maybe you have an idea how to solve these without the canvas-tree dependency ...

from react-three-fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.