Working on custom physics layers + added default entity rendering
This commit is contained in:
@@ -81,6 +81,19 @@ tick_physx :: (scene: *PhysX_Scene, dt: float) {
|
||||
PhysX.PxScene_fetchResults(scene.scene, true, null);
|
||||
}
|
||||
|
||||
//custom_filter_shader :: (attributes0: u32, filterData0: PhysX.PxFilterData, attributes1: u32, filterData1: PhysX.PxFilterData, pairFlags: *PhysX.PxPairFlags, constantBlock: *void, constantBlockSize: u32) -> PhysX.PxFilterFlags #c_call {
|
||||
// pairFlags.* = PhysX.PxPairFlags.ContactDefault;
|
||||
// return PhysX.PxFilterFlags.Default;
|
||||
//}
|
||||
|
||||
custom_filter_shader :: (attributes0: *u32, filterData0: *PhysX.PxFilterData, attributes1: *u32, filterData1: *PhysX.PxFilterData, pairFlags: *PhysX.PxPairFlags) -> u16 #c_call {
|
||||
pairFlags.* = PhysX.PxPairFlags.ContactDefault;
|
||||
push_context {
|
||||
print("DUDE!\n");
|
||||
}
|
||||
return xx PhysX.PxFilterFlags.Default;
|
||||
}
|
||||
|
||||
init_physx_scene :: (game_scene: *Scene) {
|
||||
tolerance_scale : PhysX.PxTolerancesScale;
|
||||
tolerance_scale.length = 1;
|
||||
@@ -91,7 +104,10 @@ init_physx_scene :: (game_scene: *Scene) {
|
||||
|
||||
scene_desc.cpuDispatcher = xx dispatcher;
|
||||
scene_desc.simulationEventCallback = event_callback;
|
||||
PhysX.set_default_filter_shader(*scene_desc);
|
||||
PhysX.set_custom_filter_shader(*scene_desc, PhysX.create_custom_filter_shader(custom_filter_shader));
|
||||
//scene_desc.filterShader = custom_filter_shader;//
|
||||
//scene_desc.filterShaderData = null;
|
||||
//scene_desc.filterShaderDataSize = 0;
|
||||
|
||||
scene := PhysX.PxPhysics_createScene(physics, *scene_desc);
|
||||
|
||||
@@ -203,7 +219,7 @@ create_physx_actor :: (e: *Entity) {
|
||||
case .CAPSULE; {
|
||||
geo = PhysX.PxCapsuleGeometry_new(e.physics.capsule.radius, e.physics.capsule.half_height-e.physics.capsule.radius);
|
||||
}
|
||||
case .MESH; {
|
||||
case .CONVEX_MESH; {
|
||||
if e.flags & .RENDERABLE {
|
||||
points : [..] Vector3;
|
||||
points.allocator = temp;
|
||||
@@ -213,7 +229,6 @@ create_physx_actor :: (e: *Entity) {
|
||||
model := get_model_by_handle(e.renderable.model);
|
||||
|
||||
for node, node_index: model.nodes {
|
||||
index_start : u32 = xx indices.count;
|
||||
render_data := e.renderable.nodes[node_index];
|
||||
|
||||
success, inv_matrix := inverse(e.transform.model_matrix);
|
||||
@@ -222,9 +237,63 @@ create_physx_actor :: (e: *Entity) {
|
||||
|
||||
if node.meshes.count > 0 {
|
||||
for m, mi: node.meshes {
|
||||
index_start : u32 = xx indices.count;
|
||||
mesh := parray_get(*engine.renderer.meshes, m);
|
||||
for v: mesh.positions {
|
||||
array_add(*points, transform_position(v, matrix));
|
||||
array_add(*points, v);//transform_position(v, matrix));
|
||||
}
|
||||
|
||||
for i: mesh.indices {
|
||||
array_add(*indices, index_start + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mesh_desc := PhysX.PxConvexMeshDesc_new();
|
||||
mesh_desc.points.count = xx points.count;
|
||||
mesh_desc.points.stride = size_of(Vector3);
|
||||
mesh_desc.points.data = points.data;
|
||||
|
||||
mesh_desc.polygons.count = cast(u32)(indices.count / 3);
|
||||
mesh_desc.polygons.stride = 3 * size_of(u32);
|
||||
mesh_desc.polygons.data = indices.data;
|
||||
|
||||
if !PhysX.PxValidateConvexMesh(*cooking_params, *mesh_desc) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
stream : PhysX.PxOutputStream;
|
||||
callback := PhysX.PxGetStandaloneInsertionCallback();
|
||||
//read_buffer : PhysX.PxDefaultMemoryInputData_new(;
|
||||
cond : s32;
|
||||
mesh := PhysX.PxCreateConvexMesh(*cooking_params, *mesh_desc, callback, null);
|
||||
scale := PhysX.PxMeshScale_new(*e.transform.scale);
|
||||
geo = PhysX.PxConvexMeshGeometry_new(mesh, *scale, 0);
|
||||
}
|
||||
}
|
||||
case .TRIANGLE_MESH; {
|
||||
if e.flags & .RENDERABLE {
|
||||
points : [..] Vector3;
|
||||
points.allocator = temp;
|
||||
indices : [..] u32;
|
||||
indices.allocator = temp;
|
||||
|
||||
model := get_model_by_handle(e.renderable.model);
|
||||
|
||||
for node, node_index: model.nodes {
|
||||
render_data := e.renderable.nodes[node_index];
|
||||
|
||||
success, inv_matrix := inverse(e.transform.model_matrix);
|
||||
// We need to undo the local to world part of every world matrix
|
||||
matrix := inv_matrix * render_data.transform.world_matrix;
|
||||
|
||||
if node.meshes.count > 0 {
|
||||
print("NUM MESHES %\n", node.meshes.count);
|
||||
for m, mi: node.meshes {
|
||||
index_start : u32 = xx indices.count;
|
||||
mesh := parray_get(*engine.renderer.meshes, m);
|
||||
for v: mesh.positions {
|
||||
array_add(*points, v);//transform_position(v, matrix));
|
||||
}
|
||||
|
||||
for i: mesh.indices {
|
||||
@@ -242,7 +311,7 @@ create_physx_actor :: (e: *Entity) {
|
||||
mesh_desc.triangles.stride = 3 * size_of(u32);
|
||||
mesh_desc.triangles.data = indices.data;
|
||||
|
||||
if PhysX.PxValidateTriangleMesh(*cooking_params, *mesh_desc) {
|
||||
if !PhysX.PxValidateTriangleMesh(*cooking_params, *mesh_desc) {
|
||||
assert(false);
|
||||
}
|
||||
|
||||
@@ -259,6 +328,16 @@ create_physx_actor :: (e: *Entity) {
|
||||
|
||||
shape := PhysX.PxPhysics_createShape(physics, geo, material, false, ifx e.physics.trigger then PHYSX_DEFAULT_TRIGGER_SHAPE_FLAGS else PHYSX_DEFAULT_SIMULATION_SHAPE_FLAGS);
|
||||
|
||||
// Setup layers
|
||||
filter_data := PhysX.PxFilterData_new();
|
||||
filter_data.word0 = 1;
|
||||
filter_data.word1 = 1;
|
||||
filter_data.word2 = 1;
|
||||
filter_data.word3 = 1;
|
||||
|
||||
//PhysX.PxShape_setSimulationFilterData(shape, *filter_data);
|
||||
//PhysX.PxShape_setQueryFilterData(shape, *filter_data);
|
||||
|
||||
PhysX.PxRigidActor_attachShape(actor, shape);
|
||||
|
||||
if e.physics.dynamic {
|
||||
|
||||
Reference in New Issue
Block a user