Parcourir la source

Convenience constructors for SoftBodySharedSettings & made SoftBodyCreationSettings more similar to BodyCreationSettings

Jorrit Rouwe il y a 2 ans
Parent
commit
a957cca619

+ 1 - 1
Jolt/Physics/SoftBody/SoftBodyCreationSettings.h

@@ -21,7 +21,7 @@ public:
 
 	/// Constructor
 						SoftBodyCreationSettings() = default;
-						SoftBodyCreationSettings(const SoftBodySharedSettings *inSettings, RVec3Arg inPosition = RVec3::sZero(), QuatArg inRotation = Quat::sIdentity()) : mSettings(inSettings), mPosition(inPosition), mRotation(inRotation) { }
+						SoftBodyCreationSettings(const SoftBodySharedSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, ObjectLayer inObjectLayer) : mSettings(inSettings), mPosition(inPosition), mRotation(inRotation), mObjectLayer(inObjectLayer) { }
 
 	/// Saves the state of this object in binary form to inStream. Doesn't store the shared settings nor the group filter.
 	void				SaveBinaryState(StreamOut &inStream) const;

+ 16 - 0
Jolt/Physics/SoftBody/SoftBodySharedSettings.h

@@ -47,6 +47,10 @@ public:
 	{
 		JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Vertex)
 
+		/// Constructor
+						Vertex() = default;
+						Vertex(const Float3 &inPosition, const Float3 &inVelocity = Float3(0, 0, 0), float inInvMass = 1.0f) : mPosition(inPosition), mVelocity(inVelocity), mInvMass(inInvMass) { }
+
 		Float3			mPosition { 0, 0, 0 };						///< Initial position of the vertex
 		Float3			mVelocity { 0, 0, 0 };						///< Initial velocity of the vertex
 		float			mInvMass = 1.0f;							///< Initial inverse of the mass of the vertex
@@ -57,6 +61,10 @@ public:
 	{
 		JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Face)
 
+		/// Constructor
+						Face() = default;
+						Face(uint32 inVertex1, uint32 inVertex2, uint32 inVertex3, uint32 inMaterialIndex = 0) : mVertex { inVertex1, inVertex2, inVertex3 }, mMaterialIndex(inMaterialIndex) { }
+
 		/// Check if this is a degenerate face (a face which points to the same vertex twice)
 		bool			IsDegenerate() const						{ return mVertex[0] == mVertex[1] || mVertex[0] == mVertex[2] || mVertex[1] == mVertex[2]; }
 
@@ -69,6 +77,10 @@ public:
 	{
 		JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Edge)
 
+		/// Constructor
+						Edge() = default;
+						Edge(uint32 inVertex1, uint32 inVertex2, float inCompliance = 0.0f) : mVertex { inVertex1, inVertex2 }, mCompliance(inCompliance) { }
+
 		uint32			mVertex[2];									///< Indices of the vertices that form the edge
 		float			mRestLength = 1.0f;							///< Rest length of the spring
 		float			mCompliance = 0.0f;							///< Inverse of the stiffness of the spring
@@ -79,6 +91,10 @@ public:
 	{
 		JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Volume)
 
+		/// Constructor
+						Volume() = default;
+						Volume(uint32 inVertex1, uint32 inVertex2, uint32 inVertex3, uint32 inVertex4, float inCompliance = 0.0f) : mVertex { inVertex1, inVertex2, inVertex3, inVertex4 }, mCompliance(inCompliance) { }
+
 		uint32			mVertex[4];									///< Indices of the vertices that form the tetrhedron
 		float			mSixRestVolume = 1.0f;						///< 6 times the rest volume of the tetrahedron
 		float			mCompliance = 0.0f;							///< Inverse of the stiffness of the constraint

+ 1 - 2
Samples/SamplesApp.cpp

@@ -959,8 +959,7 @@ void SamplesApp::ShootObject()
 		}
 
 		// Confgure soft body
-		SoftBodyCreationSettings creation_settings(shared_settings, GetCamera().mPos);
-		creation_settings.mObjectLayer = Layers::MOVING;
+		SoftBodyCreationSettings creation_settings(shared_settings, GetCamera().mPos, Quat::sIdentity(), Layers::MOVING);
 		creation_settings.mFriction = mShootObjectFriction;
 		creation_settings.mRestitution = mShootObjectRestitution;
 

