54 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#pragma once
 | 
						|
#include <cstdint>
 | 
						|
#include <tuple>
 | 
						|
#include <vector>
 | 
						|
using namespace std;
 | 
						|
#define sizeof_field(_struct, _field) sizeof(((_struct*)0)->_field)
 | 
						|
// 顶点最多关联4个骨骼
 | 
						|
#define MAX_NUM_BONES_PER_VERTEX 4
 | 
						|
struct Vector2 {
 | 
						|
	float x;
 | 
						|
	float y;
 | 
						|
};
 | 
						|
struct Vector3 {
 | 
						|
	float x;
 | 
						|
	float y;
 | 
						|
	float z;
 | 
						|
};
 | 
						|
struct Vertex {
 | 
						|
	struct UClass {
 | 
						|
		virtual void BindLayout() = 0;
 | 
						|
 | 
						|
	};
 | 
						|
};
 | 
						|
struct PosVertex : public Vertex {
 | 
						|
	Vector3 Position = {};
 | 
						|
	struct UClass : public Vertex::UClass{
 | 
						|
		int MemCount = 1;
 | 
						|
		tuple<int, int> Position{sizeof_field(PosVertex, Position), offsetof(PosVertex, Position)};
 | 
						|
 | 
						|
		virtual void BindLayout() {};
 | 
						|
	};
 | 
						|
};
 | 
						|
 | 
						|
struct TexVertex : public Vertex {
 | 
						|
	Vector3 Position = {};
 | 
						|
	Vector3 Normal = {};
 | 
						|
	Vector2 TexCoords = {};
 | 
						|
};
 | 
						|
struct BoneVertex : public Vertex
 | 
						|
{
 | 
						|
	Vector3 Position = {};
 | 
						|
	Vector2 TexCoords = {};
 | 
						|
	Vector3 Normal = {};
 | 
						|
	Vector3 Tangent = {};
 | 
						|
	// 骨骼蒙皮数据
 | 
						|
	float    Weights[MAX_NUM_BONES_PER_VERTEX] = {};
 | 
						|
	uint32_t BoneIDs[MAX_NUM_BONES_PER_VERTEX] = {};
 | 
						|
 | 
						|
	void AddBoneData(uint32_t boneID, float weight) {};
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
 |