src/linetypes/subfilereference.cpp

changeset 150
b6cbba6e29a1
parent 148
e1ced2523cad
child 158
5bd755eaa5a8
equal deleted inserted replaced
148:e1ced2523cad 150:b6cbba6e29a1
1 #include "subfilereference.h" 1 #include "subfilereference.h"
2 #include "documentmanager.h" 2 #include "documentmanager.h"
3 #include "invert.h" 3 #include "invert.h"
4 #include "polygoncache.h"
4 5
5 ldraw::SubfileReference::SubfileReference 6 ldraw::SubfileReference::SubfileReference
6 ( 7 (
7 const glm::mat4& transformation, 8 const glm::mat4& transformation,
8 const QString& referenceName, 9 const QString& referenceName,
43 ( 44 (
44 std::vector<gl::Polygon>& polygons, 45 std::vector<gl::Polygon>& polygons,
45 GetPolygonsContext* context 46 GetPolygonsContext* context
46 ) const 47 ) const
47 { 48 {
48 Model* referencedModel = this->resolve(context->modelId, context->documents); 49 Model* dependency = this->resolve(context->modelId, context->documents);
49 if (referencedModel != nullptr) 50 PolygonCache* referencedModelPolygonBuilder = nullptr;
51 if (dependency != nullptr)
52 {
53 const auto dependencyModelId = context->documents->findIdForModel(dependency);
54 if (dependencyModelId.has_value())
55 {
56 referencedModelPolygonBuilder = context->documents->getPolygonCacheForModel(dependencyModelId.value());
57 }
58 }
59 if (referencedModelPolygonBuilder != nullptr)
50 { 60 {
51 const bool needInverting = glm::determinant(this->transformation) < 0; 61 const bool needInverting = glm::determinant(this->transformation) < 0;
52 const std::vector<gl::Polygon> modelPolygons = referencedModel->getPolygons(context->documents); 62 const std::vector<gl::Polygon> modelPolygons = referencedModelPolygonBuilder->getPolygons(context->documents);
53 polygons.reserve(polygons.size() + modelPolygons.size()); 63 polygons.reserve(polygons.size() + modelPolygons.size());
54 for (gl::Polygon polygon : modelPolygons) 64 for (gl::Polygon polygon : modelPolygons)
55 { 65 {
56 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) 66 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1)
57 { 67 {

mercurial