I'm making a 3D monster creator, I've added a way to combine parts and have worked out all the kinks except for scaling. I combine the modelInstances by simply setting a flag, adding them to nested arraylists and having if statements that involve for loops whenever the user changes a combined instance. When scaling, the objects remain stationary but when in a group I need them to move a certain amount to keep the shape consistent.
Currently, this is my method for scaling:
switch (modelInstance[i].currentFlip) {
case 0:
modelInstance[i].scale.add(0.01f);
break;
case 1:
modelInstance[i].scale.add(-0.01f, 0.01f, 0.01f);
break;
case 2:
modelInstance[i].scale.add(-0.01f, -0.01f, 0.01f);
break;
case 3:
modelInstance[i].scale.add(0.01f, -0.01f, 0.01f);
break;
}
modelInstance[i].transform.set(modelInstance[i].basePosition, modelInstance[i].baseRotation, modelInstance[i].scale);
To clarify, here's a video of what happens: https://youtu.be/kLjlcMVKAR0 I want the combined object's shape to stay consistent despite its size and this should be done by changing the individual object's positioning. I know the individual object's position, the combined object's position, the object's current scale, and individual object's bounding box for accurate-ish dimensions.
I realised that to keep the combined shape consistent while changing the scale of an individual object I must scale the difference in position from the centre of mass to the individual object.
modelInstance[i].basePosition.set(centreMass.cpy().add(modelInstance[i].distanceFromCentreMass.cpy().scl(modelInstance[i].scale)));