Skip to content

Commit e5b8822

Browse files
committed
smaller bugfixes
1 parent b8ac9d6 commit e5b8822

File tree

8 files changed

+87
-17
lines changed

8 files changed

+87
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ lib/
55
*.7z
66
*.bat
77
__pycache__/
8+
.cache/

src/mtf_lmt/codecs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ std::string_view RetreiveFromRawString(C *clPtr, std::string_view buffer) {
106106
size_t cBuff = 0;
107107

108108
while (!buffer.empty() && cBuff < buffSize) {
109-
const auto cRef = buffer.at(0);
109+
const int cRef = buffer.at(0);
110110

111111
if (cRef < '0' || cRef > 'F' || (cRef > '9' && cRef < 'A')) {
112112
buffer.remove_prefix(1);
@@ -904,6 +904,9 @@ void Buf_BiLinearRotationQuat4_9bit::Interpolate(
904904
template <class C>
905905
void Buff_EvalShared<C>::ToString(std::string &strBuff,
906906
size_t numIdents) const {
907+
static const char *idents[] = {
908+
"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t",
909+
};
907910
std::stringstream str;
908911
str << std::endl << idents[numIdents];
909912

src/mtf_lmt/internal.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ using namespace revil;
2929

3030
struct LMTFixupStorage;
3131

32-
static const char *idents[] = {
33-
"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t",
34-
};
35-
3632
struct TrackMinMax {
3733
Vector4A16 min;
3834
Vector4A16 max;

src/reng/asset.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void REAsset::Load(BinReaderRef rd) {
4343
void REAssetImpl::Load(BinReaderRef rd) {
4444
const size_t fleSize = rd.GetSize();
4545
rd.ReadContainer(internalBuffer, fleSize);
46+
buffer = internalBuffer.data();
4647
std::vector<void *> ptrStore;
4748
Fixup(ptrStore);
4849
}

src/reng/codecs.cpp

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ struct LinearVector3Controller : RETrackController_internal {
9494
void Evaluate(uint32 id, Vector4A16 &out) const override {
9595
out = dataStorage[id];
9696
}
97+
98+
const char *CodecName() const override {
99+
return "LinearVector3Controller";
100+
}
97101
};
98102

99103
struct BiLinearVector3_5bitController : RETrackController_internal {
@@ -120,6 +124,9 @@ struct BiLinearVector3_5bitController : RETrackController_internal {
120124
out = data & componentMask;
121125
out = ((out * componentMultiplier) * minMaxBounds.min) + minMaxBounds.max;
122126
}
127+
const char *CodecName() const override {
128+
return "BiLinearVector3_5bitController";
129+
}
123130
};
124131

125132
struct BiLinearVector3_10bitController : RETrackController_internal {
@@ -146,6 +153,9 @@ struct BiLinearVector3_10bitController : RETrackController_internal {
146153
out = data & componentMask;
147154
out = ((out * componentMultiplier) * minMaxBounds.min) + minMaxBounds.max;
148155
}
156+
const char *CodecName() const override {
157+
return "BiLinearVector3_10bitController";
158+
}
149159
};
150160

151161
struct BiLinearVector3_21bitController : RETrackController_internal {
@@ -172,6 +182,9 @@ struct BiLinearVector3_21bitController : RETrackController_internal {
172182
out = data & componentMask;
173183
out = ((out * componentMultiplier) * minMaxBounds.min) + minMaxBounds.max;
174184
}
185+
const char *CodecName() const override {
186+
return "BiLinearVector3_21bitController";
187+
}
175188
};
176189

177190
struct BiLinearQuat3_13bitController : RETrackController_internal {
@@ -203,6 +216,9 @@ struct BiLinearQuat3_13bitController : RETrackController_internal {
203216
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
204217
out.QComputeElement();
205218
}
219+
const char *CodecName() const override {
220+
return "BiLinearQuat3_13bitController";
221+
}
206222
};
207223

208224
struct BiLinearQuat3_16bitController : RETrackController_internal {
@@ -224,6 +240,9 @@ struct BiLinearQuat3_16bitController : RETrackController_internal {
224240
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
225241
out.QComputeElement();
226242
}
243+
const char *CodecName() const override {
244+
return "BiLinearQuat3_16bitController";
245+
}
227246
};
228247

229248
struct BiLinearQuat3_18bitController : RETrackController_internal {
@@ -259,6 +278,9 @@ struct BiLinearQuat3_18bitController : RETrackController_internal {
259278
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
260279
out.QComputeElement();
261280
}
281+
const char *CodecName() const override {
282+
return "BiLinearQuat3_18bitController";
283+
}
262284
};
263285

264286
struct BiLinearQuat3_8bitController : RETrackController_internal {
@@ -280,17 +302,23 @@ struct BiLinearQuat3_8bitController : RETrackController_internal {
280302
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
281303
out.QComputeElement();
282304
}
305+
const char *CodecName() const override {
306+
return "BiLinearQuat3_8bitController";
307+
}
283308
};
284309

285310
struct LinearQuat3Controller : LinearVector3Controller {
286311
static constexpr uint32 ID1 = 0xB0112;
287312
static constexpr uint32 ID2 = 0xC0112;
288313

289-
void Evaluate(uint32 id, Vector4A16 &out) const {
314+
void Evaluate(uint32 id, Vector4A16 &out) const override {
290315
LinearVector3Controller::Evaluate(id, out);
291316
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
292317
out.QComputeElement();
293318
}
319+
const char *CodecName() const override {
320+
return "LinearQuat3Controller";
321+
}
294322
};
295323

296324
struct BiLinearQuat3_5bitController : BiLinearVector3_5bitController {
@@ -306,6 +334,9 @@ struct BiLinearQuat3_5bitController : BiLinearVector3_5bitController {
306334
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
307335
out.QComputeElement();
308336
}
337+
const char *CodecName() const override {
338+
return "BiLinearQuat3_5bitController";
339+
}
309340
};
310341

311342
struct BiLinearQuat3_10bitController : BiLinearVector3_10bitController {
@@ -322,6 +353,9 @@ struct BiLinearQuat3_10bitController : BiLinearVector3_10bitController {
322353
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
323354
out.QComputeElement();
324355
}
356+
const char *CodecName() const override {
357+
return "BiLinearQuat3_10bitController";
358+
}
325359
};
326360

327361
struct BiLinearQuat3_21bitController : BiLinearVector3_21bitController {
@@ -338,6 +372,9 @@ struct BiLinearQuat3_21bitController : BiLinearVector3_21bitController {
338372
out *= Vector4A16(1.f, 1.f, 1.f, 0.0f);
339373
out.QComputeElement();
340374
}
375+
const char *CodecName() const override {
376+
return "BiLinearQuat3_21bitController";
377+
}
341378
};
342379

343380
struct LinearSCVector3Controller : RETrackController_internal {
@@ -366,6 +403,9 @@ struct LinearSCVector3Controller : RETrackController_internal {
366403
out[componentID] = retreived;
367404
}
368405
}
406+
const char *CodecName() const override {
407+
return "LinearSCVector3Controller";
408+
}
369409
};
370410

371411
struct BiLinearSCVector3_16bitController : RETrackController_internal {
@@ -399,6 +439,9 @@ struct BiLinearSCVector3_16bitController : RETrackController_internal {
399439
out[componentID] = decompVal;
400440
}
401441
}
442+
const char *CodecName() const override {
443+
return "BiLinearSCVector3_16bitController";
444+
}
402445
};
403446

404447
struct BiLinearSCQuat3Controller : LinearSCVector3Controller {
@@ -409,38 +452,47 @@ struct BiLinearSCQuat3Controller : LinearSCVector3Controller {
409452
static constexpr uint32 ID5 = 0x42112;
410453
static constexpr uint32 ID6 = 0x43112;
411454

412-
void Evaluate(uint32 id, Vector4A16 &out) const {
455+
void Evaluate(uint32 id, Vector4A16 &out) const override {
413456
out[componentID] = dataStorage[id];
414457
out.QComputeElement();
415458
}
459+
const char *CodecName() const override {
460+
return "BiLinearSCQuat3Controller";
461+
}
416462
};
417463

418464
struct BiLinearSCQuat3_16bitController : BiLinearSCVector3_16bitController {
419465
static constexpr uint32 ID1 = 0x21112;
420466
static constexpr uint32 ID2 = 0x22112;
421467
static constexpr uint32 ID3 = 0x23112;
422468

423-
void Evaluate(uint32 id, Vector4A16 &out) const {
469+
void Evaluate(uint32 id, Vector4A16 &out) const override {
424470
const uint16 &retreived = dataStorage[id];
425471
out[componentID] = minMaxBounds.min[1] +
426472
(minMaxBounds.min[0] *
427473
(static_cast<float>(retreived) * componentMultiplier));
428474
out.QComputeElement();
429475
}
476+
const char *CodecName() const override {
477+
return "BiLinearSCQuat3_16bitController";
478+
}
430479
};
431480

432481
struct BiLinearSCQuat3_16bitController_old : BiLinearSCQuat3_16bitController {
433482
static constexpr uint32 ID1 = 0x21112;
434483
static constexpr uint32 ID2 = 0x22112;
435484
static constexpr uint32 ID3 = 0x23112;
436485

437-
void Evaluate(uint32 id, Vector4A16 &out) const {
486+
void Evaluate(uint32 id, Vector4A16 &out) const override {
438487
const uint16 &retreived = dataStorage[id];
439488
out[componentID] = minMaxBounds.max[componentID] +
440489
(minMaxBounds.min[componentID] *
441490
(static_cast<float>(retreived) * componentMultiplier));
442491
out.QComputeElement();
443492
}
493+
const char *CodecName() const override {
494+
return "BiLinearSCQuat3_16bitController_old";
495+
}
444496
};
445497

446498
using ptr_type_ = std::unique_ptr<RETrackController_internal>;

src/reng/motion_43.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ static Vector4A16 slerp(const Vector4A16 &v0, const Vector4A16 &_v1, float t) {
9494
}
9595

9696
void REMotionTrackWorker::GetValue(Vector4A16 &output, float time) const {
97+
// bugfix, some codecs will partialy apply elements, ensure we have identity
98+
output = Vector4A16{};
99+
97100
if (!controller) {
98101
return;
99102
}

src/reng/motion_43.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct RETrackController {
5656
virtual KnotSpan GetSpan(int32 frame) const = 0;
5757
virtual void Evaluate(uint32 id, Vector4A16 &out) const = 0;
5858
virtual ~RETrackController() = default;
59+
virtual const char *CodecName() const = 0;
5960
};
6061

6162
struct RETrackCurve43 {

toolset/re_to_gltf/reasset_to_gltf.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
#include "spike/io/binreader_stream.hpp"
66
#include "spike/io/binwritter_stream.hpp"
77
#include "spike/io/fileinfo.hpp"
8+
#include "spike/master_printer.hpp"
89
#include "spike/uni/motion.hpp"
910
#include "spike/uni/rts.hpp"
1011
#include "spike/uni/skeleton.hpp"
1112
#include <nlohmann/json.hpp>
1213

1314
std::string_view filters[]{
14-
".mot.43$", ".mot.65$", ".mot.78$",
15-
".mot.458$", ".motlist.60$", ".motlist.85$",
16-
".motlist.99$", ".motlist.486$", {},
15+
".mot.43$", ".mot.65$", ".mot.78$", ".mot.458$",
16+
".motlist.60$", ".motlist.85$", ".motlist.99$", ".motlist.486$",
1717
};
1818

1919
static AppInfo_s appInfo{
@@ -32,7 +32,7 @@ class MOTGLTF : GLTF {
3232
void MakeKeyBuffers(const uni::MotionsConst &anims);
3333
void ProcessAnimation(const uni::Motion *anim);
3434
void ProcessSkeletons(const uni::SkeletonsConst &skels);
35-
void Pipeline(const revil::REAsset &asset);
35+
bool Pipeline(const revil::REAsset &asset);
3636

3737
private:
3838
GLTFStream &CommonStream() {
@@ -127,6 +127,7 @@ void MOTGLTF::MakeKeyBuffers(const uni::MotionsConst &anims) {
127127
void MOTGLTF::ProcessAnimation(const uni::Motion *anim) {
128128
gltf::Animation animation;
129129
animation.name = anim->Name();
130+
// PrintInfo(animation.name);
130131
auto &timeData = timesByFramerate.at(anim->FrameRate());
131132
auto &times = timeData.first;
132133
uint32 keyAccessor = timeData.second;
@@ -160,6 +161,9 @@ void MOTGLTF::ProcessAnimation(const uni::Motion *anim) {
160161
curChannel.sampler = animation.samplers.size();
161162
curChannel.target.node = boneRemaps.at(a->BoneIndex());
162163

164+
// PrintInfo(nodes.at(curChannel.target.node).name, ": ", static_cast<const
165+
// REMotionTrackWorker*>(a.get())->controller->CodecName());
166+
163167
animation.samplers.emplace_back();
164168
auto &sampler = animation.samplers.back();
165169
sampler.input = keyAccessIndex;
@@ -245,23 +249,32 @@ void MOTGLTF::ProcessSkeletons(const uni::SkeletonsConst &skels) {
245249
gltfutils::VisualizeSkeleton(*this, infos);
246250
}
247251

248-
void MOTGLTF::Pipeline(const revil::REAsset &asset) {
252+
bool MOTGLTF::Pipeline(const revil::REAsset &asset) {
249253
auto skels = asset.As<uni::SkeletonsConst>();
254+
if (skels->Size() == 0) {
255+
PrintWarning("File doesn't contain skeleton, skipping.");
256+
return false;
257+
}
258+
250259
ProcessSkeletons(skels);
251260
auto anims = asset.As<uni::MotionsConst>();
252261
MakeKeyBuffers(anims);
253262

254263
for (auto a : *anims) {
255264
ProcessAnimation(a.get());
256265
}
266+
267+
return true;
257268
}
258269

259270
void AppProcessFile(AppContext *ctx) {
260271
revil::REAsset asset;
261272
asset.Load(ctx->GetStream());
262273
MOTGLTF main;
263-
main.Pipeline(asset);
264-
BinWritterRef wr(ctx->NewFile(ctx->workingFile.ChangeExtension(".glb")).str);
274+
if (main.Pipeline(asset)) {
275+
BinWritterRef wr(
276+
ctx->NewFile(ctx->workingFile.ChangeExtension(".glb")).str);
265277

266-
main.FinishAndSave(wr, std::string(ctx->workingFile.GetFolder()));
278+
main.FinishAndSave(wr, std::string(ctx->workingFile.GetFolder()));
279+
}
267280
}

0 commit comments

Comments
 (0)