Skip to content

Commit 77a1ef4

Browse files
committed
Fix-up more object animation problems
Now stuff will properly spin around! As a side benefit, models are now orientated and scaled correctly everywhere.
1 parent 5b34844 commit 77a1ef4

16 files changed

Lines changed: 120 additions & 74 deletions

File tree

apps/armoury/src/gearview.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,15 @@ void GearView::updatePart()
343343
maxLod = std::max(mdl.num_lod, maxLod);
344344

345345
gearAddition.bodyId = physis_get_race_code(fallbackRace, fallbackTribe, currentGender);
346+
347+
Transformation transformation{};
348+
transformation.scale[0] = 1;
349+
transformation.scale[1] = 1;
350+
transformation.scale[2] = 1;
351+
346352
mdlPart->addModel(mdl,
347353
true,
348-
glm::vec3(),
354+
transformation,
349355
sanitizeMdlPath(mdlPath),
350356
materials,
351357
currentLod,
@@ -401,7 +407,12 @@ void GearView::updatePart()
401407
}
402408
}
403409

404-
mdlPart->addModel(mdl, true, glm::vec3(), sanitizeMdlPath(mdlPath), materials, currentLod);
410+
Transformation transformation{};
411+
transformation.scale[0] = 1;
412+
transformation.scale[1] = 1;
413+
transformation.scale[2] = 1;
414+
415+
mdlPart->addModel(mdl, true, transformation, sanitizeMdlPath(mdlPath), materials, currentLod);
405416
}
406417
}
407418
};

apps/mateditor/src/materialview.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ void MaterialView::addSphere(physis_Material material)
4747
std::string skelNameStd = skelName.toStdString();
4848
mdlPart->setSkeleton(physis_skeleton_parse(data->platform, physis_sqpack_read(data, skelNameStd.c_str())));
4949

50-
mdlPart->addModel(m_mdl, false, glm::vec3(), QStringLiteral("mdl"), {material}, 0);
50+
Transformation transformation{};
51+
transformation.scale[0] = 1;
52+
transformation.scale[1] = 1;
53+
transformation.scale[2] = 1;
54+
55+
mdlPart->addModel(m_mdl, false, transformation, QStringLiteral("mdl"), {material}, 0);
5156
}
5257

5358
#include "moc_materialview.cpp"

apps/mdlviewer/src/mainwindow.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ void MainWindow::setupActions()
9898

9999
setWindowFilePath(fileName);
100100

101-
part->addModel(mdl, false, glm::vec3(), QStringLiteral("mdl"), {}, 0);
101+
Transformation transformation{};
102+
transformation.scale[0] = 1;
103+
transformation.scale[1] = 1;
104+
transformation.scale[2] = 1;
105+
106+
part->addModel(mdl, false, transformation, QStringLiteral("mdl"), {}, 0);
102107

103108
// Clear layout
104109
QLayoutItem *child = nullptr;

