src/linetypes/subfilereference.cpp

Sun, 16 May 2021 22:41:00 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 16 May 2021 22:41:00 +0300
changeset 103
94719518e310
parent 86
4bec0525ef1b
child 132
488d0ba6070b
permissions
-rw-r--r--

update

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

mercurial