1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-13 16:25:44 +02:00

boxWallShelf

This commit is contained in:
syuilo
2026-04-20 16:07:35 +09:00
parent 27addb49cf
commit 83a15f74ef
4 changed files with 102 additions and 0 deletions

View File

@@ -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,

View File

@@ -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: {},
};
},
});