Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sidar · Jun 12, 2011 at 12:33 PM · collision detectionnormalscalculate

How to calculate faces for collision?

Hi there,

I have a little assignment which involves collision in a 3D world. I have to create a little simulation of a "pool-table-game". I've already managed it for the balls to collide ( using vectors of course) onto each other. I'm not allowed to use any of the unity3D physics components. I have to write the "simulation" myself.

The problem is however that I do not understand how the mesh.vertices work in this matter. How do I know which vertex belongs to what face? To me this isn't very clear, neither in the documentation. I know how to calculate the normals( I want this to do myself as well ) if I know which vertices to use. But I can not figure out how the faces are calculated.

Afterwards I want to apply Barycentric calculations to see if the ball is intersecting with the faces of my mesh model. Performance is not the key here, as long it will work. I'm not sure if that will work?

Any tips on how to manually find the faces and what technique i could use?

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

Answer by Oliver Eberlei · Jun 12, 2011 at 02:23 PM

To get the connection between the vertices, use the Mesh.triangles array

http://unity3d.com/support/documentation/ScriptReference/Mesh-triangles.html

The size of this array is always a multiple of 3, since for each polygon there are three vertex indices.

So

 Mesh.triangles[ 0 ]
 Mesh.triangles[ 1 ]
 Mesh.triangles[ 2 ]

are the indices of the first face, and

 Mesh.triangles[ 3 ]
 Mesh.triangles[ 4 ]
 Mesh.triangles[ 5 ]

the indices of the second, etc.

To get the 3 Vectors that make up the first face you would do the following

 Vector3 v1 = Mesh.vertices[ Mesh.triangles[ 0 ] ];
 Vector3 v2 = Mesh.vertices[ Mesh.triangles[ 1 ] ];
 Vector3 v3 = Mesh.vertices[ Mesh.triangles[ 2 ] ];

I havent tested this, but I can imaginge the vertices in Mesh.vertices only contain the positions of the vertices when no rotation / translation is applied. To get from these root positions to the current position of the vertex, you can use

http://unity3d.com/support/documentation/ScriptReference/Transform.TransformPoint.html

or

http://unity3d.com/support/documentation/ScriptReference/Transform.InverseTransformPoint.html

Comment
Add comment · Show 3 · 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 Sidar · Jun 12, 2011 at 02:31 PM 0
Share

I'm really confused at this, as triangles returns an array with ints. I'm still not sure how this will return information on the vertices?

Thanks for the reply btw

edit: Ah...I presume that the int represents the index position in the vertices?

avatar image Oliver Eberlei · Jun 12, 2011 at 02:33 PM 0
Share

Yes, these integers are the indices from the $$anonymous$$esh.vertices array

Vector3 v1 = $$anonymous$$esh.vertices[ $$anonymous$$esh.triangles[ 0 ] ];

will get you the vertex positions.

avatar image Sidar · Jun 12, 2011 at 02:51 PM 0
Share

Thank you for that. I'll try to make this work =)

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

2 People are following this question.

avatar image avatar image

Related Questions

Mesh normals: per face or per vertex? 1 Answer

Calculating normals manually 0 Answers

Books or articles about mesh recalculation 0 Answers

Using RigidBody2D.Cast to detect all collisions with a Tilemap + Composite Collider 0 Answers

Calculating a Second Set of Normals 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