Skip to content

Commit 929c549

Browse files
committed
modify fixed scale
1 parent cc723b0 commit 929c549

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/library/merge-geometry.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ function createMergedSkeleton(meshes){
6464
if (boneArr.indexOf(bone)!==-1){
6565
const clone = boneClones.get(bone.name)
6666
if (clone == null){ // no clone was found with the bone
67+
const newBone= bone.clone(false);
68+
if (bone.name == 'hips')
69+
newBone.scale.set(0.7,0.7,0.7);
70+
newBone.position.set(newBone.x*0.7,newBone.y*0.7,newBone.z*0.7)
6771
const boneData = {
6872
index,
6973
boneInverses:mesh.skeleton.boneInverses[boneInd],
70-
bone:bone.clone(false),
74+
bone:newBone,
7175
parentName: bone.parent?.type == "Bone" ? bone.parent.name:null
7276
}
7377
index++
@@ -91,7 +95,11 @@ function createMergedSkeleton(meshes){
9195
}
9296
});
9397
const newSkeleton = new THREE.Skeleton(finalBones,finalBoneInverses);
94-
newSkeleton.pose()
98+
newSkeleton.pose();
99+
100+
newSkeleton.bones.forEach(bn => {
101+
bn.position.set(bn.position.x *0.7, bn.position.y*0.7,bn.position.z*0.7);
102+
});
95103
return newSkeleton
96104
}
97105
function getUpdatedSkinIndex(newSkeleton, mesh){
@@ -170,7 +178,6 @@ export async function combine({ transparentColor, avatar, atlasSize = 4096 }, is
170178
const newSkeleton = createMergedSkeleton(meshes);
171179

172180
meshes.forEach((mesh) => {
173-
174181
const geometry = mesh.geometry;
175182

176183
const baseIndArr = geometry.index.array
@@ -228,6 +235,14 @@ export async function combine({ transparentColor, avatar, atlasSize = 4096 }, is
228235
geometry.morphAttributes = dest.morphAttributes;
229236
geometry.morphTargetsRelative = true;
230237
geometry.setIndex(dest.index);
238+
239+
const vertices = geometry.attributes.position.array;
240+
for (let i = 0; i < vertices.length; i += 3) {
241+
vertices[i] *= 0.7;
242+
vertices[i + 1] *= 0.7;
243+
vertices[i + 2] *= 0.7;
244+
}
245+
231246
const material = new THREE.MeshStandardMaterial({
232247
map: textures["diffuse"],
233248
});
@@ -257,12 +272,6 @@ export async function combine({ transparentColor, avatar, atlasSize = 4096 }, is
257272

258273

259274
mesh.bind(newSkeleton);
260-
// clones.forEach((clone) => {
261-
// clone.bind(skeleton);
262-
// });
263-
//console.log(newSkeleton)
264-
//console.log(mesh.geometry.attributes.skinIndex.array)
265-
266275

267276
const group = new THREE.Object3D();
268277
group.name = "AvatarRoot";
@@ -363,13 +372,18 @@ function mergeSourceMorphAttributes({ meshes, sourceMorphTargetDictionaries, sou
363372
merged[propName] = [];
364373
for (let i =0; i < Object.entries(destMorphTargetDictionary).length ; i++){
365374
merged[propName][i] = BufferGeometryUtils.mergeBufferAttributes(unmerged[propName][i]);
375+
const buffArr = merged[propName][i].array;
366376
if (isVrm0){
367-
const buffArr = merged[propName][i].array;
368377
for (let j = 0; j < buffArr.length; j+=3){
369378
buffArr[j] *= -1;
370379
buffArr[j+2] *= -1;
371380
}
372381
}
382+
for (let j = 0; j < buffArr.length; j+=3){
383+
buffArr[j] *= 0.7;
384+
buffArr[j+1] *= 0.7;
385+
buffArr[j+2] *= 0.7;
386+
}
373387
}
374388
});
375389
return merged;

0 commit comments

Comments
 (0)