Giter Site home page Giter Site logo

Render to Three JS Canvas Texture about zimjs HOT 4 CLOSED

danzen avatar danzen commented on May 30, 2024
Render to Three JS Canvas Texture

from zimjs.

Comments (4)

IRobot1 avatar IRobot1 commented on May 30, 2024

Here's a couple of threejs examples using canvas texture and VR sandbox using underlying HTMLMesh

from zimjs.

danzen avatar danzen commented on May 30, 2024

We want to do that too @IRobot1. Here is a solution - you can set the F.canvas.style.display = "none". You also need to move the threejs code into the ready event as the canvas needs to be ready. If you are animating then you need to add cube.material.map.needsUpdate = true; in the render loop. If you were not animating and not using the needsUpdate then you need to S.update() before doing the threejs code so there is something on the canvas when you add it. Note, we imported our three version... optional - which also has orbitcontrols.

<script type="module">

    import zim from "https://zimjs.org/cdn/014/zim_three";

    new Frame(FIT, 256, 256, light, dark, ready);
    function ready() {

        F.makeIcon(null,dark)
            .sca(2)
            .centerReg()
            .animate({
                props:{scale:1},
                rewind:true,
                loop:true
            })            
    
        F.canvas.style.display = "none";

        // S.update(); // if not animating, make sure to update the stage before applying texture

        const scene = new THREE.Scene();
        const camera = new THREE.PerspectiveCamera(
            75,
            window.innerWidth / window.innerHeight,
            0.1,
            1000
        );
                        
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        // ****
        const canvastexture = new THREE.CanvasTexture(F.canvas)

        const controls = new OrbitControls(camera, renderer.domElement);

        const geometry = new THREE.PlaneGeometry();
        const material = new THREE.MeshBasicMaterial({ map: canvastexture });

        const cube = new THREE.Mesh(geometry, material);
        scene.add(cube);
        camera.position.z = 2;
        const animate = () => {
            requestAnimationFrame(animate);
            // ***** if animating this is needed
            cube.material.map.needsUpdate = true;
            renderer.render(scene, camera);
        };
        animate()
        
    } // end ready
    
</script>

from zimjs.

danzen avatar danzen commented on May 30, 2024

Test file: https://zimjs.com/test6/three.html

from zimjs.

danzen avatar danzen commented on May 30, 2024

https://zimjs.com/editor/view/Z_FFZ7D

from zimjs.

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.