1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-13 16:25:44 +02:00
This commit is contained in:
syuilo
2026-05-09 14:06:07 +09:00
parent 3605ffdafc
commit 414a28fb19
18 changed files with 104 additions and 49 deletions

View File

@@ -881,9 +881,9 @@ export class RoomEngine extends EventEmitter {
});
const objectInstance = await def.createInstance({
room: this,
scene: this.scene,
sr: this.sr,
lc: this.lightContainer,
root,
options: args.options,
model,

View File

@@ -112,9 +112,9 @@ export type ObjectDef<OpSc extends OptionsSchema = OptionsSchema> = {
isChair?: boolean;
treatLoaderResult?: (loaderResult: BABYLON.AssetContainer) => void;
createInstance: (args: {
room?: RoomEngine | null;
scene: BABYLON.Scene;
sr: BABYLON.SnapshotRenderingHelper;
lc: BABYLON.ClusteredLightContainer | null;
root: BABYLON.Mesh;
options: Readonly<GetOptionsSchemaValues<OpSc>>;
model: ModelManager;

View File

@@ -48,18 +48,18 @@ export const allInOnePc = defineObject({
},
placement: 'top',
hasTexture: true,
createInstance: async ({ room, scene, options, model, graphicsQuality }) => {
createInstance: async ({ lc, scene, options, model, graphicsQuality }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();
matrix.decompose(scale);
// TODO: graphicsQualityがLOWならそもそも追加しない
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
light.parent = model.root;
light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
light.radius = cm(20);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const screenMesh = model.findMesh('__X_SCREEN__');
@@ -142,6 +142,10 @@ export const allInOnePc = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -18,17 +18,22 @@ export const beamLamp = defineObject({
placement: 'top',
hasCollisions: false,
canPreMeshesMerging: true,
createInstance: ({ room, root, scene, graphicsQuality }) => {
createInstance: ({ lc, root, scene, graphicsQuality }) => {
const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, cm(10), 0), scene, lc != null);
light.parent = root;
light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2);
light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE;
light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
if (lc != null) lc.addLight(light);
return {
onInited: () => {
const light = new BABYLON.PointLight('beamLampLight', new BABYLON.Vector3(0, cm(10), 0), scene, room?.lightContainer != null);
light.parent = root;
light.diffuse = new BABYLON.Color3(1.0, 0.5, 0.2);
light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE;
light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -50,19 +50,19 @@ export const desktopPc = defineObject({
placement: 'top',
hasCollisions: true,
canPreMeshesMerging: true,
createInstance: ({ options, model, root, scene, room, graphicsQuality }) => {
createInstance: ({ options, model, root, scene, lc, graphicsQuality }) => {
// TODO: graphicsQualityがLOWならそもそも追加しない
const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(10), cm(22)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light1 = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(10), cm(22)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
light1.parent = root;
light1.intensity = 0.05 * WORLD_SCALE * WORLD_SCALE;
light1.range = cm(30) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
if (room?.lightContainer != null) room.lightContainer.addLight(light1);
if (lc != null) lc.addLight(light1);
const light2 = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(-5), cm(33), cm(-9)), new BABYLON.Vector3(1, 0, 0), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light2 = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(-5), cm(33), cm(-9)), new BABYLON.Vector3(1, 0, 0), Math.PI / 1, 2, scene, lc != null);
light2.parent = root;
light2.intensity = 0.05 * WORLD_SCALE * WORLD_SCALE;
light2.range = cm(30) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
if (room?.lightContainer != null) room.lightContainer.addLight(light2);
if (lc != null) lc.addLight(light2);
const bodyMaterial = model.findMaterial('__X_BODY__');
const coverMaterial = model.findMaterial('__X_COVER__');
@@ -127,6 +127,14 @@ export const desktopPc = defineObject({
applyLedColor();
},
interactions: {},
dispose: () => {
light1.dispose();
light2.dispose();
if (lc != null) {
lc.removeLight(light1);
lc.removeLight(light2);
}
},
};
},
});

View File

@@ -53,7 +53,7 @@ export const ductRailSpotLights = defineObject({
},
placement: 'ceiling',
hasCollisions: false,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
createInstance: ({ lc, scene, options, model, graphicsQuality }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');
const applyBodyColor = () => {
@@ -66,10 +66,10 @@ export const ductRailSpotLights = defineObject({
const lamps = model.findMeshes('__X_LAMP__');
const lights: BABYLON.SpotLight[] = [];
for (const lamp of lamps) {
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null);
light.parent = lamp;
light.radius = cm(8);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
lights.push(light);
}
@@ -126,6 +126,12 @@ export const ductRailSpotLights = defineObject({
}
},
interactions: {},
dispose: () => {
for (const light of lights) {
light.dispose();
if (lc != null) lc.removeLight(light);
}
},
};
},
});

View File

@@ -44,7 +44,7 @@ export const handheldGameConsole = defineObject({
placement: 'top',
hasCollisions: false,
hasTexture: true,
createInstance: async ({ room, scene, options, model, graphicsQuality }) => {
createInstance: async ({ scene, options, model, graphicsQuality }) => {
const screenMesh = model.findMesh('__X_SCREEN__');
const bodyMaterial = model.findMaterial('__X_BODY__');

View File

@@ -57,7 +57,7 @@ export const laptopPc = defineObject({
placement: 'top',
hasCollisions: false,
hasTexture: true,
createInstance: async ({ room, scene, options, model, graphicsQuality }) => {
createInstance: async ({ lc, scene, options, model, graphicsQuality }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();
matrix.decompose(scale);
@@ -66,12 +66,12 @@ export const laptopPc = defineObject({
const hutaNode = model.findTransformNode('__X_HUTA__');
// TODO: graphicsQualityがLOWならそもそも追加しない
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(10) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(10) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
light.parent = hutaNode;
light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
light.radius = cm(15);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const bodyMaterial = model.findMaterial('__X_BODY__');
const bezelMaterial = model.findMaterial('__X_BEZEL__');
@@ -167,6 +167,10 @@ export const laptopPc = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -30,7 +30,7 @@ export const largeMousepad = defineObject({
placement: 'top',
hasCollisions: false,
hasTexture: true,
createInstance: async ({ room, scene, options, model }) => {
createInstance: async ({ scene, options, model }) => {
const padMesh = model.findMesh('__X_PAD__');
const padMaterial = model.findMaterial('__X_PAD__');

View File

@@ -39,7 +39,7 @@ export const lavaLamp = defineObject({
placement: 'top',
hasCollisions: false,
canPreMeshesMerging: true,
createInstance: ({ options, room, scene, sr, root, model, graphicsQuality }) => {
createInstance: ({ options, lc, scene, sr, root, model, graphicsQuality }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');
const glassMaterial = model.findMaterial('__X_GLASS__');
const lightMaterial = model.findMaterial('__X_LIGHT__');
@@ -59,12 +59,12 @@ export const lavaLamp = defineObject({
applyGlassColor();
// TODO: graphicsQualityがLOWならそもそも追加しない
const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, cm(11), 0), scene, room?.lightContainer != null);
const light = new BABYLON.PointLight('lavaLampLight', new BABYLON.Vector3(0, cm(11), 0), scene, lc != null);
light.parent = root;
light.intensity = 0.03 * WORLD_SCALE * WORLD_SCALE;
light.range = cm(50) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
light.radius = cm(5);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const applyLightColor = () => {
const [r, g, b] = options.lightColor;
@@ -155,9 +155,12 @@ export const lavaLamp = defineObject({
}
},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
if (animationObserver != null) {
scene.onAfterAnimationsObservable.remove(animationObserver);
}
ps.dispose();
},
};
},

View File

@@ -43,18 +43,18 @@ export const monitor = defineObject({
},
placement: 'top',
hasTexture: true,
createInstance: async ({ room, scene, options, model, graphicsQuality }) => {
createInstance: async ({ lc, scene, options, model, graphicsQuality }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();
matrix.decompose(scale);
// TODO: graphicsQualityがLOWならそもそも追加しない
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(20) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(20) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
light.parent = model.root;
light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
light.range = cm(100) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
light.radius = cm(20);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const screenMesh = model.findMesh('__X_SCREEN__');
@@ -130,6 +130,10 @@ export const monitor = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -53,7 +53,7 @@ export const spotLight = defineObject({
},
placement: 'bottom',
hasCollisions: false,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
createInstance: ({ lc, scene, options, model, graphicsQuality }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');
const applyBodyColor = () => {
@@ -64,10 +64,10 @@ export const spotLight = defineObject({
applyBodyColor();
const lamp = model.findMesh('__X_LAMP__');
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null);
light.parent = lamp;
light.radius = cm(8);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const applyLightColor = () => {
const [r, g, b] = options.lightColor;
@@ -112,6 +112,10 @@ export const spotLight = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -40,11 +40,11 @@ export const tabletopDigitalClock = defineObject({
const scale = new BABYLON.Vector3();
matrix.decompose(scale);
//const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
//const light = new BABYLON.SpotLight('', new BABYLON.Vector3(0, cm(3), cm(1)), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
//light.parent = root;
//light.intensity = 0.01 * WORLD_SCALE * WORLD_SCALE;
//light.range = cm(30);
//if (room?.lightContainer != null) room.lightContainer.addLight(light);
//if (lc != null) lc.addLight(light);
const segmentMeshes = {
'1a': model.findMesh('__TIME_7SEG_1A__'),

View File

@@ -33,17 +33,17 @@ export const tv = defineObject({
placement: 'top',
hasCollisions: true,
hasTexture: true,
createInstance: ({ options, room, model, scene, timer, graphicsQuality }) => {
createInstance: ({ options, lc, model, scene, timer, graphicsQuality }) => {
const matrix = model.root.getWorldMatrix(true);
const scale = new BABYLON.Vector3();
matrix.decompose(scale);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(30) / Math.abs(scale.y), 0), new BABYLON.Vector3(0, 0, 1), Math.PI / 1, 2, scene, lc != null);
light.parent = model.root;
light.diffuse = new BABYLON.Color3(1.0, 1.0, 1.0);
light.range = cm(200) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
light.radius = cm(40);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const screenMesh = model.findMesh('__TV_SCREEN__');
screenMesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UVKind, true);
@@ -96,6 +96,10 @@ export const tv = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -55,7 +55,7 @@ export const wallMountSpotLight = defineObject({
hasCollisions: false,
canPreMeshesMerging: false,
hasTexture: false,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
createInstance: ({ lc, scene, options, model, graphicsQuality }) => {
const bodyMesh = model.findMesh('__X_BODY__');
const bodyMaterial = model.findMaterial('__X_BODY__');
@@ -67,10 +67,10 @@ export const wallMountSpotLight = defineObject({
applyBodyColor();
const lamp = model.findMesh('__X_LAMP__');
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null);
light.parent = lamp;
light.radius = cm(5);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
const applyLightColor = () => {
const [r, g, b] = options.lightColor;
@@ -113,6 +113,10 @@ export const wallMountSpotLight = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -42,7 +42,7 @@ export const woodRingFloorLamp = defineObject({
},
placement: 'floor',
hasCollisions: true,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
createInstance: ({ lc, scene, options, model, graphicsQuality }) => {
const shadeMaterial = model.findMaterial('__X_SHADE__');
const applyShadeColor = () => {
@@ -64,10 +64,10 @@ export const woodRingFloorLamp = defineObject({
const lamps = model.findMeshes('__X_LAMP__');
const lights: BABYLON.SpotLight[] = [];
for (const lamp of lamps) {
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, room?.lightContainer != null);
const light = new BABYLON.SpotLight('', new BABYLON.Vector3(cm(0), cm(0), 0), new BABYLON.Vector3(0, -1, 0), Math.PI / 1, 2, scene, lc != null);
light.parent = lamp;
light.radius = cm(5);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
lights.push(light);
}
@@ -105,6 +105,12 @@ export const woodRingFloorLamp = defineObject({
applyLightBrightness();
},
interactions: {},
dispose: () => {
for (const light of lights) {
light.dispose();
if (lc != null) lc.removeLight(light);
}
}
};
},
});

View File

@@ -54,7 +54,7 @@ export const woodRingsPendantLight = defineObject({
},
placement: 'ceiling',
hasCollisions: false,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
createInstance: ({ lc, scene, options, model, graphicsQuality }) => {
const shadeMaterial = model.findMaterial('__X_SHADE__');
const applyShadeColor = () => {
@@ -74,10 +74,10 @@ export const woodRingsPendantLight = defineObject({
applyBodyColor();
const lamp = model.findMesh('__X_LAMP__');
const light = new BABYLON.PointLight('', new BABYLON.Vector3(0, 0, 0), scene, room?.lightContainer != null);
const light = new BABYLON.PointLight('', new BABYLON.Vector3(0, 0, 0), scene, lc != null);
light.parent = lamp;
light.radius = cm(5);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
if (lc != null) lc.addLight(light);
//const lensFlareSystem = new BABYLON.LensFlareSystem('lensFlareSystem', light, scene);
//const flare00 = new BABYLON.LensFlare(0.1, 1.7, new BABYLON.Color3(...options.lightColor), '/client-assets/world/lensflare.png', lensFlareSystem);
@@ -126,6 +126,10 @@ export const woodRingsPendantLight = defineObject({
}
},
interactions: {},
dispose: () => {
light.dispose();
if (lc != null) lc.removeLight(light);
},
};
},
});

View File

@@ -334,7 +334,6 @@ export class RoomObjectPreviewEngine {
this.timerForEachObject = new Timer();
const objectInstance = await def.createInstance({
room: null,
scene: this.scene,
sr: this.sr,
root,