1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-14 15:45:43 +02:00
Files
misskey/packages/frontend/src/utility/room/objects/book.ts
syuilo aae03a914d wip
2026-02-20 13:15:34 +09:00

46 lines
1.1 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';
export const book = defineObject({
id: 'book',
name: 'Book',
options: {
schema: {
variation: {
type: 'enum',
label: 'Variation',
enum: [0, 1],
},
},
default: {
variation: 0,
},
},
placement: 'top',
createInstance: ({ options, root }) => {
return {
onInited: () => {
const mesh = root.getChildMeshes()[1] as BABYLON.Mesh;
mesh.markVerticesDataAsUpdatable(BABYLON.VertexBuffer.UVKind, true);
const index = options.variation ?? 0;
const x = index % 8;
const y = Math.floor(index / 8);
const uvs = mesh.getVerticesData(BABYLON.VertexBuffer.UVKind)!;
for (let i = 0; i < uvs.length / 2; i++) {
const u = uvs[i * 2];
const v = uvs[i * 2 + 1];
uvs[i * 2] = (u / 8) + (x / 8);
uvs[i * 2 + 1] = (v / 8) + (y / 8);
}
mesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
},
interactions: {},
};
},
});