Files
DarkflameServer/dUgcServer/UgcFormats.h
Aaron Kimbrell 7c5d69c1ed feat(ugc): make models like LU Toolbox does, within CPU and memory budgets
Parity with LU Toolbox's Process Model, Bake Lighting and icon renderer, with
its defaults as the settings' defaults:

- Colors from its LU palette (UgcPalette: LU colors, LDD colors mapped to the
  nearest LU one, unknown ones black), transparent bricks at 58.82% opacity, a
  brick transparent only when all of its materials are.
- Color variation: each brick's material gets its HSV value shifted in a 2.224
  gamma by up to 5% (times the color's own amount), from a random number of
  the model, brick and material, so reprocessing gives the same colors in
  every LOD. Icons get none, and the icon renderer's color corrections.
- LODs 0 and 2 with its distance logic, written as NiLODNode/NiRangeLODData
  like its exports and the game's own brick models, shapes divided at 65535
  vertices along the longest side like divide_mesh.
- Ambient occlusion like its AO-only bake: 64 rays per vertex, distance 5,
  after hidden surface removal, transparent bricks neither baked nor
  occluding, glow colors added.
- Icons from its icon scene: 50 mm lens at 53.4/19.5 degrees, sun of 2.5 at
  21/50.3 degrees with soft shadows, grey world light with occlusion; LOD 0's
  hidden surface removal and occlusion are reused for them.
- Optional ground plane for hidden surface removal; stats.json per model and
  the previous version's previews kept for comparing.

Budgets, applied live on config reload: max_cpu_percent (workers account
their thread CPU time and sleep to stay under it, long renders included),
worker_nice, max_memory_mb (jobs are estimated from their brick count and
wait until they fit), max_model_bricks and pause_hours. /status and the
traffic report show CPU, memory and throttling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:31:06 -05:00

61 lines
2.1 KiB
C++

#pragma once
#include <string>
#include <string_view>
#include <vector>
#include "UgcModel.h"
#include "UgcRender.h"
/**
* The files the UGC server writes: the mesh as a Gamebryo .nif the client loads, icons as .png and .dds, and the
* client's .checksum files for its downloads. Pure (data in, bytes out).
*/
namespace UgcFormats {
struct NifShape {
std::string name;
const UgcModel::Mesh* mesh{};
bool transparent{};
};
/**
* A Gamebryo 20.3.0.9 file (user version 0, as the client's own meshes): a root NiNode named `rootName` with one
* NiTriShape per shape (at most 65535 vertices and triangles each: UgcModel::Split), with vertex colors that are
* the diffuse and ambient color (NiVertexColorProperty), a white NiMaterialProperty, and for transparent shapes an
* NiAlphaProperty blending with the vertex alpha.
*/
std::string WriteNif(const std::string& rootName, const std::vector<NifShape>& shapes);
struct NifLod {
float nearDistance{};
float farDistance{};
std::string name; // the level's node, e.g. LOD_0
std::vector<const UgcModel::Mesh*> pieces; // its shapes (UgcModel::Divide's pieces)
};
struct NifLodGroup {
std::string name; // S01_Opaque_Model: the NiLODNode and its shapes
bool transparent{};
std::vector<NifLod> lods;
};
/**
* The layout LU Toolbox exports (setup_lod_data) and the game's own brick models (res/BrickModels/ndmade) have:
* the root node, an NiLODNode per group with NiRangeLODData holding each level's distances, a node per level and
* the level's shapes under it, named like the group. Properties as WriteNif.
*/
std::string WriteLodNif(const std::string& rootName, const std::vector<NifLodGroup>& groups);
// PNG (8-bit RGBA)
std::string EncodePng(const UgcRender::Image& image);
// DDS, uncompressed 32-bit BGRA without mipmaps
std::string EncodeDds(const UgcRender::Image& image);
// Lowercase hex MD5 of `data`
std::string Md5Hex(std::string_view data);
// What the client reads from a UGC file's .checksum: the MD5 and size of the file as it is after inflating it
std::string ChecksumXml(std::string_view data);
}