1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-21 13:25:45 +02:00
This commit is contained in:
syuilo
2026-05-04 16:25:11 +09:00
parent d451ce8c36
commit beb5d1dec5
12 changed files with 218 additions and 2 deletions

View File

@@ -0,0 +1,77 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../object.js';
export const hangingDuctRail = defineObject({
id: 'hangingDuctRail',
name: 'hangingDuctRail',
options: {
schema: {
width: {
type: 'range',
label: 'Width',
min: 0,
max: 1,
step: 0.01,
},
height: {
type: 'range',
label: 'Height',
min: 0,
max: 1,
step: 0.01,
},
bodyColor: {
type: 'color',
label: 'body color',
},
},
default: {
width: 0.2,
height: 0.2,
bodyColor: [0.05, 0.05, 0.05],
},
},
placement: 'ceiling',
hasCollisions: false,
createInstance: async ({ options, model }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');
const bodyMesh = model.findMesh('__X_BODY__');
const applySize = () => {
bodyMesh.morphTargetManager!.getTargetByName('W')!.influence = options.width;
bodyMesh.morphTargetManager!.getTargetByName('H')!.influence = options.height;
model.updated();
};
applySize();
const applyBodyColor = () => {
bodyMaterial.albedoColor = new BABYLON.Color3(...options.bodyColor);
};
applyBodyColor();
return {
onInited: () => {
},
onOptionsUpdated: ([k, v]) => {
switch (k) {
case 'width':
case 'height':
applySize();
break;
case 'bodyColor':
applyBodyColor();
break;
}
},
interactions: {},
};
},
});

View File

@@ -0,0 +1,117 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../object.js';
import { getLightRangeFactorByGraphicsQuality } from '../utility.js';
import { cm, remap, WORLD_SCALE } from '@/world/utility.js';
export const spotLight = defineObject({
id: 'spotLight',
name: 'spotLight',
options: {
schema: {
bodyColor: {
type: 'color',
label: 'Body color',
},
lightColor: {
type: 'color',
label: 'Light color',
},
lightBrightness: {
type: 'range',
label: 'Light brightness',
min: 0,
max: 1,
step: 0.01,
},
angleV: {
type: 'range',
label: 'Vertical angle',
min: 0,
max: 1,
step: 0.01,
},
angleH: {
type: 'range',
label: 'Horizontal angle',
min: 0,
max: 1,
step: 0.01,
},
},
default: {
bodyColor: [0.05, 0.05, 0.05],
lightColor: [1, 0.5, 0.2],
lightBrightness: 0.5,
angleV: 0.75,
angleH: 0.5,
},
},
placement: 'bottom',
hasCollisions: false,
createInstance: ({ room, scene, options, model, graphicsQuality }) => {
const bodyMaterial = model.findMaterial('__X_BODY__');
const applyBodyColor = () => {
const [r, g, b] = options.bodyColor;
bodyMaterial.albedoColor = new BABYLON.Color3(r, g, b);
};
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);
light.parent = lamp;
light.radius = cm(8);
if (room?.lightContainer != null) room.lightContainer.addLight(light);
const applyLightColor = () => {
const [r, g, b] = options.lightColor;
light.diffuse = new BABYLON.Color3(r, g, b);
const emissive = lamp.material as BABYLON.PBRMaterial;
emissive.emissiveColor = new BABYLON.Color3(r, g, b);
};
applyLightColor();
const applyLightBrightness = () => {
light.intensity = 2 * options.lightBrightness * WORLD_SCALE * WORLD_SCALE;
light.range = cm(300) * getLightRangeFactorByGraphicsQuality(graphicsQuality);
const emissive = lamp.material as BABYLON.PBRMaterial;
emissive.emissiveIntensity = options.lightBrightness * 20;
};
applyLightBrightness();
const shade = model.findMesh('__X_SHADE__');
const applyAngle = () => {
shade.rotationQuaternion = null;
shade.rotation = new BABYLON.Vector3(0, 0, 0);
shade.addRotation(remap(options.angleV, 0, 1, Math.PI / 2, -Math.PI / 2), 0, 0);
shade.addRotation(0, 0, remap(options.angleH, 0, 1, -Math.PI / 2, Math.PI / 2));
model.updated();
};
applyAngle();
return {
onOptionsUpdated: ([k, v]) => {
switch (k) {
case 'bodyColor': applyBodyColor(); break;
case 'lightColor': applyLightColor(); break;
case 'lightBrightness': applyLightBrightness(); break;
case 'angleV':
case 'angleH':
applyAngle();
break;
}
},
interactions: {},
};
},
});

View File

@@ -36,6 +36,10 @@ export const tabletopDigitalClock = defineObject({
hasCollisions: false,
canPreMeshesMerging: false,
createInstance: ({ root, room, options, model, scene, timer }) => {
const matrix = model.root.getWorldMatrix(true);
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);
//light.parent = root;
//light.intensity = 0.01 * WORLD_SCALE * WORLD_SCALE;
@@ -112,11 +116,11 @@ export const tabletopDigitalClock = defineObject({
// また、scalingを0にすることでも見た目上非表示にすることはできるが、なぜかその状態でsnapshot renderingが開始されるとその後にscaleを戻しても表示されなくなる(バグ?)
for (const mesh of Object.values(segmentMeshes)) {
const isVisible = onMeshes.includes(mesh);
mesh.position.y = isVisible ? defaultSegMeshDepth : defaultSegMeshDepth - cm(2);
mesh.position.y = isVisible ? defaultSegMeshDepth : defaultSegMeshDepth - (cm(2) / Math.abs(scale.y));
}
for (const mesh of colonMeshes) {
const isVisible = Date.now() % 2000 < 1000;
mesh.position.y = isVisible ? defaultSegMeshDepth : defaultSegMeshDepth - cm(2);
mesh.position.y = isVisible ? defaultSegMeshDepth : defaultSegMeshDepth - (cm(2) / Math.abs(scale.y));
}
room?.sr.updateMesh([...Object.values(segmentMeshes), ...colonMeshes]);