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 bustak · Apr 24, 2021 at 09:51 PM · scripting problemmeshcollidersmeshcollidervolume

Get the triangles of a convex mesh collider

I would like to retrieve via script the mesh that is used for collisions of an object that has a convex mesh collider. If I try this on the particular object:

 MeshCollider meshCol = GetComponent<MeshCollider>();
  Mesh mesh = meshCol.sharedMesh;

I get the exactly same mesh that I can get from mesh filter component on the object, (or at least it has the same triangle count on the one I tested). The original object is not convex so I am quite sure this is not the convex mesh that is used for collisions. I needed this to approximate volume of an object using this aproach: link

But in my case the mesh triangle count is too high and it takes several seconds to finish calculating.

Is it even possible to get this convex mesh?

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
1
Best Answer

Answer by Bunny83 · Apr 25, 2021 at 01:09 AM

AFAIK Unity does not provide any way to read the convex hull that PhyX generates for the collision detection. Keep in mind that the convex hull is not meant as a simplification but just to make the shape convex. Yes, PhysX limits the number of triangles in the convex hull so the resulting shape usually has less triangles / faces than a huge complex mesh. Though as I said, triangle reduction is not really a goal of the convex hull.


Note that the mesh does not need to be convex in order to calculate the volume. It just needs to be a closed mesh. I explained why it works for non convex meshes as well over here.


Does your mesh actually change at runtime? If not you can easily pre-calculate the volume at edit time and just store it alongside the mesh.


How many triangles do we talk about when the volume calculation takes seconds? That must be millions... If not it's possible that you did some other performace critical mistake, like reading the vertices or triangles properties in an array instead of caching it in a local variable. Do you have a snippet of the code you're using? The code provided in the answer to the SO question has such a mistake in it. Even though they cache the vertices and triangle arrays, they still use mesh,triangle.length in the for loop condition. This will create a new triangles array every for loop iteration.

Comment
Add comment · Show 1 · 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 bustak · Apr 25, 2021 at 10:30 AM 0
Share

mesh,triangle.length

thx, I actually had the same condition in my for loop, it works great now.

PhysX limits the number of triangles in the convex hull so the resulting shape usually has less triangles / faces than a huge complex mesh. Though as I said, triangle reduction is not really a goal of the convex hull.

Btw the reason I was trying to get the convex mesh of the collider was because I was under the impression it's face count is limited to 255 (my mesh filters are 40k triangles, so this I assumed would have been a big speed up). And yes this needed to be run at runtime, since the meshes change.

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

225 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 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 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 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 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 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 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 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 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 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 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

Editing Mesh Colliders? Creating a usable pot/cup 1 Answer

All colliders no longer work. 0 Answers

Terrain and character navigation 0 Answers

Colliders on this spider 1 Answer

Collision with Plane fails 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