Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TMPxyz · Apr 04, 2014 at 10:42 AM · mathmatrixskinned mesh renderer

How to calculate a vertex position of SkinnedMesh?

Hi there, I'm trying to calculate the position of the vertices in given skinned mesh. Well, the result is mostly right, but in many models there is always some visible "offset".

the formula I'm using:

pos = (bones's weight) (bone's local2world matrix) (SMR's RotationMatrix) (bindPoseMatrix) object-space-pos

the final pos is weight-sumed.

 Transform smrTr = smr.transform;    
 BoneWeight[] weights = mesh.boneWeights;
 Transform[] bones = smr.bones;
 Matrix4x4[] bindposes = mesh.bindposes;
 Vector3 localPos = mesh.vertices[vidx];

 Matrix4x4 localMat = Matrix4x4.TRS(Vector3.zero, smrTr.localRotation, Vector3.one);
 if (bw.weight0 != 0)
 {
     Matrix4x4 mat = bones[bw.boneIndex0].localToWorldMatrix * localMat * bindposes[bw.boneIndex0];
     pos += mat.MultiplyPoint(localPos) * bw.weight0;        
 }
 if (bw.weight1 != 0)
 {
     Matrix4x4 mat = bones[bw.boneIndex1].localToWorldMatrix * localMat * bindposes[bw.boneIndex1];
     pos += mat.MultiplyPoint(localPos) * bw.weight1;        
 }
 if (bw.weight2 != 0)
 {
     Matrix4x4 mat = bones[bw.boneIndex2].localToWorldMatrix * localMat * bindposes[bw.boneIndex2];
     pos += mat.MultiplyPoint(localPos) * bw.weight2;        
 }
 if (bw.weight3 != 0)
 {
     Matrix4x4 mat = bones[bw.boneIndex3].localToWorldMatrix * localMat * bindposes[bw.boneIndex3];
     pos += mat.MultiplyPoint(localPos) * bw.weight3;        
 }

You can see in the pic that, the red rect(the point I calculated) drifts away from the tips of the mesh.

I cannot figure out where this offset comes from, any help is appreciated. alt text

points.jpg (44.9 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Apr 04, 2014 at 11:01 AM 0
Share

Guessing the order of multiplication is wrong, can't remember off the top of my head what it should be though!

avatar image TMPxyz · Apr 04, 2014 at 11:10 AM 0
Share

I don't know, it looks perfectly right in some models, so I think the order might be right.

I thought there might be some factor I overlooked.

alt text

points1.jpg (40.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TMPxyz · Apr 06, 2014 at 02:39 AM

Okay, I know where I'm doing wrong.

The formula should be: pos = (bones's weight) (bone's local2world matrix) (bindPoseMatrix) * object-space-pos

There's no need to multiply the SMR's matrix, I don't understand how that comes to my head at first.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get the corrrect Stereo Projection matrices 1 Answer

How does TWO BONE IK works? 0 Answers

how to create an inverse-TRS matrix directly? 0 Answers

Affine transformations to Object 3 Answers

Matrix Multiplication, Standard Deviant and More usefull methods 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges