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