Files
Np_Term/include/vulkan_engine/asset/object/model.h

163 lines
4.8 KiB
C++

#pragma once
#include <functional>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <vector>
#include "material.h"
#include "vulkan_engine/vulkan/buffer_handle.h"
#include "vulkan_engine/vulkan/vertex.h"
#include "utils/snowflake.h"
extern std::uint8_t CLIENTID;
namespace veng {
struct Model {
Model() : graphics_(nullptr) {}
Model(class Graphics* graphics) : graphics_(graphics) {}
~Model();
Model(const Model& other)
: asset_name(other.asset_name),
vertices(other.vertices),
vertex_buffer(other.vertex_buffer),
indices(other.indices),
index_buffer(other.index_buffer),
transform(other.transform),
position(other.position),
linear_velocity(other.linear_velocity),
linear_acceleration(other.linear_acceleration),
rotation(other.rotation),
angular_velocity(other.angular_velocity),
angular_acceleration(other.angular_acceleration),
scale(other.scale),
material(other.material),
original_offset(other.original_offset),
owner(other.owner),
radius(other.radius),
lifespan(other.lifespan),
OnColision(other.OnColision),
visible(other.visible),
colision(other.colision),
networkReplicated(other.networkReplicated) {
name = "_" + other.name;
ID = utils::GenerateID(CLIENTID);
graphics_ = nullptr;
}
Model(Model&& other)
: name(other.name),
asset_name(other.asset_name),
vertices(std::move(other.vertices)),
vertex_buffer(std::move(other.vertex_buffer)),
indices(std::move(other.indices)),
index_buffer(std::move(other.index_buffer)),
transform(other.transform),
position(other.position),
linear_velocity(other.linear_velocity),
linear_acceleration(other.linear_acceleration),
rotation(other.rotation),
angular_velocity(other.angular_velocity),
angular_acceleration(other.angular_acceleration),
scale(other.scale),
material(other.material),
original_offset(other.original_offset),
owner(other.owner),
radius(other.radius),
lifespan(other.lifespan),
OnColision(other.OnColision),
visible(other.visible),
colision(other.colision),
networkReplicated(other.networkReplicated)
{
ID = other.ID;
::memset(&other.ID, 0, 8);
graphics_ = other.graphics_;
other.graphics_ = nullptr;
}
Model& operator=(Model&& other) noexcept {
if (this != &other) {
ID = other.ID;
::memset(&other.ID, 0, 8);
name = other.name;
asset_name = other.asset_name;
vertices = std::move(other.vertices);
vertex_buffer = std::move(other.vertex_buffer);
indices = std::move(other.indices);
index_buffer = std::move(other.index_buffer);
transform = other.transform;
position = other.position;
linear_velocity = other.linear_velocity;
linear_acceleration = other.linear_acceleration;
rotation = other.rotation;
angular_velocity = other.angular_velocity;
angular_acceleration = other.angular_acceleration;
scale = other.scale;
material = std::move(other.material);
original_offset = other.original_offset;
owner = other.owner;
radius = other.radius;
lifespan = other.lifespan;
OnColision = other.OnColision;
visible = other.visible;
colision = other.colision;
networkReplicated = other.networkReplicated;
graphics_ = other.graphics_;
other.graphics_ = nullptr;
}
return *this;
}
utils::Snowflake ID;
std::string name;
std::string asset_name;
std::vector<char> Serialize();
void Deserialize(std::vector<char> data);
std::vector<veng::Vertex> vertices;
veng::BufferHandle vertex_buffer;
std::vector<std::uint32_t> indices;
veng::BufferHandle index_buffer;
glm::mat4 transform = glm::rotate(glm::mat4(1.0f), glm::radians(180.f),
glm::vec3(0.f, 0.f, 1.f));
glm::vec3 position = glm::vec3(0.f);
glm::vec3 linear_velocity = glm::vec3(0.f);
glm::vec3 linear_acceleration = glm::vec3(0.f);
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
glm::vec3 angular_velocity = glm::vec3(0.f); // 축 * 각속도(rad/s)
glm::vec3 angular_acceleration = glm::vec3(0.f);
glm::vec3 scale = glm::vec3(1.f);
Material material;
void Update(float dt);
glm::vec3 original_offset = glm::vec3(0.f);
Model* owner = this;
std::float_t radius = 0.f;
std::float_t lifespan = -1.f;
std::function<void(Model* self, Model* other)> OnColision = nullptr;
bool visible = true;
bool colision = false;
bool networkReplicated = true;
bool shouldBeDestroyed = false;
bool needsUpdate = true;
private:
class Graphics* graphics_;
};
} // namespace veng