mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 10:48:34 +02:00
+ | Offset bvh in the parsing
This commit is contained in:
@ -20,8 +20,9 @@ class ObjParser
|
||||
public:
|
||||
ObjParser(std::string &filename);
|
||||
~ObjParser();
|
||||
void parse(Scene &scene);
|
||||
|
||||
void parse(Scene &scene, glm::vec3 offset);
|
||||
|
||||
private:
|
||||
glm::vec3 getVertex(std::stringstream &line);
|
||||
glm::vec2 getUV(std::stringstream &line);
|
||||
|
@ -111,7 +111,7 @@ class Scene
|
||||
void updateLightAndObjects(int mat_id);
|
||||
std::set<int> getGPULights();
|
||||
|
||||
void addBvh(std::vector<Triangle> &triangles);
|
||||
void addBvh(std::vector<Triangle> &triangles, glm::vec3 offset);
|
||||
|
||||
const std::vector<GPUObject> &getObjectData() const;
|
||||
const std::vector<GPUTriangle> &getTriangleData() const;
|
||||
|
@ -25,6 +25,7 @@ class SceneParser
|
||||
private:
|
||||
void parseMaterial(std::stringstream &line);
|
||||
void parseCamera(std::stringstream &line);
|
||||
void parseObj(std::stringstream &line);
|
||||
|
||||
Scene *_scene;
|
||||
|
||||
|
@ -24,8 +24,8 @@ pl 0 -2 0 0 1 0 2 // floor
|
||||
|
||||
qu -1 1.999 -1 2 0 0 0 0 2 6
|
||||
|
||||
OBJ obj/Dragon_80K.obj
|
||||
# OBJ obj/Dragon_80K.obj
|
||||
OBJ obj/Dragon_80K.obj 0 0 0
|
||||
OBJ obj/Dragon_80K.obj 0 0 1
|
||||
# OBJ obj/teapot.obj
|
||||
|
||||
# OBJ obj/Model.obj
|
||||
|
@ -129,7 +129,7 @@ hitInfo traverseBVHs(Ray ray)
|
||||
{
|
||||
GPUBvhData bvh_data = BvhData[i];
|
||||
|
||||
ray.origin = ray.origin + vec3(float(i), 0., 0.);
|
||||
ray.origin -= bvh_data.offset;
|
||||
hitInfo temp_hit = traceBVH(ray, bvh_data);
|
||||
|
||||
if (temp_hit.t < hit.t)
|
||||
@ -141,6 +141,8 @@ hitInfo traverseBVHs(Ray ray)
|
||||
hit.position = temp_hit.position;
|
||||
hit.normal = temp_hit.normal;
|
||||
}
|
||||
|
||||
ray.origin += bvh_data.offset;
|
||||
}
|
||||
|
||||
return (hit);
|
||||
|
@ -240,7 +240,7 @@ void ObjParser::parseMtl(std::stringstream &input_line, Scene &scene)
|
||||
file.close();
|
||||
}
|
||||
|
||||
void ObjParser::parse(Scene &scene)
|
||||
void ObjParser::parse(Scene &scene, glm::vec3 offset)
|
||||
{
|
||||
std::string line;
|
||||
std::string identifier;
|
||||
@ -275,6 +275,6 @@ void ObjParser::parse(Scene &scene)
|
||||
}
|
||||
}
|
||||
|
||||
scene.addBvh(_triangles);
|
||||
scene.addBvh(_triangles, offset);
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ void Scene::addObject(Object *obj)
|
||||
_gpu_objects.push_back(gpu_obj);
|
||||
}
|
||||
|
||||
void Scene::addBvh(std::vector<Triangle> &triangles)
|
||||
void Scene::addBvh(std::vector<Triangle> &triangles, glm::vec3 offset)
|
||||
{
|
||||
GPUBvhData new_bvh_data;
|
||||
std::vector<GPUBvh> new_bvhs_list;
|
||||
@ -153,8 +153,9 @@ void Scene::addBvh(std::vector<Triangle> &triangles)
|
||||
|
||||
BVH *bvh = new BVH(triangles, 0, triangles.size());
|
||||
new_bvhs_list = bvh->getGPUBvhs();
|
||||
|
||||
new_bvh_data.offset = glm::vec3(0., 0., 0.);
|
||||
|
||||
std::cout << glm::to_string(offset) << std::endl;
|
||||
new_bvh_data.offset = offset;
|
||||
new_bvh_data.bvh_start_index = _gpu_bvh.size();
|
||||
new_bvh_data.triangle_start_index = _gpu_triangles.size();
|
||||
|
||||
|
@ -95,6 +95,20 @@ void SceneParser::parseCamera(std::stringstream &line)
|
||||
|
||||
}
|
||||
|
||||
void SceneParser::parseObj(std::stringstream &line)
|
||||
{
|
||||
std::string name;
|
||||
float x = 0.;
|
||||
float y = 0.;
|
||||
float z = 0.;
|
||||
|
||||
line >> name;
|
||||
line >> x >> y >> z;
|
||||
|
||||
ObjParser obj(name);
|
||||
obj.parse(*_scene, glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
bool SceneParser::parseLine(const std::string &line)
|
||||
{
|
||||
if (line.empty() || line[0] == '#')
|
||||
@ -128,11 +142,7 @@ bool SceneParser::parseLine(const std::string &line)
|
||||
else if (identifier == "CAM")
|
||||
this->parseCamera(ss);
|
||||
else if (identifier == "OBJ")
|
||||
{
|
||||
ss >> identifier;
|
||||
ObjParser obj(identifier);
|
||||
obj.parse(*_scene);
|
||||
}
|
||||
this->parseObj(ss);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user