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

Video is not rendered when tried to implement "examples/arNFT_video_example.html" #334

Open
subramani01 opened this issue Dec 16, 2024 · 8 comments
Labels
question Further information is requested

Comments

@subramani01
Copy link

subramani01 commented Dec 16, 2024

I downloaded the project zip file and running the examples from there, its working, but when i tried to implement the example on my own its not working.
Can anyone help to render/display the video when the target image is shown to the camera feed.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ARnft example showing a video</title>
    <link rel="stylesheet" href="css/nft-style.css" />
</head>
<body>
    <a
        href="https://raw.githubusercontent.com/artoolkitx/artoolkit5/master/doc/Marker%20images/pinball.jpg"
        class="ui marker"
        target="_blank"
    >
        🖼 Marker Image
    </a>
    <video loop autoplay muted webkit-playsinline playsinline crossorigin="anonymous" id="arvideo">
        <source src="https://avo-content-dev.s3.amazonaws.com/videos/bg_1588085276090.mp4" type="video/mp4" />
    </video>
    <script type="importmap">
        {
            "imports": {
                "three": "/js/third_party/three.js/three.module.min.js",
                "arnft-threejs": "/js/ARnftThreejs.module.js",
                "arnft": "/dist/ARnft.module.js"
            }
        }
    </script>
    <script type="module">
        import * as THREE from "three";
        import arnft from "arnft";
        import ARnftThreejs from "arnft-threejs";
        
        const { ARnft } = arnft;
        const { SceneRendererTJS, NFTaddTJS } = ARnftThreejs;

        let width = 640;
        let height = 480;
        ARnft.init(width, height, [["src/DataNFT/pinball"]], ["pinball"], "config.json", true).then((nft) => {
            console.log('ARnft initialized:', nft);
            let mat = new THREE.MeshLambertMaterial({
                        color: 0xff0000,
            });
            let boxGeom = new THREE.BoxGeometry(1, 1, 1);
            let cube = new THREE.Mesh(boxGeom, mat);
            cube.position.z = 90;
            cube.scale.set(180, 180, 180);
            document.addEventListener("containerEvent", (ev) => {
                console.log("Container event received:", ev);
                let canvas = document.getElementById("canvas");
                let fov = (0.8 * 180) / Math.PI;
                let ratio = width / height;
                let config = {
                    renderer:{
                        alpha: true,
                        antialias: true,
                        context: null,
                        precision: "mediump",
                        premultipliedAlpha: true,
                        stencil: true,
                        depth: true,
                        logarithmicDepthBuffer: true,
                    },
                    camera: {
                        fov:fov,
                        ratio:ratio,
                        near:0.01,
                        far:1000,
                    }
                }

                let sceneThreejs = new SceneRendererTJS(config, canvas, nft.uuid, true);
                sceneThreejs.initRenderer();
                console.log("SceneRendererTJS initialized");

                let nftAddTJS = new NFTaddTJS(nft.uuid);
                // Set width, height and width and height number of segments of the PlaneGeometry.
                let imgConfig = {w:1, h:1, ws:1, hs:1 }
                nftAddTJS.addVideo("arvideo","pinball", 180, imgConfig, false)
                // console.log("Video added to NFT:", nftAddTJS);

                const tick = () => {
                    sceneThreejs.draw();
                    window.requestAnimationFrame(tick);
                }
                tick();
            })
        }).catch((error) => {
            console.log("Error initializing ARnft:", error);
        });
    </script>
</body>
</html>
Screenshot 2024-12-16 at 5 44 57 PM Screenshot 2024-12-16 at 5 50 14 PM
@kalwalt kalwalt added the question Further information is requested label Dec 16, 2024
@kalwalt
Copy link
Member

kalwalt commented Dec 16, 2024

I downloaded the project zip file and running the examples from there, its working, but when i tried to implement the example on my own its now working. Can anyone help to render/display the video when the target image is shown to the camera feed.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ARnft example showing a video</title>
    <link rel="stylesheet" href="css/nft-style.css" />
</head>
<body>
    <a
        href="https://raw.githubusercontent.com/artoolkitx/artoolkit5/master/doc/Marker%20images/pinball.jpg"
        class="ui marker"
        target="_blank"
    >
        🖼 Marker Image
    </a>
    <video loop autoplay muted webkit-playsinline playsinline crossorigin="anonymous" id="arvideo">
        <source src="https://avo-content-dev.s3.amazonaws.com/videos/bg_1588085276090.mp4" type="video/mp4" />
    </video>
    <script type="importmap">
        {
            "imports": {
                "three": "/js/third_party/three.js/three.module.min.js",
                "arnft-threejs": "/js/ARnftThreejs.module.js",
                "arnft": "/dist/ARnft.module.js"
            }
        }
    </script>
    <script type="module">
        import * as THREE from "three";
        import arnft from "arnft";
        import ARnftThreejs from "arnft-threejs";
        
        const { ARnft } = arnft;
        const { SceneRendererTJS, NFTaddTJS } = ARnftThreejs;

        let width = 640;
        let height = 480;
        ARnft.init(width, height, [["src/DataNFT/pinball"]], ["pinball"], "config.json", true).then((nft) => {
            console.log('ARnft initialized:', nft);
            let mat = new THREE.MeshLambertMaterial({
                        color: 0xff0000,
            });
            let boxGeom = new THREE.BoxGeometry(1, 1, 1);
            let cube = new THREE.Mesh(boxGeom, mat);
            cube.position.z = 90;
            cube.scale.set(180, 180, 180);
            document.addEventListener("containerEvent", (ev) => {
                console.log("Container event received:", ev);
                let canvas = document.getElementById("canvas");
                let fov = (0.8 * 180) / Math.PI;
                let ratio = width / height;
                let config = {
                    renderer:{
                        alpha: true,
                        antialias: true,
                        context: null,
                        precision: "mediump",
                        premultipliedAlpha: true,
                        stencil: true,
                        depth: true,
                        logarithmicDepthBuffer: true,
                    },
                    camera: {
                        fov:fov,
                        ratio:ratio,
                        near:0.01,
                        far:1000,
                    }
                }

                let sceneThreejs = new SceneRendererTJS(config, canvas, nft.uuid, true);
                sceneThreejs.initRenderer();
                console.log("SceneRendererTJS initialized");

                let nftAddTJS = new NFTaddTJS(nft.uuid);
                // Set width, height and width and height number of segments of the PlaneGeometry.
                let imgConfig = {w:1, h:1, ws:1, hs:1 }
                nftAddTJS.addVideo("arvideo","pinball", 180, imgConfig, false)
                // console.log("Video added to NFT:", nftAddTJS);

                const tick = () => {
                    sceneThreejs.draw();
                    window.requestAnimationFrame(tick);
                }
                tick();
            })
        }).catch((error) => {
            console.log("Error initializing ARnft:", error);
        });
    </script>
