This commit is contained in:
ninja
2025-12-15 23:22:33 +08:00
parent 019570564b
commit 8782765fbc
809 changed files with 118753 additions and 18289 deletions

View File

@@ -0,0 +1,45 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#include "ebo.h"
EBO::EBO(const array_of_indices& indices)
{
glGenBuffers(1, &id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW);
}
EBO::EBO(const std::vector<array_of_indices>& array_of_indices)
{
std::size_t start = 0;
for (const auto& indices : array_of_indices)
{
glGenBuffers(1, &id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW);
start += indices.size() * sizeof(GLuint);
}
}
void EBO::Bind()
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
}
void EBO::Unbind()
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void EBO::Delete()
{
glDeleteBuffers(1, &id);
}

View File

@@ -0,0 +1,33 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#ifndef EBO_H
#define EBO_H
#include <vector>
#include <glad/glad.h>
using array_of_indices = std::vector<unsigned int>;
class EBO
{
public:
GLuint id;
// Mesh mono color or with vertex color
EBO(const array_of_indices& indices);
// Mesh sort by faces
EBO(const std::vector<array_of_indices>& array_of_indices);
void Bind();
void Unbind();
void Delete();
};
#endif // EBO_H

View File

@@ -0,0 +1,55 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#include "mesh.h"
#include <algorithm>
#include <glm/mat4x4.hpp>
Mesh::Mesh(const utils::geometry::BufferData& data,
const glm::mat4& plnt,
const utils::properties::style::Graphics& style_)
{
placement = plnt;
style = style_;
indice_count = static_cast<int>(data.indices.size() );
box = data.mesh_box.transform(plnt);
vao.Bind();
VBO vbo(data.vertices);
EBO ebo(data.indices);
vao.LinkAttrib(vbo, 0, 3, GL_FLOAT, sizeof(utils::geometry::Vertex), (GLvoid*) 0);
vao.LinkAttrib(vbo, 1, 3, GL_FLOAT, sizeof(utils::geometry::Vertex), (GLvoid*) ( 3 * sizeof(float) ));
vao.Unbind();
vbo.Unbind();
ebo.Unbind();
}
void Mesh::draw()
{
if (indice_count == 0)
return;
vao.Bind();
// Draw the actual mesh
glDrawElements(GL_TRIANGLES, indice_count, GL_UNSIGNED_INT, 0);
vao.Unbind();
}
void Mesh::sort_by_style(std::vector<Mesh>& models)
{
auto by_style = [] (const Mesh& m1, const Mesh& m2) {
return m1.style.id < m2.style.id;
};
std::sort(models.begin(), models.end(), by_style);
}

View File

@@ -0,0 +1,41 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#ifndef MESH_H
#define MESH_H
#include "../../utils/bounding_box.h"
#include "../../utils/properties.h"
#include "../../utils/geometry.h"
#include "ebo.h"
#include "vao.h"
class Mesh
{
public:
int indice_count = 0;
utils::geometry::BoundingBox box;
glm::mat4 placement;
utils::properties::style::Graphics style;
VAO vao;
Mesh(const utils::geometry::BufferData& data,
const glm::mat4& placement,
const utils::properties::style::Graphics& style);
Mesh() = default;
~Mesh() = default;
// Draws the mesh
void draw();
static void sort_by_style(std::vector<Mesh>& models);
};
#endif // MESH_H

View File

