src/polygoncache.cpp

changeset 374
75efc3ba5a56
parent 372
b2914aaeec1a
equal deleted inserted replaced
373:e34d6a30b96d 374:75efc3ba5a56
8 { 8 {
9 return documents->findDependencyByName(callingModelId, name); 9 return documents->findDependencyByName(callingModelId, name);
10 } 10 }
11 11
12 static PolygonElement transformed( 12 static PolygonElement transformed(
13 PolygonElement element, 13 PolygonElement coloredElement,
14 const glm::mat4& transform) 14 const glm::mat4& transform)
15 { 15 {
16 visitPoints([&transform](glm::vec3& p) { 16 visitPoints([&transform](glm::vec3& p) {
17 p = transform * glm::vec4{p, 1}; 17 p = transform * glm::vec4{p, 1};
18 }, element); 18 }, coloredElement.element);
19 return element; 19 return coloredElement;
20 } 20 }
21 21
22 PolygonCache* findPolygonCacheForModel(QTextDocument* model, DocumentManager* context) 22 PolygonCache* findPolygonCacheForModel(QTextDocument* model, DocumentManager* context)
23 { 23 {
24 std::optional<ModelId> modelId = context->findIdForModel(model); 24 std::optional<ModelId> modelId = context->findIdForModel(model);
57 GetPolygonsContext* context, 57 GetPolygonsContext* context,
58 Fn&& add, 58 Fn&& add,
59 Fn2&& reserve) 59 Fn2&& reserve)
60 { 60 {
61 const bool needInverting = 0 61 const bool needInverting = 0
62 ^ (glm::determinant(ref.transformation) < 0) 62 ^ (glm::determinant(ref.element.transformation) < 0)
63 ^ (context->invertnext); 63 ^ (context->invertnext);
64 reserve(polygons.size()); 64 reserve(polygons.size());
65 for (const PolygonElement& cacheElement : polygons) { 65 for (const PolygonElement& cacheElement : polygons) {
66 PolygonElement polygon = transformed(cacheElement, ref.transformation); 66 PolygonElement polygon = transformed(cacheElement, ref.element.transformation);
67 if (needInverting) { 67 if (needInverting) {
68 gl::invert(polygon); 68 gl::invert(polygon.element);
69 } 69 }
70 if (polygon.color == MAIN_COLOR) { 70 if (polygon.color == MAIN_COLOR) {
71 polygon.color = ref.color; 71 polygon.color = ref.color;
72 } 72 }
73 add(1, polygon); 73 add(1, polygon);
104 else if (text == QStringLiteral("BFC NOCERTIFY")) { 104 else if (text == QStringLiteral("BFC NOCERTIFY")) {
105 winding = winding_e::none; 105 winding = winding_e::none;
106 } 106 }
107 }, 107 },
108 [&](const LineType2& line2) { 108 [&](const LineType2& line2) {
109 add(2, {line2.value, line2.value.color}); 109 add(2, {line2.value.element, line2.value.color});
110 }, 110 },
111 [&](const LineType3& line3) { 111 [&](const LineType3& line3) {
112 add(3, {line3.value, line3.value.color}); 112 add(3, {line3.value.element, line3.value.color});
113 }, 113 },
114 [&](const LineType4& line4) { 114 [&](const LineType4& line4) {
115 add(4, {line4.value, line4.value.color}); 115 add(4, {line4.value.element, line4.value.color});
116 }, 116 },
117 [&](const LineType5& line5) { 117 [&](const LineType5& line5) {
118 add(5, {line5.value, line5.value.color}); 118 add(5, {line5.value.element, line5.value.color});
119 }, 119 },
120 [&add, context, &reserve](const LineType1& line1) { 120 [&add, context, &reserve](const LineType1& line1) {
121 QTextDocument* const dependency = findDependency(line1.value, context); 121 QTextDocument* const dependency = findDependency(line1.value.element, context);
122 if (PolygonCache* cache = (dependency != nullptr) 122 if (PolygonCache* cache = (dependency != nullptr)
123 ? findPolygonCacheForModel(dependency, context->documents) 123 ? findPolygonCacheForModel(dependency, context->documents)
124 : nullptr 124 : nullptr
125 ) { 125 ) {
126 recacheIfNeeded(cache, dependency, context->documents); 126 recacheIfNeeded(cache, dependency, context->documents);
151 std::vector<WithId<PolygonElement>> result; 151 std::vector<WithId<PolygonElement>> result;
152 int i = 0; 152 int i = 0;
153 const auto add = [&result, &winding, &i](int lineno, const PolygonElement& poly){ 153 const auto add = [&result, &winding, &i](int lineno, const PolygonElement& poly){
154 result.push_back({poly, i}); 154 result.push_back({poly, i});
155 if (lineno != 1 and winding == winding_e::clockwise) { 155 if (lineno != 1 and winding == winding_e::clockwise) {
156 gl::invert(result.back()); 156 gl::invert(result.back().element);
157 } 157 }
158 }; 158 };
159 const auto reserve = [&result](std::size_t incomingsize){ 159 const auto reserve = [&result](std::size_t incomingsize){
160 reserveMore(result, incomingsize); 160 reserveMore(result, incomingsize);
161 }; 161 };

mercurial