apps/sagasu/src/mainwindow.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,13 @@ void MainWindow::refreshParts(const QString &indexPath, Hash hash, const QString
224224
auto exportButton = new QPushButton(QStringLiteral("Export glTF"));
225225
mdlLayout->addWidget(exportButton);
226226

227+
Transformation transformation{};
228+
transformation.scale[0] = 1;
229+
transformation.scale[1] = 1;
230+
transformation.scale[2] = 1;
231+
227232
auto mdlWidget = new MDLPart(&m_data, fileCache);
228-
mdlWidget->addModel(physis_mdl_parse(m_data.platform, file), false, glm::vec3(), QStringLiteral("mdl"), {}, 0);
233+
mdlWidget->addModel(physis_mdl_parse(m_data.platform, file), false, transformation, QStringLiteral("mdl"), {}, 0);
229234
mdlLayout->addWidget(mdlWidget);
230235

231236
connect(importButton, &QPushButton::clicked, this, [this, mdlWidget](bool) {

extern/libphysis

parts/mdl/mdlpart.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void MDLPart::clear()
8585

8686
void MDLPart::addModel(physis_MDL mdl,
8787
bool skinned,
88-
glm::vec3 position,
88+
Transformation transformation,
8989
const QString &name,
9090
std::vector<physis_Material> materials,
9191
int lod,
@@ -113,7 +113,7 @@ void MDLPart::addModel(physis_MDL mdl,
113113
}
114114

115115
Q_ASSERT(model != nullptr);
116-
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
116+
vkWindow->models.push_back(DrawObjectInstance{name, model, transformation});
117117

118118
Q_EMIT modelChanged();
119119
}
@@ -500,10 +500,10 @@ bool MDLPart::modelExists(const QString &name)
500500
return vkWindow->sourceModels.contains(name);
501501
}
502502

503-
void MDLPart::addExistingModel(const QString &name, glm::vec3 position)
503+
void MDLPart::addExistingModel(const QString &name, Transformation transformation)
504504
{
505505
auto model = vkWindow->sourceModels[name];
506-
vkWindow->models.push_back(DrawObjectInstance{name, model, position});
506+
vkWindow->models.push_back(DrawObjectInstance{name, model, transformation});
507507
}
508508

509509
#include "moc_mdlpart.cpp"

parts/mdl/mdlpart.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public Q_SLOTS:
7070

7171
void addModel(physis_MDL mdl,
7272
bool skinned,
73-
glm::vec3 position,
73+
Transformation transformation,
7474
const QString &name,
7575
std::vector<physis_Material> materials,
7676
int lod,
7777
uint16_t fromBodyId = 101,
7878
uint16_t toBodyId = 101);
7979

80-
void addExistingModel(const QString &name, glm::vec3 position);
80+
void addExistingModel(const QString &name, Transformation transformation);
8181

8282
void removeModel(const physis_MDL &mdl);
8383

parts/scene/animation.cpp

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ float FCurve::atTime(const float time) const
2929
const auto adjustedMomentStart = time - startTime; // Example: 20 - 400
3030
const auto adjustedMoment = adjustedMomentStart / duration; // ???
3131

32-
qInfo() << "Between points:" << startTime << adjustedMoment << endTime;
33-
3432
return std::lerp(startPoint.value, endPoint.value, adjustedMoment);
3533
}
3634

@@ -96,18 +94,27 @@ Animation::Animation(const ObjectScene &scene)
9694
{
9795
processScene(scene);
9896

99-
// TODO: I suspect this won't work out because nested scenes may share IDs, but I'm unsure. Then we would need an animation nesting system similar to
100-
// scenes.
101-
for (const auto &nestedScene : scene.nestedScenes.values()) {
102-
processScene(nestedScene);
103-
}
104-
10597
qInfo() << "Processed" << m_tracks.size() << "timelines with" << m_actorTracks.size() << "actors!";
10698
}
10799

108100
void Animation::update(ObjectScene &scene, const float time)
109101
{
110-
processUpdateScene(scene, time);
102+
for (const auto &[id, track] : m_actorTracks.asKeyValueRange()) {
103+
const auto newTransformation = track->transformationAtTime(time);
104+
if (scene.nestedScenes.contains(id)) {
105+
scene.nestedScenes[id].transformation = newTransformation;
106+
} else {
107+
// TODO: searches through embedded LGBs, but it really should be all objects maybe?
108+
// We really need a proper scene graph anyhow
109+
for (auto &lgb : scene.embeddedLgbs) {
110+
for (uint32_t i = 0; i < lgb.layer_count; i++) {
111+
for (uint32_t j = 0; j < lgb.layers[i].num_objects; j++) {
112+
lgb.layers[i].objects[j].transform = newTransformation;
113+
}
114+
}
115+
}
116+
}
117+
}
111118
}
112119

113120
float Animation::duration() const
@@ -222,30 +229,3 @@ void Animation::processTimeline(const physis_Tmb &timeline)
222229
}
223230
}
224231
}
225-
226-
void printTransformation(const Transformation &transformation)
227-
{
228-
qInfo() << "- pos[x] =" << transformation.translation[0];
229-
qInfo() << "- pos[y] =" << transformation.translation[1];
230-
qInfo() << "- pos[z] =" << transformation.translation[2];
231-
232-
qInfo() << "- rot[x] =" << transformation.rotation[0];
233-
qInfo() << "- rot[y] =" << transformation.rotation[1];
234-
qInfo() << "- rot[z] =" << transformation.rotation[2];
235-
236-
qInfo() << "- scl[x] =" << transformation.scale[0];
237-
qInfo() << "- scl[y] =" << transformation.scale[1];
238-
qInfo() << "- scl[z] =" << transformation.scale[2];
239-
}
240-
241-
void Animation::processUpdateScene(ObjectScene &scene, const float time)
242-
{
243-
for (const auto &[id, track] : m_actorTracks.asKeyValueRange()) {
244-
if (scene.nestedScenes.contains(id)) {
245-
qInfo() << "Updating nested scene" << id;
246-
scene.nestedScenes[id].transformation = track->transformationAtTime(time);
247-
printTransformation(scene.nestedScenes[id].transformation);
248-
qInfo() << "";
249-
}
250-
}
251-
}

