Skip to content

Commit

Permalink
Fixed light export
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Aug 18, 2024
1 parent 1f3bdf8 commit 243125d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
40 changes: 2 additions & 38 deletions src/factories/LightsFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,8 @@ ExportResult LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa
ExportResult LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto light = std::static_pointer_cast<LightsData>(raw)->mLights;
auto writer = LUS::BinaryWriter();
auto size = sizeof(light.l) / sizeof(LightRaw);

WriteHeader(writer, Torch::ResourceType::Lights, 0);

writer.Write(reinterpret_cast<char*>(light.a.l.col), 3);

writer.Write(static_cast<uint32_t>(size));

for(size_t i = 0; i < size; i++) {
writer.Write(reinterpret_cast<char*>(light.l[i].l.col), 3);
writer.Write(reinterpret_cast<char*>(light.l[i].l.dir), 3);
}
writer.Write(reinterpret_cast<char*>(&light), sizeof(Lights1Raw));
writer.Finish(write);
writer.Close();
return std::nullopt;
Expand All @@ -127,33 +117,7 @@ std::optional<std::shared_ptr<IParsedData>> LightsFactory::parse(std::vector<uin
auto decoded = Decompressor::AutoDecode(node, buffer);
auto [_, segment] = Decompressor::AutoDecode(node, buffer);
LUS::BinaryReader reader(segment.data, sizeof(Lights1Raw));

reader.SetEndianness(Torch::Endianness::Big);
Lights1Raw lights;
// Directional light

// Ambient
auto r = reader.ReadUByte();
auto g = reader.ReadUByte();
auto b = reader.ReadUByte();
//auto nil = reader.ReadInt32();
reader.Seek(5, LUS::SeekOffsetType::Current);

// Diffuse copy
auto r2 = reader.ReadUByte();
auto g2 = reader.ReadUByte();
auto b2 = reader.ReadUByte();

reader.Seek(5, LUS::SeekOffsetType::Current);

// Direction
auto x = reader.ReadInt8();
auto y = reader.ReadInt8();
auto z = reader.ReadInt8();

// TODO: This is a hack, but it works for now.
// The struct has several copies/padding. The zeros skip those for gdSPDefLights1.
lights = {r, g, b, 0, r, g, b, 0, r2, g2, b2, 0, r2, g2, b2, 0, x, y, z};

reader.Read((char*) &lights, sizeof(Lights1Raw));
return std::make_shared<LightsData>(lights);
}
2 changes: 0 additions & 2 deletions src/factories/sm64/AnimationFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::v
std::vector<uint16_t> indicesData;
for (size_t i = 0; i < indexLength; i++) {
indicesData.push_back(indices.ReadUInt16());
SPDLOG_INFO("Index: {}", indicesData.back());
}

LUS::BinaryReader values = LUS::BinaryReader(mainData + valuesAddr, valuesSize);
values.SetEndianness(Torch::Endianness::Big);
std::vector<int16_t> valuesData;
for (size_t i = 0; i < valuesSize / sizeof(int16_t); i++) {
valuesData.push_back(values.ReadInt16());
SPDLOG_INFO("Value: {}", valuesData.back());
}

return std::make_shared<AnimationData>(flags, animYTransDivisor, startFrame, loopStart, loopEnd, unusedBoneCount, length, indicesData, valuesData);
Expand Down

0 comments on commit 243125d

Please sign in to comment.