|
75 | 75 | function ProceduralMultiTileVoxelProvider(shape) { |
76 | 76 | this.shape = shape; |
77 | 77 | this.dimensions = new Cesium.Cartesian3(4, 4, 4); |
| 78 | + this.minBounds = Cesium.VoxelShapeType.getMinBounds(shape).clone(); |
| 79 | + this.maxBounds = Cesium.VoxelShapeType.getMaxBounds(shape).clone(); |
78 | 80 | this.names = ["color"]; |
79 | 81 | this.types = [Cesium.MetadataType.VEC4]; |
80 | 82 | this.componentTypes = [Cesium.MetadataComponentType.FLOAT32]; |
|
134 | 136 | return dataColor; |
135 | 137 | } |
136 | 138 |
|
137 | | - const provider = new ProceduralMultiTileVoxelProvider(Cesium.VoxelShapeType.BOX); |
138 | | - |
139 | 139 | const customShader = new Cesium.CustomShader({ |
140 | 140 | fragmentShaderText: `void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) |
141 | | - { |
| 141 | + { |
142 | 142 | vec3 voxelNormal = fsInput.attributes.normalEC; |
143 | 143 | float diffuse = max(0.0, dot(voxelNormal, czm_lightDirectionEC)); |
144 | 144 | float lighting = 0.5 + 0.5 * diffuse; |
|
147 | 147 | int sampleIndex = fsInput.voxel.sampleIndex; |
148 | 148 | vec3 cellColor = fsInput.metadata.color.rgb * lighting; |
149 | 149 | if (tileIndex == u_selectedTile && sampleIndex == u_selectedSample) { |
150 | | - material.diffuse = mix(cellColor, vec3(1.0), 0.5); |
151 | | - material.alpha = fsInput.metadata.color.a; |
| 150 | + material.diffuse = mix(cellColor, vec3(1.0), 0.5); |
| 151 | + material.alpha = fsInput.metadata.color.a; |
152 | 152 | } else { |
153 | | - material.diffuse = cellColor; |
154 | | - material.alpha = fsInput.metadata.color.a; |
| 153 | + material.diffuse = cellColor; |
| 154 | + material.alpha = fsInput.metadata.color.a; |
155 | 155 | } |
156 | | - }`, |
| 156 | + }`, |
157 | 157 | uniforms: { |
158 | 158 | u_selectedTile: { |
159 | 159 | type: Cesium.UniformType.INT, |
|
166 | 166 | }, |
167 | 167 | }); |
168 | 168 |
|
169 | | - const voxelPrimitive = scene.primitives.add( |
170 | | - new Cesium.VoxelPrimitive({ |
| 169 | + function createPrimitive(provider) { |
| 170 | + viewer.scene.primitives.removeAll(); |
| 171 | + |
| 172 | + const voxelPrimitive = new Cesium.VoxelPrimitive({ |
171 | 173 | provider: provider, |
172 | 174 | customShader: customShader, |
173 | | - }), |
174 | | - ); |
| 175 | + }); |
| 176 | + voxelPrimitive.nearestSampling = true; |
175 | 177 |
|
176 | | - voxelPrimitive.nearestSampling = true; |
| 178 | + viewer.scene.primitives.add(voxelPrimitive); |
| 179 | + camera.flyToBoundingSphere(voxelPrimitive.boundingSphere, { |
| 180 | + duration: 0.0, |
| 181 | + }); |
177 | 182 |
|
178 | | - camera.flyToBoundingSphere(voxelPrimitive.boundingSphere, { |
179 | | - duration: 0.0, |
180 | | - }); |
| 183 | + return voxelPrimitive; |
| 184 | + } |
| 185 | + |
| 186 | + Sandcastle.addToolbarMenu([ |
| 187 | + { |
| 188 | + text: "Box - Procedural Tileset", |
| 189 | + onselect: function () { |
| 190 | + const provider = new ProceduralMultiTileVoxelProvider( |
| 191 | + Cesium.VoxelShapeType.BOX, |
| 192 | + ); |
| 193 | + const primitive = createPrimitive(provider); |
| 194 | + }, |
| 195 | + }, |
| 196 | + { |
| 197 | + text: "Ellipsoid - Procedural Tileset", |
| 198 | + onselect: function () { |
| 199 | + const provider = new ProceduralMultiTileVoxelProvider( |
| 200 | + Cesium.VoxelShapeType.ELLIPSOID, |
| 201 | + ); |
| 202 | + provider.minBounds.z = 0.0; |
| 203 | + provider.maxBounds.z = 1000000.0; |
| 204 | + const primitive = createPrimitive(provider); |
| 205 | + }, |
| 206 | + }, |
| 207 | + { |
| 208 | + text: "Cylinder - Procedural Tileset", |
| 209 | + onselect: function () { |
| 210 | + const provider = new ProceduralMultiTileVoxelProvider( |
| 211 | + Cesium.VoxelShapeType.CYLINDER, |
| 212 | + ); |
| 213 | + const primitive = createPrimitive(provider); |
| 214 | + }, |
| 215 | + }, |
| 216 | + ]); |
181 | 217 |
|
182 | 218 | const handler = new Cesium.ScreenSpaceEventHandler(scene.canvas); |
183 | 219 | const pickedCoordinate = document.getElementById("pickedCoordinate"); |
|
0 commit comments