+ 2 - 4
Samples/Tests/General/LoadSaveSceneTest.cpp

@@ -181,8 +181,7 @@ Ref<PhysicsScene> LoadSaveSceneTest::sCreateScene()
 	// Add soft body cube
 	Ref<SoftBodySharedSettings> sb_cube_settings = SoftBodyCreator::CreateCube(5, 0.2f);
 	sb_cube_settings->mMaterials = { new PhysicsMaterialSimple("Soft Body Cube Material", Color::sGetDistinctColor(13)) };
-	SoftBodyCreationSettings sb_cube(sb_cube_settings, RVec3(0, cMaxHeight + 10.0f, 0));
-	sb_cube.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sb_cube(sb_cube_settings, RVec3(0, cMaxHeight + 10.0f, 0), Quat::sIdentity(), Layers::MOVING);
 	scene->AddSoftBody(sb_cube);
 
 	// Add the same shape again to test sharing
@@ -192,8 +191,7 @@ Ref<PhysicsScene> LoadSaveSceneTest::sCreateScene()
 	// Add soft body sphere
 	Ref<SoftBodySharedSettings> sb_sphere_settings = SoftBodyCreator::CreateSphere(0.5f);
 	sb_sphere_settings->mMaterials = { new PhysicsMaterialSimple("Soft Body Sphere Material", Color::sGetDistinctColor(14)) };
-	SoftBodyCreationSettings sb_sphere(sb_sphere_settings, RVec3(0, cMaxHeight + 12.0f, 0));
-	sb_sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sb_sphere(sb_sphere_settings, RVec3(0, cMaxHeight + 12.0f, 0), Quat::sIdentity(), Layers::MOVING);
 	sb_sphere.mPressure = 2000.0f;
 	scene->AddSoftBody(sb_sphere);
 

+ 2 - 4
Samples/Tests/SoftBody/SoftBodyFrictionTest.cpp

@@ -24,8 +24,7 @@ void SoftBodyFrictionTest::Initialize()
 	Ref<SoftBodySharedSettings> sphere_settings = SoftBodyCreator::CreateSphere();
 	for (SoftBodySharedSettings::Vertex &v : sphere_settings->mVertices)
 		v.mVelocity = Float3(0, 0, 10);
-	SoftBodyCreationSettings sphere(sphere_settings);
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(sphere_settings, RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 	sphere.mPressure = 2000.0f;
 
 	for (int i = 0; i <= 10; ++i)
@@ -38,8 +37,7 @@ void SoftBodyFrictionTest::Initialize()
 	Ref<SoftBodySharedSettings> cube_settings = SoftBodyCreator::CreateCube();
 	for (SoftBodySharedSettings::Vertex &v : cube_settings->mVertices)
 		v.mVelocity = Float3(0, 0, 10);
-	SoftBodyCreationSettings cube(cube_settings);
-	cube.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings cube(cube_settings, RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 
 	for (int i = 0; i <= 10; ++i)
 	{

+ 2 - 4
Samples/Tests/SoftBody/SoftBodyGravityFactorTest.cpp

@@ -20,8 +20,7 @@ void SoftBodyGravityFactorTest::Initialize()
 	CreateFloor();
 
 	// Bodies with increasing gravity factor
-	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere());
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 	sphere.mPressure = 2000.0f;
 
 	for (int i = 0; i <= 10; ++i)
@@ -31,8 +30,7 @@ void SoftBodyGravityFactorTest::Initialize()
 		mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
 	}
 
-	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube());
-	cube.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube(), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 
 	for (int i = 0; i <= 10; ++i)
 	{

+ 1 - 2
Samples/Tests/SoftBody/SoftBodyKinematicTest.cpp

@@ -24,8 +24,7 @@ void SoftBodyKinematicTest::Initialize()
 	Ref<SoftBodySharedSettings> sphere_settings = SoftBodyCreator::CreateSphere();
 	sphere_settings->mVertices[0].mInvMass = 0.0f;
 	sphere_settings->mVertices[0].mVelocity = Float3(0, 0, 5);
-	SoftBodyCreationSettings sphere(sphere_settings, RVec3(0, 5, 0));
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(sphere_settings, RVec3(0, 5, 0), Quat::sIdentity(), Layers::MOVING);
 	sphere.mPressure = 2000.0f;
 	mSphereID = mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
 }

