Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Handle glTF triangles without indices; add some examples #1385

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163,420 changes: 163,420 additions & 0 deletions assets/models/gltf/GoogleStreetMaps/Beograd_01.gltf

Large diffs are not rendered by default.

Binary file not shown.
197,321 changes: 197,321 additions & 0 deletions assets/models/gltf/GoogleStreetMaps/Dve_kule_GLTF_Small_1.gltf

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions examples/buildings/glb_GoogleStreetMaps_Beograd01.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!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"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded from content delivery network with no integrity check.
</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>
<div class="slideout-sidebar">
<img class="info-icon" src="../../assets/images/gltf_logo.png"/>
<h1>GLTFLoaderPlugin</h1>
<h2>Viewing a glTF model exported from google Street Mapsl</h2>
<p>In this example, we're using a <a
href="../../docs/class/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html"
target="_other">GLTFLoaderPlugin</a> to load the <a
href="https://sketchfab.com/bimcc"
target="_other">House Plan</a> demo model from
binary glTF (.glb).</p>
<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>
</ul>
<h3>Assets</h3>
<ul>
<li>
<a href="https://www.google.com/maps"
target="_other">Model source</a>
</li>
</ul>
</div>
</body>
<script type="module">

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

const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true,
dtxEnabled: true,
colorTextureEnabled: true
});

viewer.camera.eye = [1394.38, 3.78, -247.05];
viewer.camera.look = [1391.46, 0.89, -244.24];
viewer.camera.up = [-0.41, 0.81, 0.40];

const gltfLoader = new GLTFLoaderPlugin(viewer);

const sceneModel = gltfLoader.load({
id: "Beograd_01",
src: "../../assets/models/gltf/GoogleStreetMaps/Beograd_01.gltf"
});

sceneModel.on("loaded", () => {
viewer.cameraFlight.jumpTo(sceneModel);
});

window.viewer = viewer;
</script>
</html>
76 changes: 76 additions & 0 deletions examples/buildings/glb_GoogleStreetMaps_BeogradCenter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!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"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded from content delivery network with no integrity check.
</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>
<div class="slideout-sidebar">
<img class="info-icon" src="../../assets/images/gltf_logo.png"/>
<h1>GLTFLoaderPlugin</h1>
<h2>Viewing a glTF model exported from google Street Maps</h2>
<p>In this example, we're using a <a
href="../../docs/class/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html"
target="_other">GLTFLoaderPlugin</a> to load the <a
href="https://sketchfab.com/bimcc"
target="_other">House Plan</a> demo model from
binary glTF (.glb).</p>
<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>
</ul>
<h3>Assets</h3>
<ul>
<li>
<a href="https://www.google.com/maps"
target="_other">Model source</a>
</li>
</ul>
</div>
</body>
<script type="module">

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

const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true,
colorTextureEnabled: true
});

viewer.camera.eye = [1394.38, 3.78, -247.05];
viewer.camera.look = [1391.46, 0.89, -244.24];
viewer.camera.up = [-0.41, 0.81, 0.40];

// This is a large model, so a distant far clipping plane is recommended

viewer.camera.project.far = 10000;

const gltfLoader = new GLTFLoaderPlugin(viewer);

const sceneModel = gltfLoader.load({
id: "Beograd_Centar_Google_maps",
src: "../../assets/models/gltf/GoogleStreetMaps/Beograd_Centar_Google_maps.glb"
});

sceneModel.on("loaded", () => {
viewer.cameraFlight.jumpTo(sceneModel);
});

window.viewer = viewer;
</script>
</html>
73 changes: 73 additions & 0 deletions examples/buildings/glb_GoogleStreetMaps_DveKule.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!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"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded from content delivery network with no integrity check.
</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>
<div class="slideout-sidebar">
<img class="info-icon" src="../../assets/images/gltf_logo.png"/>
<h1>GLTFLoaderPlugin</h1>
<h2>Viewing a glTF model exported from google Street Maps</h2>
<p>In this example, we're using a <a
href="../../docs/class/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html"
target="_other">GLTFLoaderPlugin</a> to load the <a
href="https://sketchfab.com/bimcc"
target="_other">House Plan</a> demo model from
binary glTF (.glb).</p>
<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>
</ul>
<h3>Assets</h3>
<ul>
<li>
<a href="https://www.google.com/maps"
target="_other">Model source</a>
</li>
</ul>
</div>
</body>
<script type="module">

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

const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true,
dtxEnabled: true,
colorTextureEnabled: true
});

viewer.camera.eye = [1394.38, 3.78, -247.05];
viewer.camera.look = [1391.46, 0.89, -244.24];
viewer.camera.up = [-0.41, 0.81, 0.40];

const gltfLoader = new GLTFLoaderPlugin(viewer);

const sceneModel = gltfLoader.load({
id: "Dve_kule_GLTF_Small_1",
src: "../../assets/models/gltf/GoogleStreetMaps/Dve_kule_GLTF_Small_1.gltf"
});

sceneModel.on("loaded", () => {
viewer.cameraFlight.jumpTo(sceneModel);
});

window.viewer = viewer;
</script>
</html>
34 changes: 19 additions & 15 deletions examples/buildings/glb_HousePlan.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,21 @@ <h3>Assets</h3>
</body>
<script type="module">

import {Viewer, GLTFLoaderPlugin, ReflectionMap, FastNavPlugin, sRGBEncoding} from "../../dist/xeokit-sdk.min.es.js";
import {Viewer, GLTFLoaderPlugin, ReflectionMap, FastNavPlugin, sRGBEncoding} from "../../dist/xeokit-sdk.es.js";

