coastline 0.0.4
Loading...
Searching...
No Matches
decalcar.h
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstddef>
10#include <cstdint>
11#include <filesystem>
12#include <optional>
13#include <span>
14#include <string>
15#include <vector>
16
17#include <nlohmann/json.hpp>
18
19#include "common/types.h"
20#include "gltfdocument.h"
21
22namespace coastline {
23
25inline constexpr int DECAL_SLOTS = 10;
26
28inline constexpr int CAR_MATERIALS = 12;
29
31inline constexpr int CAR_MATERIAL_PAINT = 2;
32
34inline constexpr int CAR_MATERIAL_HEADLIGHTS = 10;
35
37inline constexpr int CAR_MATERIAL_REAR_LIGHTS = 11;
38
43 int width = 0;
44 int height = 0;
45};
46
48class DecalCar {
49public:
58
63 DecalTexture Texture(int material) const;
68 bool HasMaterial(int material) const;
72 bool ImagePanels() const;
74 int PanelCount() const;
81 std::vector<u8> PanelPixels(int panel) const;
99 std::size_t PixelOffset(int x, int y, int width) const;
100
106 u8 *Texels(int material);
107
109 const u8 *End() const;
110
113
121
127 const u8 *Mask(int slot) const;
128
134 u16 PaletteColor(int material, int entry) const;
135
144 void SetPaletteColor(int material, int entry, u16 color);
145
155
163
166
167private:
168 DecalCar() = default;
169 bool LoadImagePanels();
171 std::filesystem::path m_directory;
172 nlohmann::ordered_json m_images;
174 std::vector<DecalTexture> m_imageTextures;
175 std::vector<bool> m_imageDecals;
176 std::vector<u8> m_bytes;
177 bool m_imagePanels = false;
178 std::vector<std::vector<u8>> m_basePixels;
179 std::uint32_t m_imageKey = 2166136261u;
180};
181
191inline int TexelOffset(int x, int y, int width) {
192 return (((y & 1) << 3 ^ x) >> 1) + y * (width >> 1);
193}
194
195} // namespace coastline
u8 * Texels(int material)
bool ImagePanels() const
DecalTexture Texture(int material) const
std::size_t PixelOffset(int x, int y, int width) const
Locate a packed pixel in linear image layers or console body-panel rows.
const u8 * Mask(int slot) const
bool RestoreEditableData(std::span< const u8 > data)
Restore editable texels and palettes without invalidating texture pointers.
u16 PaletteColor(int material, int entry) const
std::optional< std::filesystem::path > WriteImages(const std::filesystem::path &directory) const
Write painted images and an image-override glTF document in imported image order.
const u8 * End() const
std::vector< u8 > NoteHeader() const
bool HasMaterial(int material) const
bool ValidNote(std::span< const u8 > note) const
Validate the save header, complete panel payloads, and palette before loading.
std::vector< u8 > PanelPixels(int panel) const
Composite a numbered panel over its imported RGBA pixels.
std::string DecalNote() const
std::optional< GltfDocument > ImageDocument() const
Build the image-override document of WriteImages() in memory, with each image in a buffer view.
static std::optional< DecalCar > Load(const std::filesystem::path &directory)
Reconstruct editable textures from an imported car document and its images.
void SetPaletteColor(int material, int entry, u16 color)
Replace one material palette entry without changing its indexed texels.
int PanelCount() const
std::vector< u8 > CopyEditableData() const
const std::filesystem::path & Directory() const
Definition assetimport.h:11
constexpr int DECAL_SLOTS
The decals of a car, each the texture of the material of the same number.
Definition decalcar.h:25
int TexelOffset(int x, int y, int width)
The byte of a texel of a 4-bit texture as the console loads it in one block, the 64-bit words of each...
Definition decalcar.h:191
constexpr int CAR_MATERIAL_HEADLIGHTS
The material whose palette is the headlights.
Definition decalcar.h:34
constexpr int CAR_MATERIAL_PAINT
The material whose palette is the paint, saved with the decals.
Definition decalcar.h:31
constexpr int CAR_MATERIALS
The materials of a car whose palettes the colour of the car paints.
Definition decalcar.h:28
constexpr int CAR_MATERIAL_REAR_LIGHTS
The material whose palette is the rear lights.
Definition decalcar.h:37
The byte offsets and dimensions of an indexed model texture or numbered paint layer.
Definition decalcar.h:40
std::size_t palette
Definition decalcar.h:42
std::size_t texels
Definition decalcar.h:41
int width
Definition decalcar.h:43
int height
Definition decalcar.h:44
The integer and floating-point types of the console, for headers shared with Windows.
unsigned short u16
Definition ultratypes.h:19
unsigned char u8
Definition ultratypes.h:18