106 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<html>
 | 
						|
 | 
						|
<head>
 | 
						|
    <link rel="icon" href="./demo/favicon.ico">
 | 
						|
    <link rel="stylesheet" type="text/css" href="./demo/global.css">
 | 
						|
    <style>
 | 
						|
        #myCanvas {
 | 
						|
            width: 100%;
 | 
						|
            height: 100%;
 | 
						|
        }
 | 
						|
    </style>
 | 
						|
</head>
 | 
						|
 | 
						|
<body>
 | 
						|
    <div id="app">
 | 
						|
        <div id="myCanvas" class="container"></div>
 | 
						|
    </div>
 | 
						|
    <script type="module">
 | 
						|
        import {
 | 
						|
            AxisGizmoPlugin,
 | 
						|
            BimViewer,
 | 
						|
            BimViewerToolbarPlugin,
 | 
						|
            MeasurementPlugin,
 | 
						|
            NavCubePlugin,
 | 
						|
            SectionPlugin,
 | 
						|
        } from "./demo/libs/gemini-viewer.esm.min.js";
 | 
						|
        import * as dat from "./demo/libs/dat.gui.module.js";
 | 
						|
        const gui = new dat.GUI();
 | 
						|
 | 
						|
        const project = {
 | 
						|
            "id": "building1",
 | 
						|
            "name": "building1",
 | 
						|
            "models": [{
 | 
						|
                "name": "building1",
 | 
						|
                "src": "./demo/models/gltf/building1.gltf",
 | 
						|
                "edges": true,
 | 
						|
                "visible": true
 | 
						|
            }, {
 | 
						|
                "id": "building1_dxf",
 | 
						|
                "name": "building1 plan drawing",
 | 
						|
                "src": "./demo/models/dxf/building1.dxf",
 | 
						|
                "matrix": [
 | 
						|
                    0.001, 0, 0, 0, // the dxf is in "mm", and gltf is in "meter", so need to set scale 0.001
 | 
						|
                    0, 0, -0.001, 0,
 | 
						|
                    0, 0.001, 0, 0,
 | 
						|
                    -1831.340, 17, 456.910, 1 // also need to consider the base point
 | 
						|
                ],
 | 
						|
                "edges": true,
 | 
						|
                "visible": true
 | 
						|
            }]
 | 
						|
        }
 | 
						|
        const viewer = new BimViewer({
 | 
						|
            containerId: "myCanvas",
 | 
						|
        });
 | 
						|
 | 
						|
        new AxisGizmoPlugin(viewer);
 | 
						|
        new BimViewerToolbarPlugin(viewer);
 | 
						|
        new MeasurementPlugin(viewer);
 | 
						|
        new NavCubePlugin(viewer);
 | 
						|
        new SectionPlugin(viewer);
 | 
						|
 | 
						|
        // font file is needed for loading dxf
 | 
						|
        // const fontFiles = ["./demo/libs/fonts/Microsoft_YaHei_Regular.typeface.json"];
 | 
						|
        const fontFiles = ["./demo/libs/fonts/hztxt.shx", "./demo/libs/fonts/simplex.shx"];
 | 
						|
        await viewer.setFont(fontFiles);
 | 
						|
 | 
						|
        // draco decoder path is needed to load draco encoded models.
 | 
						|
        // gemini-viewer js sdk user maintains draco decoder code somewhere, and provides the path here.
 | 
						|
        const decoderPath = "./demo/libs/draco/gltf/";
 | 
						|
        viewer.setDracoDecoderPath(decoderPath);
 | 
						|
 | 
						|
        project.models.forEach((modelCfg) => {
 | 
						|
            if (modelCfg.visible === false) {
 | 
						|
                // visible is true by default
 | 
						|
                return; // only load visible ones
 | 
						|
            }
 | 
						|
            viewer.loadModel(modelCfg, (event) => {
 | 
						|
                const progress = ((event.loaded * 100) / event.total).toFixed(1);
 | 
						|
                console.log(`[Demo] Loading '${modelCfg.id || modelCfg.name}' progress: ${progress}%`);
 | 
						|
            }, (event) => {
 | 
						|
                console.error("[Demo] Failed to load " + modelCfg.src + ". " + event.message);
 | 
						|
            }).then(() => {
 | 
						|
                console.log(`[Demo] Loaded model ${modelCfg.src}`);
 | 
						|
                // viewer.setToOrthographicCamera(false);
 | 
						|
            });
 | 
						|
        });
 | 
						|
 | 
						|
        // dat.gui controls
 | 
						|
        const controls = {
 | 
						|
            dxfElevation: 0,
 | 
						|
        }
 | 
						|
        // update dxf elevation between -2 to 30, default value is 17.
 | 
						|
        gui.add(controls, "dxfElevation", -2.0, 30.0, 0.1)
 | 
						|
            .name("Dxf elevation")
 | 
						|
            .setValue(17) // the origin value is 17
 | 
						|
            .onChange((val) => {
 | 
						|
                const dxf = viewer.loadedModels.find((model) => model.modelId.endsWith(".dxf"));
 | 
						|
                const object = dxf.object;
 | 
						|
                object.position.setY(val);
 | 
						|
                object.updateMatrix();
 | 
						|
                viewer.enableRender();
 | 
						|
            });
 | 
						|
    </script>
 | 
						|
</body>
 | 
						|
 | 
						|
</html> |