src/gldata.cpp

changeset 442
4852e815df29
parent 441
a958f6925088
child 443
a70dd25dd4bb
equal deleted inserted replaced
441:a958f6925088 442:4852e815df29
142 } 142 }
143 143
144 // ============================================================================= 144 // =============================================================================
145 // ----------------------------------------------------------------------------- 145 // -----------------------------------------------------------------------------
146 void VertexCompiler::compilePolygon ( 146 void VertexCompiler::compilePolygon (
147 LDObject* obj, 147 LDObject* drawobj,
148 VertexCompiler::Array** arrays 148 LDObject* trueobj
149 ) { 149 ) {
150 LDObject::Type objtype = obj->getType(); 150 // Note: we use the true object's color but the draw object's vertices. This
151 // is so that the index color is generated correctly - it has to reference
152 // the true object's ID, this is crucial for picking to work.
153 Array** arrays = m_objArrays[trueobj];
154 LDObject::Type objtype = drawobj->getType();
151 bool isline = (objtype == LDObject::Line || objtype == LDObject::CondLine); 155 bool isline = (objtype == LDObject::Line || objtype == LDObject::CondLine);
152 int verts = isline ? 2 : obj->vertices(); 156 int verts = isline ? 2 : drawobj->vertices();
157
158 QColor normalColor = getObjectColor (trueobj, Normal),
159 pickColor = getObjectColor (trueobj, PickColor);
153 160
154 for (int i = 0; i < verts; ++i) { 161 for (int i = 0; i < verts; ++i) {
155 compileVertex (obj->getVertex (i), getObjectColor (obj, Normal), 162 compileVertex (drawobj->getVertex (i), normalColor, arrays[isline ? EdgeArray : MainArray]);
156 arrays[isline ? EdgeArray : MainArray]); 163 compileVertex (drawobj->getVertex (i), pickColor, arrays[isline ? EdgePickArray : PickArray]);
157 } 164 }
158 165
159 // For non-lines, compile BFC data 166 // For non-lines, compile BFC data
160 if (!isline) { 167 if (!isline) {
161 QColor col = getObjectColor (obj, BFCFront); 168 QColor col = getObjectColor (trueobj, BFCFront);
162 for (int i = 0; i < verts; ++i) 169 for (int i = 0; i < verts; ++i)
163 compileVertex (obj->getVertex(i), col, arrays[BFCArray]); 170 compileVertex (drawobj->getVertex(i), col, arrays[BFCArray]);
164 171
165 col = getObjectColor (obj, BFCBack); 172 col = getObjectColor (trueobj, BFCBack);
166 for (int i = verts - 1; i >= 0; --i) 173 for (int i = verts - 1; i >= 0; --i)
167 compileVertex (obj->getVertex(i), col, arrays[BFCArray]); 174 compileVertex (drawobj->getVertex(i), col, arrays[BFCArray]);
168 } 175 }
169 } 176 }
170 177
171 // ============================================================================= 178 // =============================================================================
172 // ----------------------------------------------------------------------------- 179 // -----------------------------------------------------------------------------
183 m_objArrays[obj][i]->clear(); 190 m_objArrays[obj][i]->clear();
184 } 191 }
185 192
186 switch (obj->getType()) { 193 switch (obj->getType()) {
187 case LDObject::Triangle: 194 case LDObject::Triangle:
188 compilePolygon (obj, m_objArrays[obj]); 195 compilePolygon (obj, obj);
189 m_changed[MainArray] = true; 196 m_changed[MainArray] = true;
190 break; 197 break;
191 198
192 case LDObject::Quad: 199 case LDObject::Quad:
193 for (LDTriangleObject* triangle : static_cast<LDQuadObject*> (obj)->splitToTriangles()) 200 for (LDTriangleObject* triangle : static_cast<LDQuadObject*> (obj)->splitToTriangles())
194 compilePolygon (triangle, m_objArrays[obj]); 201 compilePolygon (triangle, obj);
195 m_changed[MainArray] = true; 202 m_changed[MainArray] = true;
196 break; 203 break;
197 204
198 case LDObject::Line: 205 case LDObject::Line:
199 compilePolygon (obj, m_objArrays[obj]); 206 compilePolygon (obj, obj);
200 break; 207 break;
201 208
202 default: 209 default:
203 break; 210 break;
204 } 211 }
263 QColor qcol; 270 QColor qcol;
264 271
265 if (!obj->isColored()) 272 if (!obj->isColored())
266 return QColor(); 273 return QColor();
267 274
268 /* 275 if (colotype == PickColor) {
269 if (list == GL::PickList) {
270 // Make the color by the object's ID if we're picking, so we can make the 276 // Make the color by the object's ID if we're picking, so we can make the
271 // ID again from the color we get from the picking results. Be sure to use 277 // ID again from the color we get from the picking results. Be sure to use
272 // the top level parent's index since we want a subfile's children point 278 // the top level parent's index since we want a subfile's children point
273 // to the subfile itself. 279 // to the subfile itself.
274 long i = obj->topLevelParent()->id(); 280 long i = obj->topLevelParent()->id();
275 281
276 // Calculate a color based from this index. This method caters for 282 // Calculate a color based from this index. This method caters for
277 // 16777216 objects. I don't think that'll be exceeded anytime soon. :) 283 // 16777216 objects. I don't think that'll be exceeded anytime soon. :)
278 // ATM biggest is 53588.dat with 12600 lines. 284 // ATM biggest is 53588.dat with 12600 lines.
279 double r = (i / (256 * 256)) % 256, 285 int r = (i / (256 * 256)) % 256,
280 g = (i / 256) % 256, 286 g = (i / 256) % 256,
281 b = i % 256; 287 b = i % 256;
282 288
283 qglColor (QColor (r, g, b)); 289 return QColor (r, g, b);
284 return; 290 }
285 }
286 */
287 291
288 if ((colotype == BFCFront || colotype == BFCBack) && 292 if ((colotype == BFCFront || colotype == BFCBack) &&
289 obj->getType() != LDObject::Line && 293 obj->getType() != LDObject::Line &&
290 obj->getType() != LDObject::CondLine) { 294 obj->getType() != LDObject::CondLine) {
291 295

mercurial