Halfedge test
This commit is contained in:
parent
b46858cf55
commit
587104651c
@ -472,7 +472,6 @@ draw :: proc() {
|
|||||||
|
|
||||||
car_body := physics.get_body(&world.physics_scene, runtime_world.car_handle)
|
car_body := physics.get_body(&world.physics_scene, runtime_world.car_handle)
|
||||||
car_model := assets.get_model(&g_mem.assetman, "assets/toyota_corolla_ae86_trueno.glb")
|
car_model := assets.get_model(&g_mem.assetman, "assets/toyota_corolla_ae86_trueno.glb")
|
||||||
car_halfedge := halfedge.mesh_from_vertex_index_list(car_model.meshes[0].vertices, car_model.meshes[0].indices, context.temp_allocator)
|
|
||||||
|
|
||||||
mesh_col: bvh.Collision
|
mesh_col: bvh.Collision
|
||||||
hit_mesh_idx := -1
|
hit_mesh_idx := -1
|
||||||
@ -577,6 +576,36 @@ draw :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if mesh_col.hit {
|
||||||
|
mesh := car_model.meshes[hit_mesh_idx]
|
||||||
|
vertices := (cast([^]rl.Vector3)mesh.vertices)[:mesh.vertexCount]
|
||||||
|
indices := mesh.indices[:mesh.triangleCount * 3]
|
||||||
|
car_halfedge := halfedge.mesh_from_vertex_index_list(vertices, indices, context.temp_allocator)
|
||||||
|
|
||||||
|
face_idx := halfedge.Face_Index(mesh_col.prim)
|
||||||
|
face := car_halfedge.faces[face_idx]
|
||||||
|
first_edge_idx := face.edge
|
||||||
|
|
||||||
|
first := true
|
||||||
|
cur_edge_idx := first_edge_idx
|
||||||
|
for first || cur_edge_idx != first_edge_idx {
|
||||||
|
first = false
|
||||||
|
edge := car_halfedge.edges[cur_edge_idx]
|
||||||
|
cur_edge_idx = edge.next
|
||||||
|
|
||||||
|
if edge.twin >= 0 {
|
||||||
|
twin_edge := car_halfedge.edges[edge.twin]
|
||||||
|
face := twin_edge.face
|
||||||
|
|
||||||
|
i1, i2, i3 := indices[face * 3 + 0], indices[face * 3 + 1], indices[face * 3 + 2]
|
||||||
|
v1, v2, v3 := vertices[i1], vertices[i2], vertices[i3]
|
||||||
|
|
||||||
|
rl.DrawTriangle3D(v1, v2, v3, rl.RED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,6 +618,7 @@ draw :: proc() {
|
|||||||
if g_mem.editor {
|
if g_mem.editor {
|
||||||
rl.DrawText("Editor", 5, 5, 8, rl.ORANGE)
|
rl.DrawText("Editor", 5, 5, 8, rl.ORANGE)
|
||||||
|
|
||||||
|
|
||||||
rl.DrawText(
|
rl.DrawText(
|
||||||
fmt.ctprintf(
|
fmt.ctprintf(
|
||||||
"mesh: %v, aabb tests: %v, tri tests: %v",
|
"mesh: %v, aabb tests: %v, tri tests: %v",
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
package halfedge
|
package halfedge
|
||||||
|
|
||||||
import rl "vendor:raylib"
|
|
||||||
|
|
||||||
debug_draw_halfedge_mesh :: proc(mesh: ^Mesh) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package halfedge
|
package halfedge
|
||||||
|
|
||||||
import "core:container/small_array"
|
|
||||||
|
|
||||||
Vec3 :: [3]f32
|
Vec3 :: [3]f32
|
||||||
|
|
||||||
Vertex :: struct {
|
Vertex :: struct {
|
||||||
@ -14,7 +12,7 @@ Face :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vertex_Index :: distinct u16
|
Vertex_Index :: distinct u16
|
||||||
Face_Index :: distinct i16
|
Face_Index :: distinct u16
|
||||||
Edge_Index :: distinct i16
|
Edge_Index :: distinct i16
|
||||||
|
|
||||||
Half_Edge :: struct {
|
Half_Edge :: struct {
|
||||||
@ -55,7 +53,7 @@ mesh_from_vertex_index_list :: proc(
|
|||||||
triangle_num := len(indices) / 3
|
triangle_num := len(indices) / 3
|
||||||
for i in 0 ..< triangle_num {
|
for i in 0 ..< triangle_num {
|
||||||
i1, i2, i3 := indices[i * 3 + 0], indices[i * 3 + 1], indices[i * 3 + 2]
|
i1, i2, i3 := indices[i * 3 + 0], indices[i * 3 + 1], indices[i * 3 + 2]
|
||||||
v1, v2, v3 := vertices[i1], vertices[i2], vertices[i3]
|
// v1, v2, v3 := vertices[i1], vertices[i2], vertices[i3]
|
||||||
e1, e2, e3 := i * 3 + 0, i * 3 + 1, i * 3 + 2
|
e1, e2, e3 := i * 3 + 0, i * 3 + 1, i * 3 + 2
|
||||||
|
|
||||||
faces[i].edge = Edge_Index(e1)
|
faces[i].edge = Edge_Index(e1)
|
||||||
@ -98,4 +96,6 @@ mesh_from_vertex_index_list :: proc(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mesh
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ internal_ray_tri_test :: proc(ray: Ray, mesh: Mesh, tri: u16, col: ^Collision) {
|
|||||||
v1, v2, v3 := mesh.vertices[i1], mesh.vertices[i2], mesh.vertices[i3]
|
v1, v2, v3 := mesh.vertices[i1], mesh.vertices[i2], mesh.vertices[i3]
|
||||||
|
|
||||||
col.triangle_tests += 1
|
col.triangle_tests += 1
|
||||||
rl.DrawTriangle3D(v1, v2, v3, debug.int_to_color(i32(tri) + 1))
|
// rl.DrawTriangle3D(v1, v2, v3, debug.int_to_color(i32(tri) + 1))
|
||||||
|
|
||||||
t, _, barycentric, ok := collision.intersect_ray_triangle(
|
t, _, barycentric, ok := collision.intersect_ray_triangle(
|
||||||
{ray.origin, ray.origin + ray.dir},
|
{ray.origin, ray.origin + ray.dir},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user