// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/ISerializable.h" #include "Engine/Core/Types/DateTime.h" #include "Engine/Core/Math/Triangle.h" #include "Engine/Core/Collections/Dictionary.h" #include "Engine/Physics/CollisionData.h" #include "Engine/Content/AssetReference.h" #include "Engine/Content/Assets/RawDataAsset.h" #include "Engine/Content/Assets/Model.h" class Scene; namespace CSG { /// /// CSG geometry data container (used per scene). /// class SceneCSGData : public ISerializable { private: Scene* _scene; public: /// /// Initializes a new instance of the class. /// /// The parent scene. SceneCSGData(Scene* scene); public: /// /// CSG mesh building action time (registered by CSG::Builder, in UTC format). Invalid if not build by active engine instance. /// DateTime BuildTime; /// /// The model mesh (used for rendering). /// AssetReference Model; /// /// The CSG mesh raw data. /// AssetReference Data; /// /// The CSG mesh collision data. /// AssetReference CollisionData; /// /// The brush data locations lookup for faster searching though Data container. /// Dictionary DataBrushLocations; /// /// The post CSG build action. Called by the CSGBuilder after CSG mesh building end. /// Action PostCSGBuild; public: /// /// Build CSG geometry for the given scene. /// /// The timeout to wait before building CSG (in milliseconds). void BuildCSG(float timeoutMs = 50) const; /// /// Determines whether this container has CSG data linked. /// bool HasData() const; public: struct SurfaceData { Array Triangles; bool Intersects(const Ray& ray, Real& distance, Vector3& normal); }; /// /// Tries the get the brush surface data (may fail if data is missing or given brush surface doesn't result with any triangle). /// /// The brush identifier. /// Index of the brush surface. /// The output data. /// True if found data, otherwise false. bool TryGetSurfaceData(const Guid& brushId, int32 brushSurfaceIndex, SurfaceData& outData); private: void OnDataChanged(); public: // [ISerializable] void Serialize(SerializeStream& stream, const void* otherObj) override; void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override; }; };