This commit is contained in:
syuilo
2026-02-27 21:57:43 +09:00
parent 3e7166bd2c
commit 5910ec68e3
15 changed files with 37 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -884,8 +884,16 @@ export class RoomEngine {
},
findMaterial: (keyword) => {
for (const m of root.getChildMeshes()) {
if (m.material != null && m.material.name.includes(keyword)) {
if (m.material == null) continue;
if (m.material.name.includes(keyword)) {
return m.material as BABYLON.PBRMaterial;
} else if ((m.material as BABYLON.MultiMaterial).subMaterials != null) {
for (const sm of (m.material as BABYLON.MultiMaterial).subMaterials) {
if (sm == null) continue;
if (sm.name.includes(keyword)) {
return sm as BABYLON.PBRMaterial;
}
}
}
}
throw new Error(`Material with keyword "${keyword}" not found for object ${args.type} (${args.id})`);

View File

@@ -3,19 +3,40 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as BABYLON from '@babylonjs/core';
import { defineObject } from '../engine.js';
export const books = defineObject({
id: 'books',
name: 'Books',
options: {
schema: {},
default: {},
schema: {
variation: {
type: 'enum',
label: 'Variation',
enum: ['A', 'B', 'C', 'D', 'E'],
},
},
default: {
variation: 'A',
},
},
placement: 'top',
mergeMeshes: ['__X_BOOK_1__', '__X_BOOK_2__', '__X_BOOK_3__', '__X_BOOK_4__', '__X_BOOK_5__', '__X_BOOK_6__', '__X_BOOK_7__', '__X_BOOK_8__', '__X_BOOK_9__', '__X_BOOK_10__'],
createInstance: ({ findMesh, root }) => {
console.log(root.getChildMeshes().map((m) => m.name));
createInstance: ({ room, options, findMesh, findMaterial }) => {
const coverMaterial = findMaterial('__X_COVER__');
const applyVariation = () => {
const coverTexture =
options.variation === 'A' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/a.png', room.scene, false, false) :
options.variation === 'B' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/b.png', room.scene, false, false) :
options.variation === 'C' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/c.png', room.scene, false, false) :
options.variation === 'D' ? new BABYLON.Texture('/client-assets/room/objects/books/textures/d.png', room.scene, false, false) :
new BABYLON.Texture('/client-assets/room/objects/books/textures/e.png', room.scene, false, false);
coverMaterial.albedoTexture = coverTexture;
};
applyVariation();
const bookMeshes = [
findMesh('__X_BOOK_1__'),
@@ -36,6 +57,9 @@ export const books = defineObject({
}
return {
onOptionsUpdated: ([k, v]) => {
applyVariation();
},
interactions: {},
};
},