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 Loius · Apr 12, 2013 at 12:46 AM · verticesaverage

How do I blend two BoneWeights?

Or fake it?

I'm creating a new vertex C, X% of the way between vertices A and B of a skinned mesh. C needs to stay between A and B such that they form a single visual edge (A-C-B) - or, as close as possible.

I can put the vertex in place but I'm not sure how to get it to stay there. I need to give C a BoneWeight which is a weighted average of A and B's weights. Often, this is pretty trivial - if A and B are on the same bone, then the new BoneWeight is just X% weight A + (1-X%) weight B. But what happens if A is affected by bones 0-3 and B is affected by bones 2-5? A vertex can only be weighted by four bones max. :confusedface:

Here's the uncommented code dump I have currently, which works great when the bones of two vertices already match exactly. If more bones than the quality settings allow are affecting a vertex, I get poor results. Is there any way around this and/or is my code doing silly things it shouldn't?

 private class ArrayBoneWeight {
         // makes it use arrays so i don't break my fingers typing
     var weights:float[];
     var bones:int[];

     ...

     static function Combine(l:ArrayBoneWeight,r:ArrayBoneWeight,left:float,bones:int) : ArrayBoneWeight {
         var right : float = 1-left;
         
         var out : ArrayBoneWeight = new ArrayBoneWeight();
         out.bones  =[l.bones[0],l.bones[1],l.bones[2],l.bones[3],-1,-1,-1,-1];
         out.weights=[l.weights[0]*left,l.weights[1]*left,l.weights[2]*left,l.weights[3]*left,-1,-1,-1,-1];
         
         var lix : int;
         var iix : int;
         var tmp : float;
         
         for ( lix = 0; lix < 4; lix++ ) {
             for ( iix = 0; iix < 8; iix++ ) {
                 if ( out.bones[iix] == -1 ) break;
                 if ( out.bones[iix]==r.bones[lix] ) {
                     out.weights[iix]+=r.weights[lix] * right;
                     break;
                 }
             }
             if ( iix < 8 && out.bones[iix] == -1 ) {
                 out.bones[iix] = r.bones[lix];
                 out.weights[iix]=r.weights[lix]*right;
             }
         }
         
         
         for ( lix = 1; lix < 8; lix++ ) {
             while ( out.weights[lix] > out.weights[lix-1] ) {
                 tmp=out.weights[lix]; out.weights[lix]=out.weights[lix-1];out.weights[lix-1]=tmp;
                 iix=out.bones[lix];out.bones[lix]=out.bones[lix-1];out.bones[lix-1]=iix;
                 if ( lix > 1 ) lix--;
             }
         }
         var bwgt : float = 0;
         for ( lix = 0; lix < bones; lix++ ) { bwgt+= out.weights[lix]; }
         bwgt = 1/bwgt;
         for ( lix = 0; lix < 8; lix++ ) { out.weights[lix]=(lix>=bones)?0:out.weights[lix]*bwgt; }
         return out;        
     }
 }
 
 // bones is the current bone quality setting - only that many bones can affect a vertex
 static private function AverageBoneWeight( left : BoneWeight, right : BoneWeight, dist : float, bones : int ) : BoneWeight {
     var bw : BoneWeight = new BoneWeight();
     var negd : float = 1-dist;
     var l : ArrayBoneWeight = new ArrayBoneWeight(left);
     var r : ArrayBoneWeight = new ArrayBoneWeight(right);
     l = ArrayBoneWeight.Combine(l,r,dist,bones);
     return l.ToWeight();
 }
 

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

10 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

Related Questions

Using multiple custom water planes together (Welding multiple planes together) 1 Answer

normalising the vertices of a cube mesh 0 Answers

How to Avoid Unity Adding Vertices to Object? 1 Answer

How do I connect my vertices in my mesh 1 Answer

How to reduce polygon count? I have meshes from pointclouds. 0 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