Interaction With 3D Geometry Stan Melax Graphics Software Engineer, Intel
3D Interaction Happens with Geometric Objects Rigid Body Skinned Characters Soft Body { { { Mesh geometry; Mesh geometry; Mesh geometry; Vec3 position; Vec3 position[]; Springs connectivity; Quat orientation; Quat orientation[]; }; }; };
Agenda – Interacting with 3D Geometry Practical topics among: ● Core Geometry Concepts ● Convex Polyhedra ● Spatial and Mass Properties ● Soft Geometry and Springs With examples and implementation issues.
Warning: Some Math Ahead 𝑣 × 𝑤 𝑛 00 𝑛 01 𝑛 02 𝑤 𝑦 v 𝑁𝑤 = 𝑛 10 𝑛 11 𝑛 12 𝑤 𝑧 v u 𝑛 20 𝑛 21 𝑛 22 𝑤 𝑨 v u 𝑣 𝑦 𝑤 𝑦 𝑣 𝑦 𝑤 𝑧 𝑣 𝑦 𝑤 𝑨 𝑣𝑤 𝑈 = 𝑣 𝑧 𝑤 𝑦 𝑣 𝑧 𝑤 𝑧 𝑣 𝑧 𝑤 𝑨 𝑣 ∙ 𝑤 > 0 u u 𝑣 𝑨 𝑤 𝑦 𝑣 𝑨 𝑤 𝑧 𝑣 𝑨 𝑤 𝑨 v 𝜖𝑔 𝜖𝑔 𝜖𝑔 𝑦 𝑦 𝑦 v 𝜖𝑤 𝑦 𝜖𝑤 𝑧 𝜖𝑤 𝑨 u v 𝜖𝑔 𝜖𝑔 𝜖𝑔 𝑒𝑔 𝑧 𝑧 𝑧 𝑒𝑤 = 𝜖𝑤 𝑦 𝜖𝑤 𝑧 𝜖𝑤 𝑨 u b 𝜖𝑔 𝜖𝑔 𝜖𝑔 𝑨 𝑨 𝑨 𝑣 ∙ 𝑤 < 0 𝑤 × 𝑣 𝜖𝑤 𝑦 𝜖𝑤 𝑧 𝜖𝑤 𝑨 a Vector Arithmetic Dot Product Cross Product Matrix Stuff
What’s an “outer product”? Familiar dot or inner product: 𝑤 𝑦 𝑣 ∙ 𝑤 = 𝑣 𝑈 𝑤 = 𝑣 𝑦 𝑣 𝑧 𝑤 𝑧 𝑣 𝑨 = 𝑣 𝑦 𝑤 𝑦 + 𝑣 𝑧 𝑤 𝑧 + 𝑣 𝑨 𝑤 𝑨 𝑤 𝑨 Outer product: 𝑣 𝑦 𝑤 𝑦 𝑣 𝑦 𝑤 𝑧 𝑣 𝑦 𝑤 𝑨 𝑣 𝑦 𝑣⨂𝑤 = 𝑣𝑤 𝑈 = 𝑤 𝑦 𝑤 𝑧 𝑤 𝑨 = 𝑣 𝑧 𝑤 𝑦 𝑣 𝑧 𝑤 𝑧 𝑣 𝑧 𝑤 𝑨 𝑣 𝑧 𝑣 𝑨 𝑤 𝑦 𝑣 𝑨 𝑤 𝑧 𝑣 𝑨 𝑤 𝑨 𝑣 𝑨
Outer Product - Geometric View v v v u u u = 1 𝑣 𝑣 ∙ 𝑤 𝑣(𝑣 ∙ 𝑤) Distance of v along u (scalar) Projection of v along u (vector) Outer product 𝒗 ⊗ 𝒗 of a 𝑣 𝑣 ∙ 𝑤 ≠ 𝑣 ∙ 𝑣 𝑤 unit vector 𝒗 projects any 𝑣 𝑣 ∙ 𝑤 = 𝑣 ⊗ 𝑣 𝑤 vector along that direction.
Outer Product for Plane Projection −𝑣 𝑣 ∙ 𝑤 −𝑣 𝑣 ∙ 𝑤 v v 𝑤 − 𝑣 𝑣 ∙ 𝑤 v u u u 𝑣 𝑣 ∙ 𝑤 Remove portion of v (𝑣 ⊗ 𝑣)𝑤 or that runs along u 𝑤 − 𝑣 𝑣 ∙ 𝑤 = 𝐽𝑤 − 𝑣 ⊗ 𝑣 𝑤 = (𝐽 − 𝑣 ⊗ 𝑣 )𝑤 𝑱 − 𝒗 ⊗ 𝒗 projects any vector onto plane with normal 𝒗 .
Numerical Precision Issues 3 “collinear” points
Triangles and Planes Could use: ● Specify Front and Back 𝐵𝑦 + 𝐶𝑧 + 𝐷𝑨 == 𝐸 Prefer convention: 𝐵𝑦 + 𝐶𝑧 + 𝐷𝑨 + 𝐸 == 0 0 0 0 c 𝑞 𝑥 Given a point [ xyz ] its 𝑞 𝑦 𝑞 𝑧 𝑞 𝑨 distance above plane is: a 𝑞 𝑦 𝑦 + 𝑞 𝑧 𝑧 + 𝑞 𝑨 𝑨 + 𝑞 𝑥 b <0 below • Triangle (𝑏 𝑐 𝑑) Plane 𝑞 = 𝑞 𝑦 𝑞 𝑧 𝑞 𝑨 𝑞 𝑥 =0 on plane • CCW winding >0 above •
Intersection of 3 planes p0 p2 𝑞0 𝑦 𝑤 𝑦 + 𝑞0 𝑧 𝑤 𝑧 + 𝑞0 𝑨 𝑤 𝑨 + 𝑞0 𝑥 == 0 p1 𝑞1 𝑦 𝑤 𝑦 + 𝑞1 𝑧 𝑤 𝑧 + 𝑞1 𝑨 𝑤 𝑨 + 𝑞1 𝑥 == 0 𝑞2 𝑦 𝑤 𝑦 + 𝑞2 𝑧 𝑤 𝑧 + 𝑞2 𝑨 𝑤 𝑨 + 𝑞2 𝑥 == 0 p0 𝑞0 𝑦 𝑞0 𝑧 𝑞0 𝑨 𝑤 𝑦 𝑞0 𝑥 𝑤 𝑧 𝑞1 𝑦 𝑞1 𝑧 𝑞1 𝑨 𝑞1 𝑥 𝑄 = , 𝑐 = , 𝑤 = 𝑤 𝑨 𝑞2 𝑥 𝑞2 𝑦 𝑞2 𝑧 𝑞2 𝑨 v 𝑄𝑤 = −𝑐 p1 p2 𝑤 = −𝑄 −1 𝑐
What if we have 4 planes? Example: Roof Planes Roof Planes Floor Only Walls overhead view As house grows bottom up, how will the 4 roof planes come together at the top of this house?
Determining How 4 Planes Meet Note: these are top down views p3 of a convex region p2 p0 ? p1 𝑞0 𝑦 𝑞0 𝑧 If 4 planes meet at a point xyz 𝑞0 𝑨 𝑞0 𝑥 𝑦 0 𝑞1 𝑦 𝑞1 𝑧 𝑞1 𝑨 𝑞1 𝑥 then we’ve found a solution to: 𝑧 0 = 𝑨 𝑞2 𝑦 𝑞2 𝑧 0 𝑞2 𝑨 𝑞2 𝑥 1 0 𝑞3 𝑦 𝑞3 𝑧 𝑞3 𝑨 𝑞3 𝑥 Only possible if matrix singular.
Determining How 4 Planes Meet p3 p2 p0 ? p1 d<0 d==0 d>0 𝑞0 𝑦 𝑞1 𝑦 𝑞2 𝑦 𝑞3 𝑦 𝑞0 𝑧 𝑞1 𝑧 𝑞2 𝑧 𝑞3 𝑧 Notes: these are top down views of a convex region. d = 𝑞0 𝑞1 𝑞2 𝑞3 = 𝑞0 𝑨 𝑞1 𝑨 𝑞2 𝑨 𝑞3 𝑨 Planes well “behaved” all point same way. Planes in CCW order. 𝑞0 𝑥 𝑞1 𝑥 𝑞2 𝑥 𝑞3 𝑥 Det of any 3x3 subblock from first 3 xyz rows is >0.
Intersect Line Plane 𝑞 𝑦𝑧𝑨 ∙ 𝑤 𝑢 + 𝑞 𝑥 distance above plane 𝑞 𝑦𝑧𝑨 v1 𝒆 𝟐 𝑒 1 = 𝑞 𝑦𝑧𝑨 ∙ 𝑤 1 +𝑞 𝑥 p time 1 0 t=? 𝑞 𝑦𝑧𝑨 = 𝑞 𝑦 𝑞 𝑧 𝑞 𝑨 v0 𝑒 0 = 𝑞 𝑦𝑧𝑨 ∙ 𝑤 0 +𝑞 𝑥 𝒆 𝟏 𝑒𝑗𝑡𝑢 = 𝑞 𝑥 −𝑒 0 𝑞 𝑦𝑧𝑨 ∙ 𝑤 0 + 𝑞 𝑥 𝑗𝑛𝑞𝑏𝑑𝑢 = 𝑤 0 + 𝑤 1 − 𝑤 0 𝑢 𝑢 = (𝑞 𝑦𝑧𝑨 ∙ 𝑤 1 + 𝑞 𝑥 ) − (𝑞 𝑦𝑧𝑨 ∙ 𝑤 0 + 𝑞 𝑥 ) = − 𝑒 1 − 𝑒 0
Simple Ray Triangle Intersection Test ● Intersect ray with plane and get a point p. p ● For each edge va to vb ● Cross product with p-va ● Dot result with tri normal n ● <0 means outside ● Backside hit if dot(n,ray)>0
Ray Mesh Intersection ● Check Against Every Polygon (spatial structures can rule out many ● quickly) Multiple impact points – take closest. ● Detecting a “hit” - might not be closest ● Numerical Robustness – don’t slip between two adjacent triangles. ● Mesh “intact” – t-intersections, holes Numeric precision can result in plane intersection point landing just caused by missing triangles. outside each time, thus missing both neighbors.
Solid Geometry ● “Water - Tight” borderless manifold mesh: ● Every edge has 1 adjacency edge going other way ● Consistent winding. Polygon normals all face to exterior. ● The mesh is the boundary representation - the infinitely thin surface that separates solid matter from empty space.
Inside/Outside Test of a point ● Cast a long ray from point ray ● point is inside if it first hits the backside of a polygon. ● point is outside the object if p it first hits a front side or nothing at all.
Convex Polyhedra
Convex Mesh 𝒄 𝒃 𝑳 Math textbook: 𝐿 𝑑𝑝𝑜𝑤𝑓𝑦 ↔ ∀𝑏, 𝑐 ∈ 𝐿 → 𝑏𝑐 ⊆ 𝐿 Neighboring face normals tilt away. ● Volume bounded by a number of planes. ● Every vertex lies at or below every face. ● Many algorithms much easier when using convex shapes instead of general meshes.
Convex In/Out test A point is inside a convex volume if it lies under every plane boundary. p w No testing with vertices or edges. q
Convex Ray Intersection v0 v0 v0 v1 v0 ● Crop Ray with all front facing planes: 𝑜 ∙ 𝑤1 − 𝑤0 < 0 ● Impact at v0 if under all backside planes
Convex Line-Segment Intersection v0 v0 v1 v1 v0 v1 ● Trim v0 for Front facing planes 𝑜 ∙ 𝑤1 − 𝑤0 < 0 ● Trim v1 for Back facing planes 𝑜 ∙ 𝑤1 − 𝑤0 > 0
Convex-Convex Contact ● Separating Axis Theorem – Two non touching convex polyhedra are separated by a plane. ● The contact between two touching convex polyhedra will be either ● A point ● A line segment ● A convex polygon Physics engines like convex objects
Convex Hull from points Convex Hull - smallest convex polyhedron that contains all the points. Convex hull of a mesh will contain the mesh. ● Often a sufficient proxy for interaction and ● collision Techniques Expanding outward: QuickHull [Eddy ’77] ● Reducing inward: Gift Wrapping [Chand ’70] ●
Compute 3D Convex Hull ● Start with 2 back to back triangles. (or a tetrahedron) ● Find a vertex outside current volume (above faces). Find edge loop silhouette (around ● all faces below point) Replace with new fan of polys ● Remove Folds (if any) ● ● Rinse and Repeat
Hull Numerical Robustness Generated skinny Flip edge to fix Grow Hull triangle with bad normal.
Hull Tri-Tet Implementation ● Simple Triangle-mesh based approach ● When point d above any [ abc ] add tetrahedron [ abcd ] (triangles [ acb ][ dab ][ dbc ][ dca ]) to mesh. ● Prune any back-to-back tris such as [ abc ] and [ bac ] d d d a c a a c c b b b
Hull Tri-Tet Numeric Robustness a a a a e c c c c e e e d b b d d b b d ● 5 points {a,b,c,d,e} are coplanar-ish at one end of the point cloud ● But next point e tests above triangle [abc] but below [adb]. ● Silhouette is {abc} for which we extrude a new tetrahedron up to e ● This produces triangles [eca],[ebc] (blue) facing the right way and [eab] (red) facing the wrong way – based on known interior point. ● This provides the hindsight to see that [adb] should also be extruded
Simplified Convex Hull ● Off-the-shelf solutions typically generate the complete hull. ● All hull vertices may not be needed and may be inefficient for usage. ● Instead use greedy incremental algorithm picking next vertex that increases hull size the most. ● Stop when vertex count or error Full Hull Simplified threshold reached
Recommend
More recommend