Matt
Matt

Reputation: 79

libGDX move a 3D Model

I'm trying to move some Nodes of a Model loaded using libGDX. This is the code:

public void render() {
    ...

    if (loading && assets.update())       //done when app starts
        doneLoading();

    if(!loading)
        moveModel();

    modelBatch.begin(cam);
    modelBatch.render(instances, environment);
    modelBatch.end();
}

private void doneLoading() {
       I_model = assets.get("data/model.g3db", Model.class);
       I_instance = new ModelInstance(I_model);
       instances.add(I_instance);
       loading = false;
}

private void moveModel(){
    for(int i=0;i<MAX_VALUE;i++){
        Node bone = I_instance.getNode(names[i]);
        if(bone != null){
            bone.rotation.set(new Vector3(1, 1, 0), values[i]);
        }
    }
    I_instance.calculateTransforms();
    instances.add(I_instance);
}

The model is correctly showed but it doesn't move at all. Any suggestions?

Upvotes: 1

Views: 1962

Answers (1)

Matsemann
Matsemann

Reputation: 21844

You should just modify the transform of the ModelInstance.
In your case, that will be I_instance.transform.translate(...)

Upvotes: 1

Related Questions