Skip to content

Instantly share code, notes, and snippets.

@dungvtdev
Last active December 18, 2016 14:50
Show Gist options
  • Save dungvtdev/ed567c0dcc4c785de2856ba3aafa35d4 to your computer and use it in GitHub Desktop.
Save dungvtdev/ed567c0dcc4c785de2856ba3aafa35d4 to your computer and use it in GitHub Desktop.

Transform concept

Model gồm skeleton (bones có kiểu Node) và skinning mesh. Hoạt động:

  • di chuyển bones.
  • render mesh, libgdx sẽ truyền vị trí các bone vào shader, gpu sẽ làm nhiệm vụ transform các vertex theo các bone liên quan tại vertex shader.

Di chuyển bones:

  • có parent là ModelInstance.
  • Node:

 - Attribute:    - inherithTransform (có inherith parent hay k,ảnh hưởng tới tính globalTransform),    - isAnimation(khi chạy anim, bone nào có animation sẽ được đánh isAnimation), nếu gọi caculateLocalTransform() với isAnimation=true thì localTransform sẽ khôngtính lại (matrix.set(translation,rotation,scale))mà giữ nguyên localTransform,do  animtion set thẳng matrix chứ khôn set translation,rotation...          

  • Matrix: localTransform, globalTransform
  • Param: translation, rotation, scale.
  • Method: caculateLocalTransform(), caculateWorldTransform(), caculateBoneTransform().
    • caculateBoneTransform sẽ di chuyển cả các mesh part liên quan của mỗi bone.
    • hàm caculateTransform(recursive) sẽ gọi đệ quy (recursive=true)cả 3hàm này với từng nút.
  • Mỗi lần thay đổi bone thì phải gọi ModelInstance.calculateTransform() để update lại BoneTransform.

Trick

Ví dụ sau bỏ inheritTransform của các bones, nhưng giữ nguyên transform mặc định.

modelInstance = new ModelInstance(this.model);
       root.calculateTransforms(true);
       spines.add(new Spine(root));
       while(bone.hasChildren()){
           bone = bone.getChild(0);
           bone.inheritTransform=false;
           bone.localTransform.set(bone.globalTransform);
           bone.localTransform.getTranslation(bone.translation);
           bone.localTransform.getRotation(bone.rotation);
           bone.localTransform.getScale(bone.scale);
       }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment