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 tyson · Apr 10, 2011 at 10:10 PM · changeslowboneweight

Bone weight set/get is very slow??

I have a lot of meshes that need their bone weight offset in realtime (basically I wrote a skinned mesh combiner that adds geometry to their meshes, and appends bone weights accordingly).

The function runs extremely fast (under a millisecond) except for the part that accesses the mesh's bone weights. All it does is retrieve the original bone weight, offsets the value, and re-applies it. However, running that subroutine through each vertex takes over 30 milliseconds! (compared to under a millisecond to set all the verts, triangles, normals and uvs for the new mesh).

The pseudocode is as follow:

for (i = 0; i < mesh.vertices.length; i++)
{
   mesh.boneWeights[i].boneIndex0 += offset;
}

Any way to speed this up?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Thomas Krog · Apr 12, 2011 at 02:30 PM

I think you need to access mesh.boneWeights as few times as possible. Try this simple performance test:

BoneWeight[] ws = new BoneWeight[mesh.boneWeights.Length];
for(int i = 0; i != ws.Length; ++i)
  ws[i].boneIndex0 = i % numBones;
mesh.boneWeights = ws;

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
avatar image
0

Answer by Paulius-Liekis · Apr 12, 2011 at 02:36 PM

I believe mesh.boneWeights[i] has to make a copy each time, so if you have 1000 vertices it will make 1000 copies. Try something like this and see if it works faster:

BoneWeight[] ws = mesh.boneWeights;
for (i = 0; i < mesh.vertices.length; i++)
{
   ws[i].boneIndex0 += offset;
}
mesh.boneWeights = ws;

Anyway... modifying a mesh at runtime is not a good idea. Unity is not optimized for that.

Comment
Add comment · Show 2 · 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 Thomas Krog · Apr 12, 2011 at 02:55 PM 0
Share

Yes I have also experienced that mesh modifications are quite slow. A bit annoying that it is so much slower than oldschool glBegin. All I want is some flexible debugdrawing which merges with the ingame rendering. I think when we have such powerful hardware we could expect more flexibility than precached meshes (does not fit very well with functional program$$anonymous$$g sml etc)

avatar image Paulius-Liekis · Apr 13, 2011 at 09:16 AM 0
Share

You should think that Unity is not good at it at the moment. It is growing in multiple directions and issues like these will be addressed in the future. You just can't be good at everything at once :)

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

No one has followed this question yet.

Related Questions

Why unused bones not imported from Blender? 1 Answer

Animated object changes position when animation is played. 1 Answer

How can I import bones without weight/deform? 0 Answers

Animation not importing right. Blender -> Unity 4 Answers

bone weights not blending in animation 1 Answer


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