2
0
Эх сурвалжийг харах

Hook up octree to spatial components

Panagiotis Christopoulos Charitos 7 жил өмнө
parent
commit
bfcbefc612

+ 6 - 0
src/anki/scene/SceneGraph.h

@@ -228,6 +228,12 @@ anki_internal:
 		return m_earlyZDist;
 	}
 
+	Octree& getOctree()
+	{
+		ANKI_ASSERT(m_octree);
+		return *m_octree;
+	}
+
 private:
 	const Timestamp* m_globalTimestamp = nullptr;
 	Timestamp m_timestamp = 0; ///< Cached timestamp

+ 0 - 2
src/anki/scene/Visibility.cpp

@@ -325,8 +325,6 @@ void VisibilityTestTask::test(ThreadHive& hive)
 				// Inside
 				ANKI_ASSERT(spIdx < MAX_U8);
 				sps[count++] = SpatialTemp{&sp, static_cast<U8>(spIdx), sp.getSpatialOrigin()};
-
-				sp.setVisibleByCamera(true);
 			}
 
 			++spIdx;

+ 12 - 4
src/anki/scene/components/SpatialComponent.cpp

@@ -22,20 +22,28 @@ SpatialComponent::SpatialComponent(SceneNode* node, const CollisionShape* shape)
 SpatialComponent::~SpatialComponent()
 {
 	getSceneGraph().getSectorGroup().spatialDeleted(this);
+
+	if(m_placed)
+	{
+		getSceneGraph().getOctree().remove(m_octreeInfo);
+	}
 }
 
 Error SpatialComponent::update(SceneNode&, Second, Second, Bool& updated)
 {
-	m_flags.unset(Flag::VISIBLE_ANY);
-
-	updated = m_flags.get(Flag::MARKED_FOR_UPDATE);
+	updated = m_markedForUpdate;
 	if(updated)
 	{
 		m_shape->computeAabb(m_aabb);
 		getSceneGraph().getSectorGroup().spatialUpdated(this);
-		m_flags.unset(Flag::MARKED_FOR_UPDATE);
+		m_markedForUpdate = false;
+
+		getSceneGraph().getOctree().place(m_aabb, &m_octreeInfo);
+		m_placed = true;
 	}
 
+	m_octreeInfo.reset();
+
 	return Error::NONE;
 }
 

+ 7 - 33
src/anki/scene/components/SpatialComponent.h

@@ -5,8 +5,8 @@
 
 #pragma once
 
-#include <anki/scene/Common.h>
 #include <anki/scene/components/SceneComponent.h>
+#include <anki/scene/Octree.h>
 #include <anki/Collision.h>
 #include <anki/util/BitMask.h>
 #include <anki/util/Enum.h>
@@ -66,13 +66,7 @@ public:
 	/// Check if it's confined in a single sector.
 	Bool getSingleSector() const
 	{
-		return m_flags.get(Flag::SINGLE_SECTOR);
-	}
-
-	/// Confine it or not in a single sector.
-	void setSingleSector(Bool yes)
-	{
-		m_flags.set(Flag::SINGLE_SECTOR, yes);
+		return false;
 	}
 
 	/// Used for sorting spatials. In most object the origin is the center of mass but for cameras the origin is the
@@ -91,19 +85,7 @@ public:
 	/// The derived class has to manually call this method when the collision shape got updated.
 	void markForUpdate()
 	{
-		m_flags.set(Flag::MARKED_FOR_UPDATE);
-	}
-
-	/// Set if visible by a camera
-	void setVisibleByCamera(Bool visible)
-	{
-		m_flags.set(Flag::VISIBLE_CAMERA, visible);
-	}
-
-	/// Check if visible by camera
-	Bool getVisibleByCamera() const
-	{
-		return m_flags.get(Flag::VISIBLE_CAMERA);
+		m_markedForUpdate = true;
 	}
 
 	/// @name SceneComponent overrides
@@ -112,23 +94,15 @@ public:
 	/// @}
 
 private:
-	/// Spatial flags
-	enum class Flag : U8
-	{
-		NONE = 0,
-		VISIBLE_CAMERA = 1 << 1,
-		VISIBLE_LIGHT = 1 << 2,
-		VISIBLE_ANY = VISIBLE_CAMERA | VISIBLE_LIGHT,
-		MARKED_FOR_UPDATE = 1 << 3,
-		SINGLE_SECTOR = 1 << 4
-	};
-	ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(Flag, friend)
+	Bool8 m_markedForUpdate = false;
+	Bool8 m_placed = false;
 
 	const CollisionShape* m_shape;
-	BitMask<Flag> m_flags;
 	Aabb m_aabb; ///< A faster shape
 	Vec4 m_origin = Vec4(MAX_F32, MAX_F32, MAX_F32, 0.0);
 	List<SectorNode*> m_sectorInfo;
+
+	OctreePlaceable m_octreeInfo;
 };
 /// @}