Alright, so I’m trying to “attach” a Spatial to a mesh, and by that I mean, and by that I mean I want it to “follow” the primitive it’s “attached” to.
I’m doing this cause I’ve switched from .dae to .md2, and .md2 doesn’t have bones, or joints to attach anything to.
This is what I got so far.
public int getTopSelection(Mesh m){
m.updateWorldBound(true);
int c = m.getMeshData().getPrimitiveCount(0);
double maxHeight = 0;
int selection = 0;
Vector3[][] v3 = new Vector3[c][3];
for(int s = 0; s < c; s++){
v3[s] = null;
v3[s] = m.getMeshData().getPrimitive(s, 0, v3[s]);
Vector3 min = new Vector3((float)Math.min((float) Math.min(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
(float)Math.min((float)Math.min(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
(float)Math.min((float)Math.min(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));
Vector3 max = new Vector3((float) Math.max((float)Math.max(v3[s][0].getXf(), v3[s][1].getXf()), v3[s][2].getXf()),
(float)Math.max((float)Math.max(v3[s][0].getYf(), v3[s][1].getYf()), v3[s][2].getYf()),
(float)Math.max((float)Math.max(v3[s][0].getZf(), v3[s][1].getZf()), v3[s][2].getZf()));
if(max.getY() < maxHeight){
maxHeight = max.getY();
selection = s;
}
}
return selection;
}
public Vector3[] getPrimitive(Mesh m, int selection){
m.updateWorldBound(true);
Vector3[] v3 = new Vector3[3];
v3 = m.getMeshData().getPrimitive(selection, 0, v3);
Vector3 min = new Vector3((float)Math.min((float) Math.min(v3[0].getXf(), v3[1].getXf()), v3[2].getXf()),
(float)Math.min((float)Math.min(v3[0].getYf(), v3[1].getYf()), v3[2].getYf()),
(float)Math.min((float)Math.min(v3[0].getZf(), v3[1].getZf()), v3[2].getZf()));
Vector3 max = new Vector3((float) Math.max((float)Math.max(v3[0].getXf(), v3[1].getXf()), v3[2].getXf()),
(float)Math.max((float)Math.max(v3[0].getYf(), v3[1].getYf()), v3[2].getYf()),
(float)Math.max((float)Math.max(v3[0].getZf(), v3[1].getZf()), v3[2].getZf()));
Vector3 middle = new Vector3(
(max.getX() - min.getX())/2,
(max.getY() - min.getY())/2,
(max.getZ() - min.getZ())/2
);
Vector3[] send = {min, middle, max};
return send;
}
And this is how I implement it:
in init
player.topSelection = getTopSelection(model);
in update
Vector3[] top = getPrimitive(model, player.topSelection);
staff.setTranslation(model.getTranslation().getX() + (top[0].getX() + top[2].getX()), model.getTranslation().getY() -(top[0].getY() + top[2].getY()), model.getTranslation().getZ() +(top[0].getZ() + top[2].getZ()));
staff.setRotation(model.getRotation());
It follows the model’s movements on the x axis, and the y axis, but when the primitive is moved down and left the spatial moves down and right, but if I reverse the x it shows up on the other side of the model. How can I fix this?