Cesium 与 Babylon.js 可视化 添加路灯

我决定不从Babylonjs 基础来讲了 直接整合cesium与babylonjs可视化来讲

我整合一个类库 后续不断更新中

  • npm i @haibalai/cesium-babylonjs

 

初始化cesium-babylonjs 类库, viewer 是 Cesium 的 viewer对象

  • import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
  • BabylonMapManager.init(viewer);

 

添加正方体

  • import { BabylonMapManager } from "@haibalai/cesium-babylonjs";
  • let scene = BabylonMapManager.getScene(map);
  • const lampLight = new BABYLON.SpotLight("lampLight", BABYLON.Vector3.Zero(), new BABYLON.Vector3(0, -1, 0), Math.PI, 10, scene);
  • lampLight.diffuse = BABYLON.Color3.Yellow();
  • //shape to extrude
  • const lampShape = [];
  • for(let i = 0; i < 20; i++) {
  • lampShape.push(new BABYLON.Vector3(Math.cos(i * Math.PI / 10), Math.sin(i * Math.PI / 10), 0));
  • }
  • lampShape.push(lampShape[0]); //close shape
  • //extrusion path
  • const lampPath = [];
  • lampPath.push(new BABYLON.Vector3(0, 0, 0));
  • lampPath.push(new BABYLON.Vector3(0, 10, 0));
  • for(let i = 0; i < 20; i++) {
  • lampPath.push(new BABYLON.Vector3(1 + Math.cos(Math.PI - i * Math.PI / 40), 10 + Math.sin(Math.PI - i * Math.PI / 40), 0));
  • }
  • lampPath.push(new BABYLON.Vector3(3, 11, 0));
  • const yellowMat = new BABYLON.StandardMaterial("yellowMat");
  • yellowMat.emissiveColor = BABYLON.Color3.Yellow();
  • //extrude lamp
  • const lamp = BABYLON.MeshBuilder.ExtrudeShape("lamp", {cap: BABYLON.Mesh.CAP_END, shape: lampShape, path: lampPath, scale: 0.5});
  • //add bulb
  • const bulb = BABYLON.MeshBuilder.CreateSphere("bulb", {diameterX: 1.5, diameterZ: 0.8});

Cesium 与 Babylon.js 可视化 添加路灯 - 小专栏

posted @ 2023-03-15 09:44  haibalai  阅读(64)  评论(0编辑  收藏  举报