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

examples(Glb): load a glb on 3D map #2155

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ The following people have contributed to iTowns.
* [Diginove](http://diginove.com/index.php/fr/diginove-lexpertise-en-traitement-dimages/):
* [Michel Benet](https://github.com/mbenevole)

* [Futurmap] (https://www.futurmap.com/)
* [Alexandre Calmels] (http://github.com/exareyn)

The following organizations are the current maintainers of iTowns:
* IGN (http://www.ign.fr)
* Ciril Group (https://www.cirilgroup.com/)
92 changes: 92 additions & 0 deletions examples/itowns_GLB.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html>
<head>
<title>Display a Glb/Gltf object with iTowns</title>

<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/example.css" />
<link rel="stylesheet" type="text/css" href="css/LoadingScreen.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
</head>

<body>
<div id="viewerDiv"></div>
<script src="../dist/itowns.js"></script>
<script type="text/javascript">
var THREE = itowns.THREE
// iTowns namespace defined here
var viewerDiv = document.getElementById("viewerDiv");

var placement = {
coord: new itowns.Coordinates(
"EPSG:4326",
4.827361189714537,
45.78537982365657,
10
),
tilt: 22,
heading: 0,
range: 2840,
};

var view = new itowns.GlobeView(viewerDiv, placement);

var orthoSource = new itowns.TMSSource({
crs: "EPSG:3857",
isInverted: true,
format: "image/png",
url: "http://osm.oslandia.io/styles/klokantech-basic/${z}/${x}/${y}.png",
attribution: {
name: "OpenStreetMap",
url: "http://www.openstreetmap.org/",
},
tileMatrixSet: "PM",
});

var orthoLayer = new itowns.ColorLayer("Ortho", {
source: orthoSource,
});

view.addLayer(orthoLayer);

// Load a new gltf object
itowns.glTFLoader.load(
"https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/models/lampadaire/scene.gltf ",
(gltf) => {
var model = gltf.scene;
model.scale.set(10,10,10)
model.updateMatrixWorld();
model.rotation.set(Math.PI / 2.1, 0, -Math.PI / 4.1);
jailln marked this conversation as resolved.
Show resolved Hide resolved

// Set coordinates of the GLB
coord = new itowns.Coordinates(
"EPSG:4326",
4.829501189714537,
45.78510982365657
).as("EPSG:4978");
model.position.set(coord.x, coord.y, coord.z);

// Set his own position to work with Itowns referencement
jailln marked this conversation as resolved.
Show resolved Hide resolved
object = model;
const boundingBox = new THREE.Box3();
boundingBox.setFromObject(object);
const center = boundingBox.getCenter(new THREE.Vector3());

object.position.x += object.position.x - center.x;
object.position.y += object.position.y - center.y;
object.position.z += object.position.z - center.z;

view.scene.add(model);
},
() => {},
(error) => {
// eslint-disable-next-line no-console
console.log("An error happened :");
// eslint-disable-next-line no-console
console.log(error);
}
);
</script>
</body>
</html>
Loading