hi , i tried to create PG but couldnt as it is built with angular, so i would like to share my code here please do have a look,
this is my component.ts file:
import { Component, Injectable, OnInit, Inject } from â@angular/coreâ;
import { RoomService } from â./service/room.serviceâ;
import { WallFactoryService } from â./service/wallfactory.serviceâ;
import { EWallType } from â./service/EWallTypeâ;
@Component({
selector: âapp-rootâ,
templateUrl: â./app.component.htmlâ,
styleUrls: [â./app.component.cssâ]
})
export class AppComponent implements OnInit {
title = âBabylonTestâ;
constructor(@Inject(âBABYLONâ) private BABYLON: any,
private roomService: RoomService,
private wallFactory: WallFactoryService) { }
ngOnInit() {
var canvas = document.getElementById(ârenderCanvasâ); // Get the canvas element
var engine = new this.BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine
var scene = this.createScene(engine, canvas); //Call the createScene function
// Register a render loop to repeatedly render the scene
engine.runRenderLoop(function () {
scene.render();
});
// Watch for browser/canvas resize events
window.addEventListener("resize", function () {
engine.resize();
});
this.roomService.getStockwerk("1.OG").subscribe(
stockwerk =>{
stockwerk.raeume.forEach(room =>{
var rearWall = this.wallFactory.createWall(scene, EWallType.eInsideWallDoor, room.presentation.length, room.presentation.width);
// TODO: rotate depends on north/south/east/west
rearWall.rotation.x = -Math.PI / 2;
rearWall.position.z = 10;
rearWall.position.y = 2;
rearWall.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
var frontWall = this.wallFactory.createWall(scene, EWallType.eOusideWallWindow2, room.presentation.length, room.presentation.width);
frontWall.rotation.x = Math.PI / 2;
frontWall.position.y = 1;
frontWall.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
var rightWall = this.wallFactory.createWall(scene, EWallType.eInsideWallSimple, room.presentation.length, room.presentation.width);
rightWall.rotation.z = Math.PI / 2;
rightWall.rotation.x = -Math.PI / 2;
rightWall.position.x = -5;
rightWall.position.z = 5;
rightWall.position.y = 2;
rightWall.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
var leftWall = this.wallFactory.createWall(scene, EWallType.eOutsideWallWindow1, room.presentation.length, room.presentation.width);
leftWall.rotation.z = -Math.PI / 2;
leftWall.rotation.x = -Math.PI / 2;
leftWall.position.x = 5;
leftWall.position.z = 5;
leftWall.position.y = 2;
leftWall.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
var floor = this.wallFactory.createWall(scene, EWallType.eFloor, room.presentation.length, room.presentation.width);
floor.position.y = -0.9;
floor.position.z = -0.1;
floor.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
var ceiling = this.wallFactory.createWall(scene, EWallType.eCeiling, room.presentation.length, room.presentation.width);
ceiling.position.y = 3.9;
ceiling.position.z = -0.1;
ceiling.position =
new this.BABYLON.Vector3(room.presentation.x, room.presentation.y, 0);
});
},
errors =>{
console.log(errors);
alert("Fail to load room data");
}
);
}
createScene(engine: any, canvas: any): any {
// Create the scene space
var scene = new this.BABYLON.Scene(engine);
// Add a camera to the scene and attach it to the canvas
var camera = new this.BABYLON.ArcRotateCamera("Camera", -Math.PI / 2, Math.PI / 3, 50, new this.BABYLON.Vector3(0, 0, 4.5), scene);
camera.attachControl(canvas, true);
// Add lights to the scene
var light1 = new this.BABYLON.HemisphericLight("light1", new this.BABYLON.Vector3(10, 10, 0), scene);
// var light2 = new this.BABYLON.PointLight("light2", new this.BABYLON.Vector3(0, 1, -1), scene);
return scene;
};
}
this is my json file:
{
âstockwerkeâ :
[
{
âstockwerkâ: â1.OGâ,
âraeumeâ:
[
{
ânummerâ: â1.2â,
âpresentationâ: {
âxâ: 0,
âyâ: 0,
âlengthâ: 5,
âwidthâ:2,
âwallsâ: {
ânorthâ: âeInsideWallSimpleâ,
âsouthâ: âeOutsideWallWindow1â,
âeastâ: âeInsideWallDoorâ,
âwestâ: âeOusideWallWindow2â,
âfloorâ: âeFloorâ,
âceilingâ: âeCeilingâ
}
},
},
]
},
]
}
Thanks in advance