
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 푚 푚 푚 푣 v 푢 × 푣 00 01 02 푥 푀푣 = 푚10 푚11 푚12 푣푦 v 푚 푚 푚 푣 u 20 21 22 푧 u v 푢푥푣푥 푢푥푣푦 푢푥푣푧 푢 ∙ 푣 > 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 c 0 0 0 푝푤 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: Floor Only Walls Roof Planes Roof Planes 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 p0 p2 ? p1 푝0 푝0 If 4 planes meet at a point xyz 푥 푦 푝0푧 푝0푤 푥 0 then we’ve found a solution to: 푝1푥 푝1푦 푝1푧 푝1푤 푦 0 푧 = 푝2푥 푝2푦 푝2푧 푝2푤 0 1 푝3푥 푝3푦 푝3푧 푝3푤 0 Only possible if matrix singular. Determining How 4 Planes Meet p3 p0 p2 ? 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. 푝0 푝1 푝2 푝3 d = = Planes well “behaved” all point same way. 푝0푧 푝1푧 푝2푧 푝3푧 Planes in CCW order. 푝0푤 푝1푤 푝2푤 푝3푤 Det of any 3x3 subblock from first 3 xyz rows is >0. Intersect Line Plane 푝푥푦푧 ∙ 푣푡 + 푝푤 푝푥푦푧 v1 푑1 = 푝푥푦푧 ∙ 푣1 +푝푤 풅ퟏ p time 0 1 푝 푝 푝 t=? 푝푥푦푧 = 푥 푦 푧 v0 푑0 = 푝푥푦푧 ∙ 푣0 +푝푤 풅ퟎ 푑푖푠푡 = 푝푤 distance above plane distance above −푑 푝푥푦푧 ∙ 푣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 it first hits a front side or p 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 Grow Hull Generated skinny Flip edge to fix 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 c a c b b b Hull Tri-Tet Numeric Robustness a a a a c c e c e c e e b d d b d b d b ● 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 Minimize Number of Planes vs Points Minimize Planes: ● Compute full hull 푝푥 푝푦 푝푧 ● Dual points 푝푤 푝푤 푝푤 ● Compute simplified hull 12 Vertices 20 Vertices ● Take Dual 20 Planes 12 Planes Convex Decomposition 3DS Max Screenshot Manual Creation of Automatic Mesh Use skinned mesh Collision Proxy Decomposition bone weights to [Ratcliff], [Mamou] create collision hulls Example: Convex Bones For Collisions Ragdolls on Stairs Hand catching coins Constructive Solid Geometry Boolean Operations Solid Geometry Boolean Operations Applications for Booleans Art tools (already have CSG) ● Modeling and level design Game Usages (less fidelity required): ● Destruction ● Geomod (tunneling) A convex based approach may suffice. Convex Cropping and Intersection ● Like general mesh cropping, but only 1 open loop that is itself a convex polygon. ● Intersecting two convexes can be done by cropping one with all the planes of the other ● Non-convex operands can be implemented as a union Convex Cropping Robustness ● Floating point issues can occur even in this most basic of mesh operations. ● One solution is to utilize plane equations to determine face/plane connectivity. Bad Slice Correct Slice Pre Slice Robustness with Quantum Planes Let all planes p of CSG Boolean operands satisfy: 푠 푝 푠 푝 ∀푝∃푠 ∶ 푠푝 = 푥 푦 푠 푝푧 푠 푝푤 , 푠 푝{푥,푦,푧,푤} ∈ ℤ, 푠푝{푥,푦,푧} ≤ 푘 푠 푝0 푠 푝0 푠 푝0 0 푥 0 푦 0 푧 푠0푝0푤 Recall how vertices are the −1 푀 = 푠1푝1푥 푠1푝1푦 푠1푝1푧 푣 = −푀 푠1푝1푤 intersection of 3 or more planes 푠2푝2푥 푠2푝2푦 푠2푝2푧 푠2푝2푤 푎 ∃푎, 푏: 푣 = , 푎, 푏 ∈ ℤ , 푏 ≤ det 푀 ≤ 6푘3 Generated points have {푥,푦,푧} 푏 Finite denominator ∴ ∃휀∀푢, 푣: 푢 − 푣 < 휀 ↔ 푢 = 푣 A fixed epsilon can now be used to indicate if two points are the same.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages72 Page
-
File Size-