@@ -0,0 +1,226 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#include "shader.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
std::string parse_file(const char* filename)
{
try
{
std::ifstream file;
file.open(filename);
std::stringstream filestream;
filestream << file.rdbuf();
file.close();
return filestream.str();
}
catch (std::ifstream::failure& e)
{
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESSFULLY_READ: " << e.what() << std::endl;
}
return "";
}
Shader::Shader(const char* vertex_filename, const char* fragment_filename)
{
std::string vertex_filepath = SHADERS_FOLDER;
vertex_filepath.append("/");
vertex_filepath.append(vertex_filename);
std::string vertexCode = parse_file(vertex_filepath.c_str());
const char* vShaderCode = vertexCode.c_str();
std::string fragment_filepath = SHADERS_FOLDER;
fragment_filepath.append("/");
fragment_filepath.append(fragment_filename);
std::string fragmentCode = parse_file(fragment_filepath.c_str());
const char* fShaderCode = fragmentCode.c_str();
unsigned int vertex, fragment;
// vertex shader
vertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertex, 1, &vShaderCode, nullptr);
glCompileShader(vertex);
compile_errors(vertex, "VERTEX");
// fragment Shader
fragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragment, 1, &fShaderCode, nullptr);
glCompileShader(fragment);
compile_errors(fragment, "FRAGMENT");
// shader Program
ID = glCreateProgram();
glAttachShader(ID, vertex);
glAttachShader(ID, fragment);
glLinkProgram(ID);
compile_errors(ID, "PROGRAM");
glDeleteShader(vertex);
glDeleteShader(fragment);
}
void Shader::use()
{
glUseProgram(ID);
}
void Shader::detach()
{
glDeleteProgram(ID);
}
void Shader::add_light_properties(const glm::vec3& light_position)
{
use();
set_vec4("lightColor", 1.f, 1.f, 1.f, 0.f);
set_vec3("lightPos", light_position);
}
void Shader::compile_errors(unsigned int shader, const std::string & type)
{
GLint success;
GLchar infoLog[1024];
if (type != "PROGRAM")
{
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n"
<< infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
else
{
glGetProgramiv(shader, GL_LINK_STATUS, &success);
if (!success)
{
glGetProgramInfoLog(shader, 1024, NULL, infoLog);
std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n"
<< infoLog << "\n -- --------------------------------------------------- -- " << std::endl;
}
}
}
void Shader::set_value(const std::string& name, float value) const
{
glUniform1fv(glGetUniformLocation(ID, name.c_str()), 1, &value);
}
void Shader::set_vec2(const std::string& name, const glm::vec2& value) const
{
glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
}
void Shader::set_vec2(const std::string& name, float x, float y) const
{
glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);
}
// ------------------------------------------------------------------------
void Shader::set_vec3(const std::string& name, const glm::vec3& value) const
{
glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
}
void Shader::set_vec3(const std::string& name, float x, float y, float z) const
{
glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);
}
// ------------------------------------------------------------------------
void Shader::set_vec4(const std::string& name, const glm::vec4& value) const
{
glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]);
}
void Shader::set_vec4(const std::string& name, float x, float y, float z, float w) const
{
glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);
}
// ------------------------------------------------------------------------
void Shader::set_mat4(const std::string& name, const glm::mat4& mat) const
{
glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]);
}
void Shader::update_view_matrix(const glm::mat4& mat) const
{
set_mat4("view", mat);
}
void Shader::update_world_matrix(const glm::mat4& mat) const
{
set_mat4("world", mat);
}
void Shader::update_model_matrix(const glm::mat4& mat) const
{
set_mat4("model", mat);
set_mat4("model_normal", glm::transpose(glm::inverse(mat)));
}
void Shader::update_projection_matrix(const glm::mat4& mat) const
{
set_mat4("projection", mat);
}
void Shader::update_mesh_color(const glm::vec4& rgba) const
{
set_vec4("material.ambiant", rgba);
set_vec4("material.diffuse", rgba);
set_vec4("material.specular", 0.5f, 0.5f, 0.5f, rgba[3]);
set_vec4("material.emissive", 0.f, 0.f, 0.f, rgba[3]);
set_value("material.shininess", 0.5f);
}
void Shader::update_mesh_material(const utils::properties::style::Material& material) const
{
set_vec4("material.ambiant", material.ambient);
set_vec4("material.diffuse", material.diffuse);
set_vec4("material.specular", material.specular);
set_vec4("material.emissive", material.emissive);
set_value("material.shininess", material.shininess);
}
void Shader::update_mesh_style(const utils::properties::style::Graphics& graphics, bool& is_first)
{
if (!is_first && current_graphics_id == graphics.id)
return;
is_first = false;
current_graphics_id = graphics.id;
if (graphics.id == -1)
{
update_mesh_material(utils::properties::style::default_material);
}
else if (graphics.type == utils::properties::style::Graphics::UNDEF)
{
update_mesh_material(utils::properties::style::default_material);
}
else if (graphics.type == utils::properties::style::Graphics::TEXTURE)
{
std::cout << "WARNING::TEXTURE::NOT_IMPLEMENTED_IN_THE_SAMPLE" << std::endl;
update_mesh_material(utils::properties::style::default_material);
}
else if (graphics.type == utils::properties::style::Graphics::RGBA)
{
update_mesh_color(graphics.rgba);
}
else if (graphics.type == utils::properties::style::Graphics::MATERIAL)
{
update_mesh_material(graphics.material);
}
else
{
std::cout << "ERROR::STYLE::UNEXPECTED" << std::endl;
update_mesh_material(utils::properties::style::default_material);
}
}

View File

