Add Render Layers to Camera and Render View for masking objects during rendering
This commit is contained in:
@@ -200,3 +200,44 @@ void GameSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* mo
|
||||
DESERIALIZE(XboxScarlettPlatform);
|
||||
DESERIALIZE(AndroidPlatform);
|
||||
}
|
||||
|
||||
void LayersAndTagsSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
||||
{
|
||||
const auto tags = stream.FindMember("Tags");
|
||||
if (tags != stream.MemberEnd())
|
||||
{
|
||||
auto& tagsArray = tags->value;
|
||||
ASSERT(tagsArray.IsArray());
|
||||
Tags.EnsureCapacity(tagsArray.Size());
|
||||
|
||||
// Note: we cannot remove tags at runtime so this should deserialize them in additive mode
|
||||
// Tags are stored as tagIndex in actors so collection change would break the linkage
|
||||
|
||||
for (uint32 i = 0; i < tagsArray.Size(); i++)
|
||||
{
|
||||
auto& v = tagsArray[i];
|
||||
if (v.IsString())
|
||||
{
|
||||
const String tag = v.GetText();
|
||||
if (!Tags.Contains(tag))
|
||||
Tags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto layers = stream.FindMember("Layers");
|
||||
if (layers != stream.MemberEnd())
|
||||
{
|
||||
auto& layersArray = layers->value;
|
||||
ASSERT(layersArray.IsArray());
|
||||
|
||||
for (uint32 i = 0; i < layersArray.Size() && i < 32; i++)
|
||||
{
|
||||
auto& v = layersArray[i];
|
||||
if (v.IsString())
|
||||
Layers[i] = v.GetText();
|
||||
else
|
||||
Layers[i].Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
47
Source/Engine/Core/Config/LayersMask.h
Normal file
47
Source/Engine/Core/Config/LayersMask.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Types/BaseTypes.h"
|
||||
#include "Engine/Serialization/SerializationFwd.h"
|
||||
|
||||
/// <summary>
|
||||
/// The objects layers selection mask (from layers and tags settings). Uses 1 bit per layer (up to 32 layers).
|
||||
/// </summary>
|
||||
API_STRUCT() struct FLAXENGINE_API LayersMask
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(LayersMask);
|
||||
|
||||
/// <summary>
|
||||
/// The layers selection mask.
|
||||
/// </summary>
|
||||
API_FIELD() uint32 Mask = MAX_uint32;
|
||||
|
||||
FORCE_INLINE bool HasLayer(int32 layerIndex) const
|
||||
{
|
||||
return (Mask & (1 << layerIndex)) != 0;
|
||||
}
|
||||
|
||||
bool HasLayer(const StringView& layerName) const;
|
||||
|
||||
bool operator==(const LayersMask& other) const;
|
||||
bool operator!=(const LayersMask& other) const;
|
||||
};
|
||||
|
||||
// @formatter:off
|
||||
namespace Serialization
|
||||
{
|
||||
inline bool ShouldSerialize(const LayersMask& v, const void* otherObj)
|
||||
{
|
||||
return !otherObj || v != *(LayersMask*)otherObj;
|
||||
}
|
||||
inline void Serialize(ISerializable::SerializeStream& stream, const LayersMask& v, const void* otherObj)
|
||||
{
|
||||
stream.Uint(v.Mask);
|
||||
}
|
||||
inline void Deserialize(ISerializable::DeserializeStream& stream, LayersMask& v, ISerializeModifier* modifier)
|
||||
{
|
||||
v.Mask = stream.GetUint();
|
||||
}
|
||||
}
|
||||
// @formatter:on
|
||||
@@ -3,7 +3,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Engine/Core/Config/Settings.h"
|
||||
#include "Engine/Serialization/Json.h"
|
||||
|
||||
/// <summary>
|
||||
/// Layers and objects tags settings.
|
||||
@@ -14,12 +13,12 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(LayersAndTagsSettings);
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// The tags names.
|
||||
/// The tag names.
|
||||
/// </summary>
|
||||
Array<String> Tags;
|
||||
|
||||
/// <summary>
|
||||
/// The layers names.
|
||||
/// The layer names.
|
||||
/// </summary>
|
||||
String Layers[32];
|
||||
|
||||
@@ -31,44 +30,5 @@ public:
|
||||
static LayersAndTagsSettings* Get();
|
||||
|
||||
// [SettingsBase]
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) final override
|
||||
{
|
||||
const auto tags = stream.FindMember("Tags");
|
||||
if (tags != stream.MemberEnd())
|
||||
{
|
||||
auto& tagsArray = tags->value;
|
||||
ASSERT(tagsArray.IsArray());
|
||||
Tags.EnsureCapacity(tagsArray.Size());
|
||||
|
||||
// Note: we cannot remove tags at runtime so this should deserialize them in additive mode
|
||||
// Tags are stored as tagIndex in actors so collection change would break the linkage
|
||||
|
||||
for (uint32 i = 0; i < tagsArray.Size(); i++)
|
||||
{
|
||||
auto& v = tagsArray[i];
|
||||
if (v.IsString())
|
||||
{
|
||||
const String tag = v.GetText();
|
||||
if (!Tags.Contains(tag))
|
||||
Tags.Add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto layers = stream.FindMember("Layers");
|
||||
if (layers != stream.MemberEnd())
|
||||
{
|
||||
auto& layersArray = layers->value;
|
||||
ASSERT(layersArray.IsArray());
|
||||
|
||||
for (uint32 i = 0; i < layersArray.Size() && i < 32; i++)
|
||||
{
|
||||
auto& v = layersArray[i];
|
||||
if (v.IsString())
|
||||
Layers[i] = v.GetText();
|
||||
else
|
||||
Layers[i].Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) final override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user