1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-26 14:54:16 +02:00
This commit is contained in:
syuilo
2026-02-15 18:33:46 +09:00
parent 0bcc5a3695
commit 0996c2d9b2
4 changed files with 270 additions and 109 deletions

View File

@@ -0,0 +1,74 @@
/*
* 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';
export const blind = defineObject({
id: 'blind',
defaultOptions: {
blades: 24,
angle: 0,
open: 1,
},
placement: 'bottom',
createInstance: ({ room, o, loaderResult, meshUpdated }) => {
const blade = loaderResult.meshes[0].getChildMeshes().find(m => m.name === 'Blade') as BABYLON.Mesh;
blade.rotation = new BABYLON.Vector3(o.options.angle, 0, 0);
let blades = [] as BABYLON.Mesh[];
const applyOpeningState = () => {
for (const b of blades) {
b.dispose();
}
blades = [];
for (let i = 0; i < o.options.blades; i++) {
if (i / o.options.blades > o.options.open) continue;
const b = blade.clone();
b.position.y -= (i * 4/*cm*/) / WORLD_SCALE;
blades.push(b);
}
meshUpdated();
};
const applyAngle = () => {
for (const b of [blade, ...blades]) {
b.rotation.x = o.options.angle;
}
};
applyOpeningState();
applyAngle();
return {
onInited: () => {
},
interactions: {
adjustBladeRotation: {
label: 'Adjust blade rotation',
fn: () => {
o.options.angle += Math.PI / 24;
if (o.options.angle > Math.PI / 2) o.options.angle = 0;
applyAngle();
},
},
openClose: {
label: 'Open/close',
fn: () => {
o.options.open -= 0.25;
if (o.options.open < 0) o.options.open = 1;
applyOpeningState();
},
},
},
primaryInteraction: 'openClose',
};
},
});