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 chiapet1021 · Nov 05, 2013 at 06:28 PM · cloth

Skinned Cloth: Modifying vertex coefficients at runtime

Hello, I was not able to find this topic on the forums or here in Answers. I hope this is not a repeat.

Here is what I am attempting to do (purely hypothetical at this point):

I would like to use a Skinned Cloth component on a cloak that I will be attaching to a player character avatar. If that avatar equips a large weapon for use in combat, the weapon will be strapped to his back when not in use. In that situation, I would like to modify the cloak's cloth vertices so that the cloak does not clip through the weapon while the character moves with it strapped to his back.

I suppose I could create two versions of the cloak: one for when the weapon is on the back and one for when it is in hand. I could have the vertices painted appropriately for each situation, then switch between the two prefabs as needed. However, I feel like that is an inelegant solution and one that may cause some graphical "popping" when the switch occurs.

Is it possible to update Skinned Cloth vertex coefficients at runtime? Could I, for example, store two sets of vertex weights in a script, and then use method calls to switch them out? Or should/can I attach two Skinned Cloth components to the cloak and dynamically set one or the other as active at runtime?

I'm a very novice programmer, so apologies in advance if I sound daft. :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by danielskovli · Mar 04, 2014 at 02:28 AM

Hi there,

I came past your post on my mission to find the answer to an identical problem I was faced with in my own scene.

Long story short, I found a solution to my specific situation, and maybe it would be of use to you as well.

The trick is to access the coefficients array under the SkinnedCloth object for your mesh.

Something like this:

 /*
     Assuming your mesh has a Skinned Cloth object attached,
     along with a Skinned Mesh Renderer.
 */
 
 private SkinnedCloth clothReference;
 public bool yourTrigger = false;
 public float yourNewValue = 5f;
 
 void Start() {
     // you probably want to do some verification stuff here
     clothReference = GetComponent<SkinnedCloth>();
 }
 
 void Update() {
     if (yourTrigger) {
         ClothSkinningCoefficient[] newCoefficients = new ClothSkinningCoefficient[clothReference.coefficients.Length];
         for (int i = 0; i < newCoefficients.Length; i++ ) {
             newCoefficients[i].maxDistance = yourNewValue;
         }
 
         clothReference.coefficients = newCoefficients;
     }

     yourTrigger = false;
 }

This example specifically targets the MaxDistance value, but you can change any of the coefficients you want. The important part is to clone out the coefficients array -> make your edits -> then replace the old array with your modified new one. Making edits directly in the original array won't update the SkinnedCloth behaviour unfortunately.

Cheers, Daniel

Edit: Typo in code. Also, I haven't really tested any of the above - it was just from memory.

Comment
Add comment · Show 6 · 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
avatar image chiapet1021 · Mar 04, 2014 at 03:20 AM 0
Share

Hi $$anonymous$$,

Thank you for this answer! It makes sense to me in theory, although I'll need to try to give it a shot in practice and see how it turns out.

One question though: Do you know how to tell what vertex the ClothSkinningCoefficient in the array corresponds to? I'd need to know where on the Skinned $$anonymous$$esh that coefficient is located to know how to adjust the coefficient values.

avatar image danielskovli · Mar 04, 2014 at 04:29 AM 0
Share

Hmm, in my mesh the number of vertices in the coefficient array is equal to the number of vertices in the mesh - so I was just assu$$anonymous$$g the vertex numbers were the same.

I would be very surprised if this wasn't the case, but that said, I don't actually know. $$anonymous$$aybe you can tell us ;)

avatar image chiapet1021 · Mar 04, 2014 at 11:39 AM 0
Share

Well I figure the number of vertices is the same, but I'm trying to understand where each vertex in the array is located on the mesh. I'd be changing the coefficients' values based on their location; it wouldn't be the same values for every vertex.

avatar image danielskovli · Mar 04, 2014 at 10:02 PM 0
Share

Assu$$anonymous$$g that the vertex number is the same, you can get the local position of the vertex by accessing mesh.vertices[] (Vector3).

https://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh-vertices.html

That's the only sort of spacial information you can extract, as far as I know.

avatar image chiapet1021 · Mar 05, 2014 at 02:49 PM 0
Share

Thanks for that reference! I'll have to play around with this. I'm thinking of another approach as well, going back to your previous code example for inspiration. I'll try to work on this later this week or by the weekend.

Show more comments

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

16 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

Related Questions

Clothing and weapon animation 1 Answer

Cloth Trampoline and 3rd Person Character 2 Answers

Cloth physics or clothing on a character. 1 Answer

How accurately can Unity simulate a shooting scenario (Cloth)? 1 Answer

Cloth problem 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