Tileset Flattening Analysis
DMap3D.analysis.flattenAnalysis is used to flatten specified regions on 3D Tiles models.
Import
import DMap3D from 'dmap3d'
import * as Cesium from 'cesium'
Basic Usage
const viewer = new Cesium.Viewer('cesiumContainer')
// Load 3D Tiles model
const tileset = await Cesium.Cesium3DTileset.fromUrl('/path/to/tileset.json')
viewer.scene.primitives.add(tileset)
// Create flattening tool
const flatten = new DMap3D.analysis.flattenAnalysis(viewer)
// Activate flattening (left-click to draw polygon, right-click to finish)
flatten.activate(tileset)
Constructor
new DMap3D.analysis.flattenAnalysis(viewer)
Parameters:
viewer- Cesium.Viewer instance
Methods
activate(tileset, height?)
Activate drawing and apply flattening. The user left-clicks to add polygon vertices, and right-clicks to finish drawing and automatically apply the flattening effect.
// Flatten to polygon center height
flatten.activate(tileset)
// Flatten to specified height (relative to polygon center, in meters)
flatten.activate(tileset, -5.0) // Flatten to 5 meters below center
flatten.activate(tileset, 10.0) // Flatten to 10 meters above center
Parameters:
tileset- Cesium.Cesium3DTileset instanceheight?- Flattening height (optional), default 0 (polygon center height)
setHeight(height)
Dynamically update the flattening height.
flatten.setHeight(-10.0) // Adjust flattening height
clear()
Clear the flattening effect and restore the original model state.
flatten.clear()
destroy()
Destroy the tool and release resources.
flatten.destroy()
Complete Example
const viewer = new Cesium.Viewer('cesiumContainer')
// Load 3D Tiles
const tileset = await Cesium.Cesium3DTileset.fromUrl('/3DTiles/DaYanTa/tileset.json')
viewer.scene.primitives.add(tileset)
await viewer.zoomTo(tileset)
// Create flattening tool
const flatten = new DMap3D.analysis.flattenAnalysis(viewer)
// Activate flattening
flatten.activate(tileset, 0)
// Dynamically adjust height
flatten.setHeight(-5.0)
// Clear flattening
flatten.clear()
// Re-flatten to a different height
flatten.activate(tileset, 10.0)
// Destroy
flatten.destroy()
Technical Principle
- Uses
CustomShaderto modify model vertex heights in the vertex shader - Precisely controls the flattening region through a texture mask
- Based on ENU local coordinate system to ensure the flattening direction is perpendicular to the ground