Working on model
This commit is contained in:
parent
f5940c729c
commit
4a784036bd
@ -40,6 +40,7 @@ namespace ZL
|
|||||||
static const std::regex pattern_int(R"([-]?\d+)");
|
static const std::regex pattern_int(R"([-]?\d+)");
|
||||||
static const std::regex pattern_boneChildren(R"(\'([^\']+)\')");
|
static const std::regex pattern_boneChildren(R"(\'([^\']+)\')");
|
||||||
static const std::regex pattern_bone_weight(R"(\'([^\']+)\'.*?([-]?\d+\.\d+))");
|
static const std::regex pattern_bone_weight(R"(\'([^\']+)\'.*?([-]?\d+\.\d+))");
|
||||||
|
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
|
|
||||||
int numberBones;
|
int numberBones;
|
||||||
@ -219,7 +220,7 @@ namespace ZL
|
|||||||
vertices[i] = Vector3f{floatValues[0], floatValues[1], floatValues[2]};
|
vertices[i] = Vector3f{floatValues[0], floatValues[1], floatValues[2]};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::getline(f, tempLine); //vertice count
|
std::getline(f, tempLine); //triangle count
|
||||||
int numberTriangles;
|
int numberTriangles;
|
||||||
|
|
||||||
if (std::regex_search(tempLine, match, pattern_count)) {
|
if (std::regex_search(tempLine, match, pattern_count)) {
|
||||||
|
|||||||
BIN
Kitchen_ceramics.bmp
Normal file
BIN
Kitchen_ceramics.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
222
TextModel.cpp
Normal file
222
TextModel.cpp
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
#include "TextModel.h"
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace ZL
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
VertexDataStruct LoadFromTextFile(const std::string& fileName)
|
||||||
|
{
|
||||||
|
VertexDataStruct result;
|
||||||
|
|
||||||
|
std::ifstream f(fileName);
|
||||||
|
|
||||||
|
//Skip first 5 lines
|
||||||
|
std::string tempLine;
|
||||||
|
|
||||||
|
std::getline(f, tempLine);
|
||||||
|
|
||||||
|
static const std::regex pattern_count(R"(\d+)");
|
||||||
|
static const std::regex pattern_float(R"([-]?\d+\.\d+)");
|
||||||
|
static const std::regex pattern_int(R"([-]?\d+)");
|
||||||
|
|
||||||
|
|
||||||
|
std::smatch match;
|
||||||
|
|
||||||
|
int numberVertices;
|
||||||
|
|
||||||
|
if (std::regex_search(tempLine, match, pattern_count)) {
|
||||||
|
std::string number_str = match.str();
|
||||||
|
numberVertices = std::stoi(number_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw std::runtime_error("No number found in the input string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Vector3f> vertices;
|
||||||
|
|
||||||
|
vertices.resize(numberVertices);
|
||||||
|
for (int i = 0; i < numberVertices; i++)
|
||||||
|
{
|
||||||
|
std::getline(f, tempLine);
|
||||||
|
|
||||||
|
std::vector<float> floatValues;
|
||||||
|
|
||||||
|
auto b = tempLine.cbegin();
|
||||||
|
auto e = tempLine.cend();
|
||||||
|
while (std::regex_search(b, e, match, pattern_float)) {
|
||||||
|
floatValues.push_back(std::stof(match.str()));
|
||||||
|
b = match.suffix().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertices[i] = Vector3f{ floatValues[0], floatValues[1], floatValues[2] };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Hello x1" << std::endl;
|
||||||
|
|
||||||
|
std::getline(f, tempLine); //===UV Coordinates:
|
||||||
|
|
||||||
|
std::getline(f, tempLine); //triangle count
|
||||||
|
int numberTriangles;
|
||||||
|
|
||||||
|
if (std::regex_search(tempLine, match, pattern_count)) {
|
||||||
|
std::string number_str = match.str();
|
||||||
|
numberTriangles = std::stoi(number_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw std::runtime_error("No number found in the input string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Now process UVs
|
||||||
|
std::vector<std::array<Vector2f, 3>> uvCoords;
|
||||||
|
|
||||||
|
uvCoords.resize(numberTriangles);
|
||||||
|
|
||||||
|
for (int i = 0; i < numberTriangles; i++)
|
||||||
|
{
|
||||||
|
std::getline(f, tempLine); //Face 0
|
||||||
|
|
||||||
|
int uvCount;
|
||||||
|
std::getline(f, tempLine);
|
||||||
|
if (std::regex_search(tempLine, match, pattern_count)) {
|
||||||
|
std::string number_str = match.str();
|
||||||
|
uvCount = std::stoi(number_str);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw std::runtime_error("No number found in the input string.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uvCount != 3)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("more than 3 uvs");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<float> floatValues;
|
||||||
|
|
||||||
|
for (int j = 0; j < 3; j++)
|
||||||
|
{
|
||||||
|
std::getline(f, tempLine); //UV <Vector (-0.3661, -1.1665)>
|
||||||
|
|
||||||
|
auto b = tempLine.cbegin();
|
||||||
|
auto e = tempLine.cend();
|
||||||
|
floatValues.clear();
|
||||||
|
while (std::regex_search(b, e, match, pattern_float)) {
|
||||||
|
floatValues.push_back(std::stof(match.str()));
|
||||||
|
b = match.suffix().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (floatValues.size() != 2)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("more than 2 uvs---");
|
||||||
|
}
|
||||||
|
|
||||||
|
uvCoords[i][j] = Vector2f{ floatValues[0],floatValues[1] };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Hello eee" << std::endl;
|
||||||
|
|
||||||
|
std::getline(f, tempLine); //===Normals:
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Vector3f> normals;
|
||||||
|
|
||||||
|
normals.resize(numberVertices);
|
||||||
|
for (int i = 0; i < numberVertices; i++)
|
||||||
|
{
|
||||||
|
std::getline(f, tempLine);
|
||||||
|
|
||||||
|
std::vector<float> floatValues;
|
||||||
|
|
||||||
|
auto b = tempLine.cbegin();
|
||||||
|
auto e = tempLine.cend();
|
||||||
|
while (std::regex_search(b, e, match, pattern_float)) {
|
||||||
|
floatValues.push_back(std::stof(match.str()));
|
||||||
|
b = match.suffix().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
normals[i] = Vector3f{ floatValues[0], floatValues[1], floatValues[2] };
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Hello x4" << std::endl;
|
||||||
|
|
||||||
|
std::getline(f, tempLine); //===Triangles: 3974
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::array<int, 3>> triangles;
|
||||||
|
|
||||||
|
triangles.resize(numberTriangles);
|
||||||
|
for (int i = 0; i < numberTriangles; i++)
|
||||||
|
{
|
||||||
|
std::getline(f, tempLine);
|
||||||
|
|
||||||
|
std::vector<int> intValues;
|
||||||
|
|
||||||
|
auto b = tempLine.cbegin();
|
||||||
|
auto e = tempLine.cend();
|
||||||
|
while (std::regex_search(b, e, match, pattern_int)) {
|
||||||
|
intValues.push_back(std::stoi(match.str()));
|
||||||
|
b = match.suffix().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
triangles[i] = { intValues[0], intValues[1], intValues[2] };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Hello x5" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Now let's process bone weights and vertices
|
||||||
|
|
||||||
|
for (int i = 0; i < numberTriangles; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
result.PositionData.push_back(vertices[triangles[i][0]]);
|
||||||
|
result.PositionData.push_back(vertices[triangles[i][1]]);
|
||||||
|
result.PositionData.push_back(vertices[triangles[i][2]]);
|
||||||
|
|
||||||
|
|
||||||
|
result.NormalData.push_back(normals[triangles[i][0]]);
|
||||||
|
result.NormalData.push_back(normals[triangles[i][1]]);
|
||||||
|
result.NormalData.push_back(normals[triangles[i][2]]);
|
||||||
|
|
||||||
|
result.TexCoordData.push_back(uvCoords[i][0]);
|
||||||
|
result.TexCoordData.push_back(uvCoords[i][1]);
|
||||||
|
result.TexCoordData.push_back(uvCoords[i][2]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Swap from Blender format to OpenGL format
|
||||||
|
for (int i = 0; i < result.PositionData.size(); i++)
|
||||||
|
{
|
||||||
|
Vector3f tempVec = result.PositionData[i];
|
||||||
|
result.PositionData[i].v[0] = tempVec.v[1];
|
||||||
|
result.PositionData[i].v[1] = tempVec.v[2];
|
||||||
|
result.PositionData[i].v[2] = tempVec.v[0];
|
||||||
|
|
||||||
|
tempVec = result.NormalData[i];
|
||||||
|
result.NormalData[i].v[0] = tempVec.v[1];
|
||||||
|
result.NormalData[i].v[1] = tempVec.v[2];
|
||||||
|
result.NormalData[i].v[2] = tempVec.v[0];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
14
TextModel.h
Normal file
14
TextModel.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Math.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
|
||||||
|
namespace ZL
|
||||||
|
{
|
||||||
|
VertexDataStruct LoadFromTextFile(const std::string& fileName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -155,6 +155,7 @@
|
|||||||
<ClCompile Include="Physics.cpp" />
|
<ClCompile Include="Physics.cpp" />
|
||||||
<ClCompile Include="Renderer.cpp" />
|
<ClCompile Include="Renderer.cpp" />
|
||||||
<ClCompile Include="ShaderManager.cpp" />
|
<ClCompile Include="ShaderManager.cpp" />
|
||||||
|
<ClCompile Include="TextModel.cpp" />
|
||||||
<ClCompile Include="TextureManager.cpp" />
|
<ClCompile Include="TextureManager.cpp" />
|
||||||
<ClCompile Include="Utils.cpp" />
|
<ClCompile Include="Utils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -169,6 +170,7 @@
|
|||||||
<ClInclude Include="Physics.h" />
|
<ClInclude Include="Physics.h" />
|
||||||
<ClInclude Include="Renderer.h" />
|
<ClInclude Include="Renderer.h" />
|
||||||
<ClInclude Include="ShaderManager.h" />
|
<ClInclude Include="ShaderManager.h" />
|
||||||
|
<ClInclude Include="TextModel.h" />
|
||||||
<ClInclude Include="TextureManager.h" />
|
<ClInclude Include="TextureManager.h" />
|
||||||
<ClInclude Include="Utils.h" />
|
<ClInclude Include="Utils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -51,6 +51,9 @@
|
|||||||
<ClCompile Include="BoneAnimatedModel.cpp">
|
<ClCompile Include="BoneAnimatedModel.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="TextModel.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="TextureManager.h">
|
<ClInclude Include="TextureManager.h">
|
||||||
@ -89,5 +92,8 @@
|
|||||||
<ClInclude Include="BoneAnimatedModel.h">
|
<ClInclude Include="BoneAnimatedModel.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="TextModel.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
44
main.cpp
44
main.cpp
@ -15,6 +15,7 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "AnimatedModel.h"
|
#include "AnimatedModel.h"
|
||||||
#include "BoneAnimatedModel.h"
|
#include "BoneAnimatedModel.h"
|
||||||
|
#include "TextModel.h"
|
||||||
|
|
||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
@ -25,7 +26,7 @@ namespace ZL
|
|||||||
|
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
/*
|
||||||
Vector2f birdStartPos;
|
Vector2f birdStartPos;
|
||||||
|
|
||||||
float backgroundSectionWidth;
|
float backgroundSectionWidth;
|
||||||
@ -33,12 +34,13 @@ namespace ZL
|
|||||||
int getActualClientHeight()
|
int getActualClientHeight()
|
||||||
{
|
{
|
||||||
return height - windowHeaderHeight;
|
return height - windowHeaderHeight;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace GameObjects
|
namespace GameObjects
|
||||||
{
|
{
|
||||||
std::shared_ptr<Texture> testObjTexturePtr;
|
std::shared_ptr<Texture> testObjTexturePtr;
|
||||||
|
std::shared_ptr<Texture> roomTexturePtr;
|
||||||
|
|
||||||
VertexDataStruct colorCubeMesh;
|
VertexDataStruct colorCubeMesh;
|
||||||
VertexRenderStruct colorCubeMeshMutable;
|
VertexRenderStruct colorCubeMeshMutable;
|
||||||
@ -49,6 +51,9 @@ namespace ZL
|
|||||||
BoneSystem bx;
|
BoneSystem bx;
|
||||||
VertexRenderStruct bxMutable;
|
VertexRenderStruct bxMutable;
|
||||||
|
|
||||||
|
VertexDataStruct textMesh;
|
||||||
|
VertexRenderStruct textMeshMutable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Window* window = NULL;
|
static SDL_Window* window = NULL;
|
||||||
@ -85,21 +90,31 @@ namespace ZL
|
|||||||
|
|
||||||
glViewport(0, 0, Env::width, Env::height);
|
glViewport(0, 0, Env::width, Env::height);
|
||||||
|
|
||||||
//renderer.shaderManager.PushShader(defaultShaderName);
|
renderer.shaderManager.PushShader(defaultShaderName);
|
||||||
renderer.shaderManager.PushShader(colorShaderName);
|
renderer.RenderUniform1i(textureUniformName, 0);
|
||||||
//renderer.RenderUniform1i(textureUniformName, 0);
|
|
||||||
|
|
||||||
renderer.EnableVertexAttribArray(vPositionName);
|
renderer.EnableVertexAttribArray(vPositionName);
|
||||||
//renderer.EnableVertexAttribArray(vTexCoordName);
|
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||||
|
|
||||||
renderer.PushPerspectiveProjectionMatrix(1.0 / 6.0, static_cast<float>(Env::width) / static_cast<float>(Env::height), 0.1, 1000);
|
renderer.PushPerspectiveProjectionMatrix(1.0 / 6.0, static_cast<float>(Env::width) / static_cast<float>(Env::height), 10, 50000);
|
||||||
renderer.PushMatrix();
|
renderer.PushMatrix();
|
||||||
|
|
||||||
renderer.LoadIdentity();
|
renderer.LoadIdentity();
|
||||||
|
|
||||||
renderer.TranslateMatrix({ 0,0, -200 });
|
renderer.TranslateMatrix({ 0,0, -4000 });
|
||||||
|
|
||||||
renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
float t = 0.7;
|
||||||
|
|
||||||
|
renderer.RotateMatrix(QuatFromRotateAroundX(t * M_PI / 2.0));
|
||||||
|
|
||||||
|
GameObjects::textMeshMutable.AssignFrom(GameObjects::textMesh);
|
||||||
|
GameObjects::textMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, GameObjects::roomTexturePtr->getTexID());
|
||||||
|
renderer.DrawVertexRenderStruct(GameObjects::textMeshMutable);
|
||||||
|
|
||||||
|
//renderer.RotateMatrix(QuatFromRotateAroundX(-M_PI / 2.0));
|
||||||
//renderer.RotateMatrix(QuatFromRotateAroundZ(-M_PI / 4.0));
|
//renderer.RotateMatrix(QuatFromRotateAroundZ(-M_PI / 4.0));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -137,16 +152,16 @@ namespace ZL
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameObjects::bxMutable.AssignFrom(GameObjects::bx.mesh);
|
//GameObjects::bxMutable.AssignFrom(GameObjects::bx.mesh);
|
||||||
GameObjects::bxMutable.RefreshVBO();
|
//GameObjects::bxMutable.RefreshVBO();
|
||||||
renderer.DrawVertexRenderStruct(GameObjects::bxMutable);
|
//renderer.DrawVertexRenderStruct(GameObjects::bxMutable);
|
||||||
|
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
|
||||||
renderer.PopProjectionMatrix();
|
renderer.PopProjectionMatrix();
|
||||||
|
|
||||||
renderer.DisableVertexAttribArray(vPositionName);
|
renderer.DisableVertexAttribArray(vPositionName);
|
||||||
//renderer.DisableVertexAttribArray(vTexCoordName);
|
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||||
|
|
||||||
renderer.shaderManager.PopShader();
|
renderer.shaderManager.PopShader();
|
||||||
|
|
||||||
@ -246,6 +261,8 @@ namespace ZL
|
|||||||
std::cout << "Hello test 3" << std::endl;
|
std::cout << "Hello test 3" << std::endl;
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
|
GameObjects::roomTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
||||||
|
|
||||||
|
|
||||||
GameObjects::colorCubeMesh = CreateCube3D(5.0);
|
GameObjects::colorCubeMesh = CreateCube3D(5.0);
|
||||||
@ -258,6 +275,7 @@ namespace ZL
|
|||||||
GameObjects::testObjMeshMutable.data = GameObjects::testObjMesh;
|
GameObjects::testObjMeshMutable.data = GameObjects::testObjMesh;
|
||||||
GameObjects::testObjMeshMutable.RefreshVBO();
|
GameObjects::testObjMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
|
GameObjects::textMesh = LoadFromTextFile("./mesh001.txt");
|
||||||
|
|
||||||
std::cout << "Hello test 4x" << std::endl;
|
std::cout << "Hello test 4x" << std::endl;
|
||||||
|
|
||||||
|
|||||||
29169
mesh001.txt
Normal file
29169
mesh001.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user