summaryrefslogtreecommitdiff
path: root/src/port/resource/importers/ColPolyFactory.cpp
blob: 91ec46020959f30c996ce8fec61cdf4589f3ba72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "ColPolyFactory.h"
#include "../type/ColPoly.h"
#include "spdlog/spdlog.h"

namespace SF64 {
std::shared_ptr<Ship::IResource> ResourceFactoryBinaryColPolyV0::ReadResource(std::shared_ptr<Ship::File> file) {
    if (!FileHasValidFormatAndReader(file)) {
        return nullptr;
    }

    auto colPoly = std::make_shared<ColPoly>(file->InitData);
    auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);

    auto colPolysCount = reader->ReadUInt32();

    SPDLOG_INFO("ColPolyCount: {}", colPolysCount);

    for (uint32_t i = 0; i < colPolysCount; i++) {
        uint16_t triX  = reader->ReadUInt16();
        uint16_t triY  = reader->ReadUInt16();
        uint16_t triZ  = reader->ReadUInt16();
        Vec3s tri = {triX, triY, triZ};
        uint16_t normX = reader->ReadUInt16();
        uint16_t normY = reader->ReadUInt16();
        uint16_t normZ = reader->ReadUInt16();
        Vec3s norm = {normX, normY, normZ};
        uint32_t dist  = reader->ReadInt32();
        colPoly->mColPolys.emplace_back(tri, 0, norm, 0, dist);
    }

    return colPoly;
}
} // namespace LUS