Skip to content

Commit

Permalink
Merge pull request #1600 from xeokit/auto-gltf-metamodel
Browse files Browse the repository at this point in the history
Auto gltf metamodel
  • Loading branch information
xeolabs committed Jul 28, 2024
2 parents d0eead5 + c2b0ada commit 16ac31c
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 1 deletion.
Binary file added assets/models/gltf/MAP/MAP.glb
Binary file not shown.
241 changes: 241 additions & 0 deletions examples/buildings/glb_autoMetaModel_MAP.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>xeokit Example</title>
<link href="../css/pageStyle.css" rel="stylesheet"/>
<style>

/* ----------------------------------------------------------------------------------------------------------*/
/* NavCubePlugin */
/* ----------------------------------------------------------------------------------------------------------*/

#myNavCubeCanvas {
position: absolute;
width: 250px;
height: 250px;
bottom: 50px;
right: 10px;
z-index: 200000;
}

/* ----------------------------------------------------------------------------------------------------------*/
/* TreeViewPlugin */
/* ----------------------------------------------------------------------------------------------------------*/

#treeViewContainer {
pointer-events: all;
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
position: absolute;
background-color: rgba(255, 255, 255, 0.2);
color: black;
top: 80px;
z-index: 200000;
float: left;
left: 0;
padding-left: 10px;
font-family: 'Roboto', sans-serif;
font-size: 15px;
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
width: 350px;
}

#treeViewContainer ul {
list-style: none;
padding-left: 1.75em;
pointer-events: none;
}

#treeViewContainer ul li {
position: relative;
width: 500px;
pointer-events: none;
padding-top: 3px;
padding-bottom: 3px;
vertical-align: middle;
}

#treeViewContainer ul li a {
background-color: #eee;
border-radius: 50%;
color: #000;
display: inline-block;
height: 1.5em;
left: -1.5em;
position: absolute;
text-align: center;
text-decoration: none;
width: 1.5em;
pointer-events: all;
}

#treeViewContainer ul li a.plus {
background-color: #ded;
pointer-events: all;
}

#treeViewContainer ul li a.minus {
background-color: #eee;
pointer-events: all;
}

#treeViewContainer ul li a:active {
top: 1px;
pointer-events: all;
}

#treeViewContainer ul li span:hover {
color: white;
cursor: pointer;
background: black;
padding-left: 2px;
pointer-events: all;
}

#treeViewContainer ul li span {
display: inline-block;
width: calc(100% - 50px);
padding-left: 2px;
pointer-events: all;
height: 23px;
}

#treeViewContainer .highlighted-node { /* Appearance of node highlighted with TreeViewPlugin#showNode() */
border: black solid 1px;
background: yellow;
color: black;
padding-left: 1px;
padding-right: 5px;
pointer-events: all;
}

</style>

<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<canvas id="myNavCubeCanvas"></canvas>
<div id="treeViewContainer"></div>
<div class="slideout-sidebar">
<img class="info-icon" style="width:280px; padding-bottom:10px;" src="../../assets/images/bim_icon.png"/>
<h1>GLTFLoaderPlugin and Data Textures</h1>
<h2>Loading a BIM model from an XKT file into a data texture model representation</h2>

<h3>Stats</h3>
<ul>
<li>
<div id="time">Loading JavaScript modules...</div>
</li>
</ul>
<h3>Components used</h3>
<ul>
<li>
<a href="../../docs/class/src/viewer/Viewer.js~Viewer.html"
target="_other">Viewer</a>
</li>
<li>
<a href="../../docs/class/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html"
target="_other">GLTFLoaderPlugin</a>
</li>
<li>
<a href="../../docs/class/src/plugins/TreeViewPlugin/TreeViewPlugin.js~TreeViewPlugin.html"
target="_other">TreeViewPlugin</a>
</li>
<li>
<a href="../../docs/class/src/plugins/NavCubePlugin/NavCubePlugin.js~NavCubePlugin.html"
target="_other">NavCubePlugin</a>
</li>
</ul>
<h3>Tutorials</h3>
<ul>
<li>
<a href="https://www.notion.so/xeokit/Compact-Model-Representation-using-Data-Textures-e8093ae372fa47bf9995c26dc24ccd53?pvs=4"
target="_other">Compact Model Representation using Data Textures</a>
</li>
</ul>
<h3>Assets</h3>
<ul>
<li><a href="https://www.cityjson.org/" target="_other">Model source</a></li>
</ul>
</div>
</body>

