Skip to content

Commit

Permalink
applied avatar config data to learning space avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
mountler committed Jan 29, 2025
1 parent 8640e25 commit c762b93
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import AvatarEditorPreviewModelViewModel from "./AvatarEditorPreviewModelViewModel";
import {
Mesh,
Skeleton,
Texture,
TransformNode,
Vector3,
} from "@babylonjs/core";
import { Mesh, Skeleton, Texture, TransformNode } from "@babylonjs/core";
import IScenePresenter from "../../../Babylon/SceneManagement/IScenePresenter";
import CoreDIContainer from "~DependencyInjection/CoreDIContainer";
import SCENE_TYPES, {
Expand All @@ -32,6 +26,10 @@ import {
AvatarMouthTexture,
AvatarNoseTexture,
} from "src/Components/Core/Domain/AvatarModels/AvatarFaceUVTexture";
import AvatarEditorUtils from "../../AvatarEditorUtils";
import AvatarModelAssetPaths from "src/Components/Core/Domain/AvatarModels/AvatarModelPaths";
import AvatarModelTransforms from "src/Components/Core/Domain/AvatarModels/AvatarModelTransforms";
import AvatarModelMaterialNames from "src/Components/Core/Domain/AvatarModels/AvatarModelMaterialNames";

const baseModelLink = require("../../../../../../Assets/3dModels/sharedModels/avatar/a-avatar-skeleton.glb");

Expand Down Expand Up @@ -75,72 +73,43 @@ export default class AvatarEditorPreviewModelView {
});

// find anchor nodes
this.viewModel.hairAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_hair",
)!;
this.viewModel.beardAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_beard",
)!;
this.viewModel.shirtAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_top",
)!;
this.viewModel.pantsAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_pants",
)!;
this.viewModel.shoesAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_shoes",
)!;
this.viewModel.headGearAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_hat",
)!;
this.viewModel.glassesAnchorNode = result.transformNodes.find(
(node) => node.name === "anchor_glasses",
)!;
this.viewModel.backpackAnchorNode = result.transformNodes.find(
(node) => node.name === "Spine",
)!;
this.viewModel.otherAnchorNode = result.transformNodes.find(
(node) => node.name === "Spine",
)!;

console.log(this.viewModel.backpackAnchorNode);
result.transformNodes.forEach((node) => {
console.log(node.name, " / ", node.parent?.name);
});

// this.viewModel.baseModelMeshes.forEach((mesh) => {
// if (mesh.name === "defaultTop") {
// mesh.dispose();
// }
// if (mesh.name === "defaultPants") {
// mesh.dispose();
// }
// if (mesh.name === "defaultShoes") {
// mesh.dispose();
// }
// });
const anchorNodes = AvatarEditorUtils.getAvatarAnchorNodes(
result.transformNodes,
);
this.viewModel.hairAnchorNode = anchorNodes.hairNode;
this.viewModel.beardAnchorNode = anchorNodes.beardNode;
this.viewModel.shirtAnchorNode = anchorNodes.shirtNode;
this.viewModel.pantsAnchorNode = anchorNodes.pantsNode;
this.viewModel.shoesAnchorNode = anchorNodes.shoesNode;
this.viewModel.headGearAnchorNode = anchorNodes.headGearNode;
this.viewModel.glassesAnchorNode = anchorNodes.glassesNode;
this.viewModel.backpackAnchorNode = anchorNodes.backpackNode;
this.viewModel.otherAnchorNode = anchorNodes.otherNode;

await CoreDIContainer.get<ILoadAvatarConfigUseCase>(
USECASE_TYPES.ILoadAvatarConfigUseCase,
).executeAsync();

// hair
this.updateModelHair(this.viewModel.currentAvatarConfig.Value.hair);
this.updateModelBeard(this.viewModel.currentAvatarConfig.Value.beard);
// face
this.updateEyeBrows(this.viewModel.currentAvatarConfig.Value.eyebrows);
this.updateEyes(this.viewModel.currentAvatarConfig.Value.eyes);
this.updateNose(this.viewModel.currentAvatarConfig.Value.nose);
this.updateMouth(this.viewModel.currentAvatarConfig.Value.mouth);
this.updateModelShirt(this.viewModel.currentAvatarConfig.Value.shirt);
this.updateModelPants(this.viewModel.currentAvatarConfig.Value.pants);
this.updateModelShoes(this.viewModel.currentAvatarConfig.Value.shoes);
// accessoires
this.updateHeadGear(this.viewModel.currentAvatarConfig.Value.headgear);
this.updateGlasses(this.viewModel.currentAvatarConfig.Value.glasses);
this.updateBackPack(this.viewModel.currentAvatarConfig.Value.backpack);
this.updateOther(this.viewModel.currentAvatarConfig.Value.other);
// clothing
this.updateModelShirt(this.viewModel.currentAvatarConfig.Value.shirt);
this.updateModelPants(this.viewModel.currentAvatarConfig.Value.pants);
this.updateModelShoes(this.viewModel.currentAvatarConfig.Value.shoes);
}

private onAvatarConfigChanged(): void {
//console.log(this.viewModel.avatarConfigDiff.Value);
if (this.viewModel.avatarConfigDiff.Value.beard)
this.updateModelBeard(this.viewModel.avatarConfigDiff.Value.beard);
if (this.viewModel.avatarConfigDiff.Value.hair)
Expand Down Expand Up @@ -172,7 +141,7 @@ export default class AvatarEditorPreviewModelView {
private updateModelHair(hair?: AvatarHairModels | undefined) {
this.updateModel(
hair,
"hair/hairstyle",
AvatarModelAssetPaths.hairPath,
this.viewModel.hairMeshes,
this.viewModel.hairAnchorNode,
);
Expand All @@ -181,7 +150,7 @@ export default class AvatarEditorPreviewModelView {
private updateModelBeard(beard?: AvatarBeardModels | undefined) {
this.updateModel(
beard,
"hair/beards",
AvatarModelAssetPaths.beardPath,
this.viewModel.beardMeshes,
this.viewModel.beardAnchorNode,
);
Expand All @@ -190,7 +159,7 @@ export default class AvatarEditorPreviewModelView {
private updateHeadGear(headgear?: AvatarHeadgearModels | undefined) {
this.updateModel(
headgear,
"accessoires/headgear",
AvatarModelAssetPaths.headGearPath,
this.viewModel.headGearMeshes,
this.viewModel.headGearAnchorNode,
);
Expand All @@ -199,7 +168,7 @@ export default class AvatarEditorPreviewModelView {
private updateGlasses(glasses?: AvatarGlassesModels | undefined) {
this.updateModel(
glasses,
"accessoires/glasses",
AvatarModelAssetPaths.glassesPath,
this.viewModel.glassesMeshes,
this.viewModel.glassesAnchorNode,
);
Expand All @@ -208,31 +177,27 @@ export default class AvatarEditorPreviewModelView {
private updateBackPack(backpack?: AvatarBackpackModels | undefined) {
this.updateModel(
backpack,
"accessoires/backpack",
AvatarModelAssetPaths.backpackPath,
this.viewModel.backpackMeshes,
this.viewModel.backpackAnchorNode,
(mesh) => {
mesh.position = this.viewModel.backpackPositionOffset;
},
AvatarModelTransforms.backpack,
);
}

private updateOther(other?: AvatarOtherModels) {
this.updateModel(
other,
"accessoires/other",
AvatarModelAssetPaths.otherPath,
this.viewModel.otherMeshes,
this.viewModel.otherAnchorNode,
(mesh) => {
mesh.position = new Vector3(0, 0.28, 0.04);
},
AvatarModelTransforms.sheriffStar,
);
}

private updateModelShirt(shirt?: AvatarShirtModels | undefined) {
this.updateModel(
shirt,
"clothing/shirts",
AvatarModelAssetPaths.shirtPath,
this.viewModel.shirtMeshes,
this.viewModel.shirtAnchorNode,
);
Expand All @@ -241,7 +206,7 @@ export default class AvatarEditorPreviewModelView {
private updateModelPants(pants?: AvatarPantsModels | undefined) {
this.updateModel(
pants,
"clothing/pants",
AvatarModelAssetPaths.pantsPath,
this.viewModel.pantsMeshes,
this.viewModel.pantsAnchorNode,
);
Expand All @@ -250,7 +215,7 @@ export default class AvatarEditorPreviewModelView {
private updateModelShoes(shoes?: AvatarShoesModels | undefined) {
this.updateModel(
shoes,
"clothing/shoes",
AvatarModelAssetPaths.shoesPath,
this.viewModel.shoesMeshes,
this.viewModel.shoesAnchorNode,
);
Expand Down Expand Up @@ -322,21 +287,15 @@ export default class AvatarEditorPreviewModelView {

// load model if not already loaded
if (!modelMap.has(newModel)) {
const result = await this.scenePresenter.loadGLTFModel(
require(
`../../../../../../Assets/3dModels/sharedModels/avatar/${modelFolder}/aa-${newModel}.glb`,
),
const result = await AvatarEditorUtils.setupAvatarAssetModel(
this.scenePresenter,
this.baseModelSkeleton,
newModel,
modelFolder,
anchorNode,
onMeshLoad,
);
result.meshes.forEach((mesh) => {
if (mesh instanceof Mesh) {
// Stelle sicher, dass es ein Mesh ist
mesh.skeleton = this.baseModelSkeleton;
}
});

modelMap.set(newModel, result.meshes as Mesh[]);
result.meshes[0].parent = anchorNode;
if (onMeshLoad) onMeshLoad(result.meshes[0] as Mesh);
modelMap.set(newModel, result!.meshes as Mesh[]);
}

// set all meshes to invisible except the new model
Expand Down
Loading

0 comments on commit c762b93

Please sign in to comment.