-
Notifications
You must be signed in to change notification settings - Fork 303
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
Exareyn
wants to merge
5
commits into
iTowns:master
Choose a base branch
from
Exareyn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b247172
examples(Glb): load a glb on 3D map
21a363c
examples(glb): add functional test
f69c046
examples(glb): correct rotation and rename file
26c4219
examples(glb): remove trailing space and rename testing file
e0f2d58
examples(glb): fix name in test file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!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.829361189714537, | ||
45.78511422365657 | ||
), | ||
tilt: 30, | ||
heading: 180, | ||
range: 250, | ||
}; | ||
|
||
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); | ||
|
||
// Set coordinates of the GLB | ||
coord = new itowns.Coordinates( | ||
"EPSG:4326", | ||
4.829501189714537, | ||
45.78510982365657, | ||
12 | ||
); | ||
|
||
// Set position and angle of the glb | ||
model.position.copy(coord.as(view.referenceCrs)); | ||
model.lookAt(model.position.clone().add(coord.geodesicNormal)); | ||
model.rotateX(Math.PI / 2); | ||
|
||
// // Set his own position to work with Itowns referencement | ||
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; | ||
|
||
model.updateMatrixWorld(); | ||
view.scene.add(model); | ||
view.notifyChange(); | ||
}, | ||
() => {}, | ||
(error) => { | ||
// eslint-disable-next-line no-console | ||
console.log("An error happened :"); | ||
// eslint-disable-next-line no-console | ||
console.log(error); | ||
} | ||
); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const assert = require('assert'); | ||
|
||
describe('misc_glft_model', function _() { | ||
let result; | ||
before(async () => { | ||
result = await loadExample( | ||
'examples/misc_gltf_model', | ||
this.fullTitle(), | ||
); | ||
}); | ||
|
||
it('should run', async () => { | ||
assert.ok(result); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove these lines.