parts/scene/animation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class Animation
5454
private:
5555
void processScene(const ObjectScene &scene);
5656
void processTimeline(const physis_Tmb &timeline);
57-
void processUpdateScene(ObjectScene &scene, float time);
5857

5958
QList<Track *> m_tracks;
6059
QHash<uint32_t, Track *> m_actorTracks;

parts/scene/mapview.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ void MapView::addTerrain(QString basePath, physis_Terrain terrain)
6969
}
7070
}
7171

72-
mdlPart->addModel(plateMdl,
73-
false,
74-
glm::vec3(terrain.plates[i].position[0], 0.0f, terrain.plates[i].position[1]),
75-
QStringLiteral("terapart%1").arg(i),
76-
materials,
77-
0);
72+
Transformation transformation{
73+
.translation = {terrain.plates[i].position[0], 0.0f, terrain.plates[i].position[1]},
74+
.rotation = {0, 0, 0},
75+
.scale = {1, 1, 1},
76+
};
77+
78+
mdlPart->addModel(plateMdl, false, transformation, QStringLiteral("terapart%1").arg(i), materials, 0);
7879

7980
// We don't need this, and it will just take up memory
8081
physis_mdl_free(&plateMdl);
@@ -142,9 +143,9 @@ void MapView::processLayer(const physis_Layer &layer, const Transformation &root
142143
a.rotation[2] + b.rotation[2],
143144
},
144145
.scale = {
145-
a.scale[0] + b.scale[0],
146-
a.scale[1] + b.scale[1],
147-
a.scale[2] + b.scale[2],
146+
a.scale[0] * b.scale[0],
147+
a.scale[1] * b.scale[1],
148+
a.scale[2] * b.scale[2],
148149
}};
149150
};
150151

@@ -176,12 +177,7 @@ void MapView::processLayer(const physis_Layer &layer, const Transformation &root
176177
}
177178
}
178179

179-
mdlPart->addModel(plateMdl,
180-
false,
181-
glm::vec3(combinedTransform.translation[0], combinedTransform.translation[1], combinedTransform.translation[2]),
182-
QString::fromStdString(assetPath),
183-
materials,
184-
0);
180+
mdlPart->addModel(plateMdl, false, combinedTransform, QString::fromStdString(assetPath), materials, 0);
185181

186182
// We don't need this, and it will just take up memory
187183
physis_mdl_free(&plateMdl);
@@ -191,8 +187,7 @@ void MapView::processLayer(const physis_Layer &layer, const Transformation &root
191187

192188
physis_free_file(&plateMdlFile);
193189
} else {
194-
mdlPart->addExistingModel(QString::fromStdString(assetPath),
195-
glm::vec3(combinedTransform.translation[0], combinedTransform.translation[1], combinedTransform.translation[2]));
190+
mdlPart->addExistingModel(QString::fromStdString(assetPath), combinedTransform);
196191
}
197192
}
198193
} break;

0 commit comments

Comments
 (0)