diff --git a/packages/frontend/assets/room/objects/cuboid/cuboid.blend b/packages/frontend/assets/room/objects/cuboid/cuboid.blend new file mode 100644 index 0000000000..047412115d Binary files /dev/null and b/packages/frontend/assets/room/objects/cuboid/cuboid.blend differ diff --git a/packages/frontend/assets/room/objects/cuboid/cuboid.glb b/packages/frontend/assets/room/objects/cuboid/cuboid.glb new file mode 100644 index 0000000000..2e7377393c Binary files /dev/null and b/packages/frontend/assets/room/objects/cuboid/cuboid.glb differ diff --git a/packages/frontend/src/utility/room/object-defs.ts b/packages/frontend/src/utility/room/object-defs.ts index e86d5e7d38..22136fda13 100644 --- a/packages/frontend/src/utility/room/object-defs.ts +++ b/packages/frontend/src/utility/room/object-defs.ts @@ -20,6 +20,7 @@ import { ceilingFanLight } from './objects/ceilingFanLight.js'; import { chair } from './objects/chair.js'; import { coffeeCup } from './objects/coffeeCup.js'; import { colorBox } from './objects/colorBox.js'; +import { cuboid } from './objects/cuboid.js'; import { cupNoodle } from './objects/cupNoodle.js'; import { custardPudding } from './objects/custardPudding.js'; import { debugHipoly } from './objects/debugHipoly.js'; @@ -102,6 +103,7 @@ export const OBJECT_DEFS = [ chair, coffeeCup, colorBox, + cuboid, cupNoodle, custardPudding, desk, diff --git a/packages/frontend/src/utility/room/objects/cuboid.ts b/packages/frontend/src/utility/room/objects/cuboid.ts new file mode 100644 index 0000000000..d2f1ee7b9c --- /dev/null +++ b/packages/frontend/src/utility/room/objects/cuboid.ts @@ -0,0 +1,87 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import * as BABYLON from '@babylonjs/core'; +import { defineObject } from '../engine.js'; + +export const cuboid = defineObject({ + id: 'cuboid', + name: 'cuboid', + options: { + schema: { + x: { + type: 'range', + label: 'X', + min: 0, + max: 1, + step: 0.01, + }, + y: { + type: 'range', + label: 'Y', + min: 0, + max: 1, + step: 0.01, + }, + z: { + type: 'range', + label: 'Z', + min: 0, + max: 1, + step: 0.01, + }, + color: { + type: 'color', + label: 'Color', + }, + }, + default: { + x: 0.01, + y: 0.01, + z: 0.01, + color: [1, 1, 1], + }, + }, + placement: 'top', + createInstance: async ({ scene, options, model }) => { + const mesh = model.findMesh('__X_BODY__'); + const mat = model.findMaterial('__X_BODY__'); + + const applySize = () => { + mesh.morphTargetManager!.getTargetByName('X')!.influence = options.x; + mesh.morphTargetManager!.getTargetByName('Y')!.influence = options.y; + mesh.morphTargetManager!.getTargetByName('Z')!.influence = options.z; + model.updated(); + }; + + applySize(); + + const applyColor = () => { + const [r, g, b] = options.color; + mat.albedoColor = new BABYLON.Color3(r, g, b); + }; + + applyColor(); + + return { + onInited: () => { + + }, + onOptionsUpdated: ([k, v]) => { + switch (k) { + case 'color': + applyColor(); + break; + case 'x': + case 'y': + case 'z': + applySize(); + break; + } + }, + interactions: {}, + }; + }, +});