mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Fix bugs, add mesh gen
This commit is contained in:
parent
cf99262dc8
commit
d7d8720c75
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
|
|
||||||
#include "gfx.hpp"
|
#include "gfx.hpp"
|
||||||
#include "gfx_device.hpp"
|
#include "gfx_device.hpp"
|
||||||
|
|
||||||
@ -24,22 +26,16 @@ public:
|
|||||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices)
|
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices)
|
||||||
: m_gfx(gfx)
|
: m_gfx(gfx)
|
||||||
{
|
{
|
||||||
m_vb = m_gfx->createBuffer(gfx::BufferType::VERTEX, vertices.size() * sizeof(Vertex), vertices.data());
|
std::vector<uint32_t> indices(vertices.size());
|
||||||
|
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||||
std::vector<uint32_t> indices(m_count);
|
|
||||||
for (uint32_t i = 0; i < m_count; i++) {
|
|
||||||
indices[i] = i;
|
indices[i] = i;
|
||||||
}
|
}
|
||||||
m_ib = m_gfx->createBuffer(gfx::BufferType::INDEX, indices.size() * sizeof(uint32_t), indices.data());
|
initMesh(vertices, indices);
|
||||||
|
|
||||||
m_count = indices.size();
|
|
||||||
}
|
}
|
||||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||||
: m_gfx(gfx)
|
: m_gfx(gfx)
|
||||||
{
|
{
|
||||||
m_vb = m_gfx->createBuffer(gfx::BufferType::VERTEX, vertices.size() * sizeof(Vertex), vertices.data());
|
initMesh(vertices, indices);
|
||||||
m_ib = m_gfx->createBuffer(gfx::BufferType::INDEX, indices.size() * sizeof(uint32_t), indices.data());
|
|
||||||
m_count = indices.size();
|
|
||||||
}
|
}
|
||||||
~Mesh()
|
~Mesh()
|
||||||
{
|
{
|
||||||
@ -60,6 +56,14 @@ private:
|
|||||||
const gfx::Buffer* m_ib;
|
const gfx::Buffer* m_ib;
|
||||||
uint32_t m_count;
|
uint32_t m_count;
|
||||||
|
|
||||||
|
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||||
|
{
|
||||||
|
m_vb = m_gfx->createBuffer(gfx::BufferType::VERTEX, vertices.size() * sizeof(Vertex), vertices.data());
|
||||||
|
m_ib = m_gfx->createBuffer(gfx::BufferType::INDEX, indices.size() * sizeof(uint32_t), indices.data());
|
||||||
|
m_count = indices.size();
|
||||||
|
INFO("Loaded mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "log.hpp"
|
||||||
|
|
||||||
#include "gfx.hpp"
|
#include "gfx.hpp"
|
||||||
#include "gfx_device.hpp"
|
#include "gfx_device.hpp"
|
||||||
|
|
||||||
@ -65,6 +67,8 @@ public:
|
|||||||
vertFormat.stride = stride;
|
vertFormat.stride = stride;
|
||||||
|
|
||||||
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4), alphaBlending, cullBackFace);
|
m_pipeline = m_gfx->createPipeline(vertPath, fragPath, vertFormat, sizeof(glm::mat4), alphaBlending, cullBackFace);
|
||||||
|
|
||||||
|
INFO("Loaded shader: {}, vertex attribs: {}", vertPath, vertFormat.attributeDescriptions.size());
|
||||||
}
|
}
|
||||||
~Shader()
|
~Shader()
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,6 @@ void main() {
|
|||||||
fragPos = vec3(constants.view * constants.model * vec4(inPosition, 1.0));
|
fragPos = vec3(constants.view * constants.model * vec4(inPosition, 1.0));
|
||||||
fragNorm = mat3(transpose(inverse(constants.view * constants.model))) * inNorm;
|
fragNorm = mat3(transpose(inverse(constants.view * constants.model))) * inNorm;
|
||||||
fragUV = inUV;
|
fragUV = inUV;
|
||||||
vec3 lightPos = vec3(-500.0, 500.0, 40.0);
|
vec3 lightPos = vec3(-10.0, 10.0, 10.0);
|
||||||
fragLightPos = vec3(constants.view * vec4(lightPos, 1.0));
|
fragLightPos = vec3(constants.view * vec4(lightPos, 1.0));
|
||||||
}
|
}
|
||||||
|
@ -81,11 +81,17 @@ namespace engine {
|
|||||||
/* logic */
|
/* logic */
|
||||||
m_sceneManager->updateActiveScene(m_window->dt());
|
m_sceneManager->updateActiveScene(m_window->dt());
|
||||||
|
|
||||||
if(m_window->getKeyPress(inputs::Key::K_L)) {
|
if(m_window->getKeyPress(inputs::Key::K_F)) [[unlikely]] {
|
||||||
// m_enableFrameLimiter = !m_enableFrameLimiter;
|
|
||||||
m_window->infoBox("fps", std::to_string(m_window->getFPS()) + " fps " + std::to_string(m_window->dt() * 1000.0f) + " ms");
|
m_window->infoBox("fps", std::to_string(m_window->getFPS()) + " fps " + std::to_string(m_window->dt() * 1000.0f) + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t now = m_window->getNanos();
|
||||||
|
if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] {
|
||||||
|
lastTick = now;
|
||||||
|
INFO("fps: {}", m_window->getAvgFPS());
|
||||||
|
m_window->resetAvgFPS();
|
||||||
|
}
|
||||||
|
|
||||||
/* draw */
|
/* draw */
|
||||||
m_gfx->renderFrame();
|
m_gfx->renderFrame();
|
||||||
|
|
||||||
@ -93,12 +99,6 @@ namespace engine {
|
|||||||
m_window->getInputAndEvents();
|
m_window->getInputAndEvents();
|
||||||
|
|
||||||
/* fps limiter */
|
/* fps limiter */
|
||||||
uint64_t now = m_window->getNanos();
|
|
||||||
if (now - lastTick >= 1000000000LL * 10LL) {
|
|
||||||
lastTick = now;
|
|
||||||
m_window->setTitle(std::to_string(m_window->getAvgFPS()));
|
|
||||||
m_window->resetAvgFPS();
|
|
||||||
}
|
|
||||||
if (m_enableFrameLimiter) {
|
if (m_enableFrameLimiter) {
|
||||||
std::this_thread::sleep_until(endFrame);
|
std::this_thread::sleep_until(endFrame);
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ namespace engine {
|
|||||||
|
|
||||||
switch (messageSeverity) {
|
switch (messageSeverity) {
|
||||||
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT:
|
||||||
TRACE("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
DEBUG("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||||
break;
|
break;
|
||||||
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
|
case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT:
|
||||||
INFO("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
INFO("VULKAN MESSAGE{}: ID: {} MSG: {}", msgType, pCallbackData->pMessageIdName, pCallbackData->pMessage);
|
||||||
@ -1233,7 +1233,7 @@ namespace engine {
|
|||||||
|
|
||||||
VkPhysicalDeviceProperties devProps;
|
VkPhysicalDeviceProperties devProps;
|
||||||
vkGetPhysicalDeviceProperties(pimpl->physicalDevice, &devProps);
|
vkGetPhysicalDeviceProperties(pimpl->physicalDevice, &devProps);
|
||||||
INFO("Selected physical device: {}", devProps.deviceName);
|
DEBUG("Selected physical device: {}", devProps.deviceName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1702,7 +1702,6 @@ namespace engine {
|
|||||||
|
|
||||||
auto vertShaderCode = util::readTextFile(vertShaderPath);
|
auto vertShaderCode = util::readTextFile(vertShaderPath);
|
||||||
auto fragShaderCode = util::readTextFile(fragShaderPath);
|
auto fragShaderCode = util::readTextFile(fragShaderPath);
|
||||||
INFO("Opened shader: {}", std::filesystem::path(vertShaderPath).filename().string());
|
|
||||||
|
|
||||||
VkShaderModule vertShaderModule = compileShader(pimpl->device, shaderc_vertex_shader, vertShaderCode->data(), vertShaderPath);
|
VkShaderModule vertShaderModule = compileShader(pimpl->device, shaderc_vertex_shader, vertShaderCode->data(), vertShaderPath);
|
||||||
VkShaderModule fragShaderModule = compileShader(pimpl->device, shaderc_fragment_shader, fragShaderCode->data(), fragShaderPath);
|
VkShaderModule fragShaderModule = compileShader(pimpl->device, shaderc_fragment_shader, fragShaderCode->data(), fragShaderPath);
|
||||||
|
@ -21,7 +21,7 @@ Texture::Texture(GFXDevice* gfxDevice, const std::string& path)
|
|||||||
|
|
||||||
m_gpuTexture = m_gfxDevice->createTexture(texbuf->data(), (uint32_t)width, (uint32_t)height, gfx::TextureFilter::LINEAR, filter);
|
m_gpuTexture = m_gfxDevice->createTexture(texbuf->data(), (uint32_t)width, (uint32_t)height, gfx::TextureFilter::LINEAR, filter);
|
||||||
|
|
||||||
DEBUG("loaded texture {}, width: {} height: {} size: {}", path, width, height, texbuf->size());
|
INFO("Loaded texture: {}, width: {} height: {}", path, width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ namespace engine {
|
|||||||
|
|
||||||
void SceneManager::updateActiveScene(float ts)
|
void SceneManager::updateActiveScene(float ts)
|
||||||
{
|
{
|
||||||
if (m_activeSceneIndex >= 0) {
|
if (m_activeSceneIndex >= 0) [[likely]] {
|
||||||
assert((size_t)m_activeSceneIndex < m_scenes.size());
|
assert((size_t)m_activeSceneIndex < m_scenes.size());
|
||||||
m_scenes[m_activeSceneIndex]->update(ts);
|
m_scenes[m_activeSceneIndex]->update(ts);
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,12 @@ namespace engine {
|
|||||||
|
|
||||||
for (uint32_t entity : m_entities) {
|
for (uint32_t entity : m_entities) {
|
||||||
|
|
||||||
|
|
||||||
auto t = m_scene->getComponent<TransformComponent>(entity);
|
auto t = m_scene->getComponent<TransformComponent>(entity);
|
||||||
auto r = m_scene->getComponent<RenderableComponent>(entity);
|
auto r = m_scene->getComponent<RenderableComponent>(entity);
|
||||||
|
|
||||||
DEBUG("rendering mesh: {}, parent: {}", t->tag, t->parent);
|
assert(r->material != nullptr);
|
||||||
|
assert(r->mesh != nullptr);
|
||||||
|
assert(r->material->m_texture != nullptr);
|
||||||
|
|
||||||
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &projMatrix, sizeof(projMatrix), 0);
|
gfx->updateUniformBuffer(r->material->getShader()->getPipeline(), &projMatrix, sizeof(projMatrix), 0);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace engine::util {
|
|||||||
public:
|
public:
|
||||||
void write(const char* message) override {
|
void write(const char* message) override {
|
||||||
(void)message;
|
(void)message;
|
||||||
DEBUG("ASSIMP: {}", message);
|
TRACE("ASSIMP: {}", message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -160,23 +160,23 @@ namespace engine::util {
|
|||||||
assert(scene->HasLights() == false);
|
assert(scene->HasLights() == false);
|
||||||
assert(scene->hasSkeletons() == false);
|
assert(scene->hasSkeletons() == false);
|
||||||
|
|
||||||
INFO("material count: {}, mesh count: {}", scene->mNumMaterials, scene->mNumMeshes);
|
TRACE("material count: {}, mesh count: {}", scene->mNumMaterials, scene->mNumMeshes);
|
||||||
|
|
||||||
std::map<int, std::shared_ptr<resources::Texture>> textures{};
|
std::map<int, std::shared_ptr<resources::Texture>> textures{};
|
||||||
|
|
||||||
for (uint32_t i = 0; i < scene->mNumMaterials; i++) {
|
for (uint32_t i = 0; i < scene->mNumMaterials; i++) {
|
||||||
const aiMaterial* m = scene->mMaterials[i];
|
const aiMaterial* m = scene->mMaterials[i];
|
||||||
INFO("Material {}:", i);
|
TRACE("Material {}:", i);
|
||||||
INFO(" Name: {}", m->GetName().C_Str());
|
TRACE(" Name: {}", m->GetName().C_Str());
|
||||||
for (uint32_t j = 0; j < m->mNumProperties; j++) {
|
for (uint32_t j = 0; j < m->mNumProperties; j++) {
|
||||||
const aiMaterialProperty* p = m->mProperties[j];
|
[[maybe_unused]] const aiMaterialProperty* p = m->mProperties[j];
|
||||||
INFO(" prop {}, key: {}", j, p->mKey.C_Str());
|
TRACE(" prop {}, key: {}", j, p->mKey.C_Str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aiGetMaterialTextureCount(m, aiTextureType_DIFFUSE) >= 1) {
|
if (aiGetMaterialTextureCount(m, aiTextureType_DIFFUSE) >= 1) {
|
||||||
aiString texPath{};
|
aiString texPath{};
|
||||||
aiGetMaterialTexture(m, aiTextureType_DIFFUSE, 0, &texPath);
|
aiGetMaterialTexture(m, aiTextureType_DIFFUSE, 0, &texPath);
|
||||||
INFO(" Diffuse tex: {}", texPath.C_Str());
|
TRACE(" Diffuse tex: {}", texPath.C_Str());
|
||||||
std::filesystem::path absPath = path;
|
std::filesystem::path absPath = path;
|
||||||
absPath = absPath.parent_path();
|
absPath = absPath.parent_path();
|
||||||
absPath /= texPath.C_Str();
|
absPath /= texPath.C_Str();
|
||||||
@ -195,8 +195,8 @@ namespace engine::util {
|
|||||||
meshMaterialIndices.push_back(m->mMaterialIndex);
|
meshMaterialIndices.push_back(m->mMaterialIndex);
|
||||||
std::vector<Vertex> vertices(m->mNumVertices);
|
std::vector<Vertex> vertices(m->mNumVertices);
|
||||||
std::vector<uint32_t> indices(m->mNumFaces * 3);
|
std::vector<uint32_t> indices(m->mNumFaces * 3);
|
||||||
INFO("Mesh {}: vertex count {}", i, vertices.size());
|
TRACE("Mesh {}: vertex count {}", i, vertices.size());
|
||||||
INFO("Mesh {}: index count {}", i, indices.size());
|
TRACE("Mesh {}: index count {}", i, indices.size());
|
||||||
|
|
||||||
for (uint32_t j = 0; j < vertices.size(); j++) {
|
for (uint32_t j = 0; j < vertices.size(); j++) {
|
||||||
Vertex v{};
|
Vertex v{};
|
||||||
@ -228,6 +228,8 @@ namespace engine::util {
|
|||||||
|
|
||||||
buildGraph(textures, meshes, meshMaterialIndices, scene->mRootNode, parent, obj);
|
buildGraph(textures, meshes, meshMaterialIndices, scene->mRootNode, parent, obj);
|
||||||
|
|
||||||
|
INFO("Loaded model: {}, meshes: {}, textures: {}", scene->GetShortFilename(path.c_str()), meshes.size(), textures.size());
|
||||||
|
|
||||||
Assimp::DefaultLogger::kill();
|
Assimp::DefaultLogger::kill();
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ set(GAME_SOURCES
|
|||||||
src/game.hpp
|
src/game.hpp
|
||||||
src/camera_controller.cpp
|
src/camera_controller.cpp
|
||||||
src/camera_controller.hpp
|
src/camera_controller.hpp
|
||||||
|
src/meshgen.cpp
|
||||||
|
src/meshgen.hpp
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "camera_controller.hpp"
|
#include "camera_controller.hpp"
|
||||||
|
#include "meshgen.hpp"
|
||||||
|
|
||||||
#include "application.hpp"
|
#include "application.hpp"
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
@ -108,7 +109,27 @@ void playGame()
|
|||||||
auto keepTexture = myScene->addResource<engine::resources::Texture>("whiteTexture", std::move(whiteTexture));
|
auto keepTexture = myScene->addResource<engine::resources::Texture>("whiteTexture", std::move(whiteTexture));
|
||||||
auto keepShader = myScene->addResource<engine::resources::Shader>("theShader", std::move(theShader));
|
auto keepShader = myScene->addResource<engine::resources::Shader>("theShader", std::move(theShader));
|
||||||
|
|
||||||
engine::util::loadMeshFromFile(myScene, app.getResourcePath("models/astronaut/astronaut.dae"));
|
// uint32_t astronaut = engine::util::loadMeshFromFile(myScene, app.getResourcePath("models/astronaut/astronaut.dae"));
|
||||||
|
// myScene->addComponent<RotateComponent>(astronaut);
|
||||||
|
|
||||||
|
uint32_t sphere = myScene->createEntity("sphere");
|
||||||
|
auto sphereRenderable = myScene->addComponent<engine::RenderableComponent>(sphere);
|
||||||
|
sphereRenderable->material = std::make_unique<engine::resources::Material>(keepShader);
|
||||||
|
sphereRenderable->material->m_texture = keepTexture;
|
||||||
|
sphereRenderable->mesh = genSphereMesh(app.gfx(), 100.0f, 100, true);
|
||||||
|
|
||||||
|
uint32_t light = myScene->createEntity("light");
|
||||||
|
myScene->getComponent<engine::TransformComponent>(light)->position = glm::vec3{-10.0f, 10.0f, 10.0f};
|
||||||
|
auto lightRenderable = myScene->addComponent<engine::RenderableComponent>(light);
|
||||||
|
lightRenderable->material = sphereRenderable->material;
|
||||||
|
lightRenderable->mesh = genSphereMesh(app.gfx(), 0.5f, 10, false, true);
|
||||||
|
|
||||||
|
uint32_t floor = myScene->createEntity("floor");
|
||||||
|
// myScene->getComponent<engine::TransformComponent>(floor)->position = glm::vec3{-50.0f, -0.5f, -50.0f};
|
||||||
|
auto floorRenderable = myScene->addComponent<engine::RenderableComponent>(floor);
|
||||||
|
floorRenderable->material = sphereRenderable->material;
|
||||||
|
floorRenderable->mesh = genCuboidMesh(app.gfx(), 1.0f, 1.0f, 1.0f);
|
||||||
|
myScene->addComponent<RotateComponent>(floor);
|
||||||
|
|
||||||
app.gameLoop();
|
app.gameLoop();
|
||||||
|
|
||||||
|
@ -4,15 +4,13 @@
|
|||||||
#include <glm/ext.hpp>
|
#include <glm/ext.hpp>
|
||||||
#include <glm/trigonometric.hpp>
|
#include <glm/trigonometric.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <thread>
|
std::unique_ptr<engine::resources::Mesh> genSphereMesh(engine::GFXDevice* gfx, float r, int detail, bool windInside, bool flipNormals)
|
||||||
|
|
||||||
std::unique_ptr<engine::resources::Mesh> genSphereMesh(float r, int detail, bool windInside)
|
|
||||||
{
|
{
|
||||||
using namespace glm;
|
using namespace glm;
|
||||||
|
|
||||||
std::vector<Vertex> vertices{};
|
std::vector<engine::Vertex> vertices{};
|
||||||
|
|
||||||
float angleStep = two_pi<float>() / (float)detail;
|
float angleStep = two_pi<float>() / (float)detail;
|
||||||
|
|
||||||
@ -66,15 +64,18 @@ std::unique_ptr<engine::resources::Mesh> genSphereMesh(float r, int detail, bool
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 vector1 = (vertices.end() - 1)->pos - (vertices.end() - 2)->pos;
|
vec3 vector1 = (vertices.end() - 1)->pos - (vertices.end() - 2)->pos;
|
||||||
glm::vec3 vector2 = (vertices.end() - 2)->pos - (vertices.end() - 3)->pos;
|
vec3 vector2 = (vertices.end() - 2)->pos - (vertices.end() - 3)->pos;
|
||||||
glm::vec3 norm = glm::normalize(glm::cross(vector1, vector2));
|
vec3 norm = normalize(cross(vector1, vector2));
|
||||||
|
|
||||||
|
|
||||||
// TODO: FIX NORMALS
|
// TODO: FIX NORMALS
|
||||||
if (!windInside)
|
if (!windInside)
|
||||||
norm = -norm;
|
norm = -norm;
|
||||||
|
|
||||||
|
if (flipNormals)
|
||||||
|
norm = -norm;
|
||||||
|
|
||||||
for (auto it = vertices.end() - 6; it != vertices.end(); it++) {
|
for (auto it = vertices.end() - 6; it != vertices.end(); it++) {
|
||||||
it->norm = norm;
|
it->norm = norm;
|
||||||
}
|
}
|
||||||
@ -82,54 +83,68 @@ std::unique_ptr<engine::resources::Mesh> genSphereMesh(float r, int detail, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<engine::resources::Mesh>(vertices);
|
return std::make_unique<engine::resources::Mesh>(gfx, vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<engine::resources::Mesh> genCuboidMesh(float x, float y, float z)
|
std::unique_ptr<engine::resources::Mesh> genCuboidMesh(engine::GFXDevice* gfx, float x, float y, float z)
|
||||||
{
|
{
|
||||||
|
|
||||||
// x goes ->
|
// x goes ->
|
||||||
// y goes ^
|
// y goes ^
|
||||||
// z goes into the screen
|
// z goes into the screen
|
||||||
|
|
||||||
using glm::vec3;
|
using namespace glm;
|
||||||
|
|
||||||
std::vector<Vertex> v{};
|
std::vector<engine::Vertex> v{};
|
||||||
|
|
||||||
// 0 top_left_front
|
|
||||||
v.push_back({{ 0.0f, y, 0.0f }, {}, {}});
|
|
||||||
// 1 bottom_left_front
|
|
||||||
v.push_back({{ 0.0f, 0.0f, 0.0f }, {}, {}});
|
|
||||||
// 2 top_right_front
|
|
||||||
v.push_back({{ x, y, 0.0f }, {}, {}});
|
|
||||||
// 3 bottom_right_front
|
|
||||||
v.push_back({{ x, 0.0f, 0.0f }, {}, {}});
|
|
||||||
|
|
||||||
// 4 top_left_back
|
|
||||||
v.push_back({{ 0.0f, y, z }, {}, {}});
|
|
||||||
// 5 bottom_left_back
|
|
||||||
v.push_back({{ 0.0f, 0.0f, z }, {}, {}});
|
|
||||||
// 6 top_right_back
|
|
||||||
v.push_back({{ x, y, z }, {}, {}});
|
|
||||||
// 7 bottom_right_back
|
|
||||||
v.push_back({{ x, 0.0f, z }, {}, {}});
|
|
||||||
|
|
||||||
// front quad
|
|
||||||
std::vector<unsigned int> indices{
|
|
||||||
// front
|
// front
|
||||||
0, 1, 3, 2, 0, 3,
|
v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
// back
|
v.push_back({{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
4, 5, 7, 6, 4, 7,
|
v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
// bottom
|
v.push_back({{x, 0.0f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
5, 1, 3, 7, 5, 3,
|
v.push_back({{0.0f, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
// top
|
v.push_back({{x, y, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}});
|
||||||
4, 0, 2, 6, 4, 2,
|
|
||||||
// left
|
|
||||||
4, 5, 1, 0, 4, 1,
|
|
||||||
// right
|
|
||||||
2, 3, 7, 6, 2, 7
|
|
||||||
};
|
|
||||||
|
|
||||||
return std::make_unique<engine::resources::Mesh>(v, indices);
|
// back
|
||||||
|
v.push_back({{0.0f, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, z}, {0.0f, 0.0f, 1.0f}, {0.0f, 0.0f}});
|
||||||
|
|
||||||
|
// left
|
||||||
|
v.push_back({{0.0f, 0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, 0.0f, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, x}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, 0.0f}, {-1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
|
||||||
|
// right
|
||||||
|
v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, y, 0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, y, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, x}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
|
||||||
|
// bottom
|
||||||
|
v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, 0.0f, z}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
|
||||||
|
// top
|
||||||
|
v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, y, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{0.0f, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
v.push_back({{x, y, z}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}});
|
||||||
|
|
||||||
|
return std::make_unique<engine::resources::Mesh>(gfx, v);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@
|
|||||||
#include "resources/mesh.hpp"
|
#include "resources/mesh.hpp"
|
||||||
|
|
||||||
// generates a UV sphere
|
// generates a UV sphere
|
||||||
std::unique_ptr<engine::resources::Mesh> genSphereMesh(float r, int detail, bool windInside = false);
|
std::unique_ptr<engine::resources::Mesh> genSphereMesh(engine::GFXDevice* gfx, float r, int detail, bool windInside = false, bool flipNormals = false);
|
||||||
std::unique_ptr<engine::resources::Mesh> genCuboidMesh(float x, float y, float z);
|
std::unique_ptr<engine::resources::Mesh> genCuboidMesh(engine::GFXDevice* gfx, float x, float y, float z);
|
||||||
|
Loading…
Reference in New Issue
Block a user