Refactored scene to use DefaultScene.
This commit is contained in:
parent
b8521be13e
commit
8bb77873cc
@ -17,6 +17,7 @@ import {
|
|||||||
import {CustomPhysics} from "./customPhysics";
|
import {CustomPhysics} from "./customPhysics";
|
||||||
import {AppConfig} from "./appConfig";
|
import {AppConfig} from "./appConfig";
|
||||||
import {GridMaterial} from "@babylonjs/materials";
|
import {GridMaterial} from "@babylonjs/materials";
|
||||||
|
import {DefaultScene} from "../defaultScene";
|
||||||
|
|
||||||
|
|
||||||
export class CustomEnvironment {
|
export class CustomEnvironment {
|
||||||
@ -24,14 +25,14 @@ export class CustomEnvironment {
|
|||||||
private readonly name: string;
|
private readonly name: string;
|
||||||
private readonly _groundMeshObservable: Observable<GroundMesh> = new Observable<GroundMesh>();
|
private readonly _groundMeshObservable: Observable<GroundMesh> = new Observable<GroundMesh>();
|
||||||
|
|
||||||
constructor(scene: Scene, name: string = "default", config: AppConfig) {
|
constructor(name: string = "default", config: AppConfig) {
|
||||||
this.scene = scene;
|
this.scene = DefaultScene.scene;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
const loading = document.querySelector('#loadingGrid');
|
const loading = document.querySelector('#loadingGrid');
|
||||||
if (loading) {
|
if (loading) {
|
||||||
loading.remove();
|
loading.remove();
|
||||||
}
|
}
|
||||||
const light = new HemisphericLight("light1", new Vector3(1, 2, 1), scene);
|
const light = new HemisphericLight("light1", new Vector3(1, 2, 1), this.scene);
|
||||||
light.groundColor = new Color3(.1, .1, .1)
|
light.groundColor = new Color3(.1, .1, .1)
|
||||||
light.diffuse = new Color3(1, 1, 1);
|
light.diffuse = new Color3(1, 1, 1);
|
||||||
light.intensity = .8;
|
light.intensity = .8;
|
||||||
@ -91,8 +92,8 @@ export class CustomEnvironment {
|
|||||||
height: 20,
|
height: 20,
|
||||||
subdivisions: 1
|
subdivisions: 1
|
||||||
}, scene);
|
}, scene);
|
||||||
createPoints(scene, 20, 20);
|
createPoints(20, 20);
|
||||||
ground.material = createGridMaterial(scene, Color3.FromHexString("#aaffaa"), Color3.FromHexString("#111511"));
|
ground.material = createGridMaterial(Color3.FromHexString("#aaffaa"), Color3.FromHexString("#111511"));
|
||||||
const color1 = Color3.FromHexString("#ff9999");
|
const color1 = Color3.FromHexString("#ff9999");
|
||||||
const color2 = Color3.FromHexString("#221111");
|
const color2 = Color3.FromHexString("#221111");
|
||||||
const color3 = Color3.FromHexString("#9999ff");
|
const color3 = Color3.FromHexString("#9999ff");
|
||||||
@ -114,12 +115,13 @@ export class CustomEnvironment {
|
|||||||
const wall = MeshBuilder.CreatePlane("wall", {width: 20, height: 20}, scene);
|
const wall = MeshBuilder.CreatePlane("wall", {width: 20, height: 20}, scene);
|
||||||
wall.position = position;
|
wall.position = position;
|
||||||
wall.rotation = rotation;
|
wall.rotation = rotation;
|
||||||
wall.material = createGridMaterial(scene, color1, color2);
|
wall.material = createGridMaterial(color1, color2);
|
||||||
return wall;
|
return wall;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createPoints(scene: Scene, divisions: number = 10, scale: number = 80) {
|
async function createPoints(divisions: number = 10, scale: number = 80) {
|
||||||
|
const scene = DefaultScene.scene;
|
||||||
const half = .5;
|
const half = .5;
|
||||||
const increment = 1 / divisions;
|
const increment = 1 / divisions;
|
||||||
let x = -half;
|
let x = -half;
|
||||||
@ -153,7 +155,8 @@ async function createPoints(scene: Scene, divisions: number = 10, scale: number
|
|||||||
mesh.parent = baseTransform;
|
mesh.parent = baseTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createGridMaterial(scene: Scene, lineColor: Color3, mainColor: Color3): Material {
|
function createGridMaterial(lineColor: Color3, mainColor: Color3): Material {
|
||||||
|
const scene = DefaultScene.scene;
|
||||||
const material = new GridMaterial("gridMaterial", scene);
|
const material = new GridMaterial("gridMaterial", scene);
|
||||||
material.minorUnitVisibility = .1;
|
material.minorUnitVisibility = .1;
|
||||||
material.gridRatio = .1;
|
material.gridRatio = .1;
|
||||||
|
|||||||
@ -60,7 +60,7 @@ export class VrApp {
|
|||||||
new Vector3(0, 1.6, 0), scene);
|
new Vector3(0, 1.6, 0), scene);
|
||||||
//camera.setTarget(new Vector3(0, 1.6, -3));
|
//camera.setTarget(new Vector3(0, 1.6, -3));
|
||||||
scene.setActiveCameraByName("Main Camera");
|
scene.setActiveCameraByName("Main Camera");
|
||||||
const environment = new CustomEnvironment(scene, "default", diagramManager.config);
|
const environment = new CustomEnvironment("default", diagramManager.config);
|
||||||
environment.groundMeshObservable.add((ground) => {
|
environment.groundMeshObservable.add((ground) => {
|
||||||
groundMeshObserver(ground, diagramManager, spinner);
|
groundMeshObserver(ground, diagramManager, spinner);
|
||||||
}, -1, false, this);
|
}, -1, false, this);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user