1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-14 08:45:44 +02:00
This commit is contained in:
syuilo
2026-05-02 21:27:17 +09:00
parent 2e5a02a85a
commit 4656d93358
5 changed files with 107 additions and 11 deletions

View File

@@ -44,6 +44,7 @@ import { ironFrameTable } from './objects/ironFrameTable.js';
import { issyoubin } from './objects/issyoubin.js';
import { keyboard } from './objects/keyboard.js';
import { laptopPc } from './objects/laptopPc.js';
import { largeMousepad } from './objects/largeMousepad.js';
import { lavaLamp } from './objects/lavaLamp.js';
import { letterCase } from './objects/letterCase.js';
import { miObjet } from './objects/mi-objet.js';
@@ -145,6 +146,7 @@ export const OBJECT_DEFS = [
issyoubin,
keyboard,
laptopPc,
largeMousepad,
lavaLamp,
letterCase,
miObjet,

View File

@@ -0,0 +1,88 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../object.js';
import { cm, WORLD_SCALE, createPlaneUvMapper } from '../../utility.js';
export const largeMousepad = defineObject({
id: 'largeMousepad',
name: 'largeMousepad',
options: {
schema: {
customPicture: {
type: 'image',
label: 'Custom picture',
},
fit: {
type: 'enum',
label: 'Custom picture fit',
enum: ['cover', 'contain', 'stretch'],
},
},
default: {
customPicture: null,
fit: 'cover',
},
},
placement: 'top',
hasCollisions: false,
hasTexture: true,
createInstance: async ({ room, scene, options, model }) => {
const padMesh = model.findMesh('__X_PAD__');
const padMaterial = model.findMaterial('__X_PAD__');
const updateUv = createPlaneUvMapper(padMesh);
const applyFit = () => {
const tex = padMaterial.albedoTexture;
if (tex == null) return;
const srcAspect = tex.getSize().width / tex.getSize().height;
const targetAspect = 70 / 30;
updateUv(srcAspect, targetAspect, options.fit);
model.updated();
};
applyFit();
const applyCustomPicture = () => new Promise<void>((resolve) => {
if (options.customPicture != null) {
padMaterial.unfreeze();
const tex = new BABYLON.Texture(options.customPicture, scene, false, false, undefined, () => {
padMaterial.albedoColor = new BABYLON.Color3(1, 1, 1);
padMaterial.albedoTexture = tex;
applyFit();
resolve();
}, (message, exception) => {
console.warn('Failed to load texture:', message, exception);
padMaterial.albedoColor = new BABYLON.Color3(0, 1, 0);
padMaterial.albedoTexture = null;
resolve();
});
tex.wrapU = BABYLON.Texture.MIRROR_ADDRESSMODE;
tex.wrapV = BABYLON.Texture.MIRROR_ADDRESSMODE;
} else {
padMaterial.albedoColor = new BABYLON.Color3(0.5, 0.5, 0.5);
padMaterial.albedoTexture = null;
resolve();
}
});
await applyCustomPicture();
return {
onOptionsUpdated: ([k, v]) => {
switch (k) {
case 'customPicture': applyCustomPicture(); break;
case 'fit': applyFit(); break;
}
},
interactions: {},
};
},
});

View File

@@ -77,10 +77,14 @@ export const lavaLamp = defineObject({
sphere.parent = root;
sphere.position = new BABYLON.Vector3(0, cm(15), 0);
sphere.material = lavaMat;
const sphere2 = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere2', { diameter: cm(2) }, scene);
const sphere2 = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere2', { diameter: cm(3) }, scene);
sphere2.parent = root;
sphere2.position = new BABYLON.Vector3(0, cm(15), 0);
sphere2.material = lavaMat;
const sphere3 = BABYLON.MeshBuilder.CreateSphere('lavaLampLightSphere3', { diameter: cm(2) }, scene);
sphere3.parent = root;
sphere3.position = new BABYLON.Vector3(0, cm(15), 0);
sphere3.material = lavaMat;
const applyLavaColor = () => {
const [r, g, b] = options.lavaColor;
@@ -96,15 +100,17 @@ export const lavaLamp = defineObject({
const anim = new BABYLON.Animation('lavaLampLightAnim', 'position.y', 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
anim.setKeys([
{ frame: 0, value: cm(11) },
{ frame: 500, value: cm(38) },
{ frame: 800, value: cm(38) },
]);
sphere.animations = [anim];
scene.beginAnimation(sphere, 0, 500, true);
scene.beginAnimation(sphere, 0, 800, true);
sphere2.animations = [anim];
scene.beginAnimation(sphere2, 0, 500, true, 0.6);
scene.beginAnimation(sphere2, 0, 800, true, 0.65);
sphere3.animations = [anim];
scene.beginAnimation(sphere3, 0, 800, true, 0.6);
animationObserver = scene.onAfterAnimationsObservable.add(() => {
room?.sr.updateMesh([sphere, sphere2], false);
room?.sr.updateMesh([sphere, sphere2, sphere3], false);
});
const emitter = new BABYLON.TransformNode('emitter', scene);
@@ -116,11 +122,11 @@ export const lavaLamp = defineObject({
ps.isLocal = true;
ps.minEmitBox = new BABYLON.Vector3(cm(-1), 0, cm(-1));
ps.maxEmitBox = new BABYLON.Vector3(cm(1), 0, cm(1));
ps.minEmitPower = cm(2);
ps.maxEmitPower = cm(3);
ps.minLifeTime = 10;
ps.maxLifeTime = 10;
ps.minSize = cm(0.5);
ps.minEmitPower = cm(1);
ps.maxEmitPower = cm(2.5);
ps.minLifeTime = 12;
ps.maxLifeTime = 12;
ps.minSize = cm(0.25);
ps.maxSize = cm(1.25);
ps.direction1 = new BABYLON.Vector3(0, 1, 0);
ps.direction2 = new BABYLON.Vector3(0, 1, 0);
@@ -129,7 +135,7 @@ export const lavaLamp = defineObject({
ps.color1 = new BABYLON.Color4(1, 1, 1, 1);
ps.color2 = new BABYLON.Color4(1, 1, 1, 0.75);
ps.colorDead = new BABYLON.Color4(1, 1, 1, 0);
ps.preWarmCycles = Math.random() * 1000;
ps.preWarmCycles = 100;
ps.start();
},
interactions: {},