define function to get boundary

This commit is contained in:
ayachi3 2022-12-13 16:03:28 +08:00
parent b145dbc567
commit 30fe45b773
3 changed files with 53 additions and 4 deletions

View File

@ -68,8 +68,8 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
// 使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息
for (int j = 0; j < 3; j++) {
vertexPosition[j] = mesh->mVertices[i][j];
left_down_back[j] = left_down_back[j] < vertexPosition[j] ? left_down_back[j] : vertexPosition[j];
right_up_front[j] = right_up_front[j] > vertexPosition[j] ? right_up_front[j] : vertexPosition[j];
_left_down_back[j] = _left_down_back[j] < vertexPosition[j] ? _left_down_back[j] : vertexPosition[j];
_right_up_front[j] = _right_up_front[j] > vertexPosition[j] ? _right_up_front[j] : vertexPosition[j];
}
//vertexPosition.x = mesh->mVertices[i].x;

View File

@ -20,9 +20,9 @@ private:
MODELSTATUS _status = LOADING;
// smallest point
glm::vec3 left_down_back = glm::vec3(3e37f, 3e37f, 3e37f);
glm::vec3 _left_down_back = glm::vec3(3e37f, 3e37f, 3e37f);
// largest point
glm::vec3 right_up_front = -left_down_back;
glm::vec3 _right_up_front = -_left_down_back;
public:
Model(std::string path);
@ -31,6 +31,13 @@ public:
public:
inline MODELSTATUS status() const { return _status; }
inline glm::vec3 get_upper_bound() {
return _right_up_front;
}
inline glm::vec3 get_lower_bound() {
return _left_down_back;
}
private:
void loadModel(std::string path);
void processNode(aiNode* node, const aiScene* scene);

View File

@ -0,0 +1,42 @@
#pragma once
#include <vector>
#include <string>
#include <Assimp/Importer.hpp>
#include <Assimp/scene.h>
#include <Assimp/postprocess.h>
#include "mesh.h"
#include "shader.h"
#include <limits>
class Model {
public:
enum MODELSTATUS { LOADING, LOADED, ERR };
private:
std::vector<Mesh> _meshes;
std::vector<Texture> _texturesLoaded;
std::string _directory;
MODELSTATUS _status = LOADING;
// smallest point
glm::vec3 left_down_back = glm::vec3(3e37f, 3e37f, 3e37f);
// largest point
glm::vec3 right_up_front = -left_down_back;
public:
Model(std::string path);
~Model();
public:
inline MODELSTATUS status() const { return _status; }
private:
void loadModel(std::string path);
void processNode(aiNode* node, const aiScene* scene);
Mesh processMesh(aiMesh* mesh, const aiScene* scene);
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, TextureType textureType);
public:
void render(const ShaderProgram& shader) const;
};