1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-24 22:04:00 +02:00

heya -> env

This commit is contained in:
syuilo
2026-05-03 16:19:03 +09:00
parent d3dc9bc86c
commit 39525c66c2
13 changed files with 74 additions and 72 deletions

View File

@@ -339,12 +339,12 @@ export class RoomController {
this.call('updateObjectOption', [objectId, key, value]);
}
public changeHeyaType(type: RoomState['heya']['type']) {
this.call('changeHeyaType', [type]);
public changeEnvType(type: RoomState['env']['type']) {
this.call('changeEnvType', [type]);
}
public updateHeyaOptions(options: RoomState['heya']['options']) {
this.call('updateHeyaOptions', [options]);
public updateEnvOptions(options: RoomState['env']['options']) {
this.call('updateEnvOptions', [options]);
}
public updateRoomLightColor(color: [number, number, number]) {

View File

@@ -18,9 +18,9 @@ import { EventEmitter } from 'eventemitter3';
import { TIME_MAP, scaleMorph, camelToKebab, cm, WORLD_SCALE, getMeshesBoundingBox, Timer, getYRotationDirection, FreeCameraManualInput, remap } from '../utility.js';
import { getObjectDef } from './object-defs.js';
import { findMaterial, ModelManager, SYSTEM_HEYA_MESH_NAMES, SYSTEM_MESH_NAMES } from './utility.js';
import { MuseumHeyaManager, SimpleHeyaManager } from './heya.js';
import { MuseumEnvManager, SimpleEnvManager } from './env.js';
import type { GridMaterial } from '@babylonjs/materials';
import type { HeyaManager, JapaneseHeyaOptions, SimpleHeyaOptions } from './heya.js';
import type { EnvManager, JapaneseEnvOptions, SimpleEnvOptions } from './env.js';
import type { ObjectDef, RoomObjectInstance, RoomStateObject } from './object.js';
import { genId } from '@/utility/id.js';
import { deepClone } from '@/utility/clone.js';
@@ -31,12 +31,12 @@ const RENDER_OUTDOOR_ENV = false;
const IN_WEB_WORKER = typeof window === 'undefined';
export type RoomState = {
heya: {
env: {
type: 'simple';
options: SimpleHeyaOptions;
options: SimpleEnvOptions;
} | {
type: 'japanese';
options: JapaneseHeyaOptions;
options: JapaneseEnvOptions;
};
roomLightColor: [number, number, number];
installedObjects: RoomStateObject<any>[];
@@ -133,7 +133,7 @@ export class RoomEngine extends EventEmitter {
instance: RoomObjectInstance;
model: ModelManager;
}> = new Map();
private heyaManager: HeyaManager | null = null;
private envManager: EnvManager | null = null;
// TODO: たぶんオブジェクト内の値のmutateはsetで検知できないので、そのような操作を実際に行うようになった & それを検知する必要性が出てきたら専用の設定関数などを新設してそれを使わせる
private _grabbingCtx: {
@@ -430,7 +430,7 @@ export class RoomEngine extends EventEmitter {
}
public async init() {
await this.loadHeya();
await this.loadEnv();
const objects = this.roomState.installedObjects.filter(o => !IGNORE_OBJECTS.includes(o.type));
let loadedCount = 0;
@@ -825,11 +825,11 @@ export class RoomEngine extends EventEmitter {
});
}
public async changeHeyaType(type: RoomState['heya']['type'], forInit = false) {
this.roomState.heya.type = type;
public async changeEnvType(type: RoomState['env']['type'], forInit = false) {
this.roomState.env.type = type;
if (this.heyaManager != null) {
this.heyaManager.dispose();
if (this.envManager != null) {
this.envManager.dispose();
}
const onMeshUpdatedCallback = (meshes: BABYLON.AbstractMesh[]) => {
@@ -856,16 +856,16 @@ export class RoomEngine extends EventEmitter {
}
};
if (this.roomState.heya.type === 'simple') {
const heyaManager = new SimpleHeyaManager(onMeshUpdatedCallback);
await heyaManager.load(this.roomState.heya.options, this.scene);
this.heyaManager = heyaManager;
} else if (this.roomState.heya.type === 'japanese') {
if (this.roomState.env.type === 'simple') {
const envManager = new SimpleEnvManager(onMeshUpdatedCallback);
await envManager.load(this.roomState.env.options, this.scene);
this.envManager = envManager;
} else if (this.roomState.env.type === 'japanese') {
// TODO
} else if (this.roomState.heya.type === 'museum') {
const heyaManager = new MuseumHeyaManager(onMeshUpdatedCallback);
await heyaManager.load(this.roomState.heya.options, this.scene);
this.heyaManager = heyaManager;
} else if (this.roomState.env.type === 'museum') {
const envManager = new MuseumEnvManager(onMeshUpdatedCallback);
await envManager.load(this.roomState.env.options, this.scene);
this.envManager = envManager;
}
if (!forInit) {
@@ -873,8 +873,8 @@ export class RoomEngine extends EventEmitter {
}
}
private async loadHeya() {
await this.changeHeyaType(this.roomState.heya.type, true);
private async loadEnv() {
await this.changeEnvType(this.roomState.env.type, true);
}
private async loadObject(args: {
@@ -1117,7 +1117,7 @@ export class RoomEngine extends EventEmitter {
(subMat as BABYLON.PBRMaterial).subSurface.isRefractionEnabled = false; // 有効にするとドローコールが激増する(babylonのバグか仕様かは不明)
(subMat as BABYLON.PBRMaterial).transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
}
(subMat as BABYLON.PBRMaterial).reflectionTexture = this.heyaManager?.envMapIndoor;
(subMat as BABYLON.PBRMaterial).reflectionTexture = this.envManager?.envMapIndoor;
(subMat as BABYLON.PBRMaterial).useGLTFLightFalloff = true; // Clustered Lightingではphysical falloffを持つマテリアルはアーチファクトが発生する https://doc.babylonjs.com/features/featuresDeepDive/lights/clusteredLighting/#materials-with-a-physical-falloff-may-cause-artefacts
(subMat as BABYLON.PBRMaterial).anisotropy.isEnabled = false; // なんかきれいにレンダリングされないため
}
@@ -1126,7 +1126,7 @@ export class RoomEngine extends EventEmitter {
(mesh.material as BABYLON.PBRMaterial).subSurface.isRefractionEnabled = false; // 有効にするとドローコールが激増する(babylonのバグか仕様かは不明)
(mesh.material as BABYLON.PBRMaterial).transparencyMode = BABYLON.PBRMaterial.PBRMATERIAL_ALPHABLEND;
}
(mesh.material as BABYLON.PBRMaterial).reflectionTexture = this.heyaManager?.envMapIndoor;
(mesh.material as BABYLON.PBRMaterial).reflectionTexture = this.envManager?.envMapIndoor;
(mesh.material as BABYLON.PBRMaterial).useGLTFLightFalloff = true; // Clustered Lightingではphysical falloffを持つマテリアルはアーチファクトが発生する https://doc.babylonjs.com/features/featuresDeepDive/lights/clusteredLighting/#materials-with-a-physical-falloff-may-cause-artefacts
(mesh.material as BABYLON.PBRMaterial).anisotropy.isEnabled = false; // なんかきれいにレンダリングされないため
}
@@ -1420,7 +1420,7 @@ export class RoomEngine extends EventEmitter {
private turnOnRoomLight(forInit = false) {
if (!forInit) this.sr.disableSnapshotRendering(); // このメソッドは参照カウント方式な点に留意
this.roomLight.intensity = 18 * WORLD_SCALE * WORLD_SCALE;
if (this.heyaManager?.envMapIndoor != null) this.heyaManager.envMapIndoor.level = 0.6;
if (this.envManager?.envMapIndoor != null) this.envManager.envMapIndoor.level = 0.6;
for (const m of this.scene.materials) {
if (m.metadata?.disableEnvMap) {
m.ambientColor = new BABYLON.Color3(0.5, 0.5, 0.5);
@@ -1438,7 +1438,7 @@ export class RoomEngine extends EventEmitter {
private turnOffRoomLight() {
this.sr.disableSnapshotRendering(); // このメソッドは参照カウント方式な点に留意
this.roomLight.intensity = 0;
if (this.heyaManager?.envMapIndoor != null) this.heyaManager.envMapIndoor.level = 0.025;
if (this.envManager?.envMapIndoor != null) this.envManager.envMapIndoor.level = 0.025;
for (const m of this.scene.materials) {
if (m.metadata?.disableEnvMap) {
m.ambientColor = new BABYLON.Color3(0.025, 0.025, 0.025);
@@ -1747,9 +1747,9 @@ export class RoomEngine extends EventEmitter {
entity.instance.onOptionsUpdated?.([key, value]);
}
public updateHeyaOptions(options: RoomState['heya']['options']) {
this.roomState.heya.options = options;
this.heyaManager.applyOptions(options);
public updateEnvOptions(options: RoomState['env']['options']) {
this.roomState.env.options = options;
this.envManager.applyOptions(options);
this.ev('changeRoomState', { roomState: this.roomState });
}

View File

@@ -8,14 +8,14 @@ import * as BABYLON from '@babylonjs/core';
import { cm, WORLD_SCALE } from '../utility.js';
import { findMaterial } from './utility.js';
//export interface HeyaManager<T = any> {
//export interface EnvManager<T = any> {
// constructor(onMeshUpdatedCallback?: ((meshes: BABYLON.AbstractMesh[]) => void) | null): void;
// load: (options: T, scene: BABYLON.Scene) => Promise<void>;
// applyOptions: (options: T) => void;
// dispose: () => void;
//}
export abstract class HeyaManager<T = any> {
export abstract class EnvManager<T = any> {
protected onMeshUpdatedCallback: ((meshes: BABYLON.AbstractMesh[]) => void) | null = null;
abstract envMapIndoor: BABYLON.CubeTexture | null;
@@ -28,7 +28,7 @@ export abstract class HeyaManager<T = any> {
abstract dispose(): void;
}
export type SimpleHeyaOptions = {
export type SimpleEnvOptions = {
dimension: [number, number];
window: 'none' | 'kosidakamado' | 'demado' | 'hakidasimado';
walls: Record<'n' | 's' | 'w' | 'e', {
@@ -54,13 +54,13 @@ export type SimpleHeyaOptions = {
};
};
export type JapaneseHeyaOptions = {
export type JapaneseEnvOptions = {
window: 'none' | 'kosidakamado' | 'demado' | 'hakidasimado';
};
// TODO: マテリアルは必要になるまで作成しないようにする
export class SimpleHeyaManager extends HeyaManager<SimpleHeyaOptions> {
export class SimpleEnvManager extends EnvManager<SimpleEnvOptions> {
private loaderResult: BABYLON.ISceneLoaderAsyncResult | null = null;
private meshes: BABYLON.Mesh[] = [];
private wallRoots: Record<'n' | 's' | 'w' | 'e', BABYLON.TransformNode> = null as any;
@@ -75,8 +75,8 @@ export class SimpleHeyaManager extends HeyaManager<SimpleHeyaOptions> {
super(onMeshUpdatedCallback);
}
public async load(options: SimpleHeyaOptions, scene: BABYLON.Scene) {
this.loaderResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300.glb', scene);
public async load(options: SimpleEnvOptions, scene: BABYLON.Scene) {
this.loaderResult = await BABYLON.ImportMeshAsync('/client-assets/room/envs/default/300.glb', scene);
this.envMapIndoor = BABYLON.CubeTexture.CreateFromPrefilteredData('/client-assets/room/indoor.env', scene);
this.envMapIndoor.boundingBoxSize = new BABYLON.Vector3(cm(500), cm(500), cm(500));
@@ -172,7 +172,7 @@ export class SimpleHeyaManager extends HeyaManager<SimpleHeyaOptions> {
await this.applyOptions(options);
}
public applyOptions(options: SimpleHeyaOptions) {
public applyOptions(options: SimpleEnvOptions) {
// TODO: 返り値をpromiseにしてちゃんとテクスチャが読み終わってからresolveする
for (const type of ['n', 's', 'w', 'e'] as const) {
@@ -339,9 +339,9 @@ export class SimpleHeyaManager extends HeyaManager<SimpleHeyaOptions> {
}
}
export type MuseumHeyaOptions = any;
export type MuseumEnvOptions = any;
export class MuseumHeyaManager extends HeyaManager<MuseumHeyaOptions> {
export class MuseumEnvManager extends EnvManager<MuseumEnvOptions> {
private loaderResult: BABYLON.ISceneLoaderAsyncResult | null = null;
private meshes: BABYLON.Mesh[] = [];
@@ -349,8 +349,8 @@ export class MuseumHeyaManager extends HeyaManager<MuseumHeyaOptions> {
super(onMeshUpdatedCallback);
}
public async load(options: MuseumHeyaOptions, scene: BABYLON.Scene) {
this.loaderResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300.glb', scene);
public async load(options: MuseumEnvOptions, scene: BABYLON.Scene) {
this.loaderResult = await BABYLON.ImportMeshAsync('/client-assets/room/envs/museum/museum.glb', scene);
this.meshes = this.loaderResult.meshes.filter(m => m instanceof BABYLON.Mesh);
this.meshes[0].scaling = this.meshes[0].scaling.scale(WORLD_SCALE);
@@ -380,7 +380,7 @@ export class MuseumHeyaManager extends HeyaManager<MuseumHeyaOptions> {
await this.applyOptions(options);
}
public applyOptions(options: MuseumHeyaOptions) {
public applyOptions(options: MuseumEnvOptions) {
this.onMeshUpdatedCallback?.(this.meshes);
}