Show realistic lighting and shadows for the specific date and time of day.
Use case
You can use realistic lighting to evaluate the shadow impact of buildings and utility infrastructure on the surrounding community. This could be useful for civil engineers and urban planners, or for events management assessing the impact of building shadows during an outdoor event.
How to use the sample
Select one of the three available lighting options to display that lighting effect. Adjust the slider to show the lighting effect for a particular time of day. The 3D buildings will display shadows when "Sun light with shadows" is selected.
How it works
Create an ArcGISSceneLayer and display it in a SceneView.
Create a Date to define the date and time of day.
Set the sun time of the scene view to the specified date and time with sceneView.sunTime.
Set the lightingMode of the scene view to NoLight, Light, or LightAndShadows with sceneView.sunLighting.
Relevant API
ArcGISSceneLayer
LightingMode
Scene
SceneView
Tags
3D, lighting, realism, realistic, rendering, shadows, sun, time
Sample Code
RealisticLightingAndShadows.qml
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// [WriteFile Name=RealisticLightingAndShadows, Category=Analysis]// [Legal]// Copyright 2020 Esri.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]import QtQuick
import QtQuick.Controls
import Esri.ArcGISRuntime
Rectangle {
width: 800height: 600// Create a scene viewSceneView {
id: sceneViewanchors.fill: parentatmosphereEffect: Enums.AtmosphereEffectRealistic
sunLighting: Enums.LightingModeLightAndShadows
sunTime: "2018-08-10T08:30"Component.onCompleted: {
// Set the focus on SceneView to initially enable keyboard navigation forceActiveFocus();
setViewpointCameraAndSeconds(camera, 0);
}
Camera {
id: cameraPoint {
y: 45.54605153789073x: -122.69033380511073z: 941.0002111233771 }
heading: 162.58544227544266pitch: 60.0roll: 0 }
// create a scene, which is a default property of scene viewScene {
// add a basemapBasemap {
initStyle: Enums.BasemapStyleArcGISTopographic
}
// add a surface, which is a default property of sceneSurface {
// add an arcgis tiled elevation source...elevation source is a default property of surfaceArcGISTiledElevationSource {
url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer" }
}
// add a scene service with ArcGISSceneLayerArcGISSceneLayer {
url: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/DevA_BuildingShells/SceneServer/layers/0" }
}
}
Rectangle {
anchors {
top: parent.top
right: parent.right
margins: 5 }
width: childrenRect.width
height: childrenRect.height
color: "#ffffff"opacity: 0.7Column {
id: settingsColumnspacing: 5padding: 15Text {
id: timeValueanchors.horizontalCenter: parent.horizontalCenter
font.pixelSize: 16text: "August 10, 2018, " + sceneView.sunTime.toLocaleTimeString("hh:mm ap")
}
ComboBox {
id: sunLightingSelectionanchors.horizontalCenter: parent.horizontalCenter
width: 200model: [
"No Light",
"Light",
"Light and Shadows" ]
currentIndex: 2 }
Slider {
id: sunTimeSlideranchors.horizontalCenter: parent.horizontalCenter
opacity: 0.7from: 0; to: 23.99value: 8.5onValueChanged: {
sceneView.sunTime = doubleToDateTime(sunTimeSlider.value)
}
}
}
}
states: [
State {
when: sunLightingSelection.currentIndex == 0PropertyChanges {
target: sceneView
sunLighting: Enums.LightingModeNoLight
}
},
State {
when: sunLightingSelection.currentIndex == 1PropertyChanges {
target: sceneView
sunLighting: Enums.LightingModeLight
}
},
State {
when: sunLightingSelection.currentIndex == 2PropertyChanges {
target: sceneView
sunLighting: Enums.LightingModeLightAndShadows
}
}
]
functiondoubleToDateTime(d) {
const remainder = d % 1;
let minute = remainder * 60;
let hour = d - remainder;
if (hour < 10) {
hour = "0" + hour;
}
if (minute < 10) {
minute = "0" + minute;
}
returnnewDate(`2018-08-10 ${hour}:${minute}`);
}
}