Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- Engine,
- Scene,
- ArcRotateCamera,
- FreeCamera,
- DeviceOrientationCamera,
- Vector3,
- HemisphericLight,
- Color3,
- Color4,
- Sound,
- Nullable,
- Mesh,
- AbstractMesh,
- VertexData,
- SceneLoader,
- Quaternion,
- MeshBuilder,
- StandardMaterial,
- } from "@babylonjs/core";
- import {
- Cartesian3,
- Ion,
- createGooglePhotorealistic3DTileset,
- Scene as CesiumScene,
- } from "cesium";
- import SceneManager from "../SceneManager";
- import GameLevel from "../IGameLevel";
- // Set up scene
- class SurfaceScreen implements GameLevel {
- private engine: Engine;
- private canvas: HTMLCanvasElement;
- private scene: Nullable<Scene>;
- private sceneManager: SceneManager;
- private cesiumScene: CesiumScene;
- private cesiumCamera: any;
- private babylonCamera: any;
- private latitude: any;
- private longitude: any;
- private altitude: any;
- private initialCesiumPosition: any;
- private tileset: any;
- constructor(
- engine: Engine,
- canvas: HTMLCanvasElement,
- sceneManager: SceneManager,
- ) {
- this.engine = engine;
- this.canvas = canvas;
- this.scene = null;
- this.sceneManager = sceneManager;
- this.longitude = -73.935242;
- this.latitude = 40.73061;
- this.altitude = 0;
- Ion.defaultAccessToken = "YOUR-API-KEY";
- this.cesiumScene = new CesiumScene({
- canvas: canvas,
- contextOptions: {
- webgl: {
- alpha: true,
- },
- },
- });
- this.cesiumCamera = this.cesiumScene.camera;
- }
- initialize() {
- console.log("Creating Surface level");
- this.scene = new Scene(this.engine);
- this.babylonCamera = new DeviceOrientationCamera(
- "deviceOrientationCamera",
- new Vector3(0, 1, -10),
- this.scene,
- );
- this.babylonCamera.attachControl(this.canvas, true);
- this.sphere = MeshBuilder.CreateSphere(
- "sphere",
- { diameter: 2 },
- this.scene,
- );
- this.sphere.parent = this.babylonCamera;
- this.sphere.position = new Vector3(0, -2, 10);
- this.scene.autoClear = false;
- // Creates a light, aiming to the sky
- const light = new HemisphericLight(
- "light",
- new Vector3(0, 1, 0),
- this.scene,
- );
- light.diffuse = Color3.White();
- light.specular = Color3.White();
- light.groundColor = Color3.White();
- light.intensity = 0.5; //Easy
- this.tileset = await createGooglePhotorealistic3DTileset();
- this.cesiumScene.primitives.add(this.tileset);
- this.cesiumCamera.setView({
- destination: Cartesian3.fromDegrees(
- this.longitude,
- this.latitude,
- this.altitude,
- ),
- });
- this.initialCesiumPosition = this.cesiumCamera.position.clone();
- }
- dispose() {
- this.scene?.dispose();
- }
- render() {
- this.cesiumCamera.setView({
- orientation: {
- heading: -this.babylonCamera.rotation.y,
- pitch: -this.babylonCamera.rotation.x,
- roll: this.babylonCamera.rotation.z,
- },
- });
- this.scene?.getEngine().wipeCaches(true);
- this.cesiumScene.render();
- this.scene?.render();
- }
- }
- export default SurfaceScreen;
Advertisement
Add Comment
Please, Sign In to add comment