Atlaslog
Atlaslog / Examples / Cesium / Google Photorealistic 3D Tiles
Cesium · Runnable Example

Google Photorealistic 3D Tiles

Runnable Cesium example: Google Photorealistic 3D Tiles. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.

Open standalone → Chinese notes All Cesium examples
/demos/cesium-google-photorealistic-3d-tiles.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/cesium-google-photorealistic-3d-tiles.html
<!--
  示例:实景三维城市
  说明:带立面纹理的城市体块,斜视角下能看到窗格与屋顶层次
  核心逻辑:canvas 生成立面纹理 → ImageMaterialProperty → 程序化城市体块
  依赖: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">立面的窗格由 canvas 绘制,纹理只生成一次,重复贴到所有楼体上。</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;

  /* 一张 128×256 的立面贴图:窗格 + 楼层线 */
  function facade() {
    var c = document.createElement('canvas');
    c.width = 128; c.height = 256;
    var ctx = c.getContext('2d');
    ctx.fillStyle = '#8b8f94'; ctx.fillRect(0, 0, 128, 256);
    for (var y = 8; y < 256; y += 24) {
      ctx.fillStyle = 'rgba(40,48,58,0.85)';
      ctx.fillRect(0, y + 18, 128, 3);
      for (var x = 10; x < 128; x += 28) {
        ctx.fillStyle = (x + y) % 3 === 0 ? '#3d4a58' : '#2a333f';
        ctx.fillRect(x, y, 18, 14);
      }
    }
    return c.toDataURL('image/png');
  }

  var tex = facade();
  var material = new Cesium.ImageMaterialProperty({
    image: tex,
    repeat: new Cesium.Cartesian2(2, 3),
    color: Cesium.Color.fromCssColorString('#dfe6ee')
  });

  for (var i = 0; i < 14; i++) {
    for (var j = 0; j < 10; j++) {
      var h = 30 + ((i * 11 + j * 7) % 8) * 12;
      viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(
          116.3846 + i * 0.00074, 39.9014 + j * 0.00070, h / 2
        ),
        box: {
          dimensions: new Cesium.Cartesian3(24, 22, h),
          material: material
        }
      });
    }
  }

  /* 屋顶压暗一层,模拟航拍中的屋顶 */
  for (var k = 0; k < 14; k++) {
    for (var m = 0; m < 10; m++) {
      var hh = 30 + ((k * 11 + m * 7) % 8) * 12;
      viewer.entities.add({
        position: Cesium.Cartesian3.fromDegrees(
          116.3846 + k * 0.00074, 39.9014 + m * 0.00070, hh + 0.4
        ),
        box: {
          dimensions: new Cesium.Cartesian3(24.4, 22.4, 0.8),
          material: Cesium.Color.fromCssColorString('#6f757c')
        }
      });
    }
  }
  viewer.camera.flyTo({
    destination: Cesium.Cartesian3.fromDegrees(116.3932, 39.8982, 420),
    orientation: { heading: Cesium.Math.toRadians(22), pitch: Cesium.Math.toRadians(-24), roll: 0 },
    duration: 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.

More Cesium examples

Cesium · EXAMPLEGoogle Photorealistic 3D Tiles with Building Insert Cesium · EXAMPLEGpx Cesium · EXAMPLEGrid