how to use Ar.js in react pwa?

259 Views Asked by At

I'm still learning react.js and I want to use AR.js in a react.js PWA but when I tested it, it always shows loading, please wait...

How do I know if it's loading or it's just stuck? and how to make it work? because when I tried the example in codepen it asked for camera permission but mine just showed loading.

this is my ar-page.js and index.html

import React from "react";
const Ar = () => {
    return (
        <div>
            <div style={{
                height: '100%',
                width: '100%',
                position: 'absolute',
                top: 0,
                left: 0,
                backgroundColor: 'white',
                zIndex: 9999,
                display: 'flex',
                justifyContent: 'center',
                alignItems: 'center',
            }}>
                <div>Loading, please wait...</div>
            </div>
            <a-scene
                vr-mode-ui="enabled: false;"
                renderer="logarithmicDepthBuffer: true;"
                embedded
                arjs="trackingMethod: best; sourceType: webcam;debugUIEnabled: false;"
            >
                <a-nft
                    type="nft"
                    url="https://arjs-cors-proxy.herokuapp.com/https://raw.githack.com/AR-js-org/AR.js/master/aframe/examples/image-tracking/nft/trex/trex-image/trex"
                    smooth="true"
                    smoothCount="10"
                    smoothTolerance=".01"
                    smoothThreshold="5"
                >
                    <a-entity
                        gltf-model="https://arjs-cors-proxy.herokuapp.com/https://raw.githack.com/AR-js-org/AR.js/master/aframe/examples/image-tracking/nft/trex/scene.gltf"
                        scale="5 5 5"
                        position="50 150 0"
                    >
                    </a-entity>
                </a-nft>
                <a-entity camera></a-entity>
            </a-scene>
        </div>
    );
};

export default Ar;
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta name="description" content="Web site created using create-react-app" />
    <link rel="apple-touch-icon" href="/logo192.png" />
    <link rel="manifest" href="/manifest.json" />
    <title>React App</title>
    <script defer="defer" src="/static/js/main.27827833.js"></script>
    <link href="/static/css/main.2d57a0fb.css" rel="stylesheet">
    <!-- <script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
    <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
    <script src="https://aframe.io/releases/1.4.0/aframe.min.js"></script> -->
    <script src="https://cdn.jsdelivr.net/gh/aframevr/aframe@1c2407b26c61958baa93967b5412487cd94b290b/dist/aframe-master.min.js"></script>
    <script src="https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/ar.js"></script>
    <!-- <script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
    <script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.6.0/aframe/build/aframe-ar.js"></script> -->
</head>

<body><noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

</body>

</html>

0

There are 0 best solutions below