AVA2 cross-platform client parity baseline
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderCommands3D.h"
|
||||
#include <gr2/gr2.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace ava2 {
|
||||
|
||||
class Gr2ModelInstance {
|
||||
public:
|
||||
static std::unique_ptr<Gr2ModelInstance> Load(const std::string& filepath);
|
||||
|
||||
// Load external animation (.gr2) to animate this model
|
||||
bool LoadExternalAnimation(const std::string& anim_filepath);
|
||||
float GetAnimationDuration() const;
|
||||
|
||||
// Bone queries & attachments
|
||||
bool GetBoneWorldTransform(const std::string& bone_name, float* out_matrix, float animation_time = -1.0f) const;
|
||||
void AttachModel(const std::string& bone_name, std::shared_ptr<Gr2ModelInstance> attachment, const float* offset_matrix = nullptr);
|
||||
void AttachPart(std::shared_ptr<Gr2ModelInstance> part);
|
||||
void DetachAll();
|
||||
|
||||
// Build 3D draw commands for this model and all attached components (weapons, hair, armor parts)
|
||||
std::vector<Render3DDraw> BuildDrawCommands(float animation_time = -1.0f, const float* world_matrix = nullptr);
|
||||
|
||||
// Build draw commands for a skinned part using an external bone palette
|
||||
std::vector<Render3DDraw> BuildDrawCommandsWithPalette(const std::vector<gr2::Mat4>& skin_matrices,
|
||||
const float* world_matrix = nullptr,
|
||||
const gr2::Skeleton* parent_skeleton = nullptr);
|
||||
|
||||
bool GetLocalBounds(float& minX, float& minY, float& minZ, float& maxX, float& maxY, float& maxZ) const;
|
||||
|
||||
const gr2::File& GetFile() const { return *m_file; }
|
||||
const gr2::FileInfo& GetInfo() const { return m_file->file_info(); }
|
||||
|
||||
private:
|
||||
struct AttachedModel {
|
||||
std::string bone_name;
|
||||
std::shared_ptr<Gr2ModelInstance> model;
|
||||
float offset[16];
|
||||
};
|
||||
|
||||
std::unique_ptr<gr2::File> m_file;
|
||||
std::string m_filepath;
|
||||
std::unique_ptr<gr2::File> m_anim_file;
|
||||
std::string m_anim_filepath;
|
||||
|
||||
std::vector<AttachedModel> m_attached_models;
|
||||
std::vector<std::shared_ptr<Gr2ModelInstance>> m_attached_parts;
|
||||
};
|
||||
|
||||
// 3D Scene and Model Renderer (modeled after 40250 pipeline architecture)
|
||||
class Gr2SceneRenderer {
|
||||
public:
|
||||
Gr2SceneRenderer(int width = 1024, int height = 768);
|
||||
~Gr2SceneRenderer();
|
||||
|
||||
void SetCameraLookAt(float eyeX, float eyeY, float eyeZ,
|
||||
float targetX, float targetY, float targetZ,
|
||||
float upX, float upY, float upZ);
|
||||
|
||||
void SetPerspective(float fovYDegrees, float aspect, float zNear, float zFar);
|
||||
|
||||
void SetViewport(int x, int y, int width, int height);
|
||||
|
||||
void Clear(uint32_t color = 0xFF101520, float depth = 1.0f);
|
||||
|
||||
// Rasterize a 3D draw command into the surface using depth buffering and lighting
|
||||
void RenderDraw(SDL_Surface* targetSurface, const Render3DDraw& draw);
|
||||
|
||||
// Rasterize a list of draw commands (CPU software rasterizer)
|
||||
void RenderScene(SDL_Surface* targetSurface, const std::vector<Render3DDraw>& draws);
|
||||
|
||||
// GPU Hardware-accelerated 3D Scene Rendering via SDL_RenderGeometry / Metal / Vulkan
|
||||
void RenderSceneGPU(SDL_Renderer* renderer, const std::vector<Render3DDraw>& draws);
|
||||
void DestroyGPUTextures();
|
||||
SDL_Texture* GetGPUTexture(SDL_Renderer* renderer, const std::string& texturePath);
|
||||
|
||||
// Exponential & Linear Depth Fog (modeled after 40250 CMapOutdoor fog)
|
||||
void SetFog(bool enable, uint32_t color = 0xFFCCDDEE, float density = 0.0003f, float fog_near = 300.0f, float fog_far = 3000.0f, bool exp_mode = true);
|
||||
bool IsFogEnabled() const { return m_fog_enabled; }
|
||||
uint32_t GetFogColor() const { return m_fog_color; }
|
||||
|
||||
const float* GetViewMatrix() const { return m_view; }
|
||||
const float* GetProjMatrix() const { return m_proj; }
|
||||
const int* GetViewport() const { return m_viewport; }
|
||||
void GetEyePosition(float& x, float& y, float& z) const { x = m_eye[0]; y = m_eye[1]; z = m_eye[2]; }
|
||||
|
||||
// Project world coordinates (X, Y, Z) to 2D screen coordinates
|
||||
bool ProjectToScreen(float worldX, float worldY, float worldZ, float& screenX, float& screenY) const;
|
||||
|
||||
// Unproject 2D screen coordinates (screenX, screenY) to a 3D ray in world space
|
||||
bool ScreenToWorldRay(float screenX, float screenY, float rayOrig[3], float rayDir[3]) const;
|
||||
|
||||
// Pick 3D point on terrain heightmap via ray marching and binary search refinement
|
||||
bool PickTerrain(float screenX, float screenY, const class TerrainHeightmap& terrain,
|
||||
float& pickX, float& pickY, float& pickZ, float maxRange = 5000.0f) const;
|
||||
|
||||
const std::vector<float>& GetDepthBuffer() const { return m_depthBuffer; }
|
||||
|
||||
private:
|
||||
struct TextureData {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
std::vector<uint8_t> rgba;
|
||||
};
|
||||
const TextureData* GetTexture(const std::string& texturePath);
|
||||
|
||||
float m_eye[3] = {0.0f, 0.0f, 0.0f};
|
||||
float m_view[16];
|
||||
float m_proj[16];
|
||||
int m_viewport[4];
|
||||
std::vector<float> m_depthBuffer;
|
||||
std::unordered_map<std::string, TextureData> m_textureCache;
|
||||
std::unordered_map<std::string, SDL_Texture*> m_gpuTextureCache;
|
||||
|
||||
bool m_fog_enabled = false;
|
||||
uint32_t m_fog_color = 0xFFCCDDEE;
|
||||
float m_fog_density = 0.0003f;
|
||||
float m_fog_near = 300.0f;
|
||||
float m_fog_far = 3000.0f;
|
||||
bool m_fog_exp = true;
|
||||
};
|
||||
|
||||
} // namespace ava2
|
||||
Reference in New Issue
Block a user