Wed, 25 May 2022 18:29:49 +0300
move drawState to Document
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | #include "polygoncache.h" |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | #include "documentmanager.h" |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | |
193 | 4 | static void getObjectPolygons( |
5 | Model* model, | |
6 | const int index, | |
7 | std::vector<gl::Polygon>& polygons_out, | |
8 | ldraw::GetPolygonsContext* context); | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | /** |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * @brief Gets a list of GL polygons that are used to represent this model. |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * @details Will build polygons if polygons are outdated. |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * @param documents Documents to use to resolve subfile references |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * @return vector of GL polygons |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | */ |
193 | 16 | const std::vector<gl::Polygon> &getCachedPolygons( |
17 | PolygonCache *cache, | |
18 | Model *model, | |
19 | DocumentManager *documents) | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | { |
193 | 21 | if (cache->needRecache) |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
22 | { |
193 | 23 | cache->cachedPolygons.clear(); |
24 | const std::optional<ModelId> modelId = documents->findIdForModel(model); | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
25 | if (modelId.has_value()) |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
26 | { |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
27 | ldraw::GetPolygonsContext context{modelId.value(), documents}; |
193 | 28 | for (int i = 0; i < model->size(); i += 1) |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | { |
193 | 30 | getObjectPolygons(model, i, cache->cachedPolygons, &context); |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
31 | } |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
32 | } |
193 | 33 | cache->needRecache = false; |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
34 | } |
193 | 35 | return cache->cachedPolygons; |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
36 | } |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
37 | |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
38 | /** |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
39 | * @brief Gets the GL polygons of the object at the specified position in the model |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
40 | * @param index Index of object in the model |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
41 | * @param polygons_out Vector to add polygons into |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
42 | * @param context Context to use to resolve subfile references |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
43 | */ |
193 | 44 | static void getObjectPolygons( |
45 | Model* model, | |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
46 | const int index, |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
47 | std::vector<gl::Polygon>& polygons_out, |
193 | 48 | ldraw::GetPolygonsContext* context) |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
49 | { |
193 | 50 | const ldraw::Object* object = (*model)[unsigned_cast(index)]; |
150
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
51 | object->getPolygons(polygons_out, context); |
b6cbba6e29a1
extract polygon cache out of Model
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
52 | } |