Skip to content

Commit

Permalink
Add avatar configuration to change default avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
sachamorgese committed Jun 17, 2024
1 parent 5a49f55 commit 435a765
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions example/multi-user-3d-web-experience/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const app = new Networked3dWebExperienceClient(holder, {
skyboxHdrJpgUrl: hdrJpgUrl,
mmlDocuments: [{ url: `${protocol}//${host}/mml-documents/example-mml.html` }],
environmentConfiguration: {},
avatarConfig: {
availableAvatars: [],
},
});

app.update();
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ type MMLDocumentConfiguration = {
};
};

type AvatarConfig = {
availableAvatars: Array<{
avatarFileType: "glb" | "html";
thumbnailUrl?: string;
isDefaultAvatar?: boolean;
avatarFileUrl: string;
avatarName?: string;
}>;
allowCustomAvatars?: boolean;
customAvatarWebhookUrl?: string;
};

export type Networked3dWebExperienceClientConfig = {
sessionToken: string;
chatNetworkAddress?: string;
Expand All @@ -64,6 +76,7 @@ export type Networked3dWebExperienceClientConfig = {
skyboxHdrJpgUrl: string;
enableTweakPane?: boolean;
updateURLLocation?: boolean;
avatarConfig?: AvatarConfig;
};

export class Networked3dWebExperienceClient {
Expand Down Expand Up @@ -395,10 +408,24 @@ export class Networked3dWebExperienceClient {
throw new Error("Own identity not found");
}

const defaultAvatar =
this.config.avatarConfig?.availableAvatars.find((avatar) => avatar.isDefaultAvatar) ??
this.config.avatarConfig?.availableAvatars[0];

const characterDescription = defaultAvatar
? ({
meshFileUrl:
defaultAvatar.avatarFileType === "glb" ? defaultAvatar.avatarFileUrl : undefined,
mmlCharacterUrl:
defaultAvatar.avatarFileType === "html" ? defaultAvatar.avatarFileUrl : undefined,
mmlCharacterString: undefined,
} as CharacterDescription)
: ownIdentity.characterDescription;

this.characterManager.spawnLocalCharacter(
this.clientId!,
ownIdentity.username,
ownIdentity.characterDescription,
characterDescription,
spawnPosition,
spawnRotation,
);
Expand Down

0 comments on commit 435a765

Please sign in to comment.