updates...
This commit is contained in:
@@ -48,7 +48,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui)
|
||||
massSlider->SetSize(XMFLOAT2(100, 30));
|
||||
massSlider->SetPos(XMFLOAT2(x, y += step));
|
||||
massSlider->OnSlide([&](wiEventArgs args) {
|
||||
PhysicsComponent* physicscomponent = wiRenderer::GetScene().physicscomponents.GetComponent(entity);
|
||||
SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity);
|
||||
if (physicscomponent != nullptr)
|
||||
{
|
||||
physicscomponent->mass = args.fValue;
|
||||
@@ -61,7 +61,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui)
|
||||
frictionSlider->SetSize(XMFLOAT2(100, 30));
|
||||
frictionSlider->SetPos(XMFLOAT2(x, y += step));
|
||||
frictionSlider->OnSlide([&](wiEventArgs args) {
|
||||
PhysicsComponent* physicscomponent = wiRenderer::GetScene().physicscomponents.GetComponent(entity);
|
||||
SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity);
|
||||
if (physicscomponent != nullptr)
|
||||
{
|
||||
physicscomponent->friction = args.fValue;
|
||||
@@ -204,7 +204,7 @@ void MeshWindow::SetEntity(Entity entity)
|
||||
impostorDistanceSlider->SetValue(mesh->impostorDistance);
|
||||
tessellationFactorSlider->SetValue(mesh->GetTessellationFactor());
|
||||
|
||||
const PhysicsComponent* physicscomponent = scene.physicscomponents.GetComponent(entity);
|
||||
SoftBodyPhysicsComponent* physicscomponent = wiRenderer::GetScene().softbodies.GetComponent(entity);
|
||||
if (physicscomponent != nullptr)
|
||||
{
|
||||
massSlider->SetValue(physicscomponent->mass);
|
||||
|
||||
@@ -513,14 +513,10 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
state.meshArray.push_back(meshEntity);
|
||||
|
||||
MeshComponent& mesh = *scene.meshes.GetComponent(meshEntity);
|
||||
|
||||
mesh.renderable = true;
|
||||
|
||||
int matIndex = -1;
|
||||
for (auto& prim : x.primitives)
|
||||
{
|
||||
matIndex++;
|
||||
|
||||
assert(prim.indices >= 0);
|
||||
|
||||
// Fill indices:
|
||||
@@ -574,10 +570,6 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
assert(0 && "unsupported index stride!");
|
||||
}
|
||||
|
||||
|
||||
bool hasBoneWeights = false;
|
||||
bool hasBoneIndices = false;
|
||||
|
||||
for (auto& attr : prim.attributes)
|
||||
{
|
||||
const string& attr_name = attr.first;
|
||||
@@ -594,6 +586,7 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
|
||||
if (!attr_name.compare("POSITION"))
|
||||
{
|
||||
size_t offset = mesh.vertex_positions.size();
|
||||
mesh.vertex_positions.resize(mesh.vertex_positions.size() + count);
|
||||
assert(stride == 12);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
@@ -603,6 +596,7 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
}
|
||||
else if (!attr_name.compare("NORMAL"))
|
||||
{
|
||||
size_t offset = mesh.vertex_normals.size();
|
||||
mesh.vertex_normals.resize(mesh.vertex_normals.size() + count);
|
||||
assert(stride == 12);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
@@ -612,6 +606,7 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
}
|
||||
else if (!attr_name.compare("TEXCOORD_0"))
|
||||
{
|
||||
size_t offset = mesh.vertex_texcoords.size();
|
||||
mesh.vertex_texcoords.resize(mesh.vertex_texcoords.size() + count);
|
||||
assert(stride == 8);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
@@ -624,10 +619,10 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
}
|
||||
else if (!attr_name.compare("JOINTS_0"))
|
||||
{
|
||||
size_t offset = mesh.vertex_boneindices.size();
|
||||
mesh.vertex_boneindices.resize(mesh.vertex_boneindices.size() + count);
|
||||
if (stride == 4)
|
||||
{
|
||||
hasBoneIndices = true;
|
||||
struct JointTmp
|
||||
{
|
||||
uint8_t ind[4];
|
||||
@@ -645,7 +640,6 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
}
|
||||
else if (stride == 8)
|
||||
{
|
||||
hasBoneIndices = true;
|
||||
struct JointTmp
|
||||
{
|
||||
uint16_t ind[4];
|
||||
@@ -668,8 +662,8 @@ Entity ImportModel_GLTF(const std::string& fileName)
|
||||
}
|
||||
else if (!attr_name.compare("WEIGHTS_0"))
|
||||
{
|
||||
size_t offset = mesh.vertex_boneweights.size();
|
||||
mesh.vertex_boneweights.resize(mesh.vertex_boneweights.size() + count);
|
||||
hasBoneWeights = true;
|
||||
assert(stride == 16);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
+18
-18
@@ -270,14 +270,14 @@ void ObjectWindow::SetEntity(Entity entity)
|
||||
cascadeMaskSlider->SetValue((float)object->cascadeMask);
|
||||
ditherSlider->SetValue(object->GetTransparency());
|
||||
|
||||
const PhysicsComponent* physicsComponent = scene.physicscomponents.GetComponent(entity);
|
||||
const RigidBodyPhysicsComponent* physicsComponent = scene.rigidbodies.GetComponent(entity);
|
||||
|
||||
if (physicsComponent != nullptr)
|
||||
{
|
||||
if (physicsComponent->rigidBody)
|
||||
{
|
||||
simulationTypeComboBox->SetSelected(1);
|
||||
}
|
||||
//if (physicsComponent->rigidBody)
|
||||
//{
|
||||
// simulationTypeComboBox->SetSelected(1);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (object->mesh != nullptr)
|
||||
@@ -299,32 +299,32 @@ void ObjectWindow::SetEntity(Entity entity)
|
||||
|
||||
kinematicCheckBox->SetCheck(physicsComponent->kinematic);
|
||||
|
||||
if (!physicsComponent->physicsType.compare("ACTIVE"))
|
||||
{
|
||||
physicsTypeComboBox->SetSelected(0);
|
||||
}
|
||||
else if (!physicsComponent->physicsType.compare("PASSIVE"))
|
||||
{
|
||||
physicsTypeComboBox->SetSelected(1);
|
||||
}
|
||||
//if (!physicsComponent->physicsType.compare("ACTIVE"))
|
||||
//{
|
||||
// physicsTypeComboBox->SetSelected(0);
|
||||
//}
|
||||
//else if (!physicsComponent->physicsType.compare("PASSIVE"))
|
||||
//{
|
||||
// physicsTypeComboBox->SetSelected(1);
|
||||
//}
|
||||
|
||||
if (!physicsComponent->collisionShape.compare("BOX"))
|
||||
if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::BOX)
|
||||
{
|
||||
collisionShapeComboBox->SetSelected(0);
|
||||
}
|
||||
else if (!physicsComponent->collisionShape.compare("SPHERE"))
|
||||
else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::SPHERE)
|
||||
{
|
||||
collisionShapeComboBox->SetSelected(1);
|
||||
}
|
||||
else if (!physicsComponent->collisionShape.compare("CAPSULE"))
|
||||
else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::CAPSULE)
|
||||
{
|
||||
collisionShapeComboBox->SetSelected(2);
|
||||
}
|
||||
else if (!physicsComponent->collisionShape.compare("CONVEX_HULL"))
|
||||
else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL)
|
||||
{
|
||||
collisionShapeComboBox->SetSelected(3);
|
||||
}
|
||||
else if (!physicsComponent->collisionShape.compare("MESH"))
|
||||
else if (physicsComponent->shape == RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH)
|
||||
{
|
||||
collisionShapeComboBox->SetSelected(4);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
|
||||
nor0.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
|
||||
nor0.y = (float)((nor_u >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
|
||||
nor0.z = (float)((nor_u >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
|
||||
materialIndex = (nor_u >> 28) & 0x0000000F;
|
||||
materialIndex = (nor_u >> 24) & 0x000000FF;
|
||||
}
|
||||
nor_u = asuint(pos_nor1.w);
|
||||
float3 nor1;
|
||||
|
||||
+143
-103
@@ -121,7 +121,7 @@ void wiBULLET::setWind(const XMFLOAT3& wind){
|
||||
}
|
||||
|
||||
|
||||
void wiBULLET::connectVerticesToSoftBody(PhysicsComponent& physicscomponent, MeshComponent& mesh)
|
||||
void wiBULLET::connectVerticesToSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh)
|
||||
{
|
||||
//if (!softBodyPhysicsEnabled)
|
||||
// return;
|
||||
@@ -155,34 +155,34 @@ void wiBULLET::connectVerticesToSoftBody(PhysicsComponent& physicscomponent, Mes
|
||||
// }
|
||||
//}
|
||||
}
|
||||
void wiBULLET::connectSoftBodyToVertices(PhysicsComponent& physicscomponent, MeshComponent& mesh)
|
||||
void wiBULLET::connectSoftBodyToVertices(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh)
|
||||
{
|
||||
if (!softBodyPhysicsEnabled)
|
||||
return;
|
||||
//if (!softBodyPhysicsEnabled)
|
||||
// return;
|
||||
|
||||
if (!firstRunWorld)
|
||||
{
|
||||
btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[physicscomponent.physicsObjectID];
|
||||
btSoftBody* softBody = btSoftBody::upcast(obj);
|
||||
//if (!firstRunWorld)
|
||||
//{
|
||||
// btCollisionObject* obj = bulletPhysics->dynamicsWorld->getCollisionObjectArray()[physicscomponent.physicsObjectID];
|
||||
// btSoftBody* softBody = btSoftBody::upcast(obj);
|
||||
|
||||
if (softBody) {
|
||||
btSoftBody::tNodeArray& nodes(softBody->m_nodes);
|
||||
// if (softBody) {
|
||||
// btSoftBody::tNodeArray& nodes(softBody->m_nodes);
|
||||
|
||||
int gvg = physicscomponent.goalVG;
|
||||
if (gvg >= 0)
|
||||
{
|
||||
int j = 0;
|
||||
for (auto it = mesh.vertexGroups[gvg].vertex_weights.begin(); it != mesh.vertexGroups[gvg].vertex_weights.end(); ++it)
|
||||
{
|
||||
int vi = (*it).first;
|
||||
int index = physicscomponent.physicalmapGP[vi];
|
||||
float weight = (*it).second;
|
||||
nodes[index].m_x = nodes[index].m_x.lerp(btVector3(physicscomponent.goalPositions[j].x, physicscomponent.goalPositions[j].y, physicscomponent.goalPositions[j].z), weight);
|
||||
++j;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// int gvg = physicscomponent.goalVG;
|
||||
// if (gvg >= 0)
|
||||
// {
|
||||
// int j = 0;
|
||||
// for (auto it = mesh.vertexGroups[gvg].vertex_weights.begin(); it != mesh.vertexGroups[gvg].vertex_weights.end(); ++it)
|
||||
// {
|
||||
// int vi = (*it).first;
|
||||
// int index = physicscomponent.physicalmapGP[vi];
|
||||
// float weight = (*it).second;
|
||||
// nodes[index].m_x = nodes[index].m_x.lerp(btVector3(physicscomponent.goalPositions[j].x, physicscomponent.goalPositions[j].y, physicscomponent.goalPositions[j].z), weight);
|
||||
// ++j;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
void wiBULLET::transformBody(const XMFLOAT4& rot, const XMFLOAT3& pos, int objectI)
|
||||
{
|
||||
@@ -228,15 +228,20 @@ PHYSICS::PhysicsTransform* wiBULLET::getObject(int index)
|
||||
return transforms[index];
|
||||
}
|
||||
|
||||
void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent& mesh, TransformComponent& transform)
|
||||
void wiBULLET::addRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform)
|
||||
{
|
||||
if (!rigidBodyPhysicsEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
btVector3 S = btVector3(transform.scale_local.x, transform.scale_local.y, transform.scale_local.z);
|
||||
btQuaternion R = btQuaternion(transform.rotation_local.x, transform.rotation_local.y, transform.rotation_local.z, transform.rotation_local.z);
|
||||
btVector3 T = btVector3(transform.translation_local.x, transform.translation_local.y, transform.translation_local.z);
|
||||
|
||||
if(physicscomponent.rigidBody&& rigidBodyPhysicsEnabled){
|
||||
|
||||
if(!physicscomponent.collisionShape.compare("BOX"))
|
||||
switch(physicscomponent.shape)
|
||||
{
|
||||
case RigidBodyPhysicsComponent::CollisionShape::BOX:
|
||||
{
|
||||
btCollisionShape* shape = new btBoxShape(S);
|
||||
shape->setMargin(btScalar(0.05));
|
||||
@@ -286,7 +291,9 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!physicscomponent.collisionShape.compare("SPHERE"))
|
||||
break;
|
||||
|
||||
case RigidBodyPhysicsComponent::CollisionShape::SPHERE:
|
||||
{
|
||||
btCollisionShape* shape = new btSphereShape(btScalar(S.x()));
|
||||
shape->setMargin(btScalar(0.05));
|
||||
@@ -336,7 +343,9 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
|
||||
}
|
||||
if(!physicscomponent.collisionShape.compare("CAPSULE"))
|
||||
break;
|
||||
|
||||
case RigidBodyPhysicsComponent::CollisionShape::CAPSULE:
|
||||
{
|
||||
btCollisionShape* shape = new btCapsuleShape(btScalar(S.x()), btScalar(S.y()));
|
||||
shape->setMargin(btScalar(0.05));
|
||||
@@ -386,7 +395,9 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!physicscomponent.collisionShape.compare("CONVEX_HULL"))
|
||||
break;
|
||||
|
||||
case RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL:
|
||||
{
|
||||
btCollisionShape* shape = new btConvexHullShape();
|
||||
for (auto& pos : mesh.vertex_positions)
|
||||
@@ -442,7 +453,9 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!physicscomponent.collisionShape.compare("MESH"))
|
||||
break;
|
||||
|
||||
case RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH:
|
||||
{
|
||||
int totalVerts = (int)mesh.vertex_positions.size();
|
||||
int totalTriangles = (int)mesh.indices.size() / 3;
|
||||
@@ -455,9 +468,10 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
|
||||
int* btInd = new int[mesh.indices.size()];
|
||||
for (unsigned int i = 0; i < mesh.indices.size(); ++i)
|
||||
i = 0;
|
||||
for (auto& ind : mesh.indices)
|
||||
{
|
||||
btInd[i] = mesh.indices[i];
|
||||
btInd[i++] = ind;
|
||||
}
|
||||
|
||||
int vertStride = sizeof(btVector3);
|
||||
@@ -526,45 +540,60 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
}
|
||||
}
|
||||
|
||||
if(physicscomponent.softBody && softBodyPhysicsEnabled)
|
||||
|
||||
|
||||
physicscomponent.physicsObjectID = ++registeredObjects;
|
||||
}
|
||||
void wiBULLET::addSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform)
|
||||
{
|
||||
if (!softBodyPhysicsEnabled)
|
||||
{
|
||||
const int vCount = (int)physicscomponent.physicsverts.size();
|
||||
btScalar* btVerts = new btScalar[vCount*3];
|
||||
for(int i=0;i<vCount*3;i+=3){
|
||||
const int vindex = i/3;
|
||||
btVerts[i] = btScalar(physicscomponent.physicsverts[vindex].x);
|
||||
btVerts[i+1] = btScalar(physicscomponent.physicsverts[vindex].y);
|
||||
btVerts[i+2] = btScalar(physicscomponent.physicsverts[vindex].z);
|
||||
return;
|
||||
}
|
||||
|
||||
btVector3 S = btVector3(transform.scale_local.x, transform.scale_local.y, transform.scale_local.z);
|
||||
btQuaternion R = btQuaternion(transform.rotation_local.x, transform.rotation_local.y, transform.rotation_local.z, transform.rotation_local.z);
|
||||
btVector3 T = btVector3(transform.translation_local.x, transform.translation_local.y, transform.translation_local.z);
|
||||
|
||||
{
|
||||
const int vCount = (int)physicscomponent.physicsvertices.size();
|
||||
btScalar* btVerts = new btScalar[vCount * 3];
|
||||
for (int i = 0; i<vCount * 3; i += 3) {
|
||||
const int vindex = i / 3;
|
||||
btVerts[i] = btScalar(physicscomponent.physicsvertices[vindex].x);
|
||||
btVerts[i + 1] = btScalar(physicscomponent.physicsvertices[vindex].y);
|
||||
btVerts[i + 2] = btScalar(physicscomponent.physicsvertices[vindex].z);
|
||||
}
|
||||
const int iCount = (int)physicscomponent.physicsindices.size();
|
||||
const int tCount = iCount/3;
|
||||
const int tCount = iCount / 3;
|
||||
int* btInd = new int[iCount];
|
||||
for(int i=0;i<iCount;++i){
|
||||
for (int i = 0; i<iCount; ++i) {
|
||||
btInd[i] = physicscomponent.physicsindices[i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
btSoftBody* softBody = btSoftBodyHelpers::CreateFromTriMesh(
|
||||
((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo()
|
||||
,&btVerts[0]
|
||||
,&btInd[0]
|
||||
,tCount
|
||||
,false
|
||||
((btSoftRigidDynamicsWorld*)bulletPhysics->dynamicsWorld)->getWorldInfo()
|
||||
, &btVerts[0]
|
||||
, &btInd[0]
|
||||
, tCount
|
||||
, false
|
||||
);
|
||||
|
||||
|
||||
|
||||
delete[] btVerts;
|
||||
delete[] btInd;
|
||||
|
||||
if(softBody){
|
||||
btSoftBody::Material* pm=softBody->appendMaterial();
|
||||
|
||||
if (softBody)
|
||||
{
|
||||
btSoftBody::Material* pm = softBody->appendMaterial();
|
||||
pm->m_kLST = 0.5;
|
||||
pm->m_kVST = 0.5;
|
||||
pm->m_kAST = 0.5;
|
||||
pm->m_flags = 0;
|
||||
softBody->generateBendingConstraints(2,pm);
|
||||
softBody->generateBendingConstraints(2, pm);
|
||||
softBody->randomizeConstraints();
|
||||
|
||||
|
||||
btTransform shapeTransform;
|
||||
shapeTransform.setIdentity();
|
||||
shapeTransform.setOrigin(T);
|
||||
@@ -573,60 +602,60 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
softBody->transform(shapeTransform);
|
||||
|
||||
|
||||
softBody->m_cfg.piterations = softBodyIterationCount;
|
||||
softBody->m_cfg.aeromodel=btSoftBody::eAeroModel::F_TwoSidedLiftDrag;
|
||||
softBody->m_cfg.piterations = softBodyIterationCount;
|
||||
softBody->m_cfg.aeromodel = btSoftBody::eAeroModel::F_TwoSidedLiftDrag;
|
||||
|
||||
softBody->m_cfg.kAHR =btScalar(.69); //0.69 Anchor hardness [0,1]
|
||||
softBody->m_cfg.kCHR =btScalar(1.0); //1 Rigid contact hardness [0,1]
|
||||
softBody->m_cfg.kDF =btScalar(0.2); //0.2 Dynamic friction coefficient [0,1]
|
||||
softBody->m_cfg.kDG =btScalar(0.01); //0 Drag coefficient [0,+inf]
|
||||
softBody->m_cfg.kDP =btScalar(0.0); //0 Damping coefficient [0,1]
|
||||
softBody->m_cfg.kKHR =btScalar(0.1); //0.1 Kinetic contact hardness [0,1]
|
||||
softBody->m_cfg.kLF =btScalar(0.1); //0 Lift coefficient [0,+inf]
|
||||
softBody->m_cfg.kMT =btScalar(0.0); //0 Pose matching coefficient [0,1]
|
||||
softBody->m_cfg.kPR =btScalar(0.0); //0 Pressure coefficient [-1,1]
|
||||
softBody->m_cfg.kSHR =btScalar(1.0); //1 Soft contacts hardness [0,1]
|
||||
softBody->m_cfg.kVC =btScalar(0.0); //0 Volume conseration coefficient [0,+inf]
|
||||
softBody->m_cfg.kVCF =btScalar(1.0); //1 Velocities correction factor (Baumgarte)
|
||||
softBody->m_cfg.kAHR = btScalar(.69); //0.69 Anchor hardness [0,1]
|
||||
softBody->m_cfg.kCHR = btScalar(1.0); //1 Rigid contact hardness [0,1]
|
||||
softBody->m_cfg.kDF = btScalar(physicscomponent.friction); //0.2 Dynamic friction coefficient [0,1]
|
||||
softBody->m_cfg.kDG = btScalar(0.01); //0 Drag coefficient [0,+inf]
|
||||
softBody->m_cfg.kDP = btScalar(0.0); //0 Damping coefficient [0,1]
|
||||
softBody->m_cfg.kKHR = btScalar(0.1); //0.1 Kinetic contact hardness [0,1]
|
||||
softBody->m_cfg.kLF = btScalar(0.1); //0 Lift coefficient [0,+inf]
|
||||
softBody->m_cfg.kMT = btScalar(0.0); //0 Pose matching coefficient [0,1]
|
||||
softBody->m_cfg.kPR = btScalar(0.0); //0 Pressure coefficient [-1,1]
|
||||
softBody->m_cfg.kSHR = btScalar(1.0); //1 Soft contacts hardness [0,1]
|
||||
softBody->m_cfg.kVC = btScalar(0.0); //0 Volume conseration coefficient [0,+inf]
|
||||
softBody->m_cfg.kVCF = btScalar(1.0); //1 Velocities correction factor (Baumgarte)
|
||||
|
||||
softBody->m_cfg.kSKHR_CL = btScalar(1.0); //1 Soft vs. kinetic hardness [0,1]
|
||||
softBody->m_cfg.kSK_SPLT_CL = btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
softBody->m_cfg.kSRHR_CL = btScalar(0.1); //0.1 Soft vs. rigid hardness [0,1]
|
||||
softBody->m_cfg.kSR_SPLT_CL = btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
softBody->m_cfg.kSSHR_CL = btScalar(0.5); //0.5 Soft vs. soft hardness [0,1]
|
||||
softBody->m_cfg.kSS_SPLT_CL = btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
|
||||
softBody->m_cfg.kSKHR_CL =btScalar(1.0); //1 Soft vs. kinetic hardness [0,1]
|
||||
softBody->m_cfg.kSK_SPLT_CL =btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
softBody->m_cfg.kSRHR_CL =btScalar(0.1); //0.1 Soft vs. rigid hardness [0,1]
|
||||
softBody->m_cfg.kSR_SPLT_CL =btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
softBody->m_cfg.kSSHR_CL =btScalar(0.5); //0.5 Soft vs. soft hardness [0,1]
|
||||
softBody->m_cfg.kSS_SPLT_CL =btScalar(0.5); //0.5 Soft vs. rigid impulse split [0,1]
|
||||
|
||||
|
||||
btScalar mass = btScalar(physicscomponent.mass);
|
||||
softBody->setTotalMass(mass);
|
||||
|
||||
int mvg = physicscomponent.massVG;
|
||||
if(mvg>=0){
|
||||
for(auto it=mesh.vertexGroups[mvg].vertex_weights.begin();it!=mesh.vertexGroups[mvg].vertex_weights.end();++it){
|
||||
int vi = (*it).first;
|
||||
float wei = (*it).second;
|
||||
int index= physicscomponent.physicalmapGP[vi];
|
||||
softBody->setMass(index,softBody->getMass(index)*btScalar(wei));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int gvg = physicscomponent.goalVG;
|
||||
if(gvg>=0){
|
||||
for(auto it=mesh.vertexGroups[gvg].vertex_weights.begin();it!=mesh.vertexGroups[gvg].vertex_weights.end();++it){
|
||||
int vi = (*it).first;
|
||||
int index= physicscomponent.physicalmapGP[vi];
|
||||
float weight = (*it).second;
|
||||
if(weight==1)
|
||||
softBody->setMass(index,0);
|
||||
}
|
||||
}
|
||||
//int mvg = physicscomponent.massVG;
|
||||
//if (mvg >= 0) {
|
||||
// for (auto it = mesh.vertexGroups[mvg].vertex_weights.begin(); it != mesh.vertexGroups[mvg].vertex_weights.end(); ++it) {
|
||||
// int vi = (*it).first;
|
||||
// float wei = (*it).second;
|
||||
// int index = physicscomponent.physicalmapGP[vi];
|
||||
// softBody->setMass(index, softBody->getMass(index)*btScalar(wei));
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
//int gvg = physicscomponent.goalVG;
|
||||
//if (gvg >= 0) {
|
||||
// for (auto it = mesh.vertexGroups[gvg].vertex_weights.begin(); it != mesh.vertexGroups[gvg].vertex_weights.end(); ++it) {
|
||||
// int vi = (*it).first;
|
||||
// int index = physicscomponent.physicalmapGP[vi];
|
||||
// float weight = (*it).second;
|
||||
// if (weight == 1)
|
||||
// softBody->setMass(index, 0);
|
||||
// }
|
||||
//}
|
||||
|
||||
softBody->getCollisionShape()->setMargin(btScalar(0.2));
|
||||
|
||||
softBody->setWindVelocity(bulletPhysics->wind);
|
||||
|
||||
softBody->setPose(true,true);
|
||||
|
||||
softBody->setPose(true, true);
|
||||
|
||||
softBody->setActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
@@ -638,15 +667,26 @@ void wiBULLET::registerObject(PhysicsComponent& physicscomponent, MeshComponent&
|
||||
|
||||
physicscomponent.physicsObjectID = ++registeredObjects;
|
||||
}
|
||||
void wiBULLET::removeObject(PhysicsComponent& physicscomponent)
|
||||
void wiBULLET::removeRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent)
|
||||
{
|
||||
|
||||
if (physicscomponent.physicsObjectID < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
deleteObject(physicscomponent.physicsObjectID);
|
||||
|
||||
physicscomponent.physicsObjectID = -1;
|
||||
}
|
||||
void wiBULLET::removeSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent)
|
||||
{
|
||||
if (physicscomponent.physicsObjectID < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
deleteObject(physicscomponent.physicsObjectID);
|
||||
|
||||
physicscomponent.physicsObjectID = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,17 @@ public:
|
||||
|
||||
virtual void setWind(const XMFLOAT3& wind) override;
|
||||
|
||||
virtual void connectVerticesToSoftBody(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) override;
|
||||
virtual void connectSoftBodyToVertices(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) override;
|
||||
virtual void connectVerticesToSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) override;
|
||||
virtual void connectSoftBodyToVertices(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) override;
|
||||
virtual void transformBody(const XMFLOAT4& rot, const XMFLOAT3& pos, int objectI) override;
|
||||
|
||||
virtual PhysicsTransform* getObject(int index) override;
|
||||
|
||||
// add object to the simulation
|
||||
virtual void registerObject(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) override;
|
||||
// remove object from simulation
|
||||
virtual void removeObject(wiSceneSystem::PhysicsComponent& physicscomponent) override;
|
||||
virtual void addRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) override;
|
||||
virtual void addSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) override;
|
||||
|
||||
virtual void removeRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent) override;
|
||||
virtual void removeSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent) override;
|
||||
|
||||
virtual void Update(float dt) override;
|
||||
virtual void ClearWorld() override;
|
||||
|
||||
@@ -37,14 +37,15 @@ public:
|
||||
|
||||
virtual void setWind(const XMFLOAT3& wind)=0;
|
||||
|
||||
virtual void connectVerticesToSoftBody(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) = 0;
|
||||
virtual void connectSoftBodyToVertices(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) = 0;
|
||||
virtual void connectVerticesToSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) = 0;
|
||||
virtual void connectSoftBodyToVertices(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh) = 0;
|
||||
virtual void transformBody(const XMFLOAT4& rot, const XMFLOAT3& pos, int objectI) = 0;
|
||||
|
||||
virtual PhysicsTransform* getObject(int index)=0;
|
||||
|
||||
// add object to the simulation
|
||||
virtual void registerObject(wiSceneSystem::PhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) = 0;
|
||||
// remove object from simulation
|
||||
virtual void removeObject(wiSceneSystem::PhysicsComponent& physicscomponent) = 0;
|
||||
virtual void addRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) = 0;
|
||||
virtual void addSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent, wiSceneSystem::MeshComponent& mesh, wiSceneSystem::TransformComponent& transform) = 0;
|
||||
|
||||
virtual void removeRigidBody(wiSceneSystem::RigidBodyPhysicsComponent& physicscomponent) = 0;
|
||||
virtual void removeSoftBody(wiSceneSystem::SoftBodyPhysicsComponent& physicscomponent) = 0;
|
||||
};
|
||||
|
||||
+217
-153
@@ -284,7 +284,8 @@ namespace wiSceneSystem
|
||||
for (size_t i = 0; i < vertices.size(); ++i)
|
||||
{
|
||||
const XMFLOAT3& pos = vertex_positions[i];
|
||||
const XMFLOAT3& nor = vertex_normals[i];
|
||||
XMFLOAT3& nor = vertex_normals[i];
|
||||
XMStoreFloat3(&nor, XMVector3Normalize(XMLoadFloat3(&nor)));
|
||||
uint32_t subsetIndex = subsetIndicesLUT[(uint32_t)i];
|
||||
vertices[i].FromFULL(pos, nor, subsetIndex);
|
||||
|
||||
@@ -356,7 +357,7 @@ namespace wiSceneSystem
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
|
||||
// texture coordinate buffers:
|
||||
// vertexBuffer - TEXCOORDS
|
||||
{
|
||||
std::vector<Vertex_TEX> vertices(vertex_texcoords.size());
|
||||
for (size_t i = 0; i < vertices.size(); ++i)
|
||||
@@ -381,176 +382,232 @@ namespace wiSceneSystem
|
||||
}
|
||||
|
||||
}
|
||||
void MeshComponent::RemoveVertex(size_t index)
|
||||
{
|
||||
for (size_t ind = 0; ind < indices.size(); ++ind)
|
||||
{
|
||||
if (indices[ind] == index)
|
||||
{
|
||||
indices[ind] = static_cast<uint32_t>(index);
|
||||
}
|
||||
else if (indices[ind] > index && indices[ind] > 0)
|
||||
{
|
||||
indices[ind]--;
|
||||
}
|
||||
}
|
||||
|
||||
vertex_positions.erase(vertex_positions.begin() + index);
|
||||
vertex_normals.erase(vertex_normals.begin() + index);
|
||||
vertex_texcoords.erase(vertex_texcoords.begin() + index);
|
||||
vertex_boneindices.erase(vertex_boneindices.begin() + index);
|
||||
vertex_boneweights.erase(vertex_boneweights.begin() + index);
|
||||
}
|
||||
void MeshComponent::ComputeNormals(bool smooth)
|
||||
{
|
||||
// Start recalculating normals:
|
||||
assert(0); // todo: fix
|
||||
|
||||
if (smooth)
|
||||
{
|
||||
// Compute smooth surface normals:
|
||||
//std::vector<uint32_t> vertex_subsetindices(vertex_positions.size());
|
||||
//uint32_t subsetCounter = 0;
|
||||
//for (auto& subset : subsets)
|
||||
//{
|
||||
// for (uint32_t i = 0; i < subset.indexCount; ++i)
|
||||
// {
|
||||
// uint32_t index = indices[subset.indexOffset + i];
|
||||
// vertex_subsetindices[index] = subsetCounter;
|
||||
// }
|
||||
// subsetCounter++;
|
||||
//}
|
||||
|
||||
// 1.) Zero normals, they will be averaged later
|
||||
for (size_t i = 0; i < vertex_normals.size() - 1; i++)
|
||||
{
|
||||
vertex_normals[i] = XMFLOAT3(0, 0, 0);
|
||||
}
|
||||
//// Start recalculating normals:
|
||||
|
||||
// 2.) Find identical vertices by POSITION, accumulate face normals
|
||||
for (size_t i = 0; i < vertex_positions.size() - 1; i++)
|
||||
{
|
||||
XMFLOAT3& v_search = vertex_positions[i];
|
||||
XMFLOAT3& v_search_nor = vertex_normals[i];
|
||||
//if (smooth)
|
||||
//{
|
||||
// // Compute smooth surface normals:
|
||||
|
||||
for (size_t ind = 0; ind < indices.size() / 3; ++ind)
|
||||
{
|
||||
uint32_t i0 = indices[ind * 3 + 0];
|
||||
uint32_t i1 = indices[ind * 3 + 1];
|
||||
uint32_t i2 = indices[ind * 3 + 2];
|
||||
// // 1.) Zero normals, they will be averaged later
|
||||
// for (size_t i = 0; i < vertex_normals.size(); i++)
|
||||
// {
|
||||
// vertex_normals[i] = XMFLOAT3(0, 0, 0);
|
||||
// }
|
||||
|
||||
XMFLOAT3& v0 = vertex_positions[i0];
|
||||
XMFLOAT3& v1 = vertex_positions[i1];
|
||||
XMFLOAT3& v2 = vertex_positions[i2];
|
||||
// // 2.) Find identical vertices by POSITION, accumulate face normals
|
||||
// for (size_t i = 0; i < vertex_positions.size(); i++)
|
||||
// {
|
||||
// XMFLOAT3& v_search_pos = vertex_positions[i];
|
||||
|
||||
bool match_pos0 =
|
||||
fabs(v_search.x - v0.x) < FLT_EPSILON &&
|
||||
fabs(v_search.y - v0.y) < FLT_EPSILON &&
|
||||
fabs(v_search.z - v0.z) < FLT_EPSILON;
|
||||
// for (size_t ind = 0; ind < indices.size() / 3; ++ind)
|
||||
// {
|
||||
// uint32_t i0 = indices[ind * 3 + 0];
|
||||
// uint32_t i1 = indices[ind * 3 + 1];
|
||||
// uint32_t i2 = indices[ind * 3 + 2];
|
||||
|
||||
bool match_pos1 =
|
||||
fabs(v_search.x - v1.x) < FLT_EPSILON &&
|
||||
fabs(v_search.y - v1.y) < FLT_EPSILON &&
|
||||
fabs(v_search.z - v1.z) < FLT_EPSILON;
|
||||
// XMFLOAT3& v0 = vertex_positions[i0];
|
||||
// XMFLOAT3& v1 = vertex_positions[i1];
|
||||
// XMFLOAT3& v2 = vertex_positions[i2];
|
||||
|
||||
bool match_pos2 =
|
||||
fabs(v_search.x - v2.x) < FLT_EPSILON &&
|
||||
fabs(v_search.y - v2.y) < FLT_EPSILON &&
|
||||
fabs(v_search.z - v2.z) < FLT_EPSILON;
|
||||
// bool match_pos0 =
|
||||
// fabs(v_search_pos.x - v0.x) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.y - v0.y) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.z - v0.z) < FLT_EPSILON;
|
||||
|
||||
if (match_pos0 || match_pos1 || match_pos2)
|
||||
{
|
||||
XMVECTOR U = XMLoadFloat3(&v2) - XMLoadFloat3(&v0);
|
||||
XMVECTOR V = XMLoadFloat3(&v1) - XMLoadFloat3(&v0);
|
||||
// bool match_pos1 =
|
||||
// fabs(v_search_pos.x - v1.x) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.y - v1.y) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.z - v1.z) < FLT_EPSILON;
|
||||
|
||||
XMVECTOR N = XMVector3Cross(U, V);
|
||||
N = XMVector3Normalize(N);
|
||||
// bool match_pos2 =
|
||||
// fabs(v_search_pos.x - v2.x) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.y - v2.y) < FLT_EPSILON &&
|
||||
// fabs(v_search_pos.z - v2.z) < FLT_EPSILON;
|
||||
|
||||
XMFLOAT3 normal;
|
||||
XMStoreFloat3(&normal, N);
|
||||
// if (match_pos0 || match_pos1 || match_pos2)
|
||||
// {
|
||||
// XMVECTOR U = XMLoadFloat3(&v2) - XMLoadFloat3(&v0);
|
||||
// XMVECTOR V = XMLoadFloat3(&v1) - XMLoadFloat3(&v0);
|
||||
|
||||
v_search_nor.x += normal.x;
|
||||
v_search_nor.y += normal.y;
|
||||
v_search_nor.z += normal.z;
|
||||
}
|
||||
// XMVECTOR N = XMVector3Cross(U, V);
|
||||
// N = XMVector3Normalize(N);
|
||||
|
||||
}
|
||||
}
|
||||
// XMFLOAT3 normal;
|
||||
// XMStoreFloat3(&normal, N);
|
||||
|
||||
std::unordered_map<uint32_t, uint32_t> subsetIndicesLUT;
|
||||
uint32_t subsetCounter = 0;
|
||||
for (auto& subset : subsets)
|
||||
{
|
||||
for (uint32_t i = 0; i < subset.indexCount; ++i)
|
||||
{
|
||||
uint32_t index = indices[subset.indexOffset + i];
|
||||
subsetIndicesLUT[index] = subsetCounter;
|
||||
}
|
||||
subsetCounter++;
|
||||
}
|
||||
// vertex_normals[i].x += normal.x;
|
||||
// vertex_normals[i].y += normal.y;
|
||||
// vertex_normals[i].z += normal.z;
|
||||
// }
|
||||
|
||||
// 3.) Find unique vertices by POSITION and TEXCOORD and MATERIAL and remove duplicates
|
||||
for (size_t i = 0; i < vertex_positions.size() - 1; i++)
|
||||
{
|
||||
const XMFLOAT3& p0 = vertex_positions[i];
|
||||
const XMFLOAT3& n0 = vertex_normals[i];
|
||||
const XMFLOAT2& t0 = vertex_texcoords[i];
|
||||
const uint32_t s0 = subsetIndicesLUT[(uint32_t)i];
|
||||
// }
|
||||
// }
|
||||
|
||||
for (size_t j = i + 1; j < vertex_positions.size(); j++)
|
||||
{
|
||||
const XMFLOAT3& p1 = vertex_positions[j];
|
||||
const XMFLOAT3& n1 = vertex_normals[j];
|
||||
const XMFLOAT2& t1 = vertex_texcoords[j];
|
||||
const uint32_t s1 = subsetIndicesLUT[(uint32_t)j];
|
||||
// // 3.) Find unique vertices by POSITION and TEXCOORD and MATERIAL and remove duplicates
|
||||
// for (size_t i = 0; i < vertex_positions.size() - 1; i++)
|
||||
// {
|
||||
// const XMFLOAT3& p0 = vertex_positions[i];
|
||||
// const XMFLOAT3& n0 = vertex_normals[i];
|
||||
// const XMFLOAT2& t0 = vertex_texcoords[i];
|
||||
// const uint32_t s0 = vertex_subsetindices[i];
|
||||
|
||||
bool unique_pos =
|
||||
fabs(p0.x - p1.x) < FLT_EPSILON &&
|
||||
fabs(p0.y - p1.y) < FLT_EPSILON &&
|
||||
fabs(p0.z - p1.z) < FLT_EPSILON;
|
||||
// for (size_t j = i + 1; j < vertex_positions.size(); j++)
|
||||
// {
|
||||
// const XMFLOAT3& p1 = vertex_positions[j];
|
||||
// const XMFLOAT3& n1 = vertex_normals[j];
|
||||
// const XMFLOAT2& t1 = vertex_texcoords[j];
|
||||
// const uint32_t s1 = vertex_subsetindices[j];
|
||||
|
||||
bool unique_tex =
|
||||
fabs(t0.x - t1.x) < FLT_EPSILON &&
|
||||
fabs(t0.y - t1.y) < FLT_EPSILON &&
|
||||
s0 == s1;
|
||||
// bool unique_pos =
|
||||
// fabs(p0.x - p1.x) < FLT_EPSILON &&
|
||||
// fabs(p0.y - p1.y) < FLT_EPSILON &&
|
||||
// fabs(p0.z - p1.z) < FLT_EPSILON;
|
||||
|
||||
if (unique_pos && unique_tex)
|
||||
{
|
||||
RemoveVertex(j);
|
||||
}
|
||||
// bool unique_tex =
|
||||
// fabs(t0.x - t1.x) < FLT_EPSILON &&
|
||||
// fabs(t0.y - t1.y) < FLT_EPSILON &&
|
||||
// s0 == s1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Compute hard surface normals:
|
||||
// if (unique_pos && unique_tex)
|
||||
// {
|
||||
// for (size_t ind = 0; ind < indices.size(); ++ind)
|
||||
// {
|
||||
// if (indices[ind] == j)
|
||||
// {
|
||||
// indices[ind] = static_cast<uint32_t>(i);
|
||||
// }
|
||||
// else if (indices[ind] > j && indices[ind] > 0)
|
||||
// {
|
||||
// indices[ind]--;
|
||||
// }
|
||||
// }
|
||||
|
||||
std::vector<uint32_t> newIndexBuffer;
|
||||
std::vector<XMFLOAT3> newVertexBuffer;
|
||||
// if (j < vertex_subsetindices.size())
|
||||
// {
|
||||
// vertex_subsetindices.erase(vertex_subsetindices.begin() + j);
|
||||
// }
|
||||
|
||||
for (size_t face = 0; face < indices.size() / 3; face++)
|
||||
{
|
||||
uint32_t i0 = indices[face * 3 + 0];
|
||||
uint32_t i1 = indices[face * 3 + 1];
|
||||
uint32_t i2 = indices[face * 3 + 2];
|
||||
// if (j < vertex_positions.size())
|
||||
// {
|
||||
// vertex_positions.erase(vertex_positions.begin() + j);
|
||||
// }
|
||||
// if (j < vertex_normals.size())
|
||||
// {
|
||||
// vertex_normals.erase(vertex_normals.begin() + j);
|
||||
// }
|
||||
// if (j < vertex_texcoords.size())
|
||||
// {
|
||||
// vertex_texcoords.erase(vertex_texcoords.begin() + j);
|
||||
// }
|
||||
// if (j < vertex_boneindices.size())
|
||||
// {
|
||||
// vertex_boneindices.erase(vertex_boneindices.begin() + j);
|
||||
// }
|
||||
// if (j < vertex_boneweights.size())
|
||||
// {
|
||||
// vertex_boneweights.erase(vertex_boneweights.begin() + j);
|
||||
// }
|
||||
// }
|
||||
|
||||
XMFLOAT3& p0 = vertex_positions[i0];
|
||||
XMFLOAT3& p1 = vertex_positions[i1];
|
||||
XMFLOAT3& p2 = vertex_positions[i2];
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// // Compute hard surface normals:
|
||||
|
||||
XMVECTOR U = XMLoadFloat3(&p2) - XMLoadFloat3(&p0);
|
||||
XMVECTOR V = XMLoadFloat3(&p1) - XMLoadFloat3(&p0);
|
||||
// std::vector<uint32_t> newIndexBuffer;
|
||||
// std::vector<XMFLOAT3> newPositionsBuffer;
|
||||
// std::vector<XMFLOAT3> newNormalsBuffer;
|
||||
// std::vector<XMFLOAT2> newTexcoordsBuffer;
|
||||
// std::vector<uint32_t> newSubsetIndexBuffer;
|
||||
|
||||
XMVECTOR N = XMVector3Cross(U, V);
|
||||
N = XMVector3Normalize(N);
|
||||
// for (size_t face = 0; face < indices.size() / 3; face++)
|
||||
// {
|
||||
// uint32_t i0 = indices[face * 3 + 0];
|
||||
// uint32_t i1 = indices[face * 3 + 1];
|
||||
// uint32_t i2 = indices[face * 3 + 2];
|
||||
|
||||
XMFLOAT3 normal;
|
||||
XMStoreFloat3(&normal, N);
|
||||
// XMFLOAT3& p0 = vertex_positions[i0];
|
||||
// XMFLOAT3& p1 = vertex_positions[i1];
|
||||
// XMFLOAT3& p2 = vertex_positions[i2];
|
||||
|
||||
newVertexBuffer.push_back(normal);
|
||||
newVertexBuffer.push_back(normal);
|
||||
newVertexBuffer.push_back(normal);
|
||||
// XMVECTOR U = XMLoadFloat3(&p2) - XMLoadFloat3(&p0);
|
||||
// XMVECTOR V = XMLoadFloat3(&p1) - XMLoadFloat3(&p0);
|
||||
|
||||
newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
}
|
||||
// XMVECTOR N = XMVector3Cross(U, V);
|
||||
// N = XMVector3Normalize(N);
|
||||
|
||||
// For hard surface normals, we created a new mesh in the previous loop through faces, so swap data:
|
||||
vertex_normals = newVertexBuffer;
|
||||
indices = newIndexBuffer;
|
||||
}
|
||||
// XMFLOAT3 normal;
|
||||
// XMStoreFloat3(&normal, N);
|
||||
|
||||
CreateRenderData();
|
||||
// newPositionsBuffer.push_back(p0);
|
||||
// newPositionsBuffer.push_back(p0);
|
||||
// newPositionsBuffer.push_back(p0);
|
||||
|
||||
// newNormalsBuffer.push_back(normal);
|
||||
// newNormalsBuffer.push_back(normal);
|
||||
// newNormalsBuffer.push_back(normal);
|
||||
|
||||
// newTexcoordsBuffer.push_back(vertex_texcoords[i0]);
|
||||
// newTexcoordsBuffer.push_back(vertex_texcoords[i0]);
|
||||
// newTexcoordsBuffer.push_back(vertex_texcoords[i0]);
|
||||
|
||||
// newSubsetIndexBuffer.push_back(vertex_subsetindices[i0]);
|
||||
// newSubsetIndexBuffer.push_back(vertex_subsetindices[i0]);
|
||||
// newSubsetIndexBuffer.push_back(vertex_subsetindices[i0]);
|
||||
|
||||
// newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
// newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
// newIndexBuffer.push_back(static_cast<uint32_t>(newIndexBuffer.size()));
|
||||
// }
|
||||
|
||||
// // For hard surface normals, we created a new mesh in the previous loop through faces, so swap data:
|
||||
// vertex_positions = newPositionsBuffer;
|
||||
// vertex_normals = newNormalsBuffer;
|
||||
// vertex_texcoords = newTexcoordsBuffer;
|
||||
// indices = newIndexBuffer;
|
||||
|
||||
// for (auto& subset : subsets)
|
||||
// {
|
||||
// subset.indexCount = 0;
|
||||
// subset.indexOffset = 0;
|
||||
// }
|
||||
// for (size_t i = 0; i < indices.size(); ++i)
|
||||
// {
|
||||
// uint32_t index = indices[i];
|
||||
// uint32_t subsetIndex = vertex_subsetindices[index];
|
||||
// subsets[subsetIndex].indexCount++;
|
||||
// }
|
||||
// if (subsets.size() > 1)
|
||||
// {
|
||||
// for (size_t i = 0; i < subsets.size() - 1; ++i)
|
||||
// {
|
||||
// subsets[i + 1].indexOffset = subsets[i].indexOffset + subsets[i].indexCount;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//// Restore subsets:
|
||||
|
||||
|
||||
//CreateRenderData();
|
||||
}
|
||||
void MeshComponent::FlipCulling()
|
||||
{
|
||||
@@ -675,7 +732,7 @@ namespace wiSceneSystem
|
||||
|
||||
RunArmatureUpdateSystem(transforms, armatures);
|
||||
|
||||
RunPhysicsUpdateSystem(transforms, meshes, objects, physicscomponents);
|
||||
RunPhysicsUpdateSystem(transforms, meshes, objects, rigidbodies, softbodies);
|
||||
|
||||
RunMaterialUpdateSystem(materials, dt);
|
||||
|
||||
@@ -702,7 +759,8 @@ namespace wiSceneSystem
|
||||
materials.Remove(entity);
|
||||
meshes.Remove(entity);
|
||||
objects.Remove(entity);
|
||||
physicscomponents.Remove(entity);
|
||||
rigidbodies.Remove(entity);
|
||||
softbodies.Remove(entity);
|
||||
cullables.Remove(entity);
|
||||
armatures.Remove(entity);
|
||||
lights.Remove(entity);
|
||||
@@ -729,7 +787,8 @@ namespace wiSceneSystem
|
||||
materials.Remove(entity);
|
||||
meshes.Remove(entity);
|
||||
objects.Remove(entity);
|
||||
physicscomponents.Remove(entity);
|
||||
rigidbodies.Remove(entity);
|
||||
softbodies.Remove(entity);
|
||||
cullables.Remove(entity);
|
||||
armatures.Remove(entity);
|
||||
lights.Remove(entity);
|
||||
@@ -744,7 +803,7 @@ namespace wiSceneSystem
|
||||
{
|
||||
for (size_t i = 0; i < names.GetCount(); ++i)
|
||||
{
|
||||
if (strcmp(names[i].name, name.c_str()) == 0)
|
||||
if (names[i] == name)
|
||||
{
|
||||
return names.GetEntity(i);
|
||||
}
|
||||
@@ -1257,19 +1316,24 @@ namespace wiSceneSystem
|
||||
ComponentManager<TransformComponent>& transforms,
|
||||
ComponentManager<MeshComponent>& meshes,
|
||||
ComponentManager<ObjectComponent>& objects,
|
||||
ComponentManager<PhysicsComponent>& physicscomponents
|
||||
ComponentManager<RigidBodyPhysicsComponent>& rigidbodies,
|
||||
ComponentManager<SoftBodyPhysicsComponent>& softbodies
|
||||
)
|
||||
{
|
||||
for (size_t i = 0; i < physicscomponents.GetCount(); ++i)
|
||||
for (size_t i = 0; i < rigidbodies.GetCount(); ++i)
|
||||
{
|
||||
PhysicsComponent& physicscomponent = physicscomponents[i];
|
||||
Entity entity = physicscomponents.GetEntity(i);
|
||||
RigidBodyPhysicsComponent& rigidbody = rigidbodies[i];
|
||||
Entity entity = rigidbodies.GetEntity(i);
|
||||
|
||||
}
|
||||
for (size_t i = 0; i < softbodies.GetCount(); ++i)
|
||||
{
|
||||
SoftBodyPhysicsComponent& softbody = softbodies[i];
|
||||
Entity entity = softbodies.GetEntity(i);
|
||||
|
||||
MeshComponent& mesh = *meshes.GetComponent(entity);
|
||||
mesh.dynamicVB = true;
|
||||
|
||||
if (physicscomponent.softBody)
|
||||
{
|
||||
MeshComponent& mesh = *meshes.GetComponent(entity);
|
||||
mesh.dynamicVB = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
void RunMaterialUpdateSystem(ComponentManager<MaterialComponent>& materials, float dt)
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace wiSceneSystem
|
||||
char name[128];
|
||||
|
||||
inline void operator=(const std::string& str) { strcpy_s(name, str.c_str()); }
|
||||
inline bool operator==(const std::string& str) const { return strcmp(name, str.c_str()) == 0; }
|
||||
};
|
||||
|
||||
struct LayerComponent
|
||||
@@ -319,7 +320,6 @@ namespace wiSceneSystem
|
||||
inline bool IsDynamicVB() const { return dynamicVB; }
|
||||
|
||||
void CreateRenderData();
|
||||
void RemoveVertex(size_t index);
|
||||
void ComputeNormals(bool smooth);
|
||||
void FlipCulling();
|
||||
void FlipNormals();
|
||||
@@ -360,30 +360,32 @@ namespace wiSceneSystem
|
||||
inline uint32_t GetRenderTypes() const { return rendertypeMask; }
|
||||
};
|
||||
|
||||
struct PhysicsComponent
|
||||
struct RigidBodyPhysicsComponent
|
||||
{
|
||||
std::string collisionShape;
|
||||
std::string physicsType;
|
||||
|
||||
enum class CollisionShape
|
||||
{
|
||||
SPHERE,
|
||||
BOX,
|
||||
CAPSULE,
|
||||
CONVEX_HULL,
|
||||
TRIANGLE_MESH,
|
||||
};
|
||||
CollisionShape shape;
|
||||
int physicsObjectID = -1;
|
||||
bool rigidBody = false;
|
||||
bool softBody = false;
|
||||
bool kinematic = false;
|
||||
float mass = 1.0f;
|
||||
float friction = 1.0f;
|
||||
float restitution = 1.0f;
|
||||
float damping = 1.0f;
|
||||
};
|
||||
|
||||
int massVG; // vertex group ID for masses
|
||||
int goalVG; // vertex group ID for soft body goals (how much the vertex is driven by anim/other than physics systems)
|
||||
int softVG; // vertex group ID for soft body softness (how much to blend in soft body sim to a vertex)
|
||||
std::vector<XMFLOAT3> goalPositions;
|
||||
std::vector<XMFLOAT3> goalNormals;
|
||||
|
||||
std::vector<XMFLOAT3> physicsverts;
|
||||
std::vector<XMFLOAT3> physicsverts_prev;
|
||||
struct SoftBodyPhysicsComponent
|
||||
{
|
||||
int physicsObjectID = -1;
|
||||
float mass = 1.0f;
|
||||
float friction = 1.0f;
|
||||
std::vector<XMFLOAT3> physicsvertices;
|
||||
std::vector<uint32_t> physicsindices;
|
||||
std::vector<int> physicalmapGP;
|
||||
};
|
||||
|
||||
struct ArmatureComponent
|
||||
@@ -686,7 +688,8 @@ namespace wiSceneSystem
|
||||
wiECS::ComponentManager<MaterialComponent> materials;
|
||||
wiECS::ComponentManager<MeshComponent> meshes;
|
||||
wiECS::ComponentManager<ObjectComponent> objects;
|
||||
wiECS::ComponentManager<PhysicsComponent> physicscomponents;
|
||||
wiECS::ComponentManager<RigidBodyPhysicsComponent> rigidbodies;
|
||||
wiECS::ComponentManager<SoftBodyPhysicsComponent> softbodies;
|
||||
wiECS::ComponentManager<CullableComponent> cullables;
|
||||
wiECS::ComponentManager<ArmatureComponent> armatures;
|
||||
wiECS::ComponentManager<LightComponent> lights;
|
||||
@@ -796,7 +799,8 @@ namespace wiSceneSystem
|
||||
wiECS::ComponentManager<TransformComponent>& transforms,
|
||||
wiECS::ComponentManager<MeshComponent>& meshes,
|
||||
wiECS::ComponentManager<ObjectComponent>& objects,
|
||||
wiECS::ComponentManager<PhysicsComponent>& physicscomponents
|
||||
wiECS::ComponentManager<RigidBodyPhysicsComponent>& rigidbodies,
|
||||
wiECS::ComponentManager<SoftBodyPhysicsComponent>& softbodies
|
||||
);
|
||||
void RunArmatureUpdateSystem(
|
||||
const wiECS::ComponentManager<TransformComponent>& transforms,
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace wiSceneSystem
|
||||
struct MaterialComponent;
|
||||
struct MeshComponent;
|
||||
struct ObjectComponent;
|
||||
struct PhysicsComponent;
|
||||
struct RigidBodyPhysicsComponent;
|
||||
struct SoftBodyPhysicsComponent;
|
||||
struct CullableComponent;
|
||||
struct ArmatureComponent;
|
||||
struct LightComponent;
|
||||
|
||||
Reference in New Issue
Block a user