<script type="module">

import {Viewer, GLTFLoaderPlugin, NavCubePlugin, TreeViewPlugin, FastNavPlugin} from "../../dist/xeokit-sdk.es.js";

const viewer = new Viewer({
canvasId: "myCanvas",
edges: true,
transparent: true,
saoEnabled: true,
dtxEnabled: true // Enable data texture model representation
});

viewer.scene.camera.eye=[1841982.9384371885, 10.031355126263318, -5173286.744630201];
viewer.scene.camera.look=[1842009.4968455553, 9.685518291306686, -5173295.851503017];
viewer.scene.camera.up=[0.011650847910481935, 0.9999241456889114, -0.003995073374452514];

viewer.cameraControl.enablePivotSphere({
size: 1
});

new NavCubePlugin(viewer, {
canvasId: "myNavCubeCanvas",
visible: true,
size: 250,
alignment: "bottomRight",
bottomMargin: 100,
rightMargin: 10
});

new FastNavPlugin(viewer, {
hideEdges: true,
hideSAO: true,
hideColorTexture: true,
hidePBR: true,
hideTransparentObjects: false,
// scaleCanvasResolution: true,
// scaleCanvasResolutionFactor: 0.5,
delayBeforeRestore: true,
delayBeforeRestoreSeconds: 0.4
});

new TreeViewPlugin(viewer, {
containerElement: document.getElementById("treeViewContainer"),
hierarchy: "containment",
autoExpandDepth: 1
});

const gltfLoaderPlugin = new GLTFLoaderPlugin(viewer);

const sceneModel = gltfLoaderPlugin.load({
id: "myModel",
src: "../../assets/models/gltf/MAP/MAP.glb",
autoMetaModel:true,
saoEnabled: true,
edges: true,
dtxEnabled: true
});

const t0 = performance.now();
document.getElementById("time").innerHTML = "Loading model...";
sceneModel.on("loaded", function () {
const t1 = performance.now();
document.getElementById("time").innerHTML = "Model loaded in " + Math.floor(t1 - t0) / 1000.0 + " seconds<br>Objects: " + sceneModel.numEntities;
});

window.viewer = viewer;

</script>
</html>
1 change: 1 addition & 0 deletions examples/buildings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@

"#Binary glTF + VBOs",

["glb_autoMetaModel_MAP", "IFC4 MAP model loaded from glTF into SceneModel using autoMetaModel option"],
["glb_HousePlan", "House plan model loaded from GLB into SceneModel using GLTFLoaderPlugin"],
["glb_VianneyHouse", "Vianney house model loaded from GLB into SceneModel using GLTFLoaderPlugin"]
],
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class GLTFLoaderPlugin extends Plugin {
* represent the returned model. Set false to always use vertex buffer objects (VBOs). Note that DTX is only applicable
* to non-textured triangle meshes, and that VBOs are always used for meshes that have textures, line segments, or point
* primitives. Only works while {@link DTX#enabled} is also ````true````.
* @param {String} [params.entityId] When supplied, causes the entire model to be loaded into a single {@link Entity} that gets this ID.
* @param {Boolean} [params.autoMetaModel] When supplied, creates a default MetaModel with a single MetaObject.
* @returns {Entity} Entity representing the model, which will have {@link Entity#isModel} set ````true```` and will be registered by {@link Entity#id} in {@link Scene#models}
*/
load(params = {}) {
Expand Down

0 comments on commit 16ac31c

Please sign in to comment.