cntrl/src/render/models.hpp

110 lines
4.1 KiB
C++

#pragma once
#include <string>
#include "raylib.h"
class ShadowMap;
// Low-poly GLB actors authored in Blender (tools/blender/build_enemies.py).
// All models are metres, origin at the feet, facing +Z (the game camera).
// The set-dressing models share the same one-mesh / painted-vertex pipeline.
enum class ActorModel {
Guard, HissStaff, MoldSpore, HissBrute, HissGhost, Shard,
Hotline, TV, Pedestal, Duck, Cabinet, Crate, Debris, Switch,
OfficeDesk, MeetingTable, OfficeChair, Computer, Plant, Sofa, FloorLamp,
Partition, GarbageCan, DocumentStack, LooseSheet,
PhoneTable, CaseFrame, CaseGlass, // projector-screen blackout ritual
ArchiveShelf, ThermoFrame, ThermoPanel,
RoundBasic, RoundTuned, RoundOvercharge, MuzzleFlash,
Count
};
class ModelBank {
public:
void init();
void shutdown();
bool ready() const { return ready_; }
// Frame-wide shader uniforms (time / corruption / camera).
void begin_frame(float time, float corruption, Vector3 camera_pos);
void set_shadow(const ShadowMap& shadow, bool enabled);
void begin_shadow_frame(float time);
void set_depth_pass(bool on) { depth_pass_ = on; }
void draw_shadow(ActorModel id, Vector3 pos, float yaw, float scale,
float walk = 0.0f, float stagger = 0.0f,
float phase = 0.0f, Vector3 stretch = {0.0f, 0.0f, 0.0f});
// Draws one actor. `flash` is a 0..1 hit flash; `yaw` rotates around Y.
// `outline` adds a back-face ink silhouette (guard / bosses, not the horde).
// `stretch` overrides the uniform scale per axis when non-zero (thermo
// door frames scale across a threshold without growing taller).
// `alpha` < 1 draws the model with depth-mask-free alpha blending (glass).
void draw(ActorModel id, Vector3 pos, float yaw, float scale, Color tint,
float flash = 0.0f, bool outline = false, float walk = 0.0f,
float stagger = 0.0f, float phase = 0.0f, float hiss = 0.0f,
Vector3 stretch = {0.0f, 0.0f, 0.0f}, float alpha = 1.0f);
// Plays a named GLB action on a skinned model (dt in seconds, 60 fps clips).
// blend_seconds > 0 cross-fades from the outgoing clip into the new one via
// raylib's two-animation blend; 0 keeps the old hard cut.
void update_animation(ActorModel id, const char* name, float dt,
float blend_seconds = 0.0f);
// Per-model visual height, used for health bars / floating labels.
static float height(ActorModel id);
static bool actor_from_name(const std::string& name, ActorModel& id);
private:
struct Entry {
Model model{};
ModelAnimation* animations = nullptr;
int animation_count = 0;
int current_animation = -1;
float animation_clock = 0.0f;
int blend_from = -1; // outgoing clip during a cross-fade
float blend_from_clock = 0.0f;
float blend_time = 0.0f;
float blend_duration = 0.0f; // 0 => no cross-fade in progress
bool loaded = false;
};
static const char* file_name(ActorModel id);
void draw_fallback(ActorModel id, Vector3 pos, float yaw, float scale, Color tint);
Entry entries_[static_cast<int>(ActorModel::Count)];
Shader shader_{};
Shader depth_shader_{};
Texture2D ramp_{};
int loc_time_ = -1;
int loc_alpha_ = -1;
int loc_flash_ = -1;
int loc_corruption_ = -1;
int loc_camera_ = -1;
int loc_outline_ = -1;
int loc_glow_ = -1;
int loc_ramp_ = -1;
int loc_walk_ = -1;
int loc_stagger_ = -1;
int loc_phase_ = -1;
int loc_rig_ = -1;
int loc_rig_scale_ = -1;
int loc_rig_mode_ = -1;
int loc_hiss_ = -1;
int loc_light_vp_ = -1;
int loc_shadow_map_ = -1;
int loc_shadow_darkness_ = -1;
int loc_depth_time_ = -1;
int loc_depth_walk_ = -1;
int loc_depth_stagger_ = -1;
int loc_depth_phase_ = -1;
int loc_depth_rig_ = -1;
int loc_depth_rig_scale_ = -1;
int loc_depth_rig_mode_ = -1;
bool shader_ok_ = false;
bool depth_ok_ = false;
bool depth_pass_ = false;
bool ready_ = false;
};