3D Tiles Point Cloud
Runnable Cesium example: 3D Tiles Point Cloud. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.
single HTML file · CDN dependencies onlyinterface may contain Chinese labels
Source
<!--
示例:点云:用点勾勒城市
说明:地面 1.5 米网格点加四栋建筑的立柱采样点,相机缓慢环绕
核心逻辑:PointPrimitiveCollection 逐点添加 → 米到经纬度换算 → postRender 环绕相机
依赖:CesiumJS 1.121 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>点云:用点勾勒城市</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Widgets/widgets.css">
<style>
html,body{height:100%;margin:0}
body{background:#0e1116;color:#e6e8ec;overflow:hidden;
font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif}
#c{height:100%}
.tip{position:absolute;left:12px;top:12px;z-index:5;
background:rgba(23,28,35,.9);border:1px solid #2a313b;border-radius:6px;
padding:8px 12px;font-size:12px;color:#a2a9b6;max-width:320px;line-height:1.6}
.cesium-viewer-bottom .cesium-widget-credits,.cesium-viewer-animationContainer,
.cesium-viewer-timelineContainer{display:none!important}
</style>
</head>
<body>
<div id="c"></div>
<div class="tip">地面的点稀疏发暗,建筑的点沿柱角排列。转动视角能看到体块轮廓。</div>
<script src="https://cdn.jsdelivr.net/npm/cesium@1.121.0/Build/Cesium/Cesium.js"></script>
<script>
(function () {
'use strict';
var viewer = new Cesium.Viewer('c', {
baseLayer: false,
baseLayerPicker: false, geocoder: false, homeButton: false,
sceneModePicker: false, navigationHelpButton: false,
animation: false, timeline: false, fullscreenButton: false,
infoBox: false, selectionIndicator: false
});
var scene = viewer.scene;
scene.globe.baseColor = Cesium.Color.fromCssColorString('#1c2733');
scene.backgroundColor = Cesium.Color.fromCssColorString('#0e1116');
scene.skyBox.show = false;
scene.sun.show = false;
scene.moon.show = false;
if (scene.skyAtmosphere) scene.skyAtmosphere.show = false;
var baseLon = 116.391, baseLat = 39.906;
var DLON = 1.17e-5, DLAT = 8.98e-6; /* 北京纬度上 1 米对应的经纬度增量 */
var pc = scene.primitives.add(new Cesium.PointPrimitiveCollection());
var seed = 12;
function rnd() { seed = (seed * 9301 + 49297) % 233280; return seed / 233280; }
/* 地面点:30 × 20 米的网格 */
for (var gx = -15; gx <= 15; gx += 1.5) {
for (var gy = -10; gy <= 10; gy += 1.5) {
var lv = 0.3 + rnd() * 0.16;
pc.add({
position: Cesium.Cartesian3.fromDegrees(baseLon + gx * DLON, baseLat + gy * DLAT, 0),
pixelSize: 2,
color: Cesium.Color.fromHsl(0.58, 0.15, lv, 0.8)
});
}
}
/* 建筑点:沿四根立柱每 2 米采一个点 */
var blocks = [
{ dx: -8, dy: 3, w: 16, d: 12, h: 26 },
{ dx: 9, dy: 4, w: 12, d: 12, h: 38 },
{ dx: 2, dy: -6, w: 20, d: 10, h: 20 },
{ dx: -13, dy: -7, w: 10, d: 10, h: 30 }
];
blocks.forEach(function (b) {
for (var hh = 1; hh < b.h; hh += 2) {
[-1, 1].forEach(function (sx) {
[-1, 1].forEach(function (sy) {
pc.add({
position: Cesium.Cartesian3.fromDegrees(
baseLon + (b.dx + sx * b.w / 2) * DLON,
baseLat + (b.dy + sy * b.d / 2) * DLAT, hh),
pixelSize: 2.4,
color: Cesium.Color.fromHsl(0.58, 0.35, 0.28 + hh / b.h * 0.35, 0.9)
});
});
});
}
});
var center = Cesium.Cartesian3.fromDegrees(baseLon, baseLat, 12);
var enu = Cesium.Transforms.eastNorthUpToFixedFrame(center);
scene.postRender.addEventListener(function () {
var a = performance.now() * 0.00009;
var p = Cesium.Matrix4.multiplyByPoint(enu,
new Cesium.Cartesian3(Math.cos(a) * 55, Math.sin(a) * 55, 26), new Cesium.Cartesian3());
viewer.camera.setView({
destination: p,
orientation: { heading: a + Math.PI / 2, pitch: Cesium.Math.toRadians(-16), roll: 0 }
});
});
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.