use b3ClothMesh as a constant resource
This commit is contained in:
@ -63,9 +63,9 @@ public:
|
||||
m_triangle = m_mesh->triangles + rayOut.triangle;
|
||||
m_x = rayOut.fraction;
|
||||
|
||||
b3Particle* p1 = m_mesh->particles[m_triangle->v1];
|
||||
b3Particle* p2 = m_mesh->particles[m_triangle->v2];
|
||||
b3Particle* p3 = m_mesh->particles[m_triangle->v3];
|
||||
b3Particle* p1 = m_cloth->GetVertexParticle(m_triangle->v1);
|
||||
b3Particle* p2 = m_cloth->GetVertexParticle(m_triangle->v2);
|
||||
b3Particle* p3 = m_cloth->GetVertexParticle(m_triangle->v3);
|
||||
|
||||
b3Vec3 v1 = p1->GetPosition();
|
||||
b3Vec3 v2 = p2->GetPosition();
|
||||
@ -151,13 +151,13 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Particle* p1 = m_mesh->particles[m_triangle->v1];
|
||||
b3Particle* p1 = m_cloth->GetVertexParticle(m_triangle->v1);
|
||||
p1->ApplyTranslation(dx);
|
||||
|
||||
b3Particle* p2 = m_mesh->particles[m_triangle->v2];
|
||||
b3Particle* p2 = m_cloth->GetVertexParticle(m_triangle->v2);
|
||||
p2->ApplyTranslation(dx);
|
||||
|
||||
b3Particle* p3 = m_mesh->particles[m_triangle->v3];
|
||||
b3Particle* p3 = m_cloth->GetVertexParticle(m_triangle->v3);
|
||||
p3->ApplyTranslation(dx);
|
||||
}
|
||||
}
|
||||
@ -166,8 +166,6 @@ public:
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
m_cloth = nullptr;
|
||||
|
||||
if (m_spring)
|
||||
{
|
||||
m_cloth->DestroyForce(m_s1);
|
||||
@ -177,24 +175,21 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
b3Particle* p1 = m_mesh->particles[m_triangle->v1];
|
||||
p1->SetType(m_t1);
|
||||
|
||||
b3Particle* p2 = m_mesh->particles[m_triangle->v2];
|
||||
p2->SetType(m_t2);
|
||||
|
||||
b3Particle* p3 = m_mesh->particles[m_triangle->v3];
|
||||
p3->SetType(m_t3);
|
||||
m_cloth->GetVertexParticle(m_triangle->v1)->SetType(m_t1);
|
||||
m_cloth->GetVertexParticle(m_triangle->v2)->SetType(m_t2);
|
||||
m_cloth->GetVertexParticle(m_triangle->v3)->SetType(m_t3);
|
||||
}
|
||||
|
||||
m_cloth = nullptr;
|
||||
}
|
||||
|
||||
b3Vec3 GetPointA() const
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
b3Vec3 A = m_mesh->particles[m_triangle->v1]->GetPosition();
|
||||
b3Vec3 B = m_mesh->particles[m_triangle->v2]->GetPosition();
|
||||
b3Vec3 C = m_mesh->particles[m_triangle->v3]->GetPosition();
|
||||
b3Vec3 A = m_cloth->GetVertexParticle(m_triangle->v1)->GetPosition();
|
||||
b3Vec3 B = m_cloth->GetVertexParticle(m_triangle->v2)->GetPosition();
|
||||
b3Vec3 C = m_cloth->GetVertexParticle(m_triangle->v3)->GetPosition();
|
||||
|
||||
return m_u * A + m_v * B + (1.0f - m_u - m_v) * C;
|
||||
}
|
||||
@ -212,7 +207,7 @@ private:
|
||||
b3World* m_world;
|
||||
|
||||
b3Cloth* m_cloth;
|
||||
b3ClothMesh* m_mesh;
|
||||
const b3ClothMesh* m_mesh;
|
||||
b3ClothMeshTriangle* m_triangle;
|
||||
float32 m_u, m_v;
|
||||
|
||||
|
@ -60,7 +60,7 @@ struct b3ClothDef
|
||||
}
|
||||
|
||||
// Cloth mesh
|
||||
b3ClothMesh* mesh;
|
||||
const b3ClothMesh* mesh;
|
||||
|
||||
// Cloth density in kg/m^3
|
||||
float32 density;
|
||||
@ -106,7 +106,10 @@ public:
|
||||
bool RayCast(b3RayCastOutput* output, const b3RayCastInput* input, u32 triangleIndex) const;
|
||||
|
||||
// Return the cloth mesh proxy.
|
||||
b3ClothMesh* GetMesh() const;
|
||||
const b3ClothMesh* GetMesh() const;
|
||||
|
||||
// Return the particle associated with the given vertex.
|
||||
b3Particle* GetVertexParticle(u32 i);
|
||||
|
||||
// Return the list of particles in this cloth.
|
||||
const b3List2<b3Particle>& GetParticleList() const;
|
||||
@ -148,8 +151,11 @@ private:
|
||||
void Solve(float32 dt, const b3Vec3& gravity);
|
||||
|
||||
// Proxy mesh
|
||||
b3ClothMesh* m_mesh;
|
||||
const b3ClothMesh* m_mesh;
|
||||
|
||||
// Vertex particles
|
||||
b3Particle** m_vertexParticles;
|
||||
|
||||
// Mesh density
|
||||
float32 m_density;
|
||||
|
||||
@ -180,7 +186,7 @@ inline b3World* b3Cloth::GetWorld()
|
||||
return m_world;
|
||||
}
|
||||
|
||||
inline b3ClothMesh* b3Cloth::GetMesh() const
|
||||
inline const b3ClothMesh* b3Cloth::GetMesh() const
|
||||
{
|
||||
return m_mesh;
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include <bounce/common/math/vec2.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
|
||||
class b3Particle;
|
||||
|
||||
struct b3ClothMeshTriangle
|
||||
{
|
||||
u32 v1, v2, v3;
|
||||
@ -47,7 +45,6 @@ struct b3ClothMesh
|
||||
{
|
||||
u32 vertexCount;
|
||||
b3Vec3* vertices;
|
||||
b3Particle** particles;
|
||||
u32 triangleCount;
|
||||
b3ClothMeshTriangle* triangles;
|
||||
u32 meshCount;
|
||||
|
Reference in New Issue
Block a user