+ 1 - 2
Samples/Tests/SoftBody/SoftBodyPressureTest.cpp

@@ -20,8 +20,7 @@ void SoftBodyPressureTest::Initialize()
 	CreateFloor();
 
 	// Bodies with increasing pressure
-	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(2.0f));
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(2.0f), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 
 	for (int i = 0; i <= 10; ++i)
 	{

+ 3 - 5
Samples/Tests/SoftBody/SoftBodyRestitutionTest.cpp

@@ -21,8 +21,7 @@ void SoftBodyRestitutionTest::Initialize()
 	floor.SetRestitution(0.0f);
 
 	// Bodies with increasing restitution
-	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere());
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
 	sphere.mPressure = 2000.0f;
 
 	for (int i = 0; i <= 10; ++i)
@@ -32,9 +31,8 @@ void SoftBodyRestitutionTest::Initialize()
 		mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
 	}
 
-	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube());
-	cube.mObjectLayer = Layers::MOVING;
-
+	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube(), RVec3::sZero(), Quat::sIdentity(), Layers::MOVING);
+	
 	for (int i = 0; i <= 10; ++i)
 	{
 		cube.mPosition = RVec3(-50.0f + i * 10.0f, 10.0f, -5.0f);

+ 3 - 6
Samples/Tests/SoftBody/SoftBodyShapesTest.cpp

@@ -32,21 +32,18 @@ void SoftBodyShapesTest::Initialize()
 	CreateMeshTerrain();
 
 	// Create cloth that's fixated at the corners
-	SoftBodyCreationSettings cloth(SoftBodyCreator::CreateCloth(), RVec3(0, 10.0f, 0), Quat::sRotation(Vec3::sAxisY(), 0.25f * JPH_PI));
-	cloth.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings cloth(SoftBodyCreator::CreateCloth(), RVec3(0, 10.0f, 0), Quat::sRotation(Vec3::sAxisY(), 0.25f * JPH_PI), Layers::MOVING);
 	cloth.mUpdatePosition = false; // Don't update the position of the cloth as it is fixed to the world
 	cloth.mMakeRotationIdentity = false; // Test explicitly checks if soft bodies with a rotation collide with shapes properly
 	mBodyInterface->CreateAndAddSoftBody(cloth, EActivation::Activate);
 
 	// Create cube
-	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube(), RVec3(20.0f, 10.0f, 0.0f), cCubeOrientation);
-	cube.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings cube(SoftBodyCreator::CreateCube(), RVec3(20.0f, 10.0f, 0.0f), cCubeOrientation, Layers::MOVING);
 	cube.mRestitution = 0.0f;
 	mBodyInterface->CreateAndAddSoftBody(cube, EActivation::Activate);
 
 	// Create pressurized sphere
-	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(), RVec3(15.0f, 10.0f, 15.0f));
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateSphere(), RVec3(15.0f, 10.0f, 15.0f), Quat::sIdentity(), Layers::MOVING);
 	sphere.mPressure = 2000.0f;
 	mBodyInterface->CreateAndAddSoftBody(sphere, EActivation::Activate);
 

+ 1 - 2
Samples/Tests/SoftBody/SoftBodyUpdatePositionTest.cpp

@@ -20,8 +20,7 @@ void SoftBodyUpdatePositionTest::Initialize()
 	CreateFloor();
 	
 	// Bodies with various settings for 'make rotation identity' and 'update position'
-	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateCube(), RVec3::sZero(), Quat::sRotation(Vec3::sReplicate(1.0f / sqrt(3.0f)), 0.25f * JPH_PI));
-	sphere.mObjectLayer = Layers::MOVING;
+	SoftBodyCreationSettings sphere(SoftBodyCreator::CreateCube(), RVec3::sZero(), Quat::sRotation(Vec3::sReplicate(1.0f / sqrt(3.0f)), 0.25f * JPH_PI), Layers::MOVING);
 
 	for (int update_position = 0; update_position < 2; ++update_position)
 		for (int make_rotation_identity = 0; make_rotation_identity < 2; ++make_rotation_identity)