diff --git a/packages/frontend/assets/room/objects/wall-glass-picture-frame/wall-glass-picture-frame.blend b/packages/frontend/assets/room/objects/wall-glass-picture-frame/wall-glass-picture-frame.blend index 8510020100..0dc3bcebe6 100644 Binary files a/packages/frontend/assets/room/objects/wall-glass-picture-frame/wall-glass-picture-frame.blend and b/packages/frontend/assets/room/objects/wall-glass-picture-frame/wall-glass-picture-frame.blend differ diff --git a/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.blend b/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.blend new file mode 100644 index 0000000000..6a3bbd85f8 Binary files /dev/null and b/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.blend differ diff --git a/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.glb b/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.glb new file mode 100644 index 0000000000..7073cc3660 Binary files /dev/null and b/packages/frontend/assets/room/objects/wood-rings-pendant-light/wood-rings-pendant-light.glb differ diff --git a/packages/frontend/src/utility/room/object-defs.ts b/packages/frontend/src/utility/room/object-defs.ts index bb16bfeb75..07b2d79174 100644 --- a/packages/frontend/src/utility/room/object-defs.ts +++ b/packages/frontend/src/utility/room/object-defs.ts @@ -85,6 +85,7 @@ import { wallGlassPictureFrame } from './objects/wallGlassPictureFrame.js'; import { wallMirror } from './objects/wallMirror.js'; import { wallShelf } from './objects/wallShelf.js'; import { woodRingFloorLamp } from './objects/woodRingFloorLamp.js'; +import { woodRingsPendantLight } from './objects/woodRingsPendantLight.js'; import { woodSoundAbsorbingPanel } from './objects/woodSoundAbsorbingPanel.js'; export const OBJECT_DEFS = [ @@ -171,6 +172,7 @@ export const OBJECT_DEFS = [ wallMirror, wallShelf, woodRingFloorLamp, + woodRingsPendantLight, woodSoundAbsorbingPanel, debugHipoly, ]; diff --git a/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts b/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts new file mode 100644 index 0000000000..54fb905109 --- /dev/null +++ b/packages/frontend/src/utility/room/objects/woodRingsPendantLight.ts @@ -0,0 +1,120 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import * as BABYLON from '@babylonjs/core'; +import { defineObject, WORLD_SCALE } from '../engine.js'; + +const remap = (value: number, fromMin: number, fromMax: number, toMin: number, toMax: number) => { + return toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin); +}; + +export const woodRingsPendantLight = defineObject({ + id: 'woodRingsPendantLight', + name: 'woodRingsPendantLight', + options: { + schema: { + shadeColor: { + type: 'color', + label: 'Shade color', + }, + 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, + }, + length: { + type: 'range', + label: 'Length', + min: 0, + max: 1, + step: 0.01, + }, + }, + default: { + shadeColor: [0.21, 0.04, 0], + bodyColor: [0.05, 0.05, 0.05], + lightColor: [1, 0.5, 0.2], + lightBrightness: 0.5, + length: 0.2, + }, + }, + placement: 'ceiling', + createInstance: ({ room, scene, options, model }) => { + const shadeMaterial = model.findMaterial('__X_SHADE__'); + + const applyShadeColor = () => { + const [r, g, b] = options.shadeColor; + shadeMaterial.albedoColor = new BABYLON.Color3(r, g, b); + }; + + applyShadeColor(); + + 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.PointLight('', new BABYLON.Vector3(0, 0, 0), scene, room?.lightContainer != null); + light.parent = lamp; + 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 = 10000 * options.lightBrightness; + light.range = 200/*cm*/ * options.lightBrightness; + const emissive = lamp.material as BABYLON.PBRMaterial; + emissive.emissiveIntensity = options.lightBrightness * 10; + }; + + applyLightBrightness(); + + const mainNode = model.findTransformNode('__X_MAIN__'); + const codeMesh = model.findMesh('__X_CODE__'); + + const applyLength = () => { + mainNode.position.y = -remap(options.length, 0, 1, 0, 200) / WORLD_SCALE; + codeMesh.morphTargetManager!.getTargetByName('Length')!.influence = options.length; + model.updated(); + }; + + applyLength(); + + return { + onOptionsUpdated: ([k, v]) => { + switch (k) { + case 'shadeColor': applyShadeColor(); break; + case 'bodyColor': applyBodyColor(); break; + case 'lightColor': applyLightColor(); break; + case 'lightBrightness': applyLightBrightness(); break; + case 'length': applyLength(); break; + } + }, + interactions: {}, + }; + }, +});