Skip to content

Commit

Permalink
testing bone remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Oct 29, 2023
1 parent c6c0fee commit 6626f25
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/library/merge-geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ export async function combineNoAtlas({ avatar, scale = 1 }, isVrm0 = false) {

const material = [];


meshes.forEach(originalMesh => {
const clonedMesh = originalMesh.clone(); // Clone the original mesh
clonedMeshes.push(clonedMesh); // Add the cloned mesh to the array
console.log("cloned mesh", clonedMesh);
if (Array.isArray(originalMesh.material)) {
// If the material property is an array (e.g., for MultiMaterial), concatenate it to the materialsArray
material.push(...originalMesh.material);
Expand Down Expand Up @@ -223,6 +221,8 @@ export async function combineNoAtlas({ avatar, scale = 1 }, isVrm0 = false) {
scale,
},isVrm0);

console.log(mesh.geometry.attributes.skinWeight)
console.log(mesh.geometry.attributes);

// change vertex positions if is vrm0
if (isVrm0){
Expand All @@ -239,15 +239,39 @@ export async function combineNoAtlas({ avatar, scale = 1 }, isVrm0 = false) {


const baseIndArr = mesh.geometry.index.array;
const baseSkinIndArr = mesh.geometry.attributes.skinIndex.array;
const offsetIndexArr = getOrderedNonDupArray(mesh.geometry.index.array);


console.log(mesh.geometry.attributes.skinIndex);
// console.log(offsetIndexArr);
// console.log(baseSkinIndArr);

const indArrange = []
const skinIndex = [];

for (let i =0 ; i < baseIndArr.length ;i++){
indArrange[i] = offsetIndexArr.indexOf(baseIndArr[i])
}

for (let i =0 ; i < baseSkinIndArr.length ;i++){
skinIndex[i] = offsetIndexArr.indexOf(baseSkinIndArr[i])
}




const indexArr = new Uint32Array(indArrange);
const indexAttribute = new BufferAttribute(indexArr,1,false);

const skinIndexArr = new Uint16Array(skinIndex);
const skinAttribute = new BufferAttribute(skinIndexArr,4,false);


//console.log(baseSkinIndArr);
console.log(baseSkinIndArr);
console.log(skinIndexArr);
geometry.setAttribute( 'skinWeight', skinAttribute );

// update attributes indices to match new offsetIndexArr
geometry.setIndex(indexAttribute)
Expand Down

0 comments on commit 6626f25

Please sign in to comment.