mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-22 01:05:40 +02:00
Update engine.ts
This commit is contained in:
@@ -217,6 +217,7 @@ const TIME_MAP = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const USE_GLOW = false; // ドローコールが増えて重い
|
const USE_GLOW = false; // ドローコールが増えて重い
|
||||||
|
const ENABLE_SUN_LIGHT = false; // ドローコールが増えて重い
|
||||||
|
|
||||||
export async function createRoomEngine(roomState: RoomState, canvas: HTMLCanvasElement) {
|
export async function createRoomEngine(roomState: RoomState, canvas: HTMLCanvasElement) {
|
||||||
//const babylonEngine = new BABYLON.WebGPUEngine(canvas);
|
//const babylonEngine = new BABYLON.WebGPUEngine(canvas);
|
||||||
@@ -230,8 +231,8 @@ export class RoomEngine {
|
|||||||
private canvas: HTMLCanvasElement;
|
private canvas: HTMLCanvasElement;
|
||||||
private engine: BABYLON.WebGPUEngine;
|
private engine: BABYLON.WebGPUEngine;
|
||||||
public scene: BABYLON.Scene;
|
public scene: BABYLON.Scene;
|
||||||
private shadowGenerator1: BABYLON.ShadowGenerator;
|
private shadowGeneratorForRoomLight: BABYLON.ShadowGenerator;
|
||||||
private shadowGenerator2: BABYLON.ShadowGenerator;
|
private shadowGeneratorForSunLight: BABYLON.ShadowGenerator | null = null;
|
||||||
public camera: BABYLON.UniversalCamera;
|
public camera: BABYLON.UniversalCamera;
|
||||||
private fixedCamera: BABYLON.UniversalCamera;
|
private fixedCamera: BABYLON.UniversalCamera;
|
||||||
private birdeyeCamera: BABYLON.ArcRotateCamera;
|
private birdeyeCamera: BABYLON.ArcRotateCamera;
|
||||||
@@ -382,25 +383,27 @@ export class RoomEngine {
|
|||||||
this.roomLight.shadowMinZ = 10/*cm*/;
|
this.roomLight.shadowMinZ = 10/*cm*/;
|
||||||
this.roomLight.shadowMaxZ = 300/*cm*/;
|
this.roomLight.shadowMaxZ = 300/*cm*/;
|
||||||
|
|
||||||
this.shadowGenerator1 = new BABYLON.ShadowGenerator(4096, this.roomLight);
|
this.shadowGeneratorForRoomLight = new BABYLON.ShadowGenerator(4096, this.roomLight);
|
||||||
this.shadowGenerator1.forceBackFacesOnly = true;
|
this.shadowGeneratorForRoomLight.forceBackFacesOnly = true;
|
||||||
this.shadowGenerator1.bias = 0.0001;
|
this.shadowGeneratorForRoomLight.bias = 0.0001;
|
||||||
this.shadowGenerator1.usePercentageCloserFiltering = true;
|
this.shadowGeneratorForRoomLight.usePercentageCloserFiltering = true;
|
||||||
this.shadowGenerator1.filteringQuality = BABYLON.ShadowGenerator.QUALITY_HIGH;
|
this.shadowGeneratorForRoomLight.filteringQuality = BABYLON.ShadowGenerator.QUALITY_HIGH;
|
||||||
//this.shadowGenerator1.useContactHardeningShadow = true;
|
//this.shadowGenerator1.useContactHardeningShadow = true;
|
||||||
|
|
||||||
const sunLight = new BABYLON.DirectionalLight('sunLight', new BABYLON.Vector3(0.2, -1, -1), this.scene);
|
if (ENABLE_SUN_LIGHT) {
|
||||||
sunLight.position = new BABYLON.Vector3(-20, 1000, 1000);
|
const sunLight = new BABYLON.DirectionalLight('sunLight', new BABYLON.Vector3(0.2, -1, -1), this.scene);
|
||||||
sunLight.diffuse = this.time === 0 ? new BABYLON.Color3(1.0, 0.9, 0.8) : this.time === 1 ? new BABYLON.Color3(1.0, 0.8, 0.6) : new BABYLON.Color3(0.6, 0.8, 1.0);
|
sunLight.position = new BABYLON.Vector3(-20, 1000, 1000);
|
||||||
sunLight.intensity = this.time === 0 ? 2 : this.time === 1 ? 1 : 0.25;
|
sunLight.diffuse = this.time === 0 ? new BABYLON.Color3(1.0, 0.9, 0.8) : this.time === 1 ? new BABYLON.Color3(1.0, 0.8, 0.6) : new BABYLON.Color3(0.6, 0.8, 1.0);
|
||||||
sunLight.shadowMinZ = 1000/*cm*/;
|
sunLight.intensity = this.time === 0 ? 2 : this.time === 1 ? 1 : 0.25;
|
||||||
sunLight.shadowMaxZ = 2000/*cm*/;
|
sunLight.shadowMinZ = 1000/*cm*/;
|
||||||
|
sunLight.shadowMaxZ = 2000/*cm*/;
|
||||||
|
|
||||||
this.shadowGenerator2 = new BABYLON.ShadowGenerator(4096, sunLight);
|
this.shadowGeneratorForSunLight = new BABYLON.ShadowGenerator(4096, sunLight);
|
||||||
this.shadowGenerator2.forceBackFacesOnly = true;
|
this.shadowGeneratorForSunLight.forceBackFacesOnly = true;
|
||||||
this.shadowGenerator2.bias = 0.0001;
|
this.shadowGeneratorForSunLight.bias = 0.0001;
|
||||||
this.shadowGenerator2.usePercentageCloserFiltering = true;
|
this.shadowGeneratorForSunLight.usePercentageCloserFiltering = true;
|
||||||
this.shadowGenerator2.usePoissonSampling = true;
|
this.shadowGeneratorForSunLight.usePoissonSampling = true;
|
||||||
|
}
|
||||||
|
|
||||||
this.turnOnRoomLight();
|
this.turnOnRoomLight();
|
||||||
|
|
||||||
@@ -497,7 +500,8 @@ export class RoomEngine {
|
|||||||
this.zGridPreviewPlane.isPickable = false;
|
this.zGridPreviewPlane.isPickable = false;
|
||||||
this.zGridPreviewPlane.isVisible = false;
|
this.zGridPreviewPlane.isVisible = false;
|
||||||
|
|
||||||
this.selectionOutlineLayer = new BABYLON.SelectionOutlineLayer('outliner', this.scene);
|
// 重い。edit modeのときだけ有効にするようにしたい
|
||||||
|
//this.selectionOutlineLayer = new BABYLON.SelectionOutlineLayer('outliner', this.scene);
|
||||||
|
|
||||||
watch(this.isEditMode, (v) => {
|
watch(this.isEditMode, (v) => {
|
||||||
if (v) {
|
if (v) {
|
||||||
@@ -563,7 +567,7 @@ export class RoomEngine {
|
|||||||
|
|
||||||
public async init() {
|
public async init() {
|
||||||
await this.loadRoomModel();
|
await this.loadRoomModel();
|
||||||
await this.loadEnvModel();
|
//await this.loadEnvModel();
|
||||||
await Promise.all(this.roomState.installedObjects.map(o => this.loadObject({
|
await Promise.all(this.roomState.installedObjects.map(o => this.loadObject({
|
||||||
id: o.id,
|
id: o.id,
|
||||||
type: o.type,
|
type: o.type,
|
||||||
@@ -841,8 +845,8 @@ export class RoomEngine {
|
|||||||
m.isPickable = false;
|
m.isPickable = false;
|
||||||
m.checkCollisions = false;
|
m.checkCollisions = false;
|
||||||
m.receiveShadows = true;
|
m.receiveShadows = true;
|
||||||
this.shadowGenerator1.addShadowCaster(m);
|
this.shadowGeneratorForRoomLight.addShadowCaster(m);
|
||||||
this.shadowGenerator2.addShadowCaster(m);
|
if (this.shadowGeneratorForSunLight != null) this.shadowGeneratorForSunLight.addShadowCaster(m);
|
||||||
//if (m.material) (m.material as BABYLON.PBRMaterial).ambientColor = new BABYLON.Color3(1, 1, 1);
|
//if (m.material) (m.material as BABYLON.PBRMaterial).ambientColor = new BABYLON.Color3(1, 1, 1);
|
||||||
if (m.material) {
|
if (m.material) {
|
||||||
(m.material as BABYLON.PBRMaterial).reflectionTexture = this.enableReflectionProbe ? this.reflectionProbe.cubeTexture : this.envMapIndoor;
|
(m.material as BABYLON.PBRMaterial).reflectionTexture = this.enableReflectionProbe ? this.reflectionProbe.cubeTexture : this.envMapIndoor;
|
||||||
@@ -934,8 +938,8 @@ export class RoomEngine {
|
|||||||
} else {
|
} else {
|
||||||
if (def.receiveShadows !== false) mesh.receiveShadows = true;
|
if (def.receiveShadows !== false) mesh.receiveShadows = true;
|
||||||
if (def.castShadows !== false) {
|
if (def.castShadows !== false) {
|
||||||
this.shadowGenerator1.addShadowCaster(mesh);
|
this.shadowGeneratorForRoomLight.addShadowCaster(mesh);
|
||||||
this.shadowGenerator2.addShadowCaster(mesh);
|
if (this.shadowGeneratorForSunLight != null) this.shadowGeneratorForSunLight.addShadowCaster(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (mesh.material) (mesh.material as BABYLON.PBRMaterial).ambientColor = new BABYLON.Color3(0.2, 0.2, 0.2);
|
//if (mesh.material) (mesh.material as BABYLON.PBRMaterial).ambientColor = new BABYLON.Color3(0.2, 0.2, 0.2);
|
||||||
|
|||||||
Reference in New Issue
Block a user