1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Resources/BsResource.h"
7#include "Math/BsVector3I.h"
8#include "Math/BsAABox.h"
9#include "Importer/BsSpecificImporter.h"
10
11namespace bs
12{
13 namespace ct { class VectorField; }
14
15 /** @addtogroup Particles
16 * @{
17 */
18
19 /** Descriptor structure used for initialization of a VectorField. */
20 struct BS_SCRIPT_EXPORT(m:Particles,pl:true,n:VectorFieldOptions) VECTOR_FIELD_DESC
21 {
22 /** Number of entries in the vector field along the X axis. */
23 UINT32 countX = 1;
24
25 /** Number of entries in the vector field along the Y axis. */
26 UINT32 countY = 1;
27
28 /** Number of entries in the vector field along the Z axis. */
29 UINT32 countZ = 1;
30
31 /** Spatial bounds of the vector field. */
32 AABox bounds = AABox::BOX_EMPTY;
33 };
34
35 /** @} */
36
37 /** @addtogroup Implementation
38 * @{
39 */
40
41 namespace detail
42 {
43 /** Common functionality for both the sim and core thread variants of VectorField. */
44 template<bool Core>
45 class BS_CORE_EXPORT TVectorField
46 {
47 public:
48 using TextureType = SPtr<CoreVariantType<Texture, Core>>;
49
50 TVectorField() = default;
51 TVectorField(const VECTOR_FIELD_DESC& desc)
52 :mDesc(desc)
53 { }
54 virtual ~TVectorField() = default;
55
56 /** Returns the internal texture representing the vector field. */
57 TextureType getTexture() const { return mTexture; }
58
59 /** Returns a structure describing the properties of the object. */
60 const VECTOR_FIELD_DESC& getDesc() const { return mDesc; }
61
62 protected:
63 VECTOR_FIELD_DESC mDesc;
64 TextureType mTexture;
65 };
66 }
67
68 /** @} */
69
70 /** @addtogroup Particles
71 * @{
72 */
73
74 /**
75 * Represents a three dimensional field of vectors. It is represented by spatial bounds which are split into a grid
76 * of values with user-defined density, where each grid cell is assigned a vector.
77 */
78 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles) VectorField : public Resource, public detail::TVectorField<false>
79 {
80 public:
81 /** Retrieves a core implementation of a vector field usable only from the core thread. */
82 SPtr<ct::VectorField> getCore() const;
83
84 /************************************************************************/
85 /* STATICS */
86 /************************************************************************/
87
88 /**
89 * Creates a new vector field.
90 *
91 * @param[in] desc Description of the vector field to create.
92 * @param[in] values Values to assign to the vector field. Number of entries must match
93 * countX * countY * countZ.
94 */
95 BS_SCRIPT_EXPORT(ec:T)
96 static HVectorField create(const VECTOR_FIELD_DESC& desc, const Vector<Vector3>& values);
97
98 /** @name Internal
99 * @{
100 */
101
102 /** Same as create() excepts it creates a pointer to the vector field instead of a handle. */
103 static SPtr<VectorField> _createPtr(const VECTOR_FIELD_DESC& desc, const Vector<Vector3>& values);
104
105 /** Creates the resource without initializing it. */
106 static SPtr<VectorField> _createEmpty();
107
108 /** @} */
109
110 protected:
111 VectorField(const VECTOR_FIELD_DESC& desc, const Vector<Vector3>& values);
112
113 /** @copydoc CoreObject::createCore */
114 SPtr<ct::CoreObject> createCore() const override;
115
116 /************************************************************************/
117 /* SERIALIZATION */
118 /************************************************************************/
119 public:
120 VectorField() = default; // Serialization only
121
122 friend class VectorFieldRTTI;
123 static RTTITypeBase* getRTTIStatic();
124 RTTITypeBase* getRTTI() const override;
125 };
126
127 /** @} */
128
129 namespace ct
130 {
131 /** @addtogroup Particles-Internal
132 * @{
133 */
134
135 /** Core thread version of a bs::VectorField. */
136 class BS_CORE_EXPORT VectorField : public CoreObject, public detail::TVectorField<true>
137 {
138 public:
139 VectorField(const VECTOR_FIELD_DESC& desc, const SPtr<Texture>& texture);
140 };
141
142 /** @} */
143 }
144
145 /** @addtogroup Particles-Internal
146 * @{
147 */
148
149 /** Imports vector fields from Fluid Grid ASCII (.fga) files. */
150 class BS_CORE_EXPORT FGAImporter : public SpecificImporter
151 {
152 public:
153 /** @copydoc SpecificImporter::isExtensionSupported */
154 bool isExtensionSupported(const String& ext) const override;
155
156 /** @copydoc SpecificImporter::isMagicNumberSupported */
157 bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const override;
158
159 /** @copydoc SpecificImporter::import */
160 SPtr<Resource> import(const Path& filePath, SPtr<const ImportOptions> importOptions) override;
161 };
162
163 /** @} */
164}
165