diff --git a/main.go b/main.go index 59a8839..18cfa46 100755 --- a/main.go +++ b/main.go @@ -38,6 +38,9 @@ func main() { groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat) s.AddActor(groundPlane.ToActor()) + //W0/W1 are filter groups the shape belongs to, and W2/W3 are a filter group mask + fd := pgo.NewFilterData(1, 1, 1, 1) + //Add box1 v := pgo.NewVec3(0, 10, 0) q := pgo.NewQuat(0, 0, 1, 0) @@ -48,12 +51,19 @@ func main() { box := pgo.NewBoxGeometry(0.5, 0.5, 0.5) dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 1, shapeOffset) + + ra := dynBox.ToRigidActor() + ra.SetSimFilterData(&fd) s.AddActor(dynBox.ToActor()) //Add box2 v = pgo.NewVec3(0.5, 12, 0) tr2 := pgo.NewTransform(v, qID) dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 1, shapeOffset) + + ra = dynBox2.ToRigidActor() + ra.SetSimFilterData(&fd) + s.AddActor(dynBox2.ToActor()) //Add sphere diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index 70877f9..6681115 100755 Binary files a/pgo/libs/libphysx-c.a and b/pgo/libs/libphysx-c.a differ diff --git a/pgo/pgo.go b/pgo/pgo.go index 67accf7..64b1508 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -164,6 +164,21 @@ func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocatio return p } +type FilterData struct { + cFilterData C.struct_CPxFilterData +} + +func NewFilterData(w0, w1, w2, w3 uint32) FilterData { + return FilterData{ + cFilterData: C.struct_CPxFilterData{ + word0: C.uint(w0), + word1: C.uint(w1), + word2: C.uint(w2), + word3: C.uint(w3), + }, + } +} + type Shape struct { cShape C.struct_CPxShape } @@ -178,6 +193,19 @@ func (s *Shape) SetLocalPose(tr *Transform) { C.CPxShape_setLocalPose(&s.cShape, &tr.cT) } +func (s *Shape) GetSimulationFilterData() FilterData { + return FilterData{ + cFilterData: C.CPxShape_getSimulationFilterData(&s.cShape), + } +} + +func (s *Shape) SetSimulationFilterData(fd *FilterData) { + C.CPxShape_setSimulationFilterData(&s.cShape, &fd.cFilterData) +} + +// CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape* cs); +// CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape* cs, CSTRUCT CPxFilterData cfd); + func CreateExclusiveShape(rigidActor RigidActor, geom *Geometry, mat *Material, shapeFlags ShapeFlags) Shape { return Shape{ cShape: C.createExclusiveShape(rigidActor.cRa, geom.cG, mat.cM, uint32(shapeFlags)), @@ -356,6 +384,12 @@ type RigidActor struct { cRa C.struct_CPxRigidActor } +func (ra *RigidActor) SetSimFilterData(fd *FilterData) { + C.CPxRigidActor_setSimFilterData(&ra.cRa, &fd.cFilterData) +} + +// CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd); + type RigidStatic struct { cRs *C.struct_CPxRigidStatic } diff --git a/pgo/physx-c/CPxFilterData.h b/pgo/physx-c/CPxFilterData.h new file mode 100755 index 0000000..9ad8fab --- /dev/null +++ b/pgo/physx-c/CPxFilterData.h @@ -0,0 +1,26 @@ +#ifndef CPxFilterData_H +#define CPxFilterData_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxFilterData + { + unsigned int word0; + unsigned int word1; + unsigned int word2; + unsigned int word3; + + //TODO: For some reason only this file breaks with CPxU32 (uint32_t). Why? + /*CPxU32 word0; + CPxU32 word1; + CPxU32 word2; + CPxU32 word3;*/ + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxFilterData_H diff --git a/pgo/physx-c/CPxRigidActor.h b/pgo/physx-c/CPxRigidActor.h index 86cbbb6..4386b1b 100755 --- a/pgo/physx-c/CPxRigidActor.h +++ b/pgo/physx-c/CPxRigidActor.h @@ -1,6 +1,8 @@ #ifndef CPxRigidActor_H #define CPxRigidActor_H +#include "CPxFilterData.h" + #ifdef __cplusplus extern "C" { #endif @@ -10,6 +12,9 @@ extern "C" { void* obj; }; + //Sets the CPxFilterData on all the shapes of the actor. + CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd); + #ifdef __cplusplus } #endif diff --git a/pgo/physx-c/CPxSceneDesc.h b/pgo/physx-c/CPxSceneDesc.h index 84ba6d3..094a800 100755 --- a/pgo/physx-c/CPxSceneDesc.h +++ b/pgo/physx-c/CPxSceneDesc.h @@ -14,7 +14,7 @@ extern "C" { }; /// - /// Creates a SceneDesc with filterShader=physx::PxDefaultSimulationFilterShader + /// Creates a SceneDesc with a custom filterShader that uses word0/word1 as groups shapes belong to, and word2/word3 as mask on the groups. /// /// /// diff --git a/pgo/physx-c/CPxShape.h b/pgo/physx-c/CPxShape.h index 9b0992e..48ac2a4 100755 --- a/pgo/physx-c/CPxShape.h +++ b/pgo/physx-c/CPxShape.h @@ -2,6 +2,7 @@ #define CPxShape_H #include "CPxTransform.h" +#include "CPxFilterData.h" #ifdef __cplusplus extern "C" { @@ -14,6 +15,8 @@ extern "C" { CPxAPI void CPxShape_setLocalPose(CSTRUCT CPxShape* cs, CSTRUCT CPxTransform* tr); CPxAPI CSTRUCT CPxTransform CPxShape_getLocalPose(CSTRUCT CPxShape* cs); + CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape* cs); + CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape* cs, CSTRUCT CPxFilterData* cfd); #ifdef __cplusplus }