我有两条手臂相连,就像3d(.g3dj file
)中的亲子一样。我的要求是当父臂旋转/移动时,子臂也应该在一点连接到父母时旋转/移动。我能够做到这一点。
子臂也可以在给定点连接到其父节点时独立旋转,在这种情况下父节点本身不应移动。我陷入了以下情况:
我认为需要骨骼层次结构。请建议方法/链接,以便在所有情况下,父子位置(在接触点)不会扭曲,无论其移动/旋转。感谢。
以下是我到目前为止尝试过的代码:
private void createBaseArm1(){
// Now load the model by name from asset folder
baseArm1 = modelLoader.loadModel(Gdx.files.getFileHandle(armPathWithName + ".g3dj", Files.FileType.Internal));
//getting boundingBox for model to retrieve its co-ordinates
baseArm1.calculateBoundingBox(baseBoundingBox);
baseArm1PositionX = 0f;
baseArm1PositionY = -3.0f;
baseArm1PositionZ = 1.0f;
baseArm1PositionVector = new Vector3(baseArm1PositionX, baseArm1PositionY, baseArm1PositionZ);
baseArm1Instance = new ModelInstance(baseArm1, baseArm1PositionVector);
baseArm1Instance.transform.set(baseArm1PositionVector, baseArm1Rotation);
baseArm1TopPositionY = baseArm1PositionY + baseBoundingBox.getHeight();
}
private void createArm2(){
arm2Vector = new Vector3(baseArm1PositionX,baseArm1TopPositionY ,baseArm1PositionZ);
armModel2 = modelLoader.loadModel(Gdx.files.getFileHandle("arm2.g3dj", Files.FileType.Internal));
arm2Instance = new ModelInstance(armModel2, arm2Vector);
arm2Instance.transform.set(arm2Vector, arm2Rotation);
}
public void moveBaseArm1() {
baseArm1Instance.transform.translate(0, 0, 0).rotate(0, 0, 1, 10).translate(0, 0, 0);
arm2Instance.transform
.translate(-0, -baseBoundingBox.getHeight(), -baseBoundingBox.getDepth())
.rotate(0, 0, 1, 10)
.translate(0, baseBoundingBox.getHeight(), baseBoundingBox.getDepth());
}
public void moveArm2() {
arm2Instance.transform.translate(0,0,0).rotate(0, 0, 1, 10).translate(0, 0, 0);
}
以下是.g3dj files
- > Parent-Child-Relationship Git Repository