</body>
</html>

Screenshot 2024-12-16 at 5 44 57 PM Screenshot 2024-12-16 at 5 50 14 PM

Hi @subramani01 thanks to report this. Please add more infos: Are you running in localhost the repository? Which OS and Browser are you using? What do you see when the marker is tracked?

@subramani01
Copy link
Author

subramani01 commented Dec 16, 2024

@kalwalt Thanks for the quick reply.

  1. Yes im running in the localhost, and shared the url to the mobile using ngrok.
  2. OS - Ios.
  3. Browser - Safari & Chrome (Checked on both)
  4. I see nothing when the marker is tracked.

I wanted this to work badly cause i saw the demo, its works perfect, the rendered video is not jittering when the target image is detected as compared to all the open source packages i tried so far in the past few days.

Can you help me with this issue.

@kalwalt
Copy link
Member

kalwalt commented Dec 16, 2024

Ok so you are using ngrock that is a bit different i think than running simply a python or node server on your local machine. I have no experience with ngrock, but try to debug if possible and check if if the video stream is interrupted for some reason or maybe a proxy? i don't know.... It's hard to me to help in this sense with so few infos with your set up.

@kalwalt
Copy link
Member

kalwalt commented Dec 16, 2024

Have you a link of your app to share?

@subramani01
Copy link
Author

Can i share the app link that is running on ngrok, you take a look and let me know

@subramani01
Copy link
Author

subramani01 commented Dec 17, 2024

        import * as THREE from "three";
        import arnft from "arnft";
        import ARnftThreejs from "arnft-threejs";
        
        const { ARnft } = arnft;
        const { SceneRendererTJS, NFTaddTJS } = ARnftThreejs;

        let width = 640;
        let height = 480;
        ARnft.init(width, height, [["src/DataNFT/pinball"]], ["pinball"], "config.json", true).then((nft) => {
            console.log('ARnft initialized:', nft);
            document.addEventListener("containerEvent", (ev) => {
                console.log("Container event received:", ev);
                let canvas = document.getElementById("canvas");
                let fov = (0.8 * 180) / Math.PI;
                let ratio = width / height;
                let config = {
                    renderer:{
                        alpha: true,
                        antialias: true,
                        context: null,
                        precision: "mediump",
                        premultipliedAlpha: true,
                        stencil: true,
                        depth: true,
                        logarithmicDepthBuffer: true,
                    },
                    camera: {
                        fov:fov,
                        ratio:ratio,
                        near:0.01,
                        far:1000,
                    }
                }

                let sceneThreejs = new SceneRendererTJS(config, canvas, nft.uuid, true);
                sceneThreejs.initRenderer();
                console.log("SceneRendererTJS initialized");

                let nftAddTJS = new NFTaddTJS(nft.uuid);
                // Set width, height and width and height number of segments of the PlaneGeometry.
                let imgConfig = {w:1, h:1, ws:1, hs:1 }
                nftAddTJS.addVideo("arvideo","pinball", 180, imgConfig, false)
                // console.log("Video added to NFT:", nftAddTJS);

                const tick = () => {
                    sceneThreejs.draw();
                    window.requestAnimationFrame(tick);
                }
                tick();
            })

            window.addEventListener("nftTrackingLost-" + nft.uuid + "-" + "pinball", function (ev) {
                console.log("lost marker");
            });

            window.addEventListener("getMatrixGL_RH-" + nft.uuid + "-" + "pinball", function (ev) {
                console.log("getMatrixGL_RH",ev);
            });
        }).catch((error) => {
            console.log("Error initializing ARnft:", error);
        });

I tried to add eventlisteners to my implementation of the example, its not working, but when i use these two events on your extracted project file its working. let me share two screenshots of console.log, one is from my implementation, other yours.

My implementation console.log:
Screenshot 2024-12-17 at 11 22 52 AM

Your implementation console.log:
Screenshot 2024-12-17 at 11 24 50 AM

@kalwalt
Copy link
Member

kalwalt commented Dec 17, 2024

Can i share the app link that is running on ngrok, you take a look and let me know

yes if possible share it please.

@subramani01
Copy link
Author

I made it work, what i did is instead of adding a new file and trying to implement the example on top of the downloaded source code. i made a new project and used the only files that are necessary to run the example.

Screenshot 2024-12-19 at 11 32 33 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants