-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
353 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Components/Core/Domain/AvatarModels/AvatarModelMaterialNames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const AvatarModelMaterialNames = { | ||
eyebrows: "mat_Eyebrows", | ||
eyes: "mat_Eyes", | ||
nose: "mat_Nose", | ||
mouth: "mat_Mouth", | ||
} as const; | ||
|
||
export default AvatarModelMaterialNames; |
13 changes: 13 additions & 0 deletions
13
src/Components/Core/Domain/AvatarModels/AvatarModelPaths.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const AvatarModelAssetPaths = { | ||
hairPath: "hair/hairstyle", | ||
beardPath: "hair/beards", | ||
headGearPath: "accessoires/headgear", | ||
glassesPath: "accessoires/glasses", | ||
backpackPath: "accessoires/backpack", | ||
otherPath: "accessoires/other", | ||
shirtPath: "clothing/shirts", | ||
pantsPath: "clothing/pants", | ||
shoesPath: "clothing/shoes", | ||
} as const; | ||
|
||
export default AvatarModelAssetPaths; |
11 changes: 11 additions & 0 deletions
11
src/Components/Core/Domain/AvatarModels/AvatarModelTransforms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Mesh, Vector3 } from "@babylonjs/core"; | ||
|
||
const AvatarModelTransforms = { | ||
backpack: (mesh: Mesh) => { | ||
mesh.position = new Vector3(0, 0.36, 0); | ||
}, | ||
sheriffStar: (mesh: Mesh) => { | ||
mesh.position = new Vector3(0, 0.28, 0.04); | ||
}, | ||
} as const; | ||
export default AvatarModelTransforms; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
src/Components/Core/Presentation/AvatarEditor/AvatarEditorUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { | ||
ISceneLoaderAsyncResult, | ||
Mesh, | ||
Skeleton, | ||
Texture, | ||
TransformNode, | ||
Vector3, | ||
} from "@babylonjs/core"; | ||
import IScenePresenter from "../Babylon/SceneManagement/IScenePresenter"; | ||
import { AvatarNoneModel } from "../../Domain/AvatarModels/AvatarModelTypes"; | ||
import { AvatarUVOffset } from "../../Domain/AvatarModels/AvatarFaceUVTexture"; | ||
|
||
export default class AvatarEditorUtils { | ||
public static async setupAvatarAssetModel<T>( | ||
scenePresenter: IScenePresenter, | ||
avatartSkeleton: Skeleton, | ||
newModel: T, | ||
modelFolder: string, | ||
anchorNode: TransformNode, | ||
onMeshLoaded?: (mesh: Mesh) => void, | ||
): Promise<ISceneLoaderAsyncResult | void> { | ||
if ( | ||
newModel === undefined || | ||
newModel === null || | ||
newModel === AvatarNoneModel.None | ||
) | ||
return; | ||
|
||
const result = await scenePresenter.loadGLTFModel( | ||
require( | ||
`src/Assets/3dModels/sharedModels/avatar/${modelFolder}/aa-${newModel}.glb`, | ||
), | ||
); | ||
result.animationGroups.forEach((animation) => { | ||
animation.dispose(); | ||
}); | ||
result.meshes.forEach((mesh) => { | ||
if (mesh instanceof Mesh) { | ||
mesh.skeleton?.dispose(); | ||
mesh.skeleton = avatartSkeleton; | ||
} | ||
}); | ||
result.meshes[0].parent = anchorNode; | ||
if (onMeshLoaded) onMeshLoaded(result.meshes[0] as Mesh); | ||
return result; | ||
} | ||
|
||
public static getAvatarAnchorNodes(nodes: TransformNode[]): { | ||
hairNode: TransformNode; | ||
beardNode: TransformNode; | ||
shirtNode: TransformNode; | ||
pantsNode: TransformNode; | ||
shoesNode: TransformNode; | ||
headGearNode: TransformNode; | ||
glassesNode: TransformNode; | ||
backpackNode: TransformNode; | ||
otherNode: TransformNode; | ||
} { | ||
const hairAnchorNode = nodes.find((node) => node.name === "anchor_hair")!; | ||
const beardAnchorNode = nodes.find((node) => node.name === "anchor_beard")!; | ||
const shirtAnchorNode = nodes.find((node) => node.name === "anchor_top")!; | ||
const pantsAnchorNode = nodes.find((node) => node.name === "anchor_pants")!; | ||
const shoesAnchorNode = nodes.find((node) => node.name === "anchor_shoes")!; | ||
const headGearAnchorNode = nodes.find( | ||
(node) => node.name === "anchor_hat", | ||
)!; | ||
const glassesAnchorNode = nodes.find( | ||
(node) => node.name === "anchor_glasses", | ||
)!; | ||
const backpackAnchorNode = nodes.find((node) => node.name === "Spine")!; | ||
const otherAnchorNode = nodes.find((node) => node.name === "Spine")!; | ||
// models are per default mirrored | ||
shirtAnchorNode.scaling = new Vector3(-1, 1, 1); | ||
pantsAnchorNode.scaling = new Vector3(-1, 1, 1); | ||
shoesAnchorNode.scaling = new Vector3(-1, 1, 1); | ||
|
||
return { | ||
hairNode: hairAnchorNode, | ||
beardNode: beardAnchorNode, | ||
shirtNode: shirtAnchorNode, | ||
pantsNode: pantsAnchorNode, | ||
shoesNode: shoesAnchorNode, | ||
headGearNode: headGearAnchorNode, | ||
glassesNode: glassesAnchorNode, | ||
backpackNode: backpackAnchorNode, | ||
otherNode: otherAnchorNode, | ||
}; | ||
} | ||
|
||
public static setupAvatarTextures( | ||
textureIndex: number, | ||
meshes: Mesh[], | ||
materialName: string, | ||
textureOffset: AvatarUVOffset[], | ||
) { | ||
if (textureIndex === undefined || textureIndex === null) return; | ||
const texture = meshes | ||
.find((mesh) => mesh.material?.name.includes(materialName)) | ||
?.material!.getActiveTextures()[0] as Texture; | ||
texture.uOffset = textureOffset[textureIndex].uOffset; | ||
texture.vOffset = textureOffset[textureIndex].vOffset; | ||
} | ||
} |
Oops, something went wrong.