// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "../Actor.h"
#include "../SceneInfo.h"
#include "Engine/Content/JsonAsset.h"
#include "SceneLightmapsData.h"
#include "SceneCSGData.h"
#include "SceneRendering.h"
#include "SceneTicking.h"
class MeshCollider;
class Level;
class NavigationScene;
class ReloadScriptsAction;
///
/// The scene root object that contains a hierarchy of actors.
///
API_CLASS() class FLAXENGINE_API Scene final : public Actor
{
DECLARE_SCENE_OBJECT(Scene);
friend Level;
friend ReloadScriptsAction;
public:
///
/// Finalizes an instance of the class.
///
~Scene();
public:
///
/// The scene metadata.
///
SceneInfo Info;
///
/// The last load time.
///
DateTime LoadTime;
///
/// The last save time.
///
DateTime SaveTime;
public:
///
/// The scene rendering manager.
///
SceneRendering Rendering;
///
/// The scene ticking manager.
///
SceneTicking Ticking;
///
/// The static light manager for this scene.
///
SceneLightmapsData LightmapsData;
///
/// The CSG data container for this scene.
///
CSG::SceneCSGData CSGData;
///
/// The navigation scene (always valid).
///
NavigationScene* Navigation;
///
/// Gets the lightmap settings (per scene).
///
API_PROPERTY(Attributes="EditorDisplay(\"Lightmap Settings\", EditorDisplayAttribute.InlineStyle)")
LightmapSettings GetLightmapSettings() const;
///
/// Sets the lightmap settings (per scene).
///
API_PROPERTY() void SetLightmapSettings(const LightmapSettings& value);
public:
///
/// Removes all baked lightmap textures from the scene.
///
API_FUNCTION() void ClearLightmaps();
///
/// Builds the CSG geometry for the given scene.
///
/// Requests are enqueued till the next game scripts update.
/// The timeout to wait before building CSG (in milliseconds).
API_FUNCTION() void BuildCSG(float timeoutMs = 50);
public:
#if USE_EDITOR
///
/// Gets path to the scene file
///
API_PROPERTY() String GetPath() const;
///
/// Gets filename of the scene file
///
API_PROPERTY() String GetFilename() const;
///
/// Gets path to the scene data folder
///
API_PROPERTY() String GetDataFolderPath() const;
#endif
private:
MeshCollider* TryGetCsgCollider();
StaticModel* TryGetCsgModel();
void CreateCsgCollider();
void CreateCsgModel();
void OnCsgCollisionDataChanged();
void OnCsgModelChanged();
#if COMPILE_WITH_CSG_BUILDER
void OnCSGBuildEnd()
{
if (CSGData.CollisionData && TryGetCsgCollider() == nullptr)
CreateCsgCollider();
if (CSGData.Model && TryGetCsgModel() == nullptr)
CreateCsgModel();
}
#endif
public:
// [Actor]
void Serialize(SerializeStream& stream, const void* otherObj) override;
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override;
void OnDeleteObject() override;
void EndPlay() override;
protected:
// [Scene]
void PostLoad() override;
void PostSpawn() override;
void BeginPlay(SceneBeginData* data) override;
void OnEnable() override;
void OnDisable() override;
void OnTransformChanged() override;
};
///
/// The scene asset.
///
API_CLASS(NoSpawn) class SceneAsset : public JsonAsset
{
DECLARE_ASSET_HEADER(SceneAsset);
protected:
bool IsInternalType() const override
{
return true;
}
};