1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-05-13 17:35:40 +02:00

TransformNode

This commit is contained in:
syuilo
2026-04-15 12:14:27 +09:00
parent 5104bafe95
commit 4254268f8d

View File

@@ -1168,8 +1168,10 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
const filePath = def.path != null ? `/client-assets/room/objects/${def.path}.glb` : `/client-assets/room/objects/${camelToKebab(args.type)}/${camelToKebab(args.type)}.glb`;
const loaderResult = await BABYLON.LoadAssetContainerAsync(filePath, this.scene);
const allMeshes = loaderResult.meshes;
// babylonによって自動で追加される右手系変換用ード
const subRoot = loaderResult.meshes[0] as BABYLON.Mesh;
let subRoot = allMeshes[0] as BABYLON.TransformNode;
if (BAKE_TRANSFORM) {
subRoot.scaling = new BABYLON.Vector3(1, 1, 1);
@@ -1186,7 +1188,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
//m.parent = root;
}
}
for (const m of loaderResult.meshes) {
for (const m of allMeshes) {
if (m.name === '__root__') continue;
if (m.parent === subRoot) {
m.setParent(root);
@@ -1297,7 +1299,19 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
subRoot.dispose();
} else {
subRoot.scaling = subRoot.scaling.scale(WORLD_SCALE);// cmをmに
// meshじゃなくtransform nodeにしてパフォーマンス向上
const _subRoot = new BABYLON.TransformNode('__root__', this.scene);
_subRoot.scaling.x = -1;
_subRoot.scaling = _subRoot.scaling.scale(WORLD_SCALE);// cmをmに
for (const m of subRoot.getChildren()) {
if (m.parent === subRoot) {
m.parent = _subRoot;
}
}
subRoot.dispose();
subRoot = _subRoot;
}
def.treatLoaderResult?.(loaderResult);
@@ -1320,7 +1334,7 @@ export class RoomEngine extends EventEmitter<RoomEngineEvents> {
root.rotation = args.rotation.clone();
root.metadata = metadata;
const model = new ModelManager(BAKE_TRANSFORM ? root : subRoot, loaderResult.meshes.filter(m => m.name !== subRoot), (meshes) => {
const model = new ModelManager(BAKE_TRANSFORM ? root : subRoot, allMeshes.filter(m => m.name !== '__root__'), (meshes) => {
if (this.selected?.objectId === args.id) {
this.highlightMeshes(meshes);
}