Serialize Collider Component done

This commit is contained in:
Sri Sham Haran 2022-10-28 19:39:39 +08:00
parent 04d372b9b8
commit ea9f90f60d
3 changed files with 18 additions and 20 deletions

View File

@ -147,3 +147,11 @@ namespace SHADE
} }
} // namespace SHADE } // namespace SHADE
RTTR_REGISTRATION
{
using namespace rttr;
using namespace SHADE;
registration::class_<SHColliderComponent>("Collider Component");
}

View File

@ -100,5 +100,6 @@ namespace SHADE
SHQuaternion orientation; SHQuaternion orientation;
Colliders colliders; Colliders colliders;
RTTR_ENABLE()
}; };
} // namespace SHADE } // namespace SHADE

View File

@ -169,24 +169,12 @@ namespace YAML
{ {
case SHCollider::Type::BOX: case SHCollider::Type::BOX:
{ {
if(auto const bb = dynamic_cast<SHBoundingBox*>(rhs.GetShape()); bb) rhs.SetBoundingBox(node[HalfExtents].as<SHVec3>());
{
if (node[HalfExtents])
{
bb->SetHalfExtents(node[HalfExtents].as<SHVec3>());
}
}
} }
break; break;
case SHCollider::Type::SPHERE: case SHCollider::Type::SPHERE:
{ {
if(auto const bs = dynamic_cast<SHBoundingSphere*>(rhs.GetShape()); bs) rhs.SetBoundingSphere(node[Radius].as<float>());
{
if (node[Radius])
{
bs->SetRadius(node[Radius].as<float>());
}
}
} }
break; break;
case SHCollider::Type::CAPSULE: break; case SHCollider::Type::CAPSULE: break;
@ -237,6 +225,7 @@ namespace YAML
const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert<SHCollider>::Type].as<std::string>()).convert<SHCollider::Type>(&ok); const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert<SHCollider>::Type].as<std::string>()).convert<SHCollider::Type>(&ok);
if (!ok) if (!ok)
return false; return false;
switch (colliderType) switch (colliderType)
{ {
case SHCollider::Type::BOX: rhs.AddBoundingBox(); break; case SHCollider::Type::BOX: rhs.AddBoundingBox(); break;
@ -244,7 +233,7 @@ namespace YAML
case SHCollider::Type::CAPSULE: break; case SHCollider::Type::CAPSULE: break;
default:; default:;
} }
rhs.GetCollider(numColliders++) = colliderNode.as<SHCollider>(); YAML::convert<SHCollider>::decode(colliderNode, rhs.GetCollider(numColliders++));
} }
} }
} }
@ -279,13 +268,13 @@ namespace YAML
propNode = rhs.GetProperty<int>(VARIABLE->offset); propNode = rhs.GetProperty<int>(VARIABLE->offset);
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2: case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR2:
propNode = SHSerializationTools::ValToYAML(rhs.GetProperty<SHVec2>(VARIABLE->offset)); propNode = rhs.GetProperty<SHVec2>(VARIABLE->offset);
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3: case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR3:
propNode = SHSerializationTools::ValToYAML(rhs.GetProperty<SHVec3>(VARIABLE->offset)); propNode = rhs.GetProperty<SHVec3>(VARIABLE->offset);
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4: case SHADE::SHShaderBlockInterface::Variable::Type::VECTOR4:
propNode = SHSerializationTools::ValToYAML(rhs.GetProperty<SHVec4>(VARIABLE->offset)); propNode = rhs.GetProperty<SHVec4>(VARIABLE->offset);
break; break;
case SHADE::SHShaderBlockInterface::Variable::Type::OTHER: case SHADE::SHShaderBlockInterface::Variable::Type::OTHER:
default: default: