Skip to content

Commit

Permalink
add vrmMeta support
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Oct 24, 2023
1 parent 48d374b commit 15b6bf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/ExportMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ExportMenu = ({getFaceScreenshot}) => {
className={styles.button}
onClick={() => {
const screenshot = getFaceScreenshot();
downloadVRM(model, avatar, name, screenshot, 4096,templateInfo.exportScale||1, true)
downloadVRM(model, avatar, name, screenshot, 4096,templateInfo.exportScale||1, true, templateInfo.vrmMeta)
}}
/>
</React.Fragment>
Expand Down
16 changes: 8 additions & 8 deletions src/library/download-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export async function getGLBBlobData(avatarToDownload, atlasSize = 4096, optimi
return new Blob([glb], { type: 'model/gltf-binary' });
}

export async function getVRMBlobData(avatarToDownload, avatar, screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false){
export async function getVRMBlobData(avatarToDownload, avatar, screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false, vrmMeta= null){
const model = await getOptimizedGLB(avatarToDownload, atlasSize,scale, isVrm0)
const vrm = await parseVRM(model, avatar, screenshot, isVrm0);
const vrm = await parseVRM(model, avatar, screenshot, isVrm0, vrmMeta);
// save it as glb now
return new Blob([vrm], { type: 'model/gltf-binary' });
}
Expand All @@ -97,17 +97,17 @@ async function getGLBData(avatarToDownload, atlasSize = 4096, optimized = true,
return parseGLB(model);
}
}
async function getVRMData(avatarToDownload, avatar, screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false){
async function getVRMData(avatarToDownload, avatar, screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false, vrmMeta = null){

const vrmModel = await getOptimizedGLB(avatarToDownload, atlasSize, scale, isVrm0);
return parseVRM(vrmModel,avatar,screenshot, isVrm0)
return parseVRM(vrmModel,avatar,screenshot, isVrm0, vrmMeta)
}

export async function downloadVRM(avatarToDownload, avatar, fileName = "", screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false){
export async function downloadVRM(avatarToDownload, avatar, fileName = "", screenshot = null, atlasSize = 4096, scale = 1, isVrm0 = false, vrmMeta = null){
const downloadFileName = `${
fileName && fileName !== "" ? fileName : "AvatarCreatorModel"
}`
getVRMData(avatarToDownload, avatar, screenshot, atlasSize,scale, isVrm0).then((vrm)=>{
getVRMData(avatarToDownload, avatar, screenshot, atlasSize,scale, isVrm0, vrmMeta).then((vrm)=>{
saveArrayBuffer(vrm, `${downloadFileName}.vrm`)
})
}
Expand Down Expand Up @@ -154,12 +154,12 @@ function parseGLB (glbModel){
})
}

function parseVRM (glbModel, avatar, screenshot = null, isVrm0 = false){
function parseVRM (glbModel, avatar, screenshot = null, isVrm0 = false, vrmMeta = null){
return new Promise((resolve) => {
const exporter = isVrm0 ? new VRMExporterv0() : new VRMExporter()
const vrmData = {
...getVRMBaseData(avatar),
...getAvatarData(glbModel, "CharacterCreator"),
...getAvatarData(glbModel, "CharacterCreator", vrmMeta),
}
let skinnedMesh;
glbModel.traverse(child => {
Expand Down
12 changes: 8 additions & 4 deletions src/library/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,21 @@ export function findChildrenByType(root, type) {
predicate: (o) => o.type === type,
});
}
export function getAvatarData (avatarModel, modelName){
export function getAvatarData (avatarModel, modelName, vrmMeta){
const skinnedMeshes = findChildrenByType(avatarModel, "SkinnedMesh")
return{
humanBones:getHumanoidByBoneNames(skinnedMeshes[0]),
materials : [avatarModel.userData.atlasMaterial],
meta : getVRMMeta(modelName)
meta : getVRMMeta(modelName, vrmMeta)
}

}


function getVRMMeta(name){
return {
function getVRMMeta(name, vrmMeta){
vrmMeta = vrmMeta||{}

const defaults = {
authors:["Webaverse"],
metaVersion:"1",
version:"v1",
Expand All @@ -505,6 +507,8 @@ function getVRMMeta(name){
allowRedistribution:false,
modification:"prohibited"
}

return { ...defaults, ...vrmMeta };
}

// function getVRMDefaultLookAt(){
Expand Down

0 comments on commit 15b6bf5

Please sign in to comment.