|
9 | 9 | #include "Utils/GLMUtil.h" |
10 | 10 |
|
11 | 11 | namespace { |
| 12 | + using namespace Satisfactory3DMap; |
| 13 | + |
12 | 14 | struct SplinePointData { |
13 | 15 | glm::vec3 location; |
14 | 16 | glm::vec3 arriveTangent; |
15 | 17 | glm::vec3 leaveTangent; |
16 | 18 | }; |
17 | 19 |
|
18 | | - std::vector<SplinePointData> getSplineData(const SatisfactorySave::SaveObject& a) { |
| 20 | + std::vector<SplinePointData> getSplineData(const s::SaveObject& a) { |
19 | 21 | if (a.Object == nullptr) { |
20 | 22 | throw std::runtime_error("Invalid Object!"); |
21 | 23 | } |
22 | | - auto& ap = a.Object->Properties.get<SatisfactorySave::ArrayProperty>("mSplineData"); |
23 | | - if (ap.ArrayType() != SatisfactorySave::StructProperty::TypeName) { |
24 | | - throw std::runtime_error("Expect StructProperty!"); |
25 | | - } |
26 | | - |
27 | | - auto& sa = dynamic_cast<SatisfactorySave::StructArray&>(*ap.Value); |
| 24 | + auto& sa = a.Object->Properties.get<s::ArrayProperty>("mSplineData").get<s::StructArray>(); |
28 | 25 | if (sa.StructName() != "SplinePointData") { |
29 | | - throw std::runtime_error("Expect SplinePointData!"); |
| 26 | + throw std::runtime_error("Expect struct SplinePointData!"); |
30 | 27 | } |
31 | 28 |
|
32 | 29 | std::vector<SplinePointData> result; |
33 | 30 | for (const auto& s : sa.Values) { |
34 | | - const auto& ps = dynamic_cast<SatisfactorySave::PropertyStruct&>(*s); |
35 | | - const auto& locationStruct = *ps.Data.get<SatisfactorySave::StructProperty>("Location").Value; |
36 | | - const auto& arriveTangentStruct = *ps.Data.get<SatisfactorySave::StructProperty>("ArriveTangent").Value; |
37 | | - const auto& leaveTangentStruct = *ps.Data.get<SatisfactorySave::StructProperty>("LeaveTangent").Value; |
38 | | - |
39 | | - SplinePointData data; |
40 | | - data.location = |
41 | | - Satisfactory3DMap::glmCast(dynamic_cast<const SatisfactorySave::VectorStruct&>(locationStruct).Data); |
42 | | - data.arriveTangent = Satisfactory3DMap::glmCast( |
43 | | - dynamic_cast<const SatisfactorySave::VectorStruct&>(arriveTangentStruct).Data); |
44 | | - data.leaveTangent = Satisfactory3DMap::glmCast( |
45 | | - dynamic_cast<const SatisfactorySave::VectorStruct&>(leaveTangentStruct).Data); |
| 31 | + const auto& ps = dynamic_cast<s::PropertyStruct&>(*s); |
| 32 | + SplinePointData data{ |
| 33 | + glmCast(ps.Data.get<s::StructProperty>("Location").get<s::VectorStruct>().Data), |
| 34 | + glmCast(ps.Data.get<s::StructProperty>("ArriveTangent").get<s::VectorStruct>().Data), |
| 35 | + glmCast(ps.Data.get<s::StructProperty>("LeaveTangent").get<s::VectorStruct>().Data), |
| 36 | + }; |
46 | 37 |
|
47 | 38 | // transform to [meter] |
48 | 39 | data.location *= glm::vec3(0.01f); |
49 | 40 | data.leaveTangent *= glm::vec3(0.01f); |
50 | 41 | data.arriveTangent *= glm::vec3(0.01f); |
51 | 42 | // transform to world-coords |
52 | | - const auto location_world = (glm::translate(glm::mat4(1.0f), data.location) * |
53 | | - Satisfactory3DMap::glmCast(a.actorHeader().Transform))[3]; |
| 43 | + const auto location_world = |
| 44 | + (glm::translate(glm::mat4(1.0f), data.location) * glmCast(a.actorHeader().Transform))[3]; |
54 | 45 | data.location = glm::vec3(location_world) / location_world.w; |
55 | 46 |
|
56 | 47 | // Subtract actor position, will be later added in shader from global transformation list. |
57 | 48 | // This allows updating the position independently of spline data. |
58 | | - data.location -= |
59 | | - glm::vec3(Satisfactory3DMap::glmCast(a.actorHeader().Transform) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); |
| 49 | + data.location -= glm::vec3(glmCast(a.actorHeader().Transform) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)); |
60 | 50 |
|
61 | 51 | result.emplace_back(data); |
62 | 52 | } |
@@ -92,7 +82,7 @@ namespace { |
92 | 82 | } |
93 | 83 | } // namespace |
94 | 84 |
|
95 | | -Satisfactory3DMap::SplineData::SplineData(const SatisfactorySave::SaveObject& actor) { |
| 85 | +Satisfactory3DMap::SplineData::SplineData(const s::SaveObject& actor) { |
96 | 86 | auto splineData = getSplineData(actor); |
97 | 87 |
|
98 | 88 | length_ = 0.0f; |
|
0 commit comments