Files
gemini-viewer-examples/public/demo/empty_model_project.html

145 lines
4.8 KiB
HTML
Raw Normal View History

2022-11-04 11:39:56 +08:00
<html>
<head>
<link rel="icon" href="./demo/favicon.ico" />
<link rel="stylesheet" type="text/css" href="./demo/global.css" />
2022-11-04 11:39:56 +08:00
<style>
2023-05-15 19:30:47 +08:00
#myCanvas {
width: 100%;
height: 100%;
}
2022-11-04 11:39:56 +08:00
.upload-btn {
margin-top: 2em;
}
.upload-btn button {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.upload-btn label {
color: #353535;
border: 0;
border-radius: 3px;
transition: ease 0.2s;
transition-property: background;
font-size: 1rem;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
display: inline-block;
overflow: hidden;
padding: 0.625rem 1.25rem;
}
.upload-btn label:hover {
background: #DDD;
}
.upload-btn svg {
width: 1em;
height: 1em;
vertical-align: middle;
fill: currentColor;
margin-top: -0.25em;
margin-right: 0.25em;
}
</style>
</head>
<body>
<div id="app">
<div id="myCanvas" class="container"></div>
2022-11-04 11:39:56 +08:00
</div>
<div style="position: absolute; top: 10px; opacity: 0.6; width: 100%;text-align: center;">
<div class="upload-btn" id="uploadBtn">
<button id="uploadModelFile" type="button">点此上传本地模型文件</button>
<label for="uploadModelFile" title="支持 gltf, dxf, obj, stl, fbx, ifc, dae等。只支持单模型文件不支持链接文件。也就是几何体、材质都要内嵌在单一模型文件中。">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"></path></svg>
<span>Upload model</span>
</label>
</div>
</div>
<script type="module">
2023-07-15 00:28:57 +08:00
import {
AxisGizmoPlugin,
BimViewer,
BottomBarPlugin,
GroundShadowPlugin,
LocalModelUploader,
MeasurementPlugin,
NavCubePlugin,
SectionPlugin,
ToolbarMenuId,
} from "./demo/libs/gemini-viewer.esm.min.js";
2022-11-04 11:39:56 +08:00
const project = {
id: "empty_project",
name: "Empty project",
camera: {
},
models: [{
"name": "model 01",
"src": "",
"rotation": [0, 0, 0],
"scale": [1, 1, 1],
"merge": false,
"visible": false
}],
};
2023-04-10 17:23:36 +08:00
const viewer = new BimViewer(
2022-11-04 11:39:56 +08:00
{
containerId: "myCanvas",
2022-11-04 11:39:56 +08:00
toolbarMenuConfig: {
[ToolbarMenuId.BimTree]: { visible: false },
},
enableContextMenu: true,
enableProgressBar: true,
2022-11-04 11:39:56 +08:00
},
project.camera
);
2023-07-15 00:28:57 +08:00
new AxisGizmoPlugin(viewer);
new BottomBarPlugin(viewer);
new GroundShadowPlugin(viewer);
new MeasurementPlugin(viewer);
new NavCubePlugin(viewer);
new SectionPlugin(viewer);
2023-04-10 17:23:36 +08:00
// 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.
2023-06-16 12:09:03 +08:00
const decoderPath = "./demo/three/js/libs/draco/gltf/";
2023-04-10 17:23:36 +08:00
viewer.setDracoDecoderPath(decoderPath);
2022-11-04 11:39:56 +08:00
// loadProjectModel
let counter = 0; // to indicate how many models are loading
project.models.forEach((modelCfg) => {
if (modelCfg.visible === false) {
// visible is true by default
return; // only load visible ones
}
counter++;
2023-04-10 17:23:36 +08:00
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`);
}
2022-11-04 11:39:56 +08:00
).then(() => {
console.log(`[Demo] Loaded model ${modelCfg.src}`);
2022-11-04 11:39:56 +08:00
});
});
2023-04-10 17:23:36 +08:00
const modelUploader = new LocalModelUploader(viewer);
2022-11-04 11:39:56 +08:00
document.getElementById("uploadModelFile").onclick = function() {
modelUploader.openFileBrowserToUpload();
}
</script>
</body>
</html>