[models] Get Triangles of mesh #2555
-
I am working on Collision Detection, but i need the triangle of a mesh A way in code would just be Triangle = GetTri(Mesh, ID); So i could loop through it if this wouldn't be done, |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
@CrezyDud What is the polygon of a mesh? Triangles are usually defined by a set of 3 vertices in a row but only if no indexes are used. |
Beta Was this translation helpful? Give feedback.
-
yes, sorry, i do mean triangles so to get one i would just have to get 1st verticy 2nd and 3rd (then 4th, 5th, 6th, for second triangle?), connect them and i have one? i tried that am i doing something wrong?
|
Beta Was this translation helpful? Give feedback.
-
The method you posted looks ok but only if mesh is not indexed. How are you loading the mesh? Is it draw correctly? Do you know if it is indexed? |
Beta Was this translation helpful? Give feedback.
-
I made a paint3d experiment quite a while ago, after ray colliding with a model I then drilled into the models tris....
however unless you are writing a physics engine and want to collide shapes accurately with a 3d terrain it is often overkill and even bad practice to collide everything by triangle to triangle for example an inverse kinematic controlled 3d character with animated mesh is often represented by a simple capsule shape when colliding - this is very common and many character controllers use this - and you can very rarely tell each triangle of the mesh (even though animated) isn't being checked |
Beta Was this translation helpful? Give feedback.
-
thanks for helpyngsdf |
Beta Was this translation helpful? Give feedback.
-
Before diving straight into triangle tests, look at broader geometrical shapes like cylinder / plane, they are a lot faster and very often don't look buggy at all especially if you add a slight margin I rolled my own tri collider as I needed to use barrycentre coordinates to work out where on a texture I was.... |
Beta Was this translation helpful? Give feedback.
-
you can work out the normal of a triangle from its vertexes (good idea to cache this if its for static terrain) where v1-3 define the triangle, take vertex p1 to be v2-v1 and p2 to be v3-v1 the normal is the cross product of p1 and p2, check its pointing the right way as it might be 180 from expected if I have something the wrong way round.... |
Beta Was this translation helpful? Give feedback.
-
Yeah you'll need to normalise that...
On Thursday, 7 July 2022, CrezyDud ***@***.***> wrote:
some of the normals are more in -1 to 1 range but other are not
0.000000, -0.000053, -1284.932251
but sometimes its more correct
0.000000, 0.000000, 1.605906
is this normal?
do i just normalize it?
did i code it wrong?
this is the C code:
Vector3 P1 = Vector3Subtract(Tri.P2, Tri.P1);
Vector3 P2 = Vector3Subtract(Tri.P3, Tri.P1);
return Vector3CrossProduct(P1, P2);
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.<
…--
blog bedroomcoders.co.uk <http://bedroomcoders.co.uk>
Free source code and tutorials!
Disclaimer:
By sending an email to ANY of my addresses you are agreeing that:
1. I am by definition, "the intended recipient"
2. All information in the email is mine to do with as I see fit and make
such financial profit, political mileage, or good joke as it lends itself
to. In particular, I may quote it where I please.
3. I may take the contents as representing the views of your company.
4. This overrides any disclaimer or statement of confidentiality that
may be included on your message.
|
Beta Was this translation helpful? Give feedback.
I made a paint3d experiment quite a while ago, after ray colliding with a model I then drilled into the models tris....