@@ -0,0 +1,57 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#ifndef SHADER_H
#define SHADER_H
#include <string>
#include <vector>
#include <glad/glad.h>
#include <glm/mat4x4.hpp>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include "../../utils/properties.h"
class Shader
{
public:
GLuint ID;
int current_graphics_id = -1;
Shader(const char* vertexFile, const char* fragmentFile);
void use();
void detach();
void add_light_properties(const glm::vec3& light_position);
void update_view_matrix(const glm::mat4& mat) const;
void update_model_matrix(const glm::mat4& mat) const;
void update_world_matrix(const glm::mat4& mat) const;
void update_projection_matrix(const glm::mat4& mat) const;
void update_mesh_style(const utils::properties::style::Graphics& graphics, bool& is_first);
void set_vec3(const std::string& name, const glm::vec3& value) const;
private:
void update_mesh_color(const glm::vec4& rgba) const;
void update_mesh_material(const utils::properties::style::Material& material) const;
void compile_errors(unsigned int shader, const std::string & type);
void set_value(const std::string& name, float value) const;
void set_vec2(const std::string& name, const glm::vec2& value) const;
void set_vec2(const std::string& name, float x, float y) const;
void set_vec3(const std::string& name, float x, float y, float z) const;
void set_vec4(const std::string& name, const glm::vec4& value) const;
void set_vec4(const std::string& name, float x, float y, float z, float w) const;
void set_mat4(const std::string& name, const glm::mat4& mat) const;
};
#endif // SHADER_H

View File

@@ -0,0 +1,42 @@
#version 420 core
out vec4 FragColor;
in vec3 Normal;
in vec3 FragPos;
in vec3 viewPos;
uniform vec3 lightPos;
uniform vec4 lightColor;
uniform vec4 meshColor;
struct Material {
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec4 emissive;
float shininess;
};
uniform Material material;
void main()
{
vec3 normal = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
vec3 viewDir = normalize(viewPos - FragPos);
vec3 halfwayDir = normalize(lightDir + viewDir);
// diffuse
float diff = max(dot(normal, lightDir), 0.0);
// specular
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec4 ambient = lightColor * material.ambient;
vec4 diffuse = lightColor * (diff * material.diffuse);
vec4 specular = lightColor * (spec *material.specular);
FragColor = ambient + diffuse + specular + material.emissive;
}

View File

@@ -0,0 +1,21 @@
#version 420 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
out vec3 FragPos;
out vec3 Normal;
out vec3 viewPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform mat4 model_normal;
uniform vec3 view_position;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.0f));
Normal = vec3(model_normal * vec4(aNormal, 1.0f));
viewPos = view_position;
gl_Position = projection * view * vec4(FragPos, 1.0f);
}

View File

@@ -0,0 +1,40 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#include "vao.h"
VAO::VAO()
{
glGenVertexArrays(1, &id);
}
void VAO::LinkAttrib(VBO& vbo, GLuint layout, GLuint numComponents, GLenum type, GLsizei stride, void* offset)
{
vbo.Bind();
glVertexAttribPointer(layout, numComponents, type, GL_FALSE, stride, offset);
glEnableVertexAttribArray(layout);
vbo.Unbind();
}
void VAO::Bind()
{
glBindVertexArray(id);
}
void VAO::Unbind()
{
glBindVertexArray(0);
}
void VAO::Delete()
{
glDeleteVertexArrays(1, &id);
}

View File

@@ -0,0 +1,30 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#ifndef VAO_H
#define VAO_H
#include <glad/glad.h>
#include "vbo.h"
class VAO
{
public:
GLuint id;
VAO();
void LinkAttrib(VBO& vbo, GLuint layout, GLuint numComponents, GLenum type, GLsizei stride, void* offset);
void Bind();
void Unbind();
void Delete();
};
#endif // VAO_H

View File

@@ -0,0 +1,34 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#include "vbo.h"
VBO::VBO(const std::vector<utils::geometry::Vertex> &vertices)
{
glGenBuffers(1, &id);
glBindBuffer(GL_ARRAY_BUFFER, id);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(utils::geometry::Vertex), vertices.data(), GL_STATIC_DRAW);
}
void VBO::Bind()
{
glBindBuffer(GL_ARRAY_BUFFER, id);
}
void VBO::Unbind()
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VBO::Delete()
{
glDeleteBuffers(1, &id);
}

View File

@@ -0,0 +1,32 @@
/***********************************************************************************************************************
*
* Copyright (c) 2010 - 2025 by Tech Soft 3D, Inc.
* The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., and considered a trade secret
* as defined under civil and criminal statutes. Tech Soft 3D shall pursue its civil and criminal remedies in the event
* of unauthorized use or misappropriation of its trade secrets. Use of this information by anyone other than authorized
* employees of Tech Soft 3D, Inc. is granted only under a written non-disclosure agreement, expressly prescribing the
* scope and manner of such use.
*
***********************************************************************************************************************/
#ifndef VBO_H
#define VBO_H
#include <vector>
#include <glm/glm.hpp>
#include <glad/glad.h>
#include "../../utils/geometry.h"
class VBO
{
public:
GLuint id;
VBO(const std::vector<utils::geometry::Vertex> &vertices);
void Bind();
void Unbind();
void Delete();
};
#endif // VBO_H