-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
298 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<meta name="description" content="Pick from ray"> | ||
<meta name="cesium-sandcastle-labels" content="Development"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> | ||
<script type="text/javascript"> | ||
if(typeof require === 'function') { | ||
require.config({ | ||
baseUrl : '../../../Source', | ||
waitSeconds : 120 | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<style> | ||
@import url(../templates/bucket.css); | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"></div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer'); | ||
var scene = viewer.scene; | ||
scene.globe.depthTestAgainstTerrain = true; | ||
|
||
var i; | ||
var drillPick = false; | ||
var limit = 10; | ||
var pickedFeatures = []; | ||
|
||
Sandcastle.addToggleButton('Drill pick', false, function(checked) { | ||
drillPick = checked; | ||
}); | ||
|
||
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ | ||
url: '../../SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json' | ||
})); | ||
|
||
viewer.zoomTo(tileset); | ||
|
||
var blueCartographic = new Cesium.Cartographic(-1.3196863177294136, 0.6988508714746624, 30.0); | ||
var redCartographic = new Cesium.Cartographic(-1.319681841889412, 0.6989153500784591, 30.0); | ||
|
||
var blueSphere = viewer.entities.add({ | ||
position : Cesium.Cartographic.toCartesian(blueCartographic), | ||
ellipsoid : { | ||
radii : new Cesium.Cartesian3(10.0, 10.0, 10.0), | ||
material : Cesium.Color.BLUE | ||
} | ||
}); | ||
|
||
var redSphere = viewer.entities.add({ | ||
position : Cesium.Cartographic.toCartesian(redCartographic), | ||
ellipsoid : { | ||
radii : new Cesium.Cartesian3(10.0, 10.0, 10.0), | ||
material : Cesium.Color.RED | ||
} | ||
}); | ||
|
||
var arrowPositions = [ | ||
Cesium.Cartographic.toCartesian(blueCartographic), | ||
Cesium.Cartographic.toCartesian(redCartographic) | ||
]; | ||
|
||
var arrow = viewer.entities.add({ | ||
polyline : { | ||
positions : arrowPositions, | ||
width : 10, | ||
followSurface : false, | ||
material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.YELLOW) | ||
} | ||
}); | ||
|
||
var hitSpheres = new Array(limit); | ||
for (i = 0; i < limit; ++i) { | ||
hitSpheres[i] = viewer.entities.add({ | ||
show : false, | ||
position : Cesium.Cartographic.toCartesian(redCartographic), | ||
ellipsoid : { | ||
radii : new Cesium.Cartesian3(3.0, 3.0, 3.0), | ||
material : Cesium.Color.RED | ||
} | ||
}); | ||
} | ||
|
||
function hideAll() { | ||
for (i = 0; i < pickedFeatures.length; ++i) { | ||
pickedFeatures[i].color = Cesium.Color.WHITE; | ||
} | ||
for (i = 0; i < limit; ++i) { | ||
hitSpheres[i].show = false; | ||
} | ||
arrow.show = false; | ||
blueSphere.show = false; | ||
redSphere.show = false; | ||
} | ||
|
||
function showAll(positions) { | ||
if (Cesium.defined(positions)) { | ||
for (i = 0; i < positions.length; ++i) { | ||
hitSpheres[i].show = true; | ||
} | ||
} | ||
arrow.show = true; | ||
blueSphere.show = true; | ||
redSphere.show = true; | ||
} | ||
|
||
function pickFromRay() { | ||
var origin = Cesium.Cartographic.toCartesian(blueCartographic); | ||
var end = Cesium.Cartographic.toCartesian(redCartographic); | ||
var direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(end, origin, new Cesium.Cartesian3()), new Cesium.Cartesian3()); | ||
var ray = new Cesium.Ray(origin, direction); | ||
|
||
var positions = []; | ||
var objects = []; | ||
|
||
if (drillPick) { | ||
positions = scene.drillPickPositionFromRay(ray, limit); | ||
objects = scene.drillPickFromRay(ray, limit); | ||
} else { | ||
var position = scene.pickPositionFromRay(ray); | ||
var object = scene.pickFromRay(ray); | ||
if (Cesium.defined(position)) { | ||
positions = [position]; | ||
} | ||
if (Cesium.defined(object)) { | ||
objects = [object]; | ||
} | ||
} | ||
|
||
pickedFeatures.length = 0; | ||
|
||
for (i = 0; i < objects.length; ++i) { | ||
if (objects[i] instanceof Cesium.Cesium3DTileFeature) { | ||
pickedFeatures.push(objects[i]); | ||
objects[i].color = Cesium.Color.YELLOW; | ||
} | ||
} | ||
for (i = 0; i < positions.length; ++i) { | ||
hitSpheres[i].position = positions[i]; | ||
} | ||
redSphere.position = Cesium.Cartographic.toCartesian(redCartographic); | ||
arrow.polyline.positions = [ | ||
Cesium.Cartographic.toCartesian(blueCartographic), | ||
Cesium.Cartographic.toCartesian(redCartographic) | ||
]; | ||
return positions; | ||
} | ||
|
||
function runAfterRender(callback) { | ||
var afterRenderFunction = function() { | ||
callback(); | ||
scene.postRender.removeEventListener(afterRenderFunction); | ||
}; | ||
scene.postRender.addEventListener(afterRenderFunction); | ||
} | ||
|
||
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas); | ||
handler.setInputAction(function(movement) { | ||
hideAll(); | ||
runAfterRender(function() { | ||
var redPosition = scene.pickPosition(movement.position); | ||
redCartographic = Cesium.Cartographic.fromCartesian(redPosition); | ||
redCartographic.height = 30.0; | ||
var positions = pickFromRay(); | ||
runAfterRender(function() { | ||
showAll(positions); | ||
}); | ||
}); | ||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
|
||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== 'undefined') { | ||
startup(Cesium); | ||
} else if (typeof require === 'function') { | ||
require(['Cesium'], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions
105
Apps/Sandcastle/gallery/development/Sun Visibility.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,105 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<meta name="description" content="Detect whether a position on a model is visible to the sun or not."> | ||
<meta name="cesium-sandcastle-labels" content="Development"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="../Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> | ||
<script type="text/javascript"> | ||
if(typeof require === 'function') { | ||
require.config({ | ||
baseUrl : '../../../Source', | ||
waitSeconds : 120 | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<style> | ||
@import url(../templates/bucket.css); | ||
</style> | ||
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"></div> | ||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
// Click on any part of the plane and a sphere will be drawn, yellow if visible to the sun or blue if in shadow. | ||
var viewer = new Cesium.Viewer('cesiumContainer', { | ||
shadows : true, | ||
selectionIndicator : false | ||
}); | ||
var scene = viewer.scene; | ||
viewer.clock.currentTime = Cesium.JulianDate.fromIso8601('2018-08-30T19:33:29.19360740161209833Z'); | ||
|
||
var url = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; | ||
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0); | ||
var heading = Cesium.Math.toRadians(135); | ||
var pitch = 0; | ||
var roll = 0; | ||
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); | ||
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); | ||
var entity = viewer.entities.add({ | ||
position : position, | ||
orientation : orientation, | ||
model : { | ||
uri : url, | ||
minimumPixelSize : 128, | ||
maximumScale : 20000 | ||
} | ||
}); | ||
viewer.trackedEntity = entity; | ||
|
||
function getSunPosition() { | ||
var transformMatrix = Cesium.Transforms.computeTemeToPseudoFixedMatrix(viewer.clock.currentTime, new Cesium.Matrix3()); | ||
var sunPosition = Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(viewer.clock.currentTime); | ||
Cesium.Matrix3.multiplyByVector(transformMatrix, sunPosition, sunPosition); | ||
return sunPosition; | ||
} | ||
|
||
function inShadow(position) { | ||
var direction = new Cesium.Cartesian3(); | ||
var origin = new Cesium.Cartesian3(); | ||
var sunPosition = getSunPosition(); | ||
direction = Cesium.Cartesian3.normalize(Cesium.Cartesian3.subtract(position, sunPosition, direction), direction); | ||
origin = Cesium.Cartesian3.add(position, Cesium.Cartesian3.multiplyByScalar(direction, -10.0, origin), origin); | ||
|
||
var ray = new Cesium.Ray(origin, direction); | ||
var pickedPosition = scene.pickPositionFromRay(ray); | ||
|
||
var shadowed = !Cesium.Cartesian3.equalsEpsilon(pickedPosition, position, Cesium.Math.EPSILON7); | ||
var color = shadowed ? Cesium.Color.BLUE : Cesium.Color.YELLOW; | ||
|
||
viewer.entities.add({ | ||
position: position, | ||
ellipsoid : { | ||
radii : new Cesium.Cartesian3(0.2, 0.2, 0.2), | ||
material : color | ||
} | ||
}); | ||
} | ||
|
||
viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) { | ||
if (scene.pickPositionSupported) { | ||
var position = scene.pickPosition(movement.position); | ||
if (Cesium.defined(position)) { | ||
inShadow(position); | ||
} | ||
} | ||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK); | ||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== 'undefined') { | ||
startup(Cesium); | ||
} else if (typeof require === 'function') { | ||
require(['Cesium'], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.