Add hydra::AABB support to KRNodeProperty. KRLODGroup now using KRNodeProperty.
This commit is contained in:
@@ -60,4 +60,34 @@ const Vector3 getXMLAttribute(const std::string& base_name, tinyxml2::XMLElement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setXMLAttribute(const std::string& base_name, tinyxml2::XMLElement* e, const AABB& value, const AABB& default_value)
|
||||||
|
{
|
||||||
|
// TODO - Increase number of digits after the decimal in floating point format (6 -> 12?)
|
||||||
|
// FINDME, TODO - This needs optimization...
|
||||||
|
if (value != default_value) {
|
||||||
|
e->SetAttribute((base_name + "_min_x").c_str(), value.min.x);
|
||||||
|
e->SetAttribute((base_name + "_min_y").c_str(), value.min.y);
|
||||||
|
e->SetAttribute((base_name + "_min_z").c_str(), value.min.z);
|
||||||
|
|
||||||
|
e->SetAttribute((base_name + "_max_x").c_str(), value.max.x);
|
||||||
|
e->SetAttribute((base_name + "_max_y").c_str(), value.max.y);
|
||||||
|
e->SetAttribute((base_name + "_max_z").c_str(), value.max.z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AABB getXMLAttribute(const std::string& base_name, tinyxml2::XMLElement* e, const AABB& default_value)
|
||||||
|
{
|
||||||
|
AABB value;
|
||||||
|
if (e->QueryFloatAttribute((base_name + "_min_x").c_str(), &value.min.x) == tinyxml2::XML_SUCCESS
|
||||||
|
&& e->QueryFloatAttribute((base_name + "_min_y").c_str(), &value.min.y) == tinyxml2::XML_SUCCESS
|
||||||
|
&& e->QueryFloatAttribute((base_name + "_min_z").c_str(), &value.min.z) == tinyxml2::XML_SUCCESS
|
||||||
|
&& e->QueryFloatAttribute((base_name + "_max_x").c_str(), &value.max.x) == tinyxml2::XML_SUCCESS
|
||||||
|
&& e->QueryFloatAttribute((base_name + "_max_y").c_str(), &value.max.y) == tinyxml2::XML_SUCCESS
|
||||||
|
&& e->QueryFloatAttribute((base_name + "_max_z").c_str(), &value.max.z) == tinyxml2::XML_SUCCESS) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kraken
|
} // namespace kraken
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ float const D2R = PI * 2 / 360;
|
|||||||
|
|
||||||
namespace kraken {
|
namespace kraken {
|
||||||
void setXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::Vector3& value, const hydra::Vector3& default_value);
|
void setXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::Vector3& value, const hydra::Vector3& default_value);
|
||||||
|
void setXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::AABB& value, const hydra::AABB& default_value);
|
||||||
const hydra::Vector3 getXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::Vector3& default_value);
|
const hydra::Vector3 getXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::Vector3& default_value);
|
||||||
|
const hydra::AABB getXMLAttribute(const std::string& base_name, ::tinyxml2::XMLElement* e, const hydra::AABB& default_value);
|
||||||
} // namespace kraken
|
} // namespace kraken
|
||||||
|
|
||||||
|
|||||||
@@ -39,19 +39,15 @@ using namespace hydra;
|
|||||||
void KRLODGroup::InitNodeInfo(KrNodeInfo* nodeInfo)
|
void KRLODGroup::InitNodeInfo(KrNodeInfo* nodeInfo)
|
||||||
{
|
{
|
||||||
KRNode::InitNodeInfo(nodeInfo);
|
KRNode::InitNodeInfo(nodeInfo);
|
||||||
nodeInfo->lod_group.min_distance = 0.0f;
|
nodeInfo->lod_group.min_distance = decltype(m_min_distance)::defaultVal;
|
||||||
nodeInfo->lod_group.max_distance = 0.0f;
|
nodeInfo->lod_group.max_distance = decltype(m_max_distance)::defaultVal;
|
||||||
nodeInfo->lod_group.reference_min = Vector3::Zero();
|
nodeInfo->lod_group.reference_min = decltype(m_reference)::defaultVal.min;
|
||||||
nodeInfo->lod_group.reference_max = Vector3::Zero();
|
nodeInfo->lod_group.reference_max = decltype(m_reference)::defaultVal.max;
|
||||||
nodeInfo->lod_group.use_world_units = true;
|
nodeInfo->lod_group.use_world_units = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRLODGroup::KRLODGroup(KRScene& scene, std::string name) : KRNode(scene, name)
|
KRLODGroup::KRLODGroup(KRScene& scene, std::string name) : KRNode(scene, name)
|
||||||
{
|
{
|
||||||
m_min_distance = 0.0f;
|
|
||||||
m_max_distance = 0.0f;
|
|
||||||
m_reference = AABB::Create(Vector3::Zero(), Vector3::Zero());
|
|
||||||
m_use_world_units = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRLODGroup::~KRLODGroup()
|
KRLODGroup::~KRLODGroup()
|
||||||
@@ -65,66 +61,20 @@ std::string KRLODGroup::getElementName()
|
|||||||
tinyxml2::XMLElement* KRLODGroup::saveXML(tinyxml2::XMLNode* parent)
|
tinyxml2::XMLElement* KRLODGroup::saveXML(tinyxml2::XMLNode* parent)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* e = KRNode::saveXML(parent);
|
tinyxml2::XMLElement* e = KRNode::saveXML(parent);
|
||||||
e->SetAttribute("min_distance", m_min_distance);
|
m_min_distance.save(e);
|
||||||
e->SetAttribute("max_distance", m_max_distance);
|
m_max_distance.save(e);
|
||||||
|
m_reference.save(e);
|
||||||
e->SetAttribute("reference_min_x", m_reference.min.x);
|
m_use_world_units.save(e);
|
||||||
e->SetAttribute("reference_min_y", m_reference.min.y);
|
|
||||||
e->SetAttribute("reference_min_z", m_reference.min.z);
|
|
||||||
|
|
||||||
|
|
||||||
e->SetAttribute("reference_max_x", m_reference.max.x);
|
|
||||||
e->SetAttribute("reference_max_y", m_reference.max.y);
|
|
||||||
e->SetAttribute("reference_max_z", m_reference.max.z);
|
|
||||||
|
|
||||||
e->SetAttribute("use_world_units", m_use_world_units ? "true" : "false");
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRLODGroup::loadXML(tinyxml2::XMLElement* e)
|
void KRLODGroup::loadXML(tinyxml2::XMLElement* e)
|
||||||
{
|
{
|
||||||
KRNode::loadXML(e);
|
KRNode::loadXML(e);
|
||||||
|
m_min_distance.load(e);
|
||||||
m_min_distance = 0.0f;
|
m_max_distance.load(e);
|
||||||
if (e->QueryFloatAttribute("min_distance", &m_min_distance) != tinyxml2::XML_SUCCESS) {
|
m_reference.load(e);
|
||||||
m_min_distance = 0.0f;
|
m_use_world_units.load(e);
|
||||||
}
|
|
||||||
|
|
||||||
m_max_distance = 0.0f;
|
|
||||||
if (e->QueryFloatAttribute("max_distance", &m_max_distance) != tinyxml2::XML_SUCCESS) {
|
|
||||||
m_max_distance = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
|
||||||
if (e->QueryFloatAttribute("reference_min_x", &x) != tinyxml2::XML_SUCCESS) {
|
|
||||||
x = 0.0f;
|
|
||||||
}
|
|
||||||
if (e->QueryFloatAttribute("reference_min_y", &y) != tinyxml2::XML_SUCCESS) {
|
|
||||||
y = 0.0f;
|
|
||||||
}
|
|
||||||
if (e->QueryFloatAttribute("reference_min_z", &z) != tinyxml2::XML_SUCCESS) {
|
|
||||||
z = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_reference.min = Vector3::Create(x, y, z);
|
|
||||||
|
|
||||||
x = 0.0f; y = 0.0f; z = 0.0f;
|
|
||||||
if (e->QueryFloatAttribute("reference_max_x", &x) != tinyxml2::XML_SUCCESS) {
|
|
||||||
x = 0.0f;
|
|
||||||
}
|
|
||||||
if (e->QueryFloatAttribute("reference_max_y", &y) != tinyxml2::XML_SUCCESS) {
|
|
||||||
y = 0.0f;
|
|
||||||
}
|
|
||||||
if (e->QueryFloatAttribute("reference_max_z", &z) != tinyxml2::XML_SUCCESS) {
|
|
||||||
z = 0.0f;
|
|
||||||
}
|
|
||||||
m_reference.max = Vector3::Create(x, y, z);
|
|
||||||
|
|
||||||
m_use_world_units = true;
|
|
||||||
if (e->QueryBoolAttribute("use_world_units", &m_use_world_units) != tinyxml2::XML_SUCCESS) {
|
|
||||||
m_use_world_units = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -152,7 +102,7 @@ KRNode::LodVisibility KRLODGroup::calcLODVisibility(const KRViewport& viewport)
|
|||||||
|
|
||||||
Vector3 world_camera_position = viewport.getCameraPosition();
|
Vector3 world_camera_position = viewport.getCameraPosition();
|
||||||
Vector3 local_camera_position = worldToLocal(world_camera_position);
|
Vector3 local_camera_position = worldToLocal(world_camera_position);
|
||||||
Vector3 local_reference_point = m_reference.nearestPoint(local_camera_position);
|
Vector3 local_reference_point = m_reference.val.nearestPoint(local_camera_position);
|
||||||
|
|
||||||
if (m_use_world_units) {
|
if (m_use_world_units) {
|
||||||
Vector3 world_reference_point = localToWorld(local_reference_point);
|
Vector3 world_reference_point = localToWorld(local_reference_point);
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ public:
|
|||||||
LodVisibility calcLODVisibility(const KRViewport& viewport);
|
LodVisibility calcLODVisibility(const KRViewport& viewport);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_min_distance;
|
KRNODE_PROPERTY(float, m_min_distance, 0.f, "min_distance");
|
||||||
float m_max_distance;
|
KRNODE_PROPERTY(float, m_max_distance, 0.f, "max_distance");
|
||||||
hydra::AABB m_reference; // Point of reference, used for distance calculation. Usually set to the bounding box center
|
KRNODE_PROPERTY(hydra::AABB, m_reference, hydra::AABB({ 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}), "reference"); // Point of reference, used for distance calculation. Usually set to the bounding box center
|
||||||
bool m_use_world_units;
|
KRNODE_PROPERTY(bool, m_use_world_units, true, "use_world_units");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -100,6 +100,8 @@ public:
|
|||||||
element->SetAttribute(config::name, val ? "true" : "false");
|
element->SetAttribute(config::name, val ? "true" : "false");
|
||||||
} else if constexpr (std::is_same<T, hydra::Vector3>::value) {
|
} else if constexpr (std::is_same<T, hydra::Vector3>::value) {
|
||||||
kraken::setXMLAttribute(config::name, element, val, config::defaultVal);
|
kraken::setXMLAttribute(config::name, element, val, config::defaultVal);
|
||||||
|
} else if constexpr (std::is_same<T, hydra::AABB>::value) {
|
||||||
|
kraken::setXMLAttribute(config::name, element, val, config::defaultVal);
|
||||||
} else if constexpr (std::is_same<T, std::string>::value) {
|
} else if constexpr (std::is_same<T, std::string>::value) {
|
||||||
element->SetAttribute(config::name, val.c_str());
|
element->SetAttribute(config::name, val.c_str());
|
||||||
} else if constexpr (std::is_base_of<KRResourceBinding, T>::value) {
|
} else if constexpr (std::is_base_of<KRResourceBinding, T>::value) {
|
||||||
@@ -128,7 +130,9 @@ public:
|
|||||||
val = config::defaultVal;
|
val = config::defaultVal;
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same<T, hydra::Vector3>::value) {
|
} else if constexpr (std::is_same<T, hydra::Vector3>::value) {
|
||||||
kraken::getXMLAttribute(config::name, element, config::defaultVal);
|
val = kraken::getXMLAttribute(config::name, element, config::defaultVal);
|
||||||
|
} else if constexpr (std::is_same<T, hydra::AABB>::value) {
|
||||||
|
val = kraken::getXMLAttribute(config::name, element, config::defaultVal);
|
||||||
} else if constexpr (std::is_same<T, std::string>::value) {
|
} else if constexpr (std::is_same<T, std::string>::value) {
|
||||||
const char* name = element->Attribute(config::name);
|
const char* name = element->Attribute(config::name);
|
||||||
if (name) {
|
if (name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user