Skip to content

Commit

Permalink
export createMMLCharacterString function (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir authored Dec 6, 2023
1 parent 6af5c28 commit b752d6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/3d-web-avatar-editor-ui/src/CharacterPartsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createMMLCharacterString } from "@mml-io/3d-web-avatar";
import { useCallback, useEffect, useState } from "react";

import { AssetDescription, CharacterComposition, CollectionDataType } from "./types";
Expand Down Expand Up @@ -32,10 +33,13 @@ export function CharacterPartsSelector<C extends CollectionDataType>({
const createMMLDescription = useCallback(() => {
const fullBody = currentSelection[fullBodyKey];
const remainingParts = Object.entries(currentSelection).filter(([key]) => key !== fullBodyKey);
const description = `<m-character src="${fullBody}">
${remainingParts.map(([key, asset]) => `<m-model src="${asset.asset}"></m-model>`).join("\n")}
</m-character>
`;

const description = createMMLCharacterString({
base: { url: fullBody.asset },
parts: remainingParts.map(([, assetDescription]) => {
return { url: assetDescription.asset };
}),
});
console.log(description);
}, [currentSelection, fullBodyKey]);

Expand Down
13 changes: 13 additions & 0 deletions packages/3d-web-avatar/src/helpers/createMMLCharacterString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MMLCharacterDescription } from "./parseMMLDescription";

export const createMMLCharacterString = (characterDescription: MMLCharacterDescription): string => {
const base = characterDescription.base.url;

const partsTags = characterDescription.parts.map(
(part) => `<m-model src="${part.url}"></m-model>`,
);

return `<m-character src="${base}">
${partsTags.join("\n ")}
</m-character>`;
};
1 change: 1 addition & 0 deletions packages/3d-web-avatar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export {
type MMLCharacterDescription,
parseMMLDescription,
} from "./helpers/parseMMLDescription";
export { createMMLCharacterString } from "./helpers/createMMLCharacterString";

0 comments on commit b752d6c

Please sign in to comment.