const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true,
pbrEnabled: true
dtxEnabled: false,
colorTextureEnabled: true
});

viewer.camera.eye = [1394.38, 3.78, -247.05];
viewer.camera.look = [1391.46, 0.89, -244.24];
viewer.camera.up = [-0.41, 0.81, 0.40];

viewer.camera.project.far = 10000000

viewer.scene.gammaInput = true;
viewer.scene.gammaOutput = true;
viewer.scene.gammaFactor = 2.4;
Expand All @@ -69,17 +72,17 @@ <h3>Assets</h3>
viewer.scene.sao.kernelRadius = 170;
viewer.scene.sao.intensity = 0.2;

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

new ReflectionMap(viewer.scene, {
src: [
Expand All @@ -97,13 +100,14 @@ <h3>Assets</h3>

const sceneModel = gltfLoader.load({
id: "myHousePlan",
src: "../../assets/models/gltf/HousePlan/glTF-Binary/HousePlan.glb",
edges: true
src: "../../assets/Bexel/Beograd_Centar_Google_maps.glb",
// edges: true
});

sceneModel.on("loaded", () => {
viewer.cameraFlight.jumpTo(sceneModel);
});

window.viewer = viewer;
</script>
</html>
9 changes: 9 additions & 0 deletions examples/buildings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,15 @@
["positioning_geodesicCoordinates", "Loading IFC with WebIFCLoaderPlugin, positioning the model with geodesic coordinates"]
],

"Google Street Maps": [

"#Viewing models from Google Street Maps",

["glb_GoogleStreetMaps_Beograd01", "Viewing a glTF model exported from google Street Maps"],
["glb_GoogleStreetMaps_BeogradCenter", "Viewing a GLB model exported from google Street Maps"],
["glb_GoogleStreetMaps_DveKule", "Viewing a GLB model exported from google Street Maps"]
],

"Misc": [
"# Simulate single-precision rendering jitter",

Expand Down
31 changes: 24 additions & 7 deletions src/viewer/scene/model/SceneModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,10 @@ export class SceneModel extends Component {
this.error("[createGeometry] Param expected: `uvDecodeMatrix` (required for `uvCompressed')");
return null;
}
if (!cfg.buckets && !cfg.indices && (cfg.primitive === "triangles" || cfg.primitive === "solid" || cfg.primitive === "surface")) {
const numPositions = (cfg.positions || cfg.positionsCompressed).length / 3;
cfg.indices = this._createDefaultIndices(numPositions);
}
if (!cfg.buckets && !cfg.indices && cfg.primitive !== "points") {
this.error(`[createGeometry] Param expected: indices (required for '${cfg.primitive}' primitive type)`);
return null;
Expand Down Expand Up @@ -2768,7 +2772,12 @@ export class SceneModel extends Component {
this.error("Param expected: 'uvCompressed' should be accompanied by `uvDecodeMatrix` ('geometryId' is absent)");
return false;
}
if (!cfg.buckets && !cfg.indices && (cfg.primitive === "triangles" || cfg.primitive === "solid" || cfg.primitive === "surface")) {
const numPositions = (cfg.positions || cfg.positionsCompressed).length / 3;
cfg.indices = this._createDefaultIndices(numPositions);
}
if (!cfg.buckets && !cfg.indices && cfg.primitive !== "points") {
cfg.indices = this._createDefaultIndices(numIndices)
this.error(`Param expected: indices (required for '${cfg.primitive}' primitive type)`);
return false;
}
Expand All @@ -2778,9 +2787,9 @@ export class SceneModel extends Component {
}

const useDTX = (!!this._dtxEnabled && (cfg.primitive === "triangles"
|| cfg.primitive === "solid"
|| cfg.primitive === "surface"))
&& (!cfg.textureSetId);
|| cfg.primitive === "solid"
|| cfg.primitive === "surface"))
&& (!cfg.textureSetId);

cfg.origin = cfg.origin ? math.addVec3(this._origin, cfg.origin, math.vec3()) : this._origin;

Expand Down Expand Up @@ -2996,9 +3005,9 @@ export class SceneModel extends Component {
}

const useDTX = (!!this._dtxEnabled
&& (cfg.geometry.primitive === "triangles"
|| cfg.geometry.primitive === "solid"
|| cfg.geometry.primitive === "surface"))
&& (cfg.geometry.primitive === "triangles"
|| cfg.geometry.primitive === "solid"
|| cfg.geometry.primitive === "surface"))
&& (!cfg.textureSetId);

if (useDTX) {
Expand Down Expand Up @@ -3053,6 +3062,14 @@ export class SceneModel extends Component {
return true;
}

_createDefaultIndices(numIndices) {
const indices = [];
for (let i = 0; i < numIndices; i++) {
indices.push(i);
}
return indices;
}

_createMesh(cfg) {
const mesh = new SceneModelMesh(this, cfg.id, cfg.color, cfg.opacity, cfg.transform, cfg.textureSet);
mesh.pickId = this.scene._renderer.getPickID(mesh);
Expand Down Expand Up @@ -3655,7 +3672,7 @@ export class SceneModel extends Component {
for (let i = 0, len = renderFlags.visibleLayers.length; i < len; i++) {
const layerIndex = renderFlags.visibleLayers[i];
this.layerList[layerIndex].drawColorOpaque(renderFlags, frameCtx);
}
}
}

/** @private */
Expand Down
Loading