Sat, 01 Feb 2020 15:33:57 +0200
wired renderstyle up
3 | 1 | #include "subfilereference.h" |
21 | 2 | #include "documentmanager.h" |
26 | 3 | #include "invert.h" |
3 | 4 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
5 | ldraw::SubfileReference::SubfileReference(const glm::mat4& transformation, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
6 | const QString& referenceName, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
7 | const Color color) : |
13 | 8 | ColoredObject{color}, |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
9 | transformation{transformation}, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
10 | referenceName{referenceName} |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
11 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
12 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
13 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
14 | QVariant ldraw::SubfileReference::getProperty(Property property) const |
3 | 15 | { |
16 | switch (property) | |
17 | { | |
18 | case Property::Transformation: | |
19 | return QVariant::fromValue(this->transformation); | |
20 | case Property::ReferenceName: | |
21 | return this->referenceName; | |
22 | default: | |
13 | 23 | return ColoredObject::getProperty(property); |
3 | 24 | } |
25 | } | |
6 | 26 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
27 | auto ldraw::SubfileReference::setProperty( |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
28 | Property property, |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
29 | const QVariant& value) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
30 | -> SetPropertyResult |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
31 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
32 | switch (property) |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
33 | { |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
34 | case Property::Transformation: |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
35 | this->transformation = value.value<glm::mat4>(); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
36 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
37 | case Property::ReferenceName: |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
38 | this->referenceName = value.toString(); |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
39 | return SetPropertyResult::Success; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
40 | default: |
13 | 41 | return ColoredObject::setProperty(property, value); |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
42 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
43 | } |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
44 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
45 | QString ldraw::SubfileReference::textRepresentation() const |
6 | 46 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
47 | return referenceName + " " + utility::vertexToStringParens(this->position()); |
6 | 48 | } |
21 | 49 | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
50 | void ldraw::SubfileReference::getPolygons( |
21 | 51 | std::vector<gl::Polygon>& polygons, |
52 | GetPolygonsContext* context) const | |
53 | { | |
54 | Model* model = this->resolve(context->documents); | |
55 | if (model != nullptr) | |
56 | { | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
57 | const bool needInverting = glm::determinant(this->transformation) < 0; |
21 | 58 | const std::vector<gl::Polygon> modelPolygons = model->getPolygons(context->documents); |
59 | polygons.reserve(polygons.size() + modelPolygons.size()); | |
60 | for (gl::Polygon polygon : modelPolygons) | |
61 | { | |
23
3387a84ddaba
fixed a pile of nonsense that caused subfiles to go haywire
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
62 | for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) |
21 | 63 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
64 | glm::vec4 vertex {polygon.vertices[i], 1}; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
65 | vertex = this->transformation * vertex; |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
66 | polygon.vertices[i] = vertex; |
21 | 67 | } |
26 | 68 | if (needInverting != this->isInverted) |
69 | { | |
70 | gl::invert(polygon); | |
71 | } | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
72 | if (polygon.color == ldraw::mainColor) |
21 | 73 | { |
74 | polygon.color = this->colorIndex; | |
75 | } | |
76 | polygon.id = this->id; | |
77 | polygons.push_back(polygon); | |
78 | } | |
79 | } | |
80 | } | |
81 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
82 | glm::vec3 ldraw::SubfileReference::position() const |
21 | 83 | { |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
84 | return {this->transformation[3][0], this->transformation[3][1], this->transformation[3][2]}; |
21 | 85 | } |
86 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
87 | void ldraw::SubfileReference::invert() |
26 | 88 | { |
89 | this->isInverted = not this->isInverted; | |
90 | } | |
91 | ||
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
33
diff
changeset
|
92 | Model* ldraw::SubfileReference::resolve(DocumentManager* documents) const |
21 | 93 | { |
94 | return documents->findModelByName(this->referenceName); | |
95 | } |