diff --git a/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.blend b/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.blend new file mode 100644 index 0000000000..7a70c777d6 Binary files /dev/null and b/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.blend differ diff --git a/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.glb b/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.glb new file mode 100644 index 0000000000..6faa6503cf Binary files /dev/null and b/packages/frontend/assets/room/objects/box-wall-shelf/box-wall-shelf.glb differ diff --git a/packages/frontend/src/world/room/object-defs.ts b/packages/frontend/src/world/room/object-defs.ts index c5dbcff3e3..a50db9b7b0 100644 --- a/packages/frontend/src/world/room/object-defs.ts +++ b/packages/frontend/src/world/room/object-defs.ts @@ -14,6 +14,7 @@ import { bed } from './objects/bed.js'; import { blind } from './objects/blind.js'; import { book } from './objects/book.js'; import { books } from './objects/books.js'; +import { boxWallShelf } from './objects/boxWallShelf.js'; import { cactusS } from './objects/cactusS.js'; import { cardboardBox } from './objects/cardboardBox.js'; import { ceilingFanLight } from './objects/ceilingFanLight.js'; @@ -105,6 +106,7 @@ export const OBJECT_DEFS = [ blind, book, books, + boxWallShelf, cactusS, cardboardBox, ceilingFanLight, diff --git a/packages/frontend/src/world/room/objects/boxWallShelf.ts b/packages/frontend/src/world/room/objects/boxWallShelf.ts new file mode 100644 index 0000000000..0188bc0b44 --- /dev/null +++ b/packages/frontend/src/world/room/objects/boxWallShelf.ts @@ -0,0 +1,100 @@ +/* + * 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 boxWallShelf = defineObject({ + id: 'boxWallShelf', + name: 'boxWallShelf', + 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', + }, + withBack: { + type: 'boolean', + label: 'With back', + }, + }, + default: { + width: 0.1, + height: 0.1, + bodyColor: [0.6, 0.35, 0.15], + withBack: true, + }, + }, + placement: 'wall', + hasCollisions: false, + hasTexture: false, + createInstance: async ({ scene, options, model }) => { + const backMesh = model.findMesh('__X_BACK__'); + const bodyMaterial = model.findMaterial('__X_BODY__'); + + const applySize = () => { + for (const mesh of model.root.getChildMeshes()) { + if (mesh.morphTargetManager != null && mesh.morphTargetManager.getTargetByName('W') != null) { + mesh.morphTargetManager.getTargetByName('W').influence = options.width; + } + if (mesh.morphTargetManager != null && mesh.morphTargetManager.getTargetByName('H') != null) { + mesh.morphTargetManager.getTargetByName('H').influence = options.height; + } + } + model.updated(); + }; + + applySize(); + + const applyBodyColor = () => { + const [r, g, b] = options.bodyColor; + bodyMaterial.albedoColor = new BABYLON.Color3(r, g, b); + }; + + applyBodyColor(); + + const applyWithBack = () => { + backMesh.isVisible = options.withBack; + model.updated(); + }; + + applyWithBack(); + + return { + onInited: () => { + + }, + onOptionsUpdated: ([k, v]) => { + switch (k) { + case 'width': + case 'height': + applySize(); + break; + case 'bodyColor': + applyBodyColor(); + break; + case 'withBack': + applyWithBack(); + break; + } + }, + interactions: {}, + }; + }, +});