TheComet / ik

Minimal Inverse Kinematics library
MIT License
496 stars 71 forks source link

IK_TWO_BONE work, IK_FABRIK - failed #14

Open Mikez2015 opened 3 years ago

Mikez2015 commented 3 years ago

Hello

I'm using a simple two-bone structure and I found that the IK_FABRIK solver didn't want to work properly. I made two videos, the first in IK_TWO_BONE mode, the second in IK_FABRIK mode. I am wondering why IK_FABRIK mode is not working. The code is the same, except for the solver mode.

IK_TWO_BONE: https://youtu.be/hR41geXbEeU

IK_FABRIK: https://youtu.be/D1ZIXcFRjW8

TheComet commented 3 years ago

Hey!

Nice demos! Which branch/commit hash are you on?

If you're on devel then unfortunately FABRIK is still being developed.

Mikez2015 commented 3 years ago

Hey!

Nice demos! Which branch/commit hash are you on?

If you're on devel then unfortunately FABRIK is still being developed.

I use Default branch (master).

Please see this short code, maybe I was wrong somewhere :

    if (!start) {

        // solver = ik.solver.create(IK_TWO_BONE);
        solver = ik.solver.create(IK_FABRIK);

        root = solver->node->create(0);
        child1 = solver->node->create_child(root, 1);
        child2 = solver->node->create_child(child1, 2);
        child1->position = ik.vec3.vec3( 0.0f, 1.0f, 0.7f);
        child2->position = ik.vec3.vec3( 0.0f, 1.0f, -0.7f);

        eff = solver->effector->create();
        solver->effector->attach(eff, child2);

        solver->flags |= IK_ENABLE_TARGET_ROTATIONS;

        ik.solver.set_tree(solver, root);
        ik.solver.rebuild(solver);

        start = true;
    }

    glm::vec3 start = glm::vec3(251.0f, 5.0f, 268.0f);

    TEST_DEBUG_IK = models[34].phys.pos - start;

    eff->target_position = ik.vec3.vec3(TEST_DEBUG_IK.x, TEST_DEBUG_IK.y, TEST_DEBUG_IK.z);

    ik.solver.solve(solver);

    glm::vec3 l1 = start + glm::vec3(child1->position.x, child1->position.y, child1->position.z);
    glm::vec3 l2 = start + glm::vec3(child2->position.x, child2->position.y, child2->position.z);

    create_DebugLine(start, l1, glm::vec4(vecColor_Red, 1.0f), 3.0f);
    create_DebugLine(l1, l2, glm::vec4(vecColor_Green, 1.0f), 3.0f);

Here are a couple more videos just for this code. First video for TWO BONES, second video for FABRIK: 1. https://youtu.be/A3N7a8Qvp8k 2. https://youtu.be/75f-jKEsZmI

Update: In Fabrik mode I noticed one strange thing. The first joint (red line) does not move at all.

donghaoye commented 3 years ago

couple more videos just for this code. F pretty! could provide the full example code?

Jerryzhangzhao commented 3 years ago

Hey! Nice demos! Which branch/commit hash are you on? If you're on devel then unfortunately FABRIK is still being developed.

I use Default branch (master).

Please see this short code, maybe I was wrong somewhere :

  if (!start) {

      // solver = ik.solver.create(IK_TWO_BONE);
      solver = ik.solver.create(IK_FABRIK);

      root = solver->node->create(0);
      child1 = solver->node->create_child(root, 1);
      child2 = solver->node->create_child(child1, 2);
      child1->position = ik.vec3.vec3( 0.0f, 1.0f, 0.7f);
      child2->position = ik.vec3.vec3( 0.0f, 1.0f, -0.7f);

      eff = solver->effector->create();
      solver->effector->attach(eff, child2);

      solver->flags |= IK_ENABLE_TARGET_ROTATIONS;

      ik.solver.set_tree(solver, root);
      ik.solver.rebuild(solver);

      start = true;
  }

  glm::vec3 start = glm::vec3(251.0f, 5.0f, 268.0f);

  TEST_DEBUG_IK = models[34].phys.pos - start;

  eff->target_position = ik.vec3.vec3(TEST_DEBUG_IK.x, TEST_DEBUG_IK.y, TEST_DEBUG_IK.z);

  ik.solver.solve(solver);

  glm::vec3 l1 = start + glm::vec3(child1->position.x, child1->position.y, child1->position.z);
  glm::vec3 l2 = start + glm::vec3(child2->position.x, child2->position.y, child2->position.z);

  create_DebugLine(start, l1, glm::vec4(vecColor_Red, 1.0f), 3.0f);
  create_DebugLine(l1, l2, glm::vec4(vecColor_Green, 1.0f), 3.0f);

Here are a couple more videos just for this code. First video for TWO BONES, second video for FABRIK: 1. https://youtu.be/A3N7a8Qvp8k 2. https://youtu.be/75f-jKEsZmI

Update: In Fabrik mode I noticed one strange thing. The first joint (red line) does not move at all.

Hi, great demo! And I met the same issue, have you already solved it?