Cleaned up KRMesh to use AABB rather than discrete Vector3 for min and max
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
2
hydra
2
hydra
Submodule hydra updated: cc7dffbb9a...17b4ec2cde
@@ -100,7 +100,7 @@ AABB KRCollider::getBounds()
|
|||||||
{
|
{
|
||||||
loadModel();
|
loadModel();
|
||||||
if (m_model.val.isBound()) {
|
if (m_model.val.isBound()) {
|
||||||
return AABB::Create(m_model.val.get()->getMinPoint(), m_model.val.get()->getMaxPoint(), getModelMatrix());
|
return AABB::Create(m_model.val.get()->getExtents(), getModelMatrix());
|
||||||
} else {
|
} else {
|
||||||
return AABB::Infinite();
|
return AABB::Infinite();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,13 +337,13 @@ AABB KRModel::getBounds()
|
|||||||
}
|
}
|
||||||
KRMesh* mesh = m_meshes[lod].val.get();
|
KRMesh* mesh = m_meshes[lod].val.get();
|
||||||
if (m_faces_camera) {
|
if (m_faces_camera) {
|
||||||
AABB normal_bounds = AABB::Create(mesh->getMinPoint(), mesh->getMaxPoint(), getModelMatrix());
|
AABB normal_bounds = AABB::Create(mesh->getExtents(), getModelMatrix());
|
||||||
float max_dimension = normal_bounds.longest_radius();
|
float max_dimension = normal_bounds.longest_radius();
|
||||||
return AABB::Create(normal_bounds.center() - Vector3::Create(max_dimension), normal_bounds.center() + Vector3::Create(max_dimension));
|
return AABB::Create(normal_bounds.center() - Vector3::Create(max_dimension), normal_bounds.center() + Vector3::Create(max_dimension));
|
||||||
} else {
|
} else {
|
||||||
if (!(m_boundsCachedMat == getModelMatrix())) {
|
if (!(m_boundsCachedMat == getModelMatrix())) {
|
||||||
m_boundsCachedMat = getModelMatrix();
|
m_boundsCachedMat = getModelMatrix();
|
||||||
m_boundsCached = AABB::Create(mesh->getMinPoint(), mesh->getMaxPoint(), getModelMatrix());
|
m_boundsCached = AABB::Create(mesh->getExtents(), getModelMatrix());
|
||||||
}
|
}
|
||||||
return m_boundsCached;
|
return m_boundsCached;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public:
|
|||||||
|
|
||||||
KrResult update(const KrNodeInfo* nodeInfo) override;
|
KrResult update(const KrNodeInfo* nodeInfo) override;
|
||||||
|
|
||||||
virtual std::string getElementName();
|
virtual std::string getElementName() override;
|
||||||
virtual tinyxml2::XMLElement* saveXML(tinyxml2::XMLNode* parent) override;
|
virtual tinyxml2::XMLElement* saveXML(tinyxml2::XMLNode* parent) override;
|
||||||
virtual void loadXML(tinyxml2::XMLElement* e) override;
|
virtual void loadXML(tinyxml2::XMLElement* e) override;
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
virtual void getResourceBindings(std::list<KRResourceBinding*>& bindings) override;
|
virtual void getResourceBindings(std::list<KRResourceBinding*>& bindings) override;
|
||||||
virtual void preStream(const KRViewport& viewport, std::list<KRResourceRequest>& resourceRequests) override;
|
virtual void preStream(const KRViewport& viewport, std::list<KRResourceRequest>& resourceRequests) override;
|
||||||
|
|
||||||
virtual hydra::AABB getBounds();
|
virtual hydra::AABB getBounds() override;
|
||||||
|
|
||||||
void setRimColor(const hydra::Vector3& rim_color);
|
void setRimColor(const hydra::Vector3& rim_color);
|
||||||
void setRimPower(float rim_power);
|
void setRimPower(float rim_power);
|
||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
void setLightMap(const std::string& name);
|
void setLightMap(const std::string& name);
|
||||||
std::string getLightMap();
|
std::string getLightMap();
|
||||||
|
|
||||||
virtual kraken_stream_level getStreamLevel(const KRViewport& viewport);
|
virtual kraken_stream_level getStreamLevel(const KRViewport& viewport) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -150,8 +150,7 @@ void KRMesh::loadPack(Block* data)
|
|||||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8);
|
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8);
|
||||||
m_pIndexBaseData->lock();
|
m_pIndexBaseData->lock();
|
||||||
|
|
||||||
m_minPoint = Vector3::Create(ph.minx, ph.miny, ph.minz);
|
m_extents = ph.extents;
|
||||||
m_maxPoint = Vector3::Create(ph.maxx, ph.maxy, ph.maxz);
|
|
||||||
|
|
||||||
updateAttributeOffsets();
|
updateAttributeOffsets();
|
||||||
}
|
}
|
||||||
@@ -295,9 +294,10 @@ void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, cons
|
|||||||
float KRMesh::getMaxDimension()
|
float KRMesh::getMaxDimension()
|
||||||
{
|
{
|
||||||
float m = 0.0;
|
float m = 0.0;
|
||||||
if (m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x;
|
Vector3 size = m_extents.size();
|
||||||
if (m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y;
|
if (size.x > m) m = size.x;
|
||||||
if (m_maxPoint.z - m_minPoint.z > m) m = m_maxPoint.z - m_minPoint.z;
|
if (size.y > m) m = size.y;
|
||||||
|
if (size.z > m) m = size.z;
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,15 +645,10 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
|||||||
}
|
}
|
||||||
if (bFirstVertex) {
|
if (bFirstVertex) {
|
||||||
bFirstVertex = false;
|
bFirstVertex = false;
|
||||||
m_minPoint = source_vertex;
|
m_extents.min = source_vertex;
|
||||||
m_maxPoint = source_vertex;
|
m_extents.max = source_vertex;
|
||||||
} else {
|
} else {
|
||||||
if (source_vertex.x < m_minPoint.x) m_minPoint.x = source_vertex.x;
|
m_extents.encapsulate(source_vertex);
|
||||||
if (source_vertex.y < m_minPoint.y) m_minPoint.y = source_vertex.y;
|
|
||||||
if (source_vertex.z < m_minPoint.z) m_minPoint.z = source_vertex.z;
|
|
||||||
if (source_vertex.x > m_maxPoint.x) m_maxPoint.x = source_vertex.x;
|
|
||||||
if (source_vertex.y > m_maxPoint.y) m_maxPoint.y = source_vertex.y;
|
|
||||||
if (source_vertex.z > m_maxPoint.z) m_maxPoint.z = source_vertex.z;
|
|
||||||
}
|
}
|
||||||
if ((int)mi.uva.size() > iVertex) {
|
if ((int)mi.uva.size() > iVertex) {
|
||||||
setVertexUVA(iVertex, mi.uva[iVertex]);
|
setVertexUVA(iVertex, mi.uva[iVertex]);
|
||||||
@@ -669,13 +664,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pHeader->minx = m_minPoint.x;
|
pHeader->extents = m_extents;
|
||||||
pHeader->miny = m_minPoint.y;
|
|
||||||
pHeader->minz = m_minPoint.z;
|
|
||||||
pHeader->maxx = m_maxPoint.x;
|
|
||||||
pHeader->maxy = m_maxPoint.y;
|
|
||||||
pHeader->maxz = m_maxPoint.z;
|
|
||||||
|
|
||||||
|
|
||||||
__uint16_t* index_data = getIndexData();
|
__uint16_t* index_data = getIndexData();
|
||||||
for (std::vector<__uint16_t>::const_iterator itr = mi.vertex_indexes.begin(); itr != mi.vertex_indexes.end(); itr++) {
|
for (std::vector<__uint16_t>::const_iterator itr = mi.vertex_indexes.begin(); itr != mi.vertex_indexes.end(); itr++) {
|
||||||
@@ -765,14 +754,9 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 KRMesh::getMinPoint() const
|
const AABB& KRMesh::getExtents() const
|
||||||
{
|
{
|
||||||
return m_minPoint;
|
return m_extents;
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 KRMesh::getMaxPoint() const
|
|
||||||
{
|
|
||||||
return m_maxPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int KRMesh::getLODCoverage() const
|
int KRMesh::getLODCoverage() const
|
||||||
|
|||||||
@@ -140,8 +140,7 @@ public:
|
|||||||
|
|
||||||
float getMaxDimension();
|
float getMaxDimension();
|
||||||
|
|
||||||
hydra::Vector3 getMinPoint() const;
|
const hydra::AABB& getExtents() const;
|
||||||
hydra::Vector3 getMaxPoint() const;
|
|
||||||
|
|
||||||
class Submesh
|
class Submesh
|
||||||
{
|
{
|
||||||
@@ -258,11 +257,7 @@ private:
|
|||||||
|
|
||||||
bool m_hasTransparency;
|
bool m_hasTransparency;
|
||||||
|
|
||||||
|
hydra::AABB m_extents;
|
||||||
hydra::Vector3 m_minPoint, m_maxPoint;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -272,12 +267,14 @@ private:
|
|||||||
int32_t vertex_count;
|
int32_t vertex_count;
|
||||||
int32_t submesh_count;
|
int32_t submesh_count;
|
||||||
int32_t bone_count;
|
int32_t bone_count;
|
||||||
float minx, miny, minz, maxx, maxy, maxz; // Axis aligned bounding box, in model's coordinate space
|
hydra::AABB extents; // Axis aligned bounding box, in model's coordinate space
|
||||||
int32_t index_count;
|
int32_t index_count;
|
||||||
int32_t index_base_count;
|
int32_t index_base_count;
|
||||||
unsigned char reserved[444]; // Pad out to 512 bytes
|
unsigned char reserved[444]; // Pad out to 512 bytes
|
||||||
} pack_header;
|
} pack_header;
|
||||||
|
|
||||||
|
static_assert(sizeof(pack_header) == 512);
|
||||||
|
|
||||||
vector<Submesh> m_submeshes;
|
vector<Submesh> m_submeshes;
|
||||||
int m_vertex_attribute_offset[KRENGINE_NUM_ATTRIBUTES];
|
int m_vertex_attribute_offset[KRENGINE_NUM_ATTRIBUTES];
|
||||||
int m_vertex_size;
|
int m_vertex_size;
|
||||||
|
|||||||
Reference in New Issue
Block a user