mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-15 03:25:47 +02:00
wip
This commit is contained in:
@@ -5,16 +5,47 @@
|
||||
|
||||
import * as BABYLON from '@babylonjs/core';
|
||||
import { defineObject, WORLD_SCALE } from '../engine.js';
|
||||
import { createOverridedStates } from '../utility.js';
|
||||
|
||||
export const blind = defineObject({
|
||||
id: 'blind',
|
||||
defaultOptions: {
|
||||
blades: 24,
|
||||
angle: 0,
|
||||
open: 1,
|
||||
name: 'Blind',
|
||||
options: {
|
||||
schema: {
|
||||
blades: {
|
||||
type: 'number',
|
||||
label: 'Number of blades',
|
||||
min: 1,
|
||||
max: 100,
|
||||
},
|
||||
angle: {
|
||||
type: 'number',
|
||||
label: 'Blade rotation angle (radian)',
|
||||
min: -Math.PI / 2,
|
||||
max: Math.PI / 2,
|
||||
step: 0.01,
|
||||
},
|
||||
open: {
|
||||
type: 'number',
|
||||
label: 'Opening state',
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.01,
|
||||
},
|
||||
},
|
||||
default: {
|
||||
blades: 24,
|
||||
angle: 0,
|
||||
open: 1,
|
||||
},
|
||||
},
|
||||
placement: 'bottom',
|
||||
createInstance: ({ options, loaderResult, meshUpdated }) => {
|
||||
const temp = createOverridedStates({
|
||||
angle: () => options.angle,
|
||||
open: () => options.open,
|
||||
});
|
||||
|
||||
const blade = loaderResult.meshes[0].getChildMeshes().find(m => m.name === 'Blade') as BABYLON.Mesh;
|
||||
blade.rotation = new BABYLON.Vector3(options.angle, 0, 0);
|
||||
|
||||
@@ -28,10 +59,10 @@ export const blind = defineObject({
|
||||
|
||||
for (let i = 0; i < options.blades; i++) {
|
||||
const b = blade.clone();
|
||||
if (i / options.blades < options.open) {
|
||||
if (i / options.blades < temp.open) {
|
||||
b.position.y -= (i * 4/*cm*/) / WORLD_SCALE;
|
||||
} else {
|
||||
b.position.y -= (((options.blades - 1) * options.open * 4/*cm*/) + (i * 0.3/*cm*/)) / WORLD_SCALE;
|
||||
b.position.y -= (((options.blades - 1) * temp.open * 4/*cm*/) + (i * 0.3/*cm*/)) / WORLD_SCALE;
|
||||
}
|
||||
blades.push(b);
|
||||
}
|
||||
@@ -41,7 +72,7 @@ export const blind = defineObject({
|
||||
|
||||
const applyAngle = () => {
|
||||
for (const b of [blade, ...blades]) {
|
||||
b.rotation.x = options.angle;
|
||||
b.rotation.x = temp.angle;
|
||||
b.rotation.x += Math.random() * 0.3 - 0.15;
|
||||
}
|
||||
};
|
||||
@@ -57,20 +88,25 @@ export const blind = defineObject({
|
||||
adjustBladeRotation: {
|
||||
label: 'Adjust blade rotation',
|
||||
fn: () => {
|
||||
options.angle += Math.PI / 8;
|
||||
if (options.angle >= Math.PI / 2) options.angle = -Math.PI / 2;
|
||||
temp.angle += Math.PI / 8;
|
||||
if (temp.angle >= Math.PI / 2) temp.angle = -Math.PI / 2;
|
||||
applyAngle();
|
||||
},
|
||||
},
|
||||
openClose: {
|
||||
label: 'Open/close',
|
||||
fn: () => {
|
||||
options.open -= 0.25;
|
||||
if (options.open < 0) options.open = 1;
|
||||
temp.open -= 0.25;
|
||||
if (temp.open < 0) temp.open = 1;
|
||||
applyOpeningState();
|
||||
},
|
||||
},
|
||||
},
|
||||
resetTemporaryState: () => {
|
||||
temp.$reset();
|
||||
applyAngle();
|
||||
applyOpeningState();
|
||||
},
|
||||
primaryInteraction: 'openClose',
|
||||
};
|
||||
},
|
||||
|
||||
@@ -29,16 +29,21 @@ export const tabletopDigitalClock = defineObject({
|
||||
},
|
||||
placement: 'top',
|
||||
createInstance: ({ room, options, root }) => {
|
||||
const applyBodyColor = () => {
|
||||
const bodyMesh = root.getChildMeshes().find(m => m.name.includes('__X_BODY__')) as BABYLON.Mesh;
|
||||
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
|
||||
|
||||
if (options.bodyStyle === 'color') {
|
||||
const [r, g, b] = options.bodyColor;
|
||||
bodyMaterial.albedoColor = new BABYLON.Color3(r, g, b);
|
||||
} else {
|
||||
bodyMaterial.albedoTexture = room.scene.getTextureByName('tabletop_digital_clock_wood');
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
onInited: () => {
|
||||
const bodyMesh = root.getChildMeshes().find(m => m.name.includes('__X_BODY__')) as BABYLON.Mesh;
|
||||
|
||||
const bodyMaterial = bodyMesh.material as BABYLON.PBRMaterial;
|
||||
|
||||
if (options.bodyStyle === 'color') {
|
||||
const [r, g, b] = options.bodyColor;
|
||||
bodyMaterial.albedoColor = new BABYLON.Color3(r, g, b);
|
||||
}
|
||||
applyBodyColor();
|
||||
|
||||
const segmentMeshes = {
|
||||
'1a': root.getChildMeshes().find(m => m.name.includes('__TIME_7SEG_1A__')),
|
||||
@@ -85,6 +90,11 @@ export const tabletopDigitalClock = defineObject({
|
||||
}
|
||||
}, 1000));
|
||||
},
|
||||
onOptionsUpdated: ([k, v]) => {
|
||||
if (k === 'bodyColor') {
|
||||
applyBodyColor();
|
||||
}
|
||||
},
|
||||
interactions: {},
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user