From 2ab8528e86737a83dfdd03624d94fd43de29e40e Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 8 Jul 2025 01:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8PrimitiveComponent/MeshComponent?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0GetBoundingBox=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMCore | 2 +- CMSceneGraph | 2 +- example/Basic/RenderBoundBox.cpp | 4 ++-- inc/hgl/component/MeshComponent.h | 11 +++++++++++ inc/hgl/component/PrimitiveComponent.h | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CMCore b/CMCore index 8e733a24..6b97ffdf 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 8e733a241536efcaff8cbff66c8a3a4f1255ed86 +Subproject commit 6b97ffdf79ff978fff89ca5276a21c1a18c98669 diff --git a/CMSceneGraph b/CMSceneGraph index 1e7e4a02..584ac021 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 1e7e4a025cdd03125144e167b62f70a8efdaf245 +Subproject commit 584ac02106791566f6df9a45ccd0678f333efbc7 diff --git a/example/Basic/RenderBoundBox.cpp b/example/Basic/RenderBoundBox.cpp index 65af266e..53fced5d 100644 --- a/example/Basic/RenderBoundBox.cpp +++ b/example/Basic/RenderBoundBox.cpp @@ -231,7 +231,7 @@ private: CreateComponentInfo cci(GetSceneRoot()); { - cci.mat=scale(10,10,1); + cci.mat=ScaleMatrix(10,10,1); rm_plane->component=CreateComponent(&cci,rm_plane->cdp); } @@ -250,7 +250,7 @@ private: { CreateComponentInfo cci(GetSceneRoot()); - cci.mat=rm_torus->component->GetLocalMatrix(); + //cci.mat=rm_torus->component->GetLocalMatrix()*rm_torus->component->GetMesh()->GetBoundingBox(); CreateComponent(&cci,rm_box->cdp); diff --git a/inc/hgl/component/MeshComponent.h b/inc/hgl/component/MeshComponent.h index e1fd60e9..d10d0469 100644 --- a/inc/hgl/component/MeshComponent.h +++ b/inc/hgl/component/MeshComponent.h @@ -101,6 +101,17 @@ public: return mcd->mesh; } + const bool GetBoundingBox(AABB &box) const override + { + Mesh *mesh=GetMesh(); + + if (!mesh) + return false; + + box=mesh->GetBoundingBox(); + return true; + } + public: Pipeline *GetPipeline() const diff --git a/inc/hgl/component/PrimitiveComponent.h b/inc/hgl/component/PrimitiveComponent.h index 38452530..678f1750 100644 --- a/inc/hgl/component/PrimitiveComponent.h +++ b/inc/hgl/component/PrimitiveComponent.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include COMPONENT_NAMESPACE_BEGIN @@ -15,6 +17,20 @@ public: using SceneComponent::SceneComponent; virtual ~PrimitiveComponent()=default; + + virtual const bool GetBoundingBox(AABB &box) const =0; + + const bool GetBoundingBox(OBB &box) + { + AABB aabb; + + if(!GetBoundingBox(aabb)) + return false; + + box.Set(GetLocalToWorldMatrix(),aabb); + + return true; + } };//class PrimitiveComponent COMPONENT_NAMESPACE_END