mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 15:38:11 +08:00
add check_boundary
This commit is contained in:
parent
30fe45b773
commit
14a3a08bf6
@ -66,15 +66,15 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
|
||||
|
||||
// Process vertex positions
|
||||
// 使用循环避免代码重复,如果可行的话,可以在此循环中确定法向量等信息
|
||||
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];
|
||||
}
|
||||
//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];
|
||||
//}
|
||||
|
||||
//vertexPosition.x = mesh->mVertices[i].x;
|
||||
//vertexPosition.y = mesh->mVertices[i].y;
|
||||
//vertexPosition.z = mesh->mVertices[i].z;
|
||||
vertexPosition.x = mesh->mVertices[i].x;
|
||||
vertexPosition.y = mesh->mVertices[i].y;
|
||||
vertexPosition.z = mesh->mVertices[i].z;
|
||||
|
||||
// Process vertex normals
|
||||
if (mesh->mNormals) {
|
||||
@ -184,3 +184,19 @@ void Model::render(const ShaderProgram& shader) const {
|
||||
_meshes[i].render(shader);
|
||||
}
|
||||
}
|
||||
|
||||
void Model::check_boundary() {
|
||||
for (int i = 0; i < _meshes.size(); i++) {
|
||||
for (int j = 0; j < _meshes[i].vertices().size();j++) {
|
||||
// 0,1,2 for x,y,z
|
||||
for (int k = 0; k < 3; k++) {
|
||||
_left_down_back[k] = _left_down_back[k] < _meshes[i].vertices()[j]._position[k] ?
|
||||
_left_down_back[k] : _meshes[i].vertices()[j]._position[k];
|
||||
|
||||
_right_up_front[k] = _right_up_front[k] > _meshes[i].vertices()[j]._position[k] ?
|
||||
_right_up_front[k] : _meshes[i].vertices()[j]._position[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -20,7 +20,7 @@ private:
|
||||
MODELSTATUS _status = LOADING;
|
||||
|
||||
// smallest point
|
||||
glm::vec3 _left_down_back = glm::vec3(3e37f, 3e37f, 3e37f);
|
||||
glm::vec3 _left_down_back = glm::vec3(3e36f, 3e36f, 3e36f);
|
||||
// largest point
|
||||
glm::vec3 _right_up_front = -_left_down_back;
|
||||
|
||||
@ -31,6 +31,8 @@ public:
|
||||
public:
|
||||
inline MODELSTATUS status() const { return _status; }
|
||||
|
||||
|
||||
// maybe we can check if boundary has not been set yet
|
||||
inline glm::vec3 get_upper_bound() {
|
||||
return _right_up_front;
|
||||
}
|
||||
@ -46,4 +48,5 @@ private:
|
||||
|
||||
public:
|
||||
void render(const ShaderProgram& shader) const;
|
||||
void check_boundary();
|
||||
};
|
||||
@ -1,42 +0,0 @@
|
||||
#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;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user