<? include_once 'auth.php'; ?>
<header>
    <title>multimodel load v7+</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
	<link rel="shortcut icon" href="#">
    <link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" type="text/css">
</header>

<body style="margin:0">
    <div id="forgeViewer"></div>
</body>

<script src="https://xf79h9aa3l.execute-api.us-west-2.amazonaws.com/toolkit2/api/_adsk.js"></script>
<script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.js"></script>

<script>
let viewer = null;

function loadModels(urns) {

    const viewerOptions = {
        env: 'AutodeskProduction',
        accessToken: <? echo "'". json_decode($data,true)[access_token] . "'" ?>,
    };

    Autodesk.Viewing.Initializer(viewerOptions, () => {

        const div = document.getElementById('forgeViewer');
        viewer = new Autodesk.Viewing.Private.GuiViewer3D(div, {});
        viewer.start();
        urns.map((m)=>{
            Autodesk.Viewing.Document.load(`urn:${m.urn}`, (doc) => {
                var viewables = doc.getRoot().getDefaultGeometry();
                viewer.loadDocumentNode(doc, viewables,{
                    //placementTransform: (new THREE.Matrix4()).setPosition(m.xform),
                    keepCurrentModels: true,
                    globalOffset: {x:0,y:0,z:0}
                })
                .then( onLoadFinished );
            });

        })
    });

    function onLoadFinished(doc) {
       
    }
}
window.addEventListener('DOMContentLoaded', ()=>
    loadModels([
        { urn: "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXRqbGprN2huM2dpdmNpemR6d2NiaGhzbHk4NHB4MTZfdHV0b3JpYWxfYnVja2V0LzNEJTIwR3JpZHMlMjBNb2RlbC5ud2M", xform: {x:0,y:0,z:0} },
        { urn: "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXRqbGprN2huM2dpdmNpemR6d2NiaGhzbHk4NHB4MTZfdHV0b3JpYWxfYnVja2V0L09NQS0wMDQtMDAxLUFFQy1BLUJJTS0wMC0wMDA2Lm53Yw", xform: {x:0,y:0,z:0} },
        ])
);


</script>