Giter Site home page Giter Site logo

Mapping the Legs about vrigunity HOT 4 CLOSED

kariaro avatar kariaro commented on May 28, 2024
Mapping the Legs

from vrigunity.

Comments (4)

Kariaro avatar Kariaro commented on May 28, 2024

Hi @Zumbalamambo

Thanks for the complements! :D

When I started writing the code I flipped left and right because I couldn't get the VRM model to render correctly when flipped.

I've not used any references when making my code so I can sadly not give you any sources but I can describe how I would solve this πŸ‘

// Fetch data points from Mediapipe
Vector3 rHip   = ConvertPoint(eventArgs.value, 23);
Vector3 rKnee  = ConvertPoint(eventArgs.value, 25);
Vector3 rAnkle = ConvertPoint(eventArgs.value, 27);

We know that the default vector of the upperleg to the knee is pointing downwards, we want to calculate the deviation from that vector

// If we were standing normally this would (*when normalized*) be close to (0, -1, 0)
Vector3 rHipKneeDiff    = rKnee - rHip;
Vector3 rHipKneeDefault = Vector3.down;

// Calculate the rotation needed to go from (0, -1, 0) to hip-knee vector
Quaternion rHipRotation = Quaternion.FromToRotation(rHipKneeDefault, rHipKneeDiff);

// Normally the knee-ankle vector is pointing in the same direction as the hip-knee vector
Vector3 rKneeAnkleDiff    = rAnkle - rKnee;
Vector3 rKneeAnkleDefault = rHipKneeDiff;

// Calculating the knee rotation can be done similarly.
Quaterion rKneeAnkle = Quaterion.FromToRotation(rKneeAnkleDefault, rKneeAnkleDiff);

I've not tested this code but I would write something similar to this

from vrigunity.

Zumbalamambo avatar Zumbalamambo commented on May 28, 2024

@Kariaro thank you! I have adopted the code as follows,

rUpperLeg = rHipRotation;
rLowerLeg = rKneeAnkle;

Later setting the instance variables as follows,

this.rUpperLeg.Set(rUpperLeg,TimeNow);
this.rLowerLeg.Set(rLowerLeg,TimeNow);

and applied it to the vrm ,

rLowerLeg.UpdateRotation(animator.GetBoneTransform(HumanBodyBones.RightLowerLeg), time);
rUpperLeg.UpdateRotation(animator.GetBoneTransform(HumanBodyBones.RightUpperLeg), time);

Unfortunately, the leg is twisted backwards. Am I missing something? thanks again!

from vrigunity.

Kariaro avatar Kariaro commented on May 28, 2024

Hi @Zumbalamambo

I think this might be because vectors do not keep the forward direction.
The forward vector could be computed from the knee direction relative to the hip. I won’t be able to help with code for the next few days because I will not be at my computer.

from vrigunity.

Zumbalamambo avatar Zumbalamambo commented on May 28, 2024

@Kariaro thanks for the hint!

from vrigunity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.