1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-30 16:53:59 +02:00
This commit is contained in:
syuilo
2026-03-05 16:55:03 +09:00
parent 7322697707
commit 295c91c245
6 changed files with 68 additions and 54 deletions

View File

@@ -216,7 +216,7 @@ const data = localStorage.getItem('roomData') != null ? { ...JSON.parse(localSto
}, },
wallE: { wallE: {
material: null, material: null,
color: [0.9, 0.9, 0.9], color: [0.33, 0.34, 0.35],
}, },
wallS: { wallS: {
material: null, material: null,

View File

@@ -30,7 +30,7 @@ import { reactive, ref, shallowRef, triggerRef, watch } from 'vue';
import { genId } from '../id.js'; import { genId } from '../id.js';
import { deepClone } from '../clone.js'; import { deepClone } from '../clone.js';
import { getObjectDef } from './object-defs.js'; import { getObjectDef } from './object-defs.js';
import { HorizontalCameraKeyboardMoveInput } from './utility.js'; import { HorizontalCameraKeyboardMoveInput, findMaterial } from './utility.js';
import * as sound from '@/utility/sound.js'; import * as sound from '@/utility/sound.js';
// babylonのドメイン知識は持たない // babylonのドメイン知識は持たない
@@ -758,6 +758,7 @@ export class RoomEngine {
const meshes: BABYLON.Mesh[] = []; const meshes: BABYLON.Mesh[] = [];
if (this.roomState.heya.type === 'simple') {
const floorResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-floor.glb', this.scene); const floorResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-floor.glb', this.scene);
floorResult.meshes[0].scaling = floorResult.meshes[0].scaling.scale(WORLD_SCALE); floorResult.meshes[0].scaling = floorResult.meshes[0].scaling.scale(WORLD_SCALE);
const floorRoot = new BABYLON.Mesh('floor', this.scene); const floorRoot = new BABYLON.Mesh('floor', this.scene);
@@ -778,6 +779,8 @@ export class RoomEngine {
wallERoot.position = new BABYLON.Vector3(-150/*cm*/, 0, 0); wallERoot.position = new BABYLON.Vector3(-150/*cm*/, 0, 0);
wallERoot.rotation = new BABYLON.Vector3(0, Math.PI, 0); wallERoot.rotation = new BABYLON.Vector3(0, Math.PI, 0);
meshes.push(wallERoot); meshes.push(wallERoot);
const wallEMaterial = findMaterial(wallEResult.meshes[0], '__X_WALL__');
wallEMaterial.albedoColor = new BABYLON.Color3(...this.roomState.heya.options.wallE.color);
const wallWResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall.glb', this.scene); const wallWResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall.glb', this.scene);
wallWResult.meshes[0].scaling = wallWResult.meshes[0].scaling.scale(WORLD_SCALE); wallWResult.meshes[0].scaling = wallWResult.meshes[0].scaling.scale(WORLD_SCALE);
@@ -785,6 +788,8 @@ export class RoomEngine {
wallWRoot.addChild(wallWResult.meshes[0]); wallWRoot.addChild(wallWResult.meshes[0]);
wallWRoot.position = new BABYLON.Vector3(150/*cm*/, 0, 0); wallWRoot.position = new BABYLON.Vector3(150/*cm*/, 0, 0);
meshes.push(wallWRoot); meshes.push(wallWRoot);
const wallWMaterial = findMaterial(wallWResult.meshes[0], '__X_WALL__');
wallWMaterial.albedoColor = new BABYLON.Color3(...this.roomState.heya.options.wallW.color);
const wallNResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall.glb', this.scene); const wallNResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall.glb', this.scene);
wallNResult.meshes[0].scaling = wallNResult.meshes[0].scaling.scale(WORLD_SCALE); wallNResult.meshes[0].scaling = wallNResult.meshes[0].scaling.scale(WORLD_SCALE);
@@ -793,6 +798,8 @@ export class RoomEngine {
wallNRoot.position = new BABYLON.Vector3(0, 0, -150/*cm*/); wallNRoot.position = new BABYLON.Vector3(0, 0, -150/*cm*/);
wallNRoot.rotation = new BABYLON.Vector3(0, Math.PI / 2, 0); wallNRoot.rotation = new BABYLON.Vector3(0, Math.PI / 2, 0);
meshes.push(wallNRoot); meshes.push(wallNRoot);
const wallNMaterial = findMaterial(wallNResult.meshes[0], '__X_WALL__');
wallNMaterial.albedoColor = new BABYLON.Color3(...this.roomState.heya.options.wallN.color);
const wallSResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall-demado.glb', this.scene); const wallSResult = await BABYLON.ImportMeshAsync('/client-assets/room/rooms/default/300-wall-demado.glb', this.scene);
wallSResult.meshes[0].scaling = wallSResult.meshes[0].scaling.scale(WORLD_SCALE); wallSResult.meshes[0].scaling = wallSResult.meshes[0].scaling.scale(WORLD_SCALE);
@@ -801,6 +808,9 @@ export class RoomEngine {
wallSRoot.position = new BABYLON.Vector3(0, 0, 150/*cm*/); wallSRoot.position = new BABYLON.Vector3(0, 0, 150/*cm*/);
wallSRoot.rotation = new BABYLON.Vector3(0, -Math.PI / 2, 0); wallSRoot.rotation = new BABYLON.Vector3(0, -Math.PI / 2, 0);
meshes.push(wallSRoot); meshes.push(wallSRoot);
const wallSMaterial = findMaterial(wallSResult.meshes[0], '__X_WALL__');
wallSMaterial.albedoColor = new BABYLON.Color3(...this.roomState.heya.options.wallS.color);
}
for (const mesh of meshes) { for (const mesh of meshes) {
for (const m of mesh.getChildMeshes()) { for (const m of mesh.getChildMeshes()) {
@@ -944,20 +954,7 @@ export class RoomEngine {
return meshes as BABYLON.Mesh[]; return meshes as BABYLON.Mesh[];
}, },
findMaterial: (keyword) => { findMaterial: (keyword) => {
for (const m of root.getChildMeshes()) { return findMaterial(root, 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

@@ -467,3 +467,20 @@ export function createPlaneUvMapper(mesh: BABYLON.Mesh) {
mesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs); mesh.updateVerticesData(BABYLON.VertexBuffer.UVKind, uvs);
}; };
} }
export function findMaterial(rootMesh: BABYLON.AbstractMesh, keyword: string): BABYLON.PBRMaterial {
for (const m of rootMesh.getChildMeshes()) {
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`);
}