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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
| <template> <CesiumMap @viewerCreated="viewerCreated" /> <el-select class="select" v-model="styleVal" placeholder="空" @change="handleStyleChange"> <el-option v-for="item in styles" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </template>
<script setup>
let viewer, scene, tileset, style;
const styleVal = ref("Step Red/Blue");
const styles = [ { value: "Step Red/Blue", label: "红蓝阈值分段" }, { value: "Interpolate Red/Blue", label: "红蓝线性渐变" }, { value: "Red", label: "纯红色" }, { value: "Color Gradient", label: "动态颜色渐变" }, { value: "Color Ramp", label: "多级色阶分段" }, { value: "Transparency", label: "透明度动态控制" }, { value: "Hide Low Temperature", label: "低温隐藏" }, { value: "Show Subsections", label: "ID区间筛选显示" }, { value: "Mod", label: "奇偶ID筛选" }, { value: "Abs", label: "绝对值着色" }, { value: "Trigonometric Functions", label: "三角函数混合着色" }, { value: "Arc Trigonometric Functions", label: "反三角函数混合着色" }, { value: "Sqrt", label: "平方根动态着色" }, { value: "Sign", label: "坐标符号映射" }, { value: "Rounding Functions", label: "坐标取整着色" }, { value: "Exp and Log Functions", label: "颜色通道做指数/对数运算" }, { value: "Fractional Part", label: "截取小数部分着色" }, { value: "Pow", label: "幂函数(三次方)着色" }, { value: "Min and Max", label: "坐标极值组成颜色通道" }, { value: "Clamp and Mix", label: "温度值的约束(clamp)" }, { value: "Secondary Color", label: "辅助色分级控制" }, { value: "Use point colors", label: "点颜色灰度混合" }, { value: "Use point positions", label: "坐标阈值筛选" }, { value: "Color based on position", label: "依据坐标着色" }, { value: "Style point size", label: "依据温度来设置点尺寸" }, { value: "Multiple defines", label: "多个属性形成的复合样式" }, { value: "No Style", label: "无样式" }, ];
function viewerCreated(v) { viewer = v; scene = viewer.scene; viewer.clock.currentTime = new Cesium.JulianDate(2457522.154792); addPointCloudData(); }
async function addPointCloudData() { try { tileset = await Cesium.Cesium3DTileset.fromUrl( "./SampleData/Cesium3DTiles/PointCloud/PointCloudWithPerPointProperties/tileset.json" ); handleStyleChange(styleVal.value); viewer.scene.primitives.add(tileset); viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(1.0, -1.0, 15.0)); } catch (error) { ElMessage.error(`加载点云数据加载出错: ${error}`); } }
function handleStyleChange(value) { switch (value) { case "Step Red/Blue": style = { color: "${temperature} > 0.5 ? color('red') : color('blue')", }; break; case "Interpolate Red/Blue": style = { color: "color('red') * ${temperature} + color('blue') * (1.0 - ${temperature})", }; break; case "Red": style = { color: "color('#ff0000')", }; break; case "Color Gradient": style = { color: "color() * ${temperature}", }; break; case "Color Ramp": style = { color: { conditions: [ ["${temperature} < 0.1", "color('#000099')"], ["${temperature} < 0.2", "color('#00cc99', 1.0)"], ["${temperature} < 0.3", "color('#66ff33', 0.5)"], ["${temperature} < 0.4", "rgba(255, 255, 0, 0.1)"], ["${temperature} < 0.5", "rgb(255, 128, 0)"], ["${temperature} < 0.6", "color('red')"], ["${temperature} < 0.7", "color('rgb(255, 102, 102)')"], ["${temperature} < 0.8", "hsl(0.875, 1.0, 0.6)"], ["${temperature} < 0.9", "hsla(0.83, 1.0, 0.5, 0.1)"], ["true", "color('#FFFFFF', 1.0)"], ], }, }; break; case "Transparency": style = { color: "rgba(0, 255, 0, ${temperature})", }; break; case "Hide Low Temperature": style = { color: "rgb(${temperature}*255, 0, 0)", show: "${temperature} > 0.3", }; break; case "Show Subsections": style = { show: "${id} === 1 || ${id} > 250 && ${id} < 300", }; break; case "Mod": style = { show: "${id} % 2 === 0", }; break; case "Abs": style = { color: "color() * abs(${temperature} - 0.5)", }; break; case "Trigonometric Functions": style = { color: "color() * radians(cos(${temperature})) + color() * sin(${temperature}) + color() * tan(${temperature})", }; break; case "Arc Trigonometric Functions": style = { color: "color() * acos(degrees(${temperature})) + color() * asin(${temperature}) + color() * atan(${temperature}) + color() * atan2(${POSITION}[0],${temperature})", }; break; case "Sqrt": style = { color: "color() * sqrt(${temperature})", }; break; case "Sign": style = { color: "rgb(sign(${POSITION}[0]) * 255, sign(${POSITION}[1]) * 255, sign(${POSITION}[2]) * 255)", }; break; case "Rounding Functions": style = { color: "rgb(floor(${POSITION}[0]) * 255, ceil(${POSITION}[1]) * 255, round(${POSITION}[2]) * 255)", }; break; case "Exp and Log Functions": style = { color: "rgb(log(${POSITION}[0]) * 255, log2(${POSITION}[1]) * 255 + exp2(${POSITION}[1]) * 255, exp(${POSITION}[2]) * 255)", }; break; case "Fractional Part": style = { color: "rgb(fract(${POSITION}[0]) * 255, fract(${POSITION}[1]) * 255, fract(${POSITION}[2]) * 255)", }; break; case "Pow": style = { color: "color() * pow(${temperature}, 3)", }; break; case "Min and Max": style = { color: "rgb(min(${POSITION}.x, 0.75) * 255, max(${POSITION}.z, 0.25) * 255, 255)", }; break; case "Clamp and Mix": style = { color: "color() * clamp(${temperature}, 0.1, 0.2)", }; break; case "Secondary Color": style = { color: { conditions: [ ["${id} < 250", "vec4(${secondaryColor}, 1.0)"], ["${id} < 500", "vec4(${secondaryColor} * ${secondaryColor}, 1.0)"], ["${id} < 750", "vec4(${secondaryColor} / 5.0, 1.0)"], [ "${id} < 1000", "rgb(0, 0, Number(${secondaryColor}.x < 0.5) * 255)", ], ], }, }; break; case "Use point colors": style = { color: "${COLOR} * ${temperature} + rgb(128,128,128)", }; break; case "Use point positions": style = { show: "${POSITION}[0] > 0.5 || ${POSITION}[1] > 0.5 || ${POSITION}[2] > 0.5", }; break; case "Color based on position": style = { color: "vec4(${POSITION}, 1.0)", }; break; case "Style point size": style = { color: "color('red')", pointSize: "${temperature} * 10", }; break; case "Multiple defines": style = { defines: { length: "length(${POSITION})", time: "${tiles3d_tileset_time} * 3.0", }, color: { conditions: [ ["${length} < 0.5", "${length} * color('red')"], [ "${length} < 1.0", "vec4(vec3(${temperature} * fract(${time})), 1.0)", ], ["true", "${COLOR}"], ], }, pointSize: "5.0 - ${length} * 2.0", show: "${length} < 2.0", }; break; case "No Style": style = {}; break; default: style = {}; break; } style.pointSize = Cesium.defaultValue(style.pointSize, 5.0); if (!Cesium.defined(tileset)) { return; } tileset.style = new Cesium.Cesium3DTileStyle(style); }
</script>
<style lang="scss" scoped> .select { position: absolute; top: 20px; right: 20px; width: 240px; } </style>
|