Доработка класса модели

This commit is contained in:
2023-07-19 20:58:49 +03:00
committed by re.kovalev
parent 2a465469cc
commit 24e509aa1f
2 changed files with 42 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
#include "Model.h"
#include <algorithm>
#include <stdexcept>
// Конструктор с заданным родителем (по умолчанию NULL)
Node::Node(Node* parent_) : parent(parent_), result_transform(1), parent_changed(false),
@@ -201,7 +202,7 @@ Node& Node::operator=(const Node& other)
}
// Конструктор по умолчанию
Model::Model(Node *parent) : Node(parent), verteces_count(0), first_index_byteOffset(0), indices_count(0),
Model::Model(Node *parent) : Node(parent), verteces_count(0), first_index_byteOffset(0), indices_count(0), indices_datatype(GL_UNSIGNED_INT),
vertex_vbo(VERTEX), index_vbo(ELEMENT), normals_vbo(VERTEX), texCoords_vbo(VERTEX),
tangent_vbo(VERTEX), bitangent_vbo(VERTEX)
{
@@ -213,7 +214,7 @@ tangent_vbo(VERTEX), bitangent_vbo(VERTEX)
// Конструктор копирования
Model::Model(const Model& copy) : Node(copy),
vao(copy.vao),
verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count),
verteces_count(copy.verteces_count), first_index_byteOffset(copy.first_index_byteOffset), indices_count(copy.indices_count), indices_datatype(copy.indices_datatype),
vertex_vbo(copy.vertex_vbo), index_vbo(copy.index_vbo), normals_vbo(copy.normals_vbo), texCoords_vbo(copy.texCoords_vbo),
tangent_vbo(copy.tangent_vbo), bitangent_vbo(copy.bitangent_vbo),
texture_albedo(copy.texture_albedo), texture_roughness(copy.texture_roughness), texture_metallic(copy.texture_metallic), texture_specular(copy.texture_specular), texture_emitted(copy.texture_emitted),
@@ -270,7 +271,7 @@ void Model::render()
if (indices_count)
{
index_vbo.use();
glDrawElements(GL_TRIANGLES, indices_count, GL_UNSIGNED_INT, (void*)(first_index_byteOffset));
glDrawElements(GL_TRIANGLES, indices_count, indices_datatype, (void*)(first_index_byteOffset));
}
// Если есть вершины - рисуем на основании массива вершин
else if (verteces_count)
@@ -400,10 +401,11 @@ void Model::load_normals(glm::vec3* normals, GLuint count)
}
// Ограничение диапазона из буфера индексов
void Model::set_index_range(size_t first_byteOffset, size_t count)
void Model::set_index_range(size_t first_byteOffset, size_t count, size_t type)
{
first_index_byteOffset = first_byteOffset;
indices_count = count;
indices_datatype = type;
}
// Привязка текстуры к модели
@@ -497,6 +499,37 @@ void Model::load_bitangent(glm::vec3* bitangent, GLuint count)
bitangent_attrib_config();
}
// Замена вершинного буфера по номеру его привязки
void Model::setBO(int attribute, BO & bo)
{
switch(attribute)
{
case 0:
vertex_vbo = bo;
break;
case 1:
texCoords_vbo = bo;
break;
case 2:
normals_vbo = bo;
break;
case 3:
tangent_vbo = bo;
break;
case 4:
bitangent_vbo = bo;
break;
default:
throw std::runtime_error("Unknown attribute buffer");
};
}
// Замена индексного буфера
void Model::setIndicesBO(BO & data)
{
index_vbo = data;
}
// Генерирует сферу заданного радиуса с определенным количеством сегментов
Model genShpere(float radius, int sectorsCount, Node* parent)
{