mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Better parsing
This commit is contained in:
@ -57,22 +57,16 @@ class Scene
|
|||||||
void addObject(Object *object);
|
void addObject(Object *object);
|
||||||
void addMaterial(Material *material);
|
void addMaterial(Material *material);
|
||||||
|
|
||||||
void updateGPUData();
|
|
||||||
|
|
||||||
const std::vector<GPUObject> &getObjectData() const;
|
const std::vector<GPUObject> &getObjectData() const;
|
||||||
std::vector<GPUMaterial> &getMaterialData();
|
std::vector<GPUMaterial> &getMaterialData();
|
||||||
|
|
||||||
Camera *getCamera(void) const;
|
Camera *getCamera(void) const;
|
||||||
Material *getMaterial(int material_index);
|
GPUMaterial getMaterial(int material_index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Object *> _objects;
|
|
||||||
std::vector<Material *> _materials;
|
|
||||||
|
|
||||||
std::vector<GPUObject> _gpu_objects;
|
std::vector<GPUObject> _gpu_objects;
|
||||||
std::vector<GPUMaterial> _gpu_materials;
|
std::vector<GPUMaterial> _gpu_materials;
|
||||||
|
|
||||||
|
|
||||||
Camera *_camera;
|
Camera *_camera;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,29 +50,9 @@ bool Scene::parseScene(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Scene::addObject(Object *object)
|
void Scene::addObject(Object *obj)
|
||||||
{
|
|
||||||
_objects.push_back(object);
|
|
||||||
this->updateGPUData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::addMaterial(Material *material)
|
|
||||||
{
|
|
||||||
_materials.push_back(material);
|
|
||||||
this->updateGPUData();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scene::updateGPUData()
|
|
||||||
{
|
{
|
||||||
GPUObject gpu_obj;
|
GPUObject gpu_obj;
|
||||||
GPUMaterial gpu_mat;
|
|
||||||
|
|
||||||
_gpu_objects.clear();
|
|
||||||
_gpu_materials.clear();
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < _objects.size(); i++)
|
|
||||||
{
|
|
||||||
Object *obj = _objects[i];
|
|
||||||
|
|
||||||
gpu_obj.mat_index = obj->getMaterialIndex();
|
gpu_obj.mat_index = obj->getMaterialIndex();
|
||||||
gpu_obj.position = obj->getPosition();
|
gpu_obj.position = obj->getPosition();
|
||||||
@ -121,11 +101,13 @@ void Scene::updateGPUData()
|
|||||||
gpu_obj.normal = portal->getNormal();
|
gpu_obj.normal = portal->getNormal();
|
||||||
gpu_obj.transform = glm::mat4(portal->getRotation());
|
gpu_obj.transform = glm::mat4(portal->getRotation());
|
||||||
|
|
||||||
Portal *linked = static_cast<Portal *>(_objects[i - 2]);
|
int i = _gpu_objects.size();
|
||||||
|
|
||||||
|
GPUObject &linked = _gpu_objects[i - 2];
|
||||||
|
|
||||||
if (portal->getLinkedPortalIndex() == -1)
|
if (portal->getLinkedPortalIndex() == -1)
|
||||||
{
|
{
|
||||||
if (linked->getType() == Object::Type::PORTAL && linked->getLinkedPortalIndex() == static_cast<int>(i))
|
if (linked.type == (int)Object::Type::PORTAL && linked.radius == static_cast<int>(i))
|
||||||
portal->setLinkedPortalIndex(i - 2);
|
portal->setLinkedPortalIndex(i - 2);
|
||||||
else
|
else
|
||||||
portal->setLinkedPortalIndex(i + 2);
|
portal->setLinkedPortalIndex(i + 2);
|
||||||
@ -135,9 +117,12 @@ void Scene::updateGPUData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_gpu_objects.push_back(gpu_obj);
|
_gpu_objects.push_back(gpu_obj);
|
||||||
}
|
}
|
||||||
for (const auto &material : _materials)
|
|
||||||
{
|
void Scene::addMaterial(Material *material)
|
||||||
|
{
|
||||||
|
GPUMaterial gpu_mat;
|
||||||
|
|
||||||
gpu_mat.color = material->color;
|
gpu_mat.color = material->color;
|
||||||
gpu_mat.emission = material->emission;
|
gpu_mat.emission = material->emission;
|
||||||
gpu_mat.roughness = material->roughness;
|
gpu_mat.roughness = material->roughness;
|
||||||
@ -146,7 +131,6 @@ void Scene::updateGPUData()
|
|||||||
gpu_mat.type = material->type;
|
gpu_mat.type = material->type;
|
||||||
|
|
||||||
_gpu_materials.push_back(gpu_mat);
|
_gpu_materials.push_back(gpu_mat);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<GPUObject>& Scene::getObjectData() const
|
const std::vector<GPUObject>& Scene::getObjectData() const
|
||||||
@ -164,9 +148,9 @@ Camera *Scene::getCamera(void) const
|
|||||||
return (_camera);
|
return (_camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
Material *Scene::getMaterial(int material_index)
|
GPUMaterial Scene::getMaterial(int material_index)
|
||||||
{
|
{
|
||||||
if (material_index < 0 || material_index >= (int)_materials.size())
|
if (material_index < 0 || material_index >= (int)_gpu_materials.size())
|
||||||
throw std::runtime_error("Incorrect material index");
|
throw std::runtime_error("Incorrect material index");
|
||||||
return (_materials[material_index]);
|
return (_gpu_materials[material_index]);
|
||||||
}
|
}
|
Reference in New Issue
Block a user