mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-14 08:45:44 +02:00
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import * as BABYLON from '@babylonjs/core';
|
|
import { defineObject } from '../engine.js';
|
|
import { cm } from '../utility.js';
|
|
|
|
export const books = defineObject({
|
|
id: 'books',
|
|
name: 'Books',
|
|
options: {
|
|
schema: {
|
|
variation: {
|
|
type: 'enum',
|
|
label: 'Variation',
|
|
enum: ['A', 'B', 'C', 'D', 'E'],
|
|
},
|
|
},
|
|
default: {
|
|
variation: 'A',
|
|
},
|
|
},
|
|
placement: 'top',
|
|
hasCollisions: false,
|
|
createInstance: ({ scene, options, model }) => {
|
|
const coverMaterial = model.findMaterial('__X_COVER__');
|
|
|
|
const applyVariation = () => {
|
|
const coverTexture =
|
|
options.variation === 'A' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/a.png', scene, false, false) :
|
|
options.variation === 'B' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/b.png', scene, false, false) :
|
|
options.variation === 'C' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/c.png', scene, false, false) :
|
|
options.variation === 'D' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/d.png', scene, false, false) :
|
|
new BABYLON.Texture('/client-assets/room/objects/books/textures/e.png', scene, false, false);
|
|
coverMaterial.albedoTexture = coverTexture;
|
|
};
|
|
|
|
applyVariation();
|
|
|
|
const bookMeshes = [
|
|
model.findMeshes('__X_BOOK_1__'),
|
|
model.findMeshes('__X_BOOK_2__'),
|
|
model.findMeshes('__X_BOOK_3__'),
|
|
model.findMeshes('__X_BOOK_4__'),
|
|
model.findMeshes('__X_BOOK_5__'),
|
|
model.findMeshes('__X_BOOK_6__'),
|
|
model.findMeshes('__X_BOOK_7__'),
|
|
model.findMeshes('__X_BOOK_8__'),
|
|
model.findMeshes('__X_BOOK_9__'),
|
|
model.findMeshes('__X_BOOK_10__'),
|
|
];
|
|
|
|
for (const meshes of bookMeshes) {
|
|
const z = Math.random() * cm(0.005);
|
|
const y = Math.random() * cm(0.0025);
|
|
for (const mesh of meshes) {
|
|
mesh.position.z -= z;
|
|
mesh.position.y += y;
|
|
}
|
|
}
|
|
|
|
return {
|
|
onOptionsUpdated: ([k, v]) => {
|
|
applyVariation();
|
|
},
|
|
interactions: {},
|
|
};
|
|
},
|
|
});
|