14#include <unordered_map>
21 void V3(std::ostream& o,
const T& v)
29 std::istringstream& s,
41 const std::filesystem::path& path)
43 std::ofstream out(path);
48 out <<
"NOJOB_SCENE 1\n";
49 out << std::setprecision(9);
52 const_cast<Scene&
>(scene);
55 mutableScene.GetEntities())
69 << std::quoted(tag.Tag)
90 out <<
"LAYER " << layer.
Layer <<
'\n';
99 << int(c.ProjectionType) <<
' '
101 << c.PerspectiveFOV <<
' '
102 << c.PerspectiveNear <<
' '
103 << c.PerspectiveFar <<
' '
104 << c.OrthographicSize <<
' '
105 << c.OrthographicNear <<
' '
115 out <<
"DIRECTIONAL ";
121 << c.CastShadows <<
' '
138 << c.CastShadows <<
' '
155 << c.InnerAngle <<
' '
156 << c.OuterAngle <<
' '
157 << c.CastShadows <<
' '
167 out <<
"AUDIO_SOURCE_V2 "
168 << std::quoted(c.ClipPath) <<
' '
173 << c.SpatialBlend <<
' '
174 << c.MinDistance <<
' '
175 << c.MaxDistance <<
' '
185 out <<
"AUDIO_LISTENER "
195 out <<
"PARTICLE_SYSTEM_V2 "
199 << c.StartLifetime <<
' '
200 << c.LifetimeRandom <<
' '
201 << c.StartSpeed <<
' '
202 << c.SpeedRandom <<
' '
203 << c.StartSize <<
' '
204 << c.SizeRandom <<
' '
205 << c.StartColor.r <<
' '
206 << c.StartColor.g <<
' '
207 << c.StartColor.b <<
' '
208 << c.StartColor.a <<
' '
209 << c.EndColor.r <<
' '
210 << c.EndColor.g <<
' '
211 << c.EndColor.b <<
' '
212 << c.EndColor.a <<
' '
213 << c.EndSizeMultiplier <<
' '
214 << c.EmissionRate <<
' '
215 << c.MaxParticles <<
' '
216 << c.Direction.x <<
' '
217 << c.Direction.y <<
' '
218 << c.Direction.z <<
' '
219 << c.Gravity.x <<
' '
220 << c.Gravity.y <<
' '
221 << c.Gravity.z <<
' '
222 <<
static_cast<int>(c.Shape) <<
' '
223 << c.ShapeRadius <<
' '
224 << c.ConeAngle <<
' '
225 <<
static_cast<int>(c.BlendMode) <<
' '
226 << std::quoted(c.TexturePath)
238 c.Animation->SourcePath())
243 << std::quoted(source) <<
' '
244 << c.ClipIndex <<
' '
256 << std::quoted(c.ScriptName) <<
' '
260 for (
const auto& [name, value] :
263 out <<
"SCRIPT_FIELD "
264 << std::quoted(name) <<
' '
265 << int(value.Type) <<
' ';
272 else if (value.Type ==
277 else if (value.Type ==
284 out << std::quoted(value.String);
305 << int(c.Type) <<
' '
320 out <<
"NAV_AGENT_V2 "
323 << c.StoppingDistance <<
' ';
325 V3(out, c.Destination);
328 << c.HasDestination <<
' '
337 out <<
"PERCEPTION_V1 "
339 << c.DetectionMask <<
' '
340 << c.DetectionRadius <<
' '
341 << c.FieldOfView <<
' '
342 << c.EyeHeight <<
' '
343 << c.MemoryDuration <<
' '
344 << c.UpdateInterval <<
' '
345 << c.DebugDraw <<
'\n';
359 << c.Material.Friction <<
' '
360 << c.Material.Bounciness
371 << c.IsTrigger <<
' '
372 << c.Material.Friction <<
' '
373 << c.Material.Bounciness
385 << c.IsTrigger <<
' '
386 << c.Material.Friction <<
' '
387 << c.Material.Bounciness
401 out <<
"MESH CUBE\n";
422 out <<
"MATERIAL_V2 "
427 << m->Metallic() <<
' '
428 << m->Roughness() <<
' '
429 << m->AmbientOcclusion() <<
' '
430 << m->NormalStrength() <<
' ';
437 << m->EmissiveStrength() <<
' '
438 << m->UseTexture() <<
' '
452 m->GetNormalTexture())
455 const auto metallic =
457 m->GetMetallicTexture())
460 const auto roughness =
462 m->GetRoughnessTexture())
470 const auto emissive =
472 m->GetEmissiveTexture())
476 << std::quoted(albedo) <<
' '
477 << std::quoted(normal) <<
' '
478 << std::quoted(metallic) <<
' '
479 << std::quoted(roughness) <<
' '
480 << std::quoted(ao) <<
' '
481 << std::quoted(emissive)
493 const std::filesystem::path& path,
494 const std::shared_ptr<Mesh>& defaultMesh,
495 const std::shared_ptr<Material>& defaultMaterial)
497 std::ifstream in(path);
523 std::uint32_t parentHandle =
526 bool materialUseTextureExplicit =
532 std::uint32_t oldParent;
535 std::vector<ParentRequest>
547 std::istringstream s(line);
559 >> std::quoted(name);
565 materialUseTextureExplicit =
570 std::uint32_t
>(id)] =
577 else if (k ==
"LAYER")
589 else if (k ==
"TRANSFORM")
607 else if (k ==
"PARENT")
620 else if (k ==
"CAMERA")
640 else if (k ==
"DIRECTIONAL")
655 else if (k ==
"POINT")
671 else if (k ==
"SPOT")
689 else if (k ==
"AUDIO_SOURCE")
702 else if (k ==
"AUDIO_SOURCE_V2")
719 else if (k ==
"AUDIO_LISTENER")
728 else if (k ==
"ANIMATOR")
730 std::string animationPath;
738 s >> std::quoted(animationPath)
744 if (!animationPath.empty())
755 animation->HasAnimations())
793 "Scene animation load failed: " +
798 else if (k ==
"PARTICLE_SYSTEM")
824 else if (k ==
"PARTICLE_SYSTEM_V2")
875 else if (k ==
"SCRIPT")
908 else if (k ==
"SCRIPT_V2")
912 std::size_t fieldCount =
926 k ==
"SCRIPT_FIELD" &&
934 s >> std::quoted(name)
959 s >> std::quoted(v.
String);
970 script.Fields[name] = v;
972 else if (k ==
"RIGIDBODY")
993 else if (k ==
"NAV_AGENT" ||
1006 if (k ==
"NAV_AGENT_V2")
1010 std::max(c.
Speed, 0.0f);
1021 else if (k ==
"PERCEPTION_V1")
1044 else if (k ==
"BOX")
1059 else if (k ==
"SPHERE")
1071 else if (k ==
"CAPSULE")
1084 else if (k ==
"MESH")
1088 s >> std::quoted(mp);
1109 "Scene mesh load failed, using fallback: " +
1118 else if (k ==
"MATERIAL")
1133 >> m->AmbientOcclusion()
1134 >> m->NormalStrength();
1138 m->EmissiveColor());
1140 s >> m->EmissiveStrength();
1156 else if (k ==
"MATERIAL_V2")
1177 >> m->AmbientOcclusion()
1178 >> m->NormalStrength();
1182 m->EmissiveColor());
1184 s >> m->EmissiveStrength()
1187 >> m->AlphaCutoff();
1195 materialUseTextureExplicit =
1216 std::string metallic;
1217 std::string roughness;
1219 std::string emissive;
1221 s >> std::quoted(albedo)
1222 >> std::quoted(normal)
1223 >> std::quoted(metallic)
1224 >> std::quoted(roughness)
1226 >> std::quoted(emissive);
1235 [](
const std::string& path)
1247 if (!albedo.empty())
1252 if (!materialUseTextureExplicit)
1259 m->SetNormalTexture(
1262 m->SetMetallicTexture(
1265 m->SetRoughnessTexture(
1271 m->SetEmissiveTexture(
Animation declarations for the Animation subsystem.
AssetManager declarations for the Asset subsystem.
Components declarations for the Scenes and Native Scripting subsystem.
Log declarations for the Core subsystem.
Material declarations for the Rendering subsystem.
Mesh declarations for the Rendering subsystem.
Scene declarations for the Scenes and Native Scripting subsystem.
Scene serialization and deserialization.
static std::shared_ptr< AnimationAsset > Load(const std::filesystem::path &path)
static std::filesystem::path ToProjectRelative(const std::filesystem::path &path)
static std::filesystem::path GetTexturePath(const std::shared_ptr< Texture2D > &texture)
static std::shared_ptr< Mesh > LoadMesh(const std::filesystem::path &path)
static std::shared_ptr< Texture2D > LoadTexture(const std::filesystem::path &path)
static std::filesystem::path GetMeshPath(const std::shared_ptr< Mesh > &mesh)
std::uint32_t GetHandle() const
T & AddComponent(Args &&... args)
bool HasComponent() const
static void Warn(std::string_view message)
std::vector< Entity > GetEntities()
bool SetParent(Entity child, Entity parent, bool keepWorldTransform=true)
Entity CreateEntity(const std::string &name="Entity")
void DestroyEntity(Entity entity)
std::vector< NativeScriptComponent > & GetAdditionalNativeScripts(std::uint32_t handle)
static bool Load(Scene &scene, const std::filesystem::path &path, const std::shared_ptr< Mesh > &defaultMesh, const std::shared_ptr< Material > &defaultMaterial)
static bool Save(const Scene &scene, const std::filesystem::path &path)
constexpr std::uint32_t Default
constexpr std::uint32_t MaxLayers
std::shared_ptr< AnimationAsset > Animation
CameraProjectionType ProjectionType
std::shared_ptr< Mesh > MeshAsset
std::shared_ptr< Material > MaterialAsset
std::unordered_map< std::string, ScriptFieldValue > Fields
ParticleBlendMode BlendMode
std::uint32_t MaxParticles
static ScriptFieldValue MakeFloat(float value)
static ScriptFieldValue MakeVec3(glm::vec3 value)