3D Tiles Batch Table Hierarchy.html 6.75 KB
Newer Older
Schaaf's avatar
Schaaf committed
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- Use Chrome Frame in IE -->
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
    />
    <meta
      name="description"
      content="Demonstrates use cases for a batch table hierarchy."
    />
    <meta name="cesium-sandcastle-labels" content="3D Tiles" />
    <title>Cesium Demo</title>
    <script type="text/javascript" src="../Sandcastle-header.js"></script>
    <script
      type="text/javascript"
      src="../../../Build/CesiumUnminified/Cesium.js"
      nomodule
    ></script>
    <script type="module" src="../load-cesium-es6.js"></script>
  </head>
  <body
    class="sandcastle-loading"
    data-sandcastle-bucket="bucket-requirejs.html"
  >
    <style>
      @import url(../templates/bucket.css);
      #toolbar button {
        display: block;
      }
    </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

        // Doorknobs, doors, roofs, and walls are styled with the batch table hierarchy.
        // Since buildings and zones are not backed by geometry they are not styled directly. However
        // styles may be written that take building and zone properties into account.
        //
        // Hierarchy layout (doorknobs are children of doors):
        //
        //   zone0
        //     building0
        //       roof0
        //       wall0
        //       door0 - doorknob0
        //       door1 - doorknob1
        //       door2 - doorknob2
        //       door3 - doorknob3
        //     building1
        //       roof1
        //       wall1
        //       door4 - doorknob4
        //       door5 - doorknob5
        //       door6 - doorknob6
        //       door7 - doorknob7
        //     building2
        //       roof2
        //       wall2
        //       door8 - doorknob8
        //       door9 - doorknob9
        //       door10 - doorknob10
        //       door11 - doorknob11
        //
        // Class properties:
        //
        //   zone:
        //     * zone_building
        //     * zone_name
        //   building:
        //     * building_area
        //     * building_name
        //   wall:
        //     * wall_paint
        //     * wall_windows
        //     * wall_name
        //   roof:
        //     * roof_paint
        //     * roof_name
        //   door:
        //     * door_mass
        //     * door_width
        //     * door_name
        //   doorknob:
        //     * doorknob_size
        //     * doorknob_name

        var viewer = new Cesium.Viewer("cesiumContainer");
        viewer.clock.currentTime = new Cesium.JulianDate(2457522.154792);

        var tileset = new Cesium.Cesium3DTileset({
          url:
            "../../SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json",
        });

        viewer.scene.primitives.add(tileset);
        viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.3, 0.0));

        var styles = [];
        function addStyle(name, style) {
          styles.push({
            name: name,
            style: style,
          });
        }

        addStyle("No style", {});

        addStyle("Color by building", {
          color: {
            conditions: [
              ["${building_name} === 'building0'", "color('purple')"],
              ["${building_name} === 'building1'", "color('red')"],
              ["${building_name} === 'building2'", "color('orange')"],
              ["true", "color('blue')"],
            ],
          },
        });

        addStyle("Color all doors", {
          color: {
            conditions: [
              ["isExactClass('door')", "color('orange')"],
              ["true", "color('white')"],
            ],
          },
        });

        addStyle("Color all features derived from door", {
          color: {
            conditions: [
              ["isClass('door')", "color('orange')"],
              ["true", "color('white')"],
            ],
          },
        });

        addStyle("Color features by class name", {
          defines: {
            suffix: "regExp('door(.*)').exec(getExactClassName())",
          },
          color: {
            conditions: [
              ["${suffix} === 'knob'", "color('yellow')"],
              ["${suffix} === ''", "color('lime')"],
              ["${suffix} === null", "color('gray')"],
              ["true", "color('blue')"],
            ],
          },
        });

        addStyle("Style by height", {
          color: {
            conditions: [
              ["${height} >= 10", "color('purple')"],
              ["${height} >= 6", "color('red')"],
              ["${height} >= 5", "color('orange')"],
              ["true", "color('blue')"],
            ],
          },
        });

        function setStyle(style) {
          return function () {
            tileset.style = new Cesium.Cesium3DTileStyle(style);
          };
        }

        var styleOptions = [];
        for (var i = 0; i < styles.length; ++i) {
          var style = styles[i];
          styleOptions.push({
            text: style.name,
            onselect: setStyle(style.style),
          });
        }

        Sandcastle.addToolbarMenu(styleOptions);

        var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);

        // When a feature is left clicked, print its class name and properties
        handler.setInputAction(function (movement) {
          var feature = viewer.scene.pick(movement.position);
          if (!Cesium.defined(feature)) {
            return;
          }
          console.log("Class: " + feature.getExactClassName());
          console.log("Properties:");
          var propertyNames = feature.getPropertyNames();
          var length = propertyNames.length;
          for (var i = 0; i < length; ++i) {
            var name = propertyNames[i];
            var value = feature.getProperty(name);
            console.log("  " + name + ": " + value);
          }
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

        // When a feature is middle clicked, hide it
        handler.setInputAction(function (movement) {
          var feature = viewer.scene.pick(movement.position);
          if (!Cesium.defined(feature)) {
            return;
          }
          feature.show = false;
        }, Cesium.ScreenSpaceEventType.MIDDLE_CLICK);
        //Sandcastle_End
        Sandcastle.finishedLoading();
      }
      if (typeof Cesium !== "undefined") {
        window.startupCalled = true;
        startup(Cesium);
      }
    </script>
  </body>
</html>