mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-06-25 17:10:43 +00:00
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import * as BABYLON from '@babylonjs/core/pure.js';
|
|
import { defineFurniture } from '../furniture.js';
|
|
import { boxWallShelf_schema } from 'misskey-world/src/room/furnitures/boxWallShelf.schema.js';
|
|
|
|
export const boxWallShelf = defineFurniture(boxWallShelf_schema, {
|
|
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 applyBodyMat = () => {
|
|
bodyMaterial.albedoColor = new BABYLON.Color3(options.bodyMat.color[0], options.bodyMat.color[1], options.bodyMat.color[2]);
|
|
bodyMaterial.roughness = options.bodyMat.roughness;
|
|
bodyMaterial.metallic = options.bodyMat.metallic;
|
|
};
|
|
|
|
applyBodyMat();
|
|
|
|
const applyWithBack = () => {
|
|
backMesh.isVisible = options.withBack;
|
|
model.updated();
|
|
};
|
|
|
|
applyWithBack();
|
|
|
|
return {
|
|
onInited: () => {
|
|
|
|
},
|
|
onOptionsUpdated: ([k, v]) => {
|
|
switch (k) {
|
|
case 'width':
|
|
case 'height':
|
|
applySize();
|
|
break;
|
|
case 'bodyMat':
|
|
applyBodyMat();
|
|
break;
|
|
case 'withBack':
|
|
applyWithBack();
|
|
break;
|
|
}
|
|
},
|
|
interactions: {},
|
|
dispose: () => {},
|
|
};
|
|
},
|
|
});
|