/src/assimp/code/AssetLib/DXF/DXFLoader.cpp
Line | Count | Source |
1 | | /* |
2 | | --------------------------------------------------------------------------- |
3 | | Open Asset Import Library (assimp) |
4 | | --------------------------------------------------------------------------- |
5 | | |
6 | | Copyright (c) 2006-2026, assimp team |
7 | | |
8 | | All rights reserved. |
9 | | |
10 | | Redistribution and use of this software in source and binary forms, |
11 | | with or without modification, are permitted provided that the following |
12 | | conditions are met: |
13 | | |
14 | | * Redistributions of source code must retain the above |
15 | | copyright notice, this list of conditions and the |
16 | | following disclaimer. |
17 | | |
18 | | * Redistributions in binary form must reproduce the above |
19 | | copyright notice, this list of conditions and the |
20 | | following disclaimer in the documentation and/or other |
21 | | materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the assimp team, nor the names of its |
24 | | contributors may be used to endorse or promote products |
25 | | derived from this software without specific prior |
26 | | written permission of the assimp team. |
27 | | |
28 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
29 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
31 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
32 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
33 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
34 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
35 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
36 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
37 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | | --------------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | /** @file DXFLoader.cpp |
43 | | * @brief Implementation of the DXF importer class |
44 | | */ |
45 | | |
46 | | #ifndef ASSIMP_BUILD_NO_DXF_IMPORTER |
47 | | |
48 | | #include "DXFLoader.h" |
49 | | #include "DXFHelper.h" |
50 | | #include "PostProcessing/ConvertToLHProcess.h" |
51 | | |
52 | | #include <assimp/ParsingUtils.h> |
53 | | #include <assimp/fast_atof.h> |
54 | | #include <assimp/IOSystem.hpp> |
55 | | #include <assimp/scene.h> |
56 | | #include <assimp/importerdesc.h> |
57 | | |
58 | | #include <numeric> |
59 | | #include <utility> |
60 | | |
61 | | using namespace Assimp; |
62 | | |
63 | | // AutoCAD Binary DXF<CR><LF><SUB><NULL> |
64 | | static constexpr char AI_DXF_BINARY_IDENT[] = "AutoCAD Binary DXF\r\n\x1a"; |
65 | | static constexpr size_t AI_DXF_BINARY_IDENT_LEN = sizeof AI_DXF_BINARY_IDENT; |
66 | | |
67 | | // default vertex color that all uncolored vertices will receive |
68 | | static const aiColor4D AI_DXF_DEFAULT_COLOR(aiColor4D(0.6f, 0.6f, 0.6f, 0.6f)); |
69 | | |
70 | | // color indices for DXF - 256 are supported, the table is |
71 | | // taken directly from the AutoCad Index (ACI) table |
72 | | // https://gohtx.com/acadcolors.php |
73 | | //STH 2024-0126 |
74 | | static const aiColor4D g_aclrDxfIndexColors[256] = { |
75 | | aiColor4D (0.0f, 0.0f ,0.0f, 1.0f), //dxf color code 0 |
76 | | aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 1 |
77 | | aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 2 |
78 | | aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 3 |
79 | | aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 4 |
80 | | aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 5 |
81 | | aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 6 |
82 | | aiColor4D (1.0f, 1.0f ,1.0f, 1.0f), //dxf color code 7 |
83 | | aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 8 |
84 | | aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 9 |
85 | | aiColor4D (1.0f, 0.0f ,0.0f, 1.0f), //dxf color code 10 |
86 | | aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 11 |
87 | | aiColor4D (0.7f, 0.0f ,0.0f, 1.0f), //dxf color code 12 |
88 | | aiColor4D (0.7f, 0.5f ,0.5f, 1.0f), //dxf color code 13 |
89 | | aiColor4D (0.5f, 0.0f ,0.0f, 1.0f), //dxf color code 14 |
90 | | aiColor4D (0.5f, 0.3f ,0.3f, 1.0f), //dxf color code 15 |
91 | | aiColor4D (0.4f, 0.0f ,0.0f, 1.0f), //dxf color code 16 |
92 | | aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 17 |
93 | | aiColor4D (0.3f, 0.0f ,0.0f, 1.0f), //dxf color code 18 |
94 | | aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 19 |
95 | | aiColor4D (1.0f, 0.2f ,0.0f, 1.0f), //dxf color code 20 |
96 | | aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 21 |
97 | | aiColor4D (0.7f, 0.2f ,0.0f, 1.0f), //dxf color code 22 |
98 | | aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 23 |
99 | | aiColor4D (0.5f, 0.1f ,0.0f, 1.0f), //dxf color code 24 |
100 | | aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 25 |
101 | | aiColor4D (0.4f, 0.1f ,0.0f, 1.0f), //dxf color code 26 |
102 | | aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 27 |
103 | | aiColor4D (0.3f, 0.1f ,0.0f, 1.0f), //dxf color code 28 |
104 | | aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 29 |
105 | | aiColor4D (1.0f, 0.5f ,0.0f, 1.0f), //dxf color code 30 |
106 | | aiColor4D (1.0f, 0.8f ,0.7f, 1.0f), //dxf color code 31 |
107 | | aiColor4D (0.7f, 0.4f ,0.0f, 1.0f), //dxf color code 32 |
108 | | aiColor4D (0.7f, 0.6f ,0.5f, 1.0f), //dxf color code 33 |
109 | | aiColor4D (0.5f, 0.3f ,0.0f, 1.0f), //dxf color code 34 |
110 | | aiColor4D (0.5f, 0.4f ,0.3f, 1.0f), //dxf color code 35 |
111 | | aiColor4D (0.4f, 0.2f ,0.0f, 1.0f), //dxf color code 36 |
112 | | aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 37 |
113 | | aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 38 |
114 | | aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 39 |
115 | | aiColor4D (1.0f, 0.7f ,0.0f, 1.0f), //dxf color code 40 |
116 | | aiColor4D (1.0f, 0.9f ,0.7f, 1.0f), //dxf color code 41 |
117 | | aiColor4D (0.7f, 0.6f ,0.0f, 1.0f), //dxf color code 42 |
118 | | aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 43 |
119 | | aiColor4D (0.5f, 0.4f ,0.0f, 1.0f), //dxf color code 44 |
120 | | aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 45 |
121 | | aiColor4D (0.4f, 0.3f ,0.0f, 1.0f), //dxf color code 46 |
122 | | aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 47 |
123 | | aiColor4D (0.3f, 0.2f ,0.0f, 1.0f), //dxf color code 48 |
124 | | aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 49 |
125 | | aiColor4D (1.0f, 1.0f ,0.0f, 1.0f), //dxf color code 50 |
126 | | aiColor4D (1.0f, 1.0f ,0.7f, 1.0f), //dxf color code 51 |
127 | | aiColor4D (0.7f, 0.7f ,0.0f, 1.0f), //dxf color code 52 |
128 | | aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 53 |
129 | | aiColor4D (0.5f, 0.5f ,0.0f, 1.0f), //dxf color code 54 |
130 | | aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 55 |
131 | | aiColor4D (0.4f, 0.4f ,0.0f, 1.0f), //dxf color code 56 |
132 | | aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 57 |
133 | | aiColor4D (0.3f, 0.3f ,0.0f, 1.0f), //dxf color code 58 |
134 | | aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 59 |
135 | | aiColor4D (0.7f, 1.0f ,0.0f, 1.0f), //dxf color code 60 |
136 | | aiColor4D (0.9f, 1.0f ,0.7f, 1.0f), //dxf color code 61 |
137 | | aiColor4D (0.6f, 0.7f ,0.0f, 1.0f), //dxf color code 62 |
138 | | aiColor4D (0.7f, 0.7f ,0.5f, 1.0f), //dxf color code 63 |
139 | | aiColor4D (0.4f, 0.5f ,0.0f, 1.0f), //dxf color code 64 |
140 | | aiColor4D (0.5f, 0.5f ,0.3f, 1.0f), //dxf color code 65 |
141 | | aiColor4D (0.3f, 0.4f ,0.0f, 1.0f), //dxf color code 66 |
142 | | aiColor4D (0.4f, 0.4f ,0.3f, 1.0f), //dxf color code 67 |
143 | | aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 68 |
144 | | aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 69 |
145 | | aiColor4D (0.5f, 1.0f ,0.0f, 1.0f), //dxf color code 70 |
146 | | aiColor4D (0.8f, 1.0f ,0.7f, 1.0f), //dxf color code 71 |
147 | | aiColor4D (0.4f, 0.7f ,0.0f, 1.0f), //dxf color code 72 |
148 | | aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 73 |
149 | | aiColor4D (0.3f, 0.5f ,0.0f, 1.0f), //dxf color code 74 |
150 | | aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 75 |
151 | | aiColor4D (0.2f, 0.4f ,0.0f, 1.0f), //dxf color code 76 |
152 | | aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 77 |
153 | | aiColor4D (0.2f, 0.3f ,0.0f, 1.0f), //dxf color code 78 |
154 | | aiColor4D (0.3f, 0.3f ,0.2f, 1.0f), //dxf color code 79 |
155 | | aiColor4D (0.2f, 1.0f ,0.0f, 1.0f), //dxf color code 80 |
156 | | aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 81 |
157 | | aiColor4D (0.2f, 0.7f ,0.0f, 1.0f), //dxf color code 82 |
158 | | aiColor4D (0.6f, 0.7f ,0.5f, 1.0f), //dxf color code 83 |
159 | | aiColor4D (0.1f, 0.5f ,0.0f, 1.0f), //dxf color code 84 |
160 | | aiColor4D (0.4f, 0.5f ,0.3f, 1.0f), //dxf color code 85 |
161 | | aiColor4D (0.1f, 0.4f ,0.0f, 1.0f), //dxf color code 86 |
162 | | aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 87 |
163 | | aiColor4D (0.1f, 0.3f ,0.0f, 1.0f), //dxf color code 88 |
164 | | aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 89 |
165 | | aiColor4D (0.0f, 1.0f ,0.0f, 1.0f), //dxf color code 90 |
166 | | aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 91 |
167 | | aiColor4D (0.0f, 0.7f ,0.0f, 1.0f), //dxf color code 92 |
168 | | aiColor4D (0.5f, 0.7f ,0.5f, 1.0f), //dxf color code 93 |
169 | | aiColor4D (0.0f, 0.5f ,0.0f, 1.0f), //dxf color code 94 |
170 | | aiColor4D (0.3f, 0.5f ,0.3f, 1.0f), //dxf color code 95 |
171 | | aiColor4D (0.0f, 0.4f ,0.0f, 1.0f), //dxf color code 96 |
172 | | aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 97 |
173 | | aiColor4D (0.0f, 0.3f ,0.0f, 1.0f), //dxf color code 98 |
174 | | aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 99 |
175 | | aiColor4D (0.0f, 1.0f ,0.2f, 1.0f), //dxf color code 100 |
176 | | aiColor4D (0.7f, 1.0f ,0.7f, 1.0f), //dxf color code 101 |
177 | | aiColor4D (0.0f, 0.7f ,0.2f, 1.0f), //dxf color code 102 |
178 | | aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 103 |
179 | | aiColor4D (0.0f, 0.5f ,0.1f, 1.0f), //dxf color code 104 |
180 | | aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 105 |
181 | | aiColor4D (0.0f, 0.4f ,0.1f, 1.0f), //dxf color code 106 |
182 | | aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 107 |
183 | | aiColor4D (0.0f, 0.3f ,0.1f, 1.0f), //dxf color code 108 |
184 | | aiColor4D (0.2f, 0.3f ,0.2f, 1.0f), //dxf color code 109 |
185 | | aiColor4D (0.0f, 1.0f ,0.5f, 1.0f), //dxf color code 110 |
186 | | aiColor4D (0.7f, 1.0f ,0.8f, 1.0f), //dxf color code 111 |
187 | | aiColor4D (0.0f, 0.7f ,0.4f, 1.0f), //dxf color code 112 |
188 | | aiColor4D (0.5f, 0.7f ,0.6f, 1.0f), //dxf color code 113 |
189 | | aiColor4D (0.0f, 0.5f ,0.3f, 1.0f), //dxf color code 114 |
190 | | aiColor4D (0.3f, 0.5f ,0.4f, 1.0f), //dxf color code 115 |
191 | | aiColor4D (0.0f, 0.4f ,0.2f, 1.0f), //dxf color code 116 |
192 | | aiColor4D (0.3f, 0.4f ,0.3f, 1.0f), //dxf color code 117 |
193 | | aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 118 |
194 | | aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 119 |
195 | | aiColor4D (0.0f, 1.0f ,0.7f, 1.0f), //dxf color code 120 |
196 | | aiColor4D (0.7f, 1.0f ,0.9f, 1.0f), //dxf color code 121 |
197 | | aiColor4D (0.0f, 0.7f ,0.6f, 1.0f), //dxf color code 122 |
198 | | aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 123 |
199 | | aiColor4D (0.0f, 0.5f ,0.4f, 1.0f), //dxf color code 124 |
200 | | aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 125 |
201 | | aiColor4D (0.0f, 0.4f ,0.3f, 1.0f), //dxf color code 126 |
202 | | aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 127 |
203 | | aiColor4D (0.0f, 0.3f ,0.2f, 1.0f), //dxf color code 128 |
204 | | aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 129 |
205 | | aiColor4D (0.0f, 1.0f ,1.0f, 1.0f), //dxf color code 130 |
206 | | aiColor4D (0.7f, 1.0f ,1.0f, 1.0f), //dxf color code 131 |
207 | | aiColor4D (0.0f, 0.7f ,0.7f, 1.0f), //dxf color code 132 |
208 | | aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 133 |
209 | | aiColor4D (0.0f, 0.5f ,0.5f, 1.0f), //dxf color code 134 |
210 | | aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 135 |
211 | | aiColor4D (0.0f, 0.4f ,0.4f, 1.0f), //dxf color code 136 |
212 | | aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 137 |
213 | | aiColor4D (0.0f, 0.3f ,0.3f, 1.0f), //dxf color code 138 |
214 | | aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 139 |
215 | | aiColor4D (0.0f, 0.7f ,1.0f, 1.0f), //dxf color code 140 |
216 | | aiColor4D (0.7f, 0.9f ,1.0f, 1.0f), //dxf color code 141 |
217 | | aiColor4D (0.0f, 0.6f ,0.7f, 1.0f), //dxf color code 142 |
218 | | aiColor4D (0.5f, 0.7f ,0.7f, 1.0f), //dxf color code 143 |
219 | | aiColor4D (0.0f, 0.4f ,0.5f, 1.0f), //dxf color code 144 |
220 | | aiColor4D (0.3f, 0.5f ,0.5f, 1.0f), //dxf color code 145 |
221 | | aiColor4D (0.0f, 0.3f ,0.4f, 1.0f), //dxf color code 146 |
222 | | aiColor4D (0.3f, 0.4f ,0.4f, 1.0f), //dxf color code 147 |
223 | | aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 148 |
224 | | aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 149 |
225 | | aiColor4D (0.0f, 0.5f ,1.0f, 1.0f), //dxf color code 150 |
226 | | aiColor4D (0.7f, 0.8f ,1.0f, 1.0f), //dxf color code 151 |
227 | | aiColor4D (0.0f, 0.4f ,0.7f, 1.0f), //dxf color code 152 |
228 | | aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 153 |
229 | | aiColor4D (0.0f, 0.3f ,0.5f, 1.0f), //dxf color code 154 |
230 | | aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 155 |
231 | | aiColor4D (0.0f, 0.2f ,0.4f, 1.0f), //dxf color code 156 |
232 | | aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 157 |
233 | | aiColor4D (0.0f, 0.2f ,0.3f, 1.0f), //dxf color code 158 |
234 | | aiColor4D (0.2f, 0.3f ,0.3f, 1.0f), //dxf color code 159 |
235 | | aiColor4D (0.0f, 0.2f ,1.0f, 1.0f), //dxf color code 160 |
236 | | aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 161 |
237 | | aiColor4D (0.0f, 0.2f ,0.7f, 1.0f), //dxf color code 162 |
238 | | aiColor4D (0.5f, 0.6f ,0.7f, 1.0f), //dxf color code 163 |
239 | | aiColor4D (0.0f, 0.1f ,0.5f, 1.0f), //dxf color code 164 |
240 | | aiColor4D (0.3f, 0.4f ,0.5f, 1.0f), //dxf color code 165 |
241 | | aiColor4D (0.0f, 0.1f ,0.4f, 1.0f), //dxf color code 166 |
242 | | aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 167 |
243 | | aiColor4D (0.0f, 0.1f ,0.3f, 1.0f), //dxf color code 168 |
244 | | aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 169 |
245 | | aiColor4D (0.0f, 0.0f ,1.0f, 1.0f), //dxf color code 170 |
246 | | aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 171 |
247 | | aiColor4D (0.0f, 0.0f ,0.7f, 1.0f), //dxf color code 172 |
248 | | aiColor4D (0.5f, 0.5f ,0.7f, 1.0f), //dxf color code 173 |
249 | | aiColor4D (0.0f, 0.0f ,0.5f, 1.0f), //dxf color code 174 |
250 | | aiColor4D (0.3f, 0.3f ,0.5f, 1.0f), //dxf color code 175 |
251 | | aiColor4D (0.0f, 0.0f ,0.4f, 1.0f), //dxf color code 176 |
252 | | aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 177 |
253 | | aiColor4D (0.0f, 0.0f ,0.3f, 1.0f), //dxf color code 178 |
254 | | aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 179 |
255 | | aiColor4D (0.2f, 0.0f ,1.0f, 1.0f), //dxf color code 180 |
256 | | aiColor4D (0.7f, 0.7f ,1.0f, 1.0f), //dxf color code 181 |
257 | | aiColor4D (0.2f, 0.0f ,0.7f, 1.0f), //dxf color code 182 |
258 | | aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 183 |
259 | | aiColor4D (0.1f, 0.0f ,0.5f, 1.0f), //dxf color code 184 |
260 | | aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 185 |
261 | | aiColor4D (0.1f, 0.0f ,0.4f, 1.0f), //dxf color code 186 |
262 | | aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 187 |
263 | | aiColor4D (0.1f, 0.0f ,0.3f, 1.0f), //dxf color code 188 |
264 | | aiColor4D (0.2f, 0.2f ,0.3f, 1.0f), //dxf color code 189 |
265 | | aiColor4D (0.5f, 0.0f ,1.0f, 1.0f), //dxf color code 190 |
266 | | aiColor4D (0.8f, 0.7f ,1.0f, 1.0f), //dxf color code 191 |
267 | | aiColor4D (0.4f, 0.0f ,0.7f, 1.0f), //dxf color code 192 |
268 | | aiColor4D (0.6f, 0.5f ,0.7f, 1.0f), //dxf color code 193 |
269 | | aiColor4D (0.3f, 0.0f ,0.5f, 1.0f), //dxf color code 194 |
270 | | aiColor4D (0.4f, 0.3f ,0.5f, 1.0f), //dxf color code 195 |
271 | | aiColor4D (0.2f, 0.0f ,0.4f, 1.0f), //dxf color code 196 |
272 | | aiColor4D (0.3f, 0.3f ,0.4f, 1.0f), //dxf color code 197 |
273 | | aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 198 |
274 | | aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 199 |
275 | | aiColor4D (0.7f, 0.0f ,1.0f, 1.0f), //dxf color code 200 |
276 | | aiColor4D (0.9f, 0.7f ,1.0f, 1.0f), //dxf color code 201 |
277 | | aiColor4D (0.6f, 0.0f ,0.7f, 1.0f), //dxf color code 202 |
278 | | aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 203 |
279 | | aiColor4D (0.4f, 0.0f ,0.5f, 1.0f), //dxf color code 204 |
280 | | aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 205 |
281 | | aiColor4D (0.3f, 0.0f ,0.4f, 1.0f), //dxf color code 206 |
282 | | aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 207 |
283 | | aiColor4D (0.2f, 0.0f ,0.3f, 1.0f), //dxf color code 208 |
284 | | aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 209 |
285 | | aiColor4D (1.0f, 0.0f ,1.0f, 1.0f), //dxf color code 210 |
286 | | aiColor4D (1.0f, 0.7f ,1.0f, 1.0f), //dxf color code 211 |
287 | | aiColor4D (0.7f, 0.0f ,0.7f, 1.0f), //dxf color code 212 |
288 | | aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 213 |
289 | | aiColor4D (0.5f, 0.0f ,0.5f, 1.0f), //dxf color code 214 |
290 | | aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 215 |
291 | | aiColor4D (0.4f, 0.0f ,0.4f, 1.0f), //dxf color code 216 |
292 | | aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 217 |
293 | | aiColor4D (0.3f, 0.0f ,0.3f, 1.0f), //dxf color code 218 |
294 | | aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 219 |
295 | | aiColor4D (1.0f, 0.0f ,0.7f, 1.0f), //dxf color code 220 |
296 | | aiColor4D (1.0f, 0.7f ,0.9f, 1.0f), //dxf color code 221 |
297 | | aiColor4D (0.7f, 0.0f ,0.6f, 1.0f), //dxf color code 222 |
298 | | aiColor4D (0.7f, 0.5f ,0.7f, 1.0f), //dxf color code 223 |
299 | | aiColor4D (0.5f, 0.0f ,0.4f, 1.0f), //dxf color code 224 |
300 | | aiColor4D (0.5f, 0.3f ,0.5f, 1.0f), //dxf color code 225 |
301 | | aiColor4D (0.4f, 0.0f ,0.3f, 1.0f), //dxf color code 226 |
302 | | aiColor4D (0.4f, 0.3f ,0.4f, 1.0f), //dxf color code 227 |
303 | | aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 228 |
304 | | aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 229 |
305 | | aiColor4D (1.0f, 0.0f ,0.5f, 1.0f), //dxf color code 230 |
306 | | aiColor4D (1.0f, 0.7f ,0.8f, 1.0f), //dxf color code 231 |
307 | | aiColor4D (0.7f, 0.0f ,0.4f, 1.0f), //dxf color code 232 |
308 | | aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 233 |
309 | | aiColor4D (0.5f, 0.0f ,0.3f, 1.0f), //dxf color code 234 |
310 | | aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 235 |
311 | | aiColor4D (0.4f, 0.0f ,0.2f, 1.0f), //dxf color code 236 |
312 | | aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 237 |
313 | | aiColor4D (0.3f, 0.0f ,0.2f, 1.0f), //dxf color code 238 |
314 | | aiColor4D (0.3f, 0.2f ,0.3f, 1.0f), //dxf color code 239 |
315 | | aiColor4D (1.0f, 0.0f ,0.2f, 1.0f), //dxf color code 240 |
316 | | aiColor4D (1.0f, 0.7f ,0.7f, 1.0f), //dxf color code 241 |
317 | | aiColor4D (0.7f, 0.0f ,0.2f, 1.0f), //dxf color code 242 |
318 | | aiColor4D (0.7f, 0.5f ,0.6f, 1.0f), //dxf color code 243 |
319 | | aiColor4D (0.5f, 0.0f ,0.1f, 1.0f), //dxf color code 244 |
320 | | aiColor4D (0.5f, 0.3f ,0.4f, 1.0f), //dxf color code 245 |
321 | | aiColor4D (0.4f, 0.0f ,0.1f, 1.0f), //dxf color code 246 |
322 | | aiColor4D (0.4f, 0.3f ,0.3f, 1.0f), //dxf color code 247 |
323 | | aiColor4D (0.3f, 0.0f ,0.1f, 1.0f), //dxf color code 248 |
324 | | aiColor4D (0.3f, 0.2f ,0.2f, 1.0f), //dxf color code 249 |
325 | | aiColor4D (0.2f, 0.2f ,0.2f, 1.0f), //dxf color code 250 |
326 | | aiColor4D (0.3f, 0.3f ,0.3f, 1.0f), //dxf color code 251 |
327 | | aiColor4D (0.4f, 0.4f ,0.4f, 1.0f), //dxf color code 252 |
328 | | aiColor4D (0.5f, 0.5f ,0.5f, 1.0f), //dxf color code 253 |
329 | | aiColor4D (0.7f, 0.7f ,0.7f, 1.0f), //dxf color code 254 |
330 | | aiColor4D (1.0f, 1.0f ,1.0f, 1.0f) //dxf color code 255 |
331 | | }; |
332 | | |
333 | 51.2k | #define AI_DXF_NUM_INDEX_COLORS (sizeof(g_aclrDxfIndexColors)/sizeof(g_aclrDxfIndexColors[0])) |
334 | 6.04k | #define AI_DXF_ENTITIES_MAGIC_BLOCK "$ASSIMP_ENTITIES_MAGIC" |
335 | | |
336 | | static const int GroupCode_Name = 2; |
337 | | static const int GroupCode_XComp = 10; |
338 | | static const int GroupCode_YComp = 20; |
339 | | static const int GroupCode_ZComp = 30; |
340 | | |
341 | | static constexpr aiImporterDesc desc = { |
342 | | "Drawing Interchange Format (DXF) Importer", |
343 | | "", |
344 | | "", |
345 | | "", |
346 | | aiImporterFlags_SupportTextFlavour | aiImporterFlags_LimitedSupport, |
347 | | 0, |
348 | | 0, |
349 | | 0, |
350 | | 0, |
351 | | "dxf" |
352 | | }; |
353 | | |
354 | | // ------------------------------------------------------------------------------------------------ |
355 | | // Returns whether the class can handle the format of the given file. |
356 | 21.5k | bool DXFImporter::CanRead( const std::string& filename, IOSystem* pIOHandler, bool /*checkSig*/ ) const { |
357 | 21.5k | static const char *tokens[] = { "SECTION", "HEADER", "ENDSEC", "BLOCKS" }; |
358 | 21.5k | return SearchFileHeaderForToken(pIOHandler, filename, tokens, AI_COUNT_OF(tokens), 32); |
359 | 21.5k | } |
360 | | |
361 | | // ------------------------------------------------------------------------------------------------ |
362 | | // Get a list of all supported file extensions |
363 | 164k | const aiImporterDesc* DXFImporter::GetInfo () const { |
364 | 164k | return &desc; |
365 | 164k | } |
366 | | |
367 | | // ------------------------------------------------------------------------------------------------ |
368 | | // Imports the given file into the given scene structure. |
369 | 2.63k | void DXFImporter::InternReadFile( const std::string& filename, aiScene* pScene, IOSystem* pIOHandler) { |
370 | 2.63k | std::shared_ptr<IOStream> file = std::shared_ptr<IOStream>( pIOHandler->Open( filename) ); |
371 | | |
372 | | // Check whether we can read the file |
373 | 2.63k | if (file == nullptr) { |
374 | 0 | throw DeadlyImportError( "Failed to open DXF file ", filename, ""); |
375 | 0 | } |
376 | | |
377 | | // Check whether this is a binary DXF file - we can't read binary DXF files :-( |
378 | 2.63k | char buff[AI_DXF_BINARY_IDENT_LEN] = {0}; |
379 | 2.63k | file->Read(buff,AI_DXF_BINARY_IDENT_LEN,1); |
380 | | |
381 | 2.63k | if (0 == memcmp(AI_DXF_BINARY_IDENT,buff,AI_DXF_BINARY_IDENT_LEN)) { |
382 | 1 | throw DeadlyImportError("DXF: Binary files are not supported at the moment"); |
383 | 1 | } |
384 | | |
385 | | // DXF files can grow very large, so read them via the StreamReader, |
386 | | // which will choose a suitable strategy. |
387 | 2.63k | file->Seek(0,aiOrigin_SET); |
388 | 2.63k | StreamReaderLE stream( std::move(file) ); |
389 | | |
390 | 2.63k | DXF::LineReader reader (stream); |
391 | 2.63k | DXF::FileData output; |
392 | | |
393 | | // now get all lines of the file and process top-level sections |
394 | 2.63k | bool eof = false; |
395 | 68.3k | while(!reader.End()) { |
396 | | |
397 | | // blocks table - these 'build blocks' are later (in ENTITIES) |
398 | | // referenced an included via INSERT statements. |
399 | 65.7k | if (reader.Is(2,"BLOCKS")) { |
400 | 3.04k | ParseBlocks(reader,output); |
401 | 3.04k | continue; |
402 | 3.04k | } |
403 | | |
404 | | // primary entity table |
405 | 62.7k | if (reader.Is(2,"ENTITIES")) { |
406 | 3.02k | ParseEntities(reader,output); |
407 | 3.02k | continue; |
408 | 3.02k | } |
409 | | |
410 | | // skip unneeded sections entirely to avoid any problems with them |
411 | | // altogether. |
412 | 59.7k | else if (reader.Is(2,"CLASSES") || reader.Is(2,"TABLES")) { |
413 | 1.52k | SkipSection(reader); |
414 | 1.52k | continue; |
415 | 1.52k | } |
416 | | |
417 | 58.1k | else if (reader.Is(2,"HEADER")) { |
418 | 1.53k | ParseHeader(reader,output); |
419 | 1.53k | continue; |
420 | 1.53k | } |
421 | | |
422 | | // comments |
423 | 56.6k | else if (reader.Is(999)) { |
424 | 541 | ASSIMP_LOG_INFO("DXF Comment: ", reader.Value()); |
425 | 541 | } |
426 | | |
427 | | // don't read past the official EOF sign |
428 | 56.1k | else if (reader.Is(0,"EOF")) { |
429 | 27 | eof = true; |
430 | 27 | break; |
431 | 27 | } |
432 | | |
433 | 56.6k | ++reader; |
434 | 56.6k | } |
435 | 2.63k | if (!eof) { |
436 | 2.54k | ASSIMP_LOG_WARN("DXF: EOF reached, but did not encounter DXF EOF marker"); |
437 | 2.54k | } |
438 | | |
439 | 2.63k | ConvertMeshes(pScene,output); |
440 | | |
441 | | // Now rotate the whole scene by 90 degrees around the x axis to convert from AutoCAD's to Assimp's coordinate system |
442 | 2.63k | pScene->mRootNode->mTransformation = aiMatrix4x4( |
443 | 2.63k | 1.f,0.f,0.f,0.f, |
444 | 2.63k | 0.f,0.f,1.f,0.f, |
445 | 2.63k | 0.f,-1.f,0.f,0.f, |
446 | 2.63k | 0.f,0.f,0.f,1.f) * pScene->mRootNode->mTransformation; |
447 | 2.63k | } |
448 | | |
449 | | // ------------------------------------------------------------------------------------------------ |
450 | 2.57k | void DXFImporter::ConvertMeshes(aiScene* pScene, DXF::FileData& output) { |
451 | | // the process of resolving all the INSERT statements can grow the |
452 | | // poly-count excessively, so log the original number. |
453 | | // XXX Option to import blocks as separate nodes? |
454 | 2.57k | if (!DefaultLogger::isNullLogger()) { |
455 | 0 | unsigned int vcount = 0, icount = 0; |
456 | 0 | for (const DXF::Block& bl : output.blocks) { |
457 | 0 | for (std::shared_ptr<const DXF::PolyLine> pl : bl.lines) { |
458 | 0 | vcount += static_cast<unsigned int>(pl->positions.size()); |
459 | 0 | icount += static_cast<unsigned int>(pl->counts.size()); |
460 | 0 | } |
461 | 0 | } |
462 | |
|
463 | 0 | ASSIMP_LOG_VERBOSE_DEBUG("DXF: Unexpanded polycount is ", icount, ", vertex count is ", vcount); |
464 | 0 | } |
465 | | |
466 | 2.57k | if (output.blocks.empty()) { |
467 | 652 | throw DeadlyImportError("DXF: no data blocks loaded"); |
468 | 652 | } |
469 | | |
470 | 1.91k | DXF::Block* entities( nullptr ); |
471 | | |
472 | | // index blocks by name |
473 | 1.91k | DXF::BlockMap blocks_by_name; |
474 | 5.74k | for (DXF::Block& bl : output.blocks) { |
475 | 5.74k | blocks_by_name[bl.name] = &bl; |
476 | 5.74k | if ( !entities && bl.name == AI_DXF_ENTITIES_MAGIC_BLOCK ) { |
477 | 1.08k | entities = &bl; |
478 | 1.08k | } |
479 | 5.74k | } |
480 | | |
481 | 1.91k | if (!entities) { |
482 | 831 | throw DeadlyImportError("DXF: no ENTITIES data block loaded"); |
483 | 831 | } |
484 | | |
485 | 1.08k | typedef std::map<std::string, unsigned int> LayerMap; |
486 | | |
487 | 1.08k | LayerMap layers; |
488 | 1.08k | std::vector< std::vector< const DXF::PolyLine*> > corr; |
489 | | |
490 | | // now expand all block references in the primary ENTITIES block |
491 | | // XXX this involves heavy memory copying, consider a faster solution for future versions. |
492 | 1.08k | ExpandBlockReferences(*entities,blocks_by_name); |
493 | | |
494 | 1.08k | unsigned int cur = 0; |
495 | 6.82k | for (std::shared_ptr<const DXF::PolyLine> pl : entities->lines) { |
496 | 6.82k | if (pl->positions.size()) { |
497 | | |
498 | 6.78k | std::map<std::string, unsigned int>::iterator it = layers.find(pl->layer); |
499 | 6.78k | if (it == layers.end()) { |
500 | 820 | ++pScene->mNumMeshes; |
501 | | |
502 | 820 | layers[pl->layer] = cur++; |
503 | | |
504 | 820 | std::vector< const DXF::PolyLine* > pv; |
505 | 820 | pv.push_back(&*pl); |
506 | | |
507 | 820 | corr.push_back(pv); |
508 | 820 | } |
509 | 5.96k | else { |
510 | 5.96k | corr[(*it).second].push_back(&*pl); |
511 | 5.96k | } |
512 | 6.78k | } |
513 | 6.82k | } |
514 | | |
515 | 1.08k | if ( 0 == pScene->mNumMeshes) { |
516 | 628 | throw DeadlyImportError("DXF: this file contains no 3d data"); |
517 | 628 | } |
518 | | |
519 | 460 | pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ] (); |
520 | | |
521 | 818 | for(const LayerMap::value_type& elem : layers){ |
522 | 818 | aiMesh* const mesh = pScene->mMeshes[elem.second] = new aiMesh(); |
523 | 818 | mesh->mName.Set(elem.first); |
524 | | |
525 | 818 | unsigned int cvert = 0,cface = 0; |
526 | 6.78k | for(const DXF::PolyLine* pl : corr[elem.second]){ |
527 | | // sum over all faces since we need to 'verbosify' them. |
528 | 6.78k | cvert += std::accumulate(pl->counts.begin(),pl->counts.end(),0); |
529 | 6.78k | cface += static_cast<unsigned int>(pl->counts.size()); |
530 | 6.78k | } |
531 | | |
532 | 818 | aiVector3D* verts = mesh->mVertices = new aiVector3D[cvert]; |
533 | 818 | aiColor4D* colors = mesh->mColors[0] = new aiColor4D[cvert]; |
534 | 818 | aiFace* faces = mesh->mFaces = new aiFace[cface]; |
535 | | |
536 | 818 | mesh->mNumVertices = cvert; |
537 | 818 | mesh->mNumFaces = cface; |
538 | | |
539 | 818 | unsigned int prims = 0; |
540 | 818 | unsigned int overall_indices = 0; |
541 | 6.78k | for(const DXF::PolyLine* pl : corr[elem.second]){ |
542 | | |
543 | 6.78k | std::vector<unsigned int>::const_iterator it = pl->indices.begin(); |
544 | 31.5k | for(unsigned int facenumv : pl->counts) { |
545 | 31.5k | aiFace& face = *faces++; |
546 | 31.5k | face.mIndices = new unsigned int[face.mNumIndices = facenumv]; |
547 | | |
548 | 130k | for (unsigned int i = 0; i < facenumv; ++i) { |
549 | 99.3k | face.mIndices[i] = overall_indices++; |
550 | | |
551 | 99.3k | ai_assert(pl->positions.size() == pl->colors.size()); |
552 | 99.3k | if (*it >= pl->positions.size()) { |
553 | 40 | throw DeadlyImportError("DXF: vertex index out of bounds"); |
554 | 40 | } |
555 | | |
556 | 99.3k | *verts++ = pl->positions[*it]; |
557 | 99.3k | *colors++ = pl->colors[*it++]; |
558 | 99.3k | } |
559 | | |
560 | | // set primitive flags now, this saves the extra pass in ScenePreprocessor. |
561 | 31.5k | switch(face.mNumIndices) { |
562 | 108 | case 1: |
563 | 108 | prims |= aiPrimitiveType_POINT; |
564 | 108 | break; |
565 | 1.65k | case 2: |
566 | 1.65k | prims |= aiPrimitiveType_LINE; |
567 | 1.65k | break; |
568 | 23.1k | case 3: |
569 | 23.1k | prims |= aiPrimitiveType_TRIANGLE; |
570 | 23.1k | break; |
571 | 6.63k | default: |
572 | 6.63k | prims |= aiPrimitiveType_POLYGON; |
573 | 6.63k | break; |
574 | 31.5k | } |
575 | 31.5k | } |
576 | 6.78k | } |
577 | | |
578 | 778 | mesh->mPrimitiveTypes = prims; |
579 | 778 | mesh->mMaterialIndex = 0; |
580 | 778 | } |
581 | | |
582 | 420 | GenerateHierarchy(pScene,output); |
583 | 420 | GenerateMaterials(pScene,output); |
584 | 420 | } |
585 | | |
586 | | |
587 | | // ------------------------------------------------------------------------------------------------ |
588 | 1.08k | void DXFImporter::ExpandBlockReferences(DXF::Block& bl,const DXF::BlockMap& blocks_by_name) { |
589 | 1.42k | for (const DXF::InsertBlock& insert : bl.insertions) { |
590 | | |
591 | | // first check if the referenced blocks exists ... |
592 | 1.42k | const DXF::BlockMap::const_iterator it = blocks_by_name.find(insert.name); |
593 | 1.42k | if (it == blocks_by_name.end()) { |
594 | 952 | ASSIMP_LOG_ERROR("DXF: Failed to resolve block reference: ", insert.name,"; skipping" ); |
595 | 952 | continue; |
596 | 952 | } |
597 | | |
598 | | // XXX this would be the place to implement recursive expansion if needed. |
599 | 468 | const DXF::Block& bl_src = *(*it).second; |
600 | | |
601 | 468 | const size_t size = bl_src.lines.size(); // the size may increase in the loop |
602 | 633 | for (size_t i = 0; i < size; ++i) { |
603 | 165 | std::shared_ptr<const DXF::PolyLine> pl_in = bl_src.lines[i]; |
604 | 165 | if (!pl_in) { |
605 | 0 | ASSIMP_LOG_ERROR("DXF: PolyLine instance is nullptr, skipping."); |
606 | 0 | continue; |
607 | 0 | } |
608 | | |
609 | 165 | std::shared_ptr<DXF::PolyLine> pl_out = std::shared_ptr<DXF::PolyLine>(new DXF::PolyLine(*pl_in)); |
610 | | |
611 | 165 | if (bl_src.base.Length() || insert.scale.x!=1.f || insert.scale.y!=1.f || insert.scale.z!=1.f || insert.angle || insert.pos.Length()) { |
612 | | // manual coordinate system transformation |
613 | | // XXX order |
614 | 13 | aiMatrix4x4 trafo, tmp; |
615 | 13 | aiMatrix4x4::Translation(-bl_src.base,trafo); |
616 | | //Need to translate position before scaling the insert |
617 | | //otherwise the position ends up being the position*scaling |
618 | | //STH 2024.01.17 |
619 | 13 | trafo *= aiMatrix4x4::Translation(insert.pos,tmp); |
620 | 13 | trafo *= aiMatrix4x4::Scaling(insert.scale,tmp); |
621 | | //trafo *= aiMatrix4x4::Translation(insert.pos,tmp); |
622 | | |
623 | | // XXX rotation currently ignored - I didn't find an appropriate sample model. |
624 | 13 | if (insert.angle != 0.f) { |
625 | 3 | ASSIMP_LOG_WARN("DXF: BLOCK rotation not currently implemented"); |
626 | 3 | } |
627 | | |
628 | 10.3k | for (aiVector3D& v : pl_out->positions) { |
629 | 10.3k | v *= trafo; |
630 | 10.3k | } |
631 | 13 | } |
632 | | |
633 | 165 | bl.lines.push_back(pl_out); |
634 | 165 | } |
635 | 468 | } |
636 | 1.08k | } |
637 | | |
638 | | // ------------------------------------------------------------------------------------------------ |
639 | 420 | void DXFImporter::GenerateMaterials(aiScene* pScene, DXF::FileData& /*output*/) { |
640 | | // generate an almost-white default material. Reason: |
641 | | // the default vertex color is GREY, so we are |
642 | | // already at Assimp's usual default color. |
643 | | // generate a default material |
644 | 420 | aiMaterial* pcMat = new aiMaterial(); |
645 | 420 | aiString s; |
646 | 420 | s.Set(AI_DEFAULT_MATERIAL_NAME); |
647 | 420 | pcMat->AddProperty(&s, AI_MATKEY_NAME); |
648 | | |
649 | 420 | aiColor4D clrDiffuse(0.9f,0.9f,0.9f,1.0f); |
650 | 420 | pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_DIFFUSE); |
651 | | |
652 | 420 | clrDiffuse = aiColor4D(1.0f,1.0f,1.0f,1.0f); |
653 | 420 | pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_SPECULAR); |
654 | | |
655 | 420 | clrDiffuse = aiColor4D(0.05f,0.05f,0.05f,1.0f); |
656 | 420 | pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_AMBIENT); |
657 | | |
658 | 420 | pScene->mNumMaterials = 1; |
659 | 420 | pScene->mMaterials = new aiMaterial*[1]; |
660 | 420 | pScene->mMaterials[0] = pcMat; |
661 | 420 | } |
662 | | |
663 | | // ------------------------------------------------------------------------------------------------ |
664 | 420 | void DXFImporter::GenerateHierarchy(aiScene* pScene, DXF::FileData& /*output*/) { |
665 | | // generate the output scene graph, which is just the root node with a single child for each layer. |
666 | 420 | pScene->mRootNode = new aiNode(); |
667 | 420 | pScene->mRootNode->mName.Set("<DXF_ROOT>"); |
668 | | |
669 | 420 | if (1 == pScene->mNumMeshes) { |
670 | 265 | pScene->mRootNode->mMeshes = new unsigned int[ pScene->mRootNode->mNumMeshes = 1 ]; |
671 | 265 | pScene->mRootNode->mMeshes[0] = 0; |
672 | 265 | } else { |
673 | 155 | pScene->mRootNode->mChildren = new aiNode*[ pScene->mRootNode->mNumChildren = pScene->mNumMeshes ]; |
674 | 664 | for (unsigned int m = 0; m < pScene->mRootNode->mNumChildren;++m) { |
675 | 509 | aiNode* p = pScene->mRootNode->mChildren[m] = new aiNode(); |
676 | 509 | p->mName = pScene->mMeshes[m]->mName; |
677 | | |
678 | 509 | p->mMeshes = new unsigned int[p->mNumMeshes = 1]; |
679 | 509 | p->mMeshes[0] = m; |
680 | 509 | p->mParent = pScene->mRootNode; |
681 | 509 | } |
682 | 155 | } |
683 | 420 | } |
684 | | |
685 | | |
686 | | // ------------------------------------------------------------------------------------------------ |
687 | 1.52k | void DXFImporter::SkipSection(DXF::LineReader& reader) { |
688 | 35.9k | for( ;!reader.End() && !reader.Is(0,"ENDSEC"); reader++); |
689 | 1.52k | } |
690 | | |
691 | | // ------------------------------------------------------------------------------------------------ |
692 | 1.53k | void DXFImporter::ParseHeader(DXF::LineReader& reader, DXF::FileData& ) { |
693 | 58.2k | for( ;!reader.End() && !reader.Is(0,"ENDSEC"); reader++); |
694 | 1.53k | } |
695 | | |
696 | | // ------------------------------------------------------------------------------------------------ |
697 | 3.04k | void DXFImporter::ParseBlocks(DXF::LineReader& reader, DXF::FileData& output) { |
698 | 34.5k | while( !reader.End() && !reader.Is(0,"ENDSEC")) { |
699 | 31.5k | if (reader.Is(0,"BLOCK")) { |
700 | 3.01k | ParseBlock(++reader,output); |
701 | 3.01k | continue; |
702 | 3.01k | } |
703 | 28.5k | ++reader; |
704 | 28.5k | } |
705 | | |
706 | 3.04k | ASSIMP_LOG_VERBOSE_DEBUG("DXF: got ", output.blocks.size()," entries in BLOCKS" ); |
707 | 3.04k | } |
708 | | |
709 | | // ------------------------------------------------------------------------------------------------ |
710 | 3.01k | void DXFImporter::ParseBlock(DXF::LineReader& reader, DXF::FileData& output) { |
711 | | // push a new block onto the stack. |
712 | 3.01k | output.blocks.emplace_back(); |
713 | 3.01k | DXF::Block& block = output.blocks.back(); |
714 | | |
715 | 147k | while( !reader.End() && !reader.Is(0,"ENDBLK")) { |
716 | | |
717 | 145k | switch(reader.GroupCode()) { |
718 | 4.84k | case GroupCode_Name: |
719 | 4.84k | block.name = reader.Value(); |
720 | 4.84k | break; |
721 | | |
722 | 7.89k | case GroupCode_XComp: |
723 | 7.89k | block.base.x = reader.ValueAsFloat(); |
724 | 7.89k | break; |
725 | 7.22k | case GroupCode_YComp: |
726 | 7.22k | block.base.y = reader.ValueAsFloat(); |
727 | 7.22k | break; |
728 | 7.13k | case GroupCode_ZComp: |
729 | 7.13k | block.base.z = reader.ValueAsFloat(); |
730 | 7.13k | break; |
731 | 145k | } |
732 | | |
733 | 145k | if (reader.Is(0,"POLYLINE")) { |
734 | 1.18k | ParsePolyLine(++reader,output); |
735 | 1.18k | continue; |
736 | 1.18k | } |
737 | | |
738 | | // XXX is this a valid case? |
739 | 144k | if (reader.Is(0,"INSERT")) { |
740 | 830 | ASSIMP_LOG_WARN("DXF: INSERT within a BLOCK not currently supported; skipping"); |
741 | 29.6k | for( ;!reader.End() && !reader.Is(0,"ENDBLK"); ++reader); |
742 | 830 | break; |
743 | 830 | } |
744 | | |
745 | 143k | else if (reader.Is(0,"3DFACE") || reader.Is(0,"LINE") || reader.Is(0,"3DLINE")) { |
746 | | //http://sourceforge.net/tracker/index.php?func=detail&aid=2970566&group_id=226462&atid=1067632 |
747 | 485 | Parse3DFace(++reader, output); |
748 | 485 | continue; |
749 | 485 | } |
750 | 143k | else if (reader.Is(0,"POINT")) { |
751 | 82 | ParsePoint(++reader, output); |
752 | 82 | continue; |
753 | 82 | } |
754 | 143k | ++reader; |
755 | 143k | } |
756 | 3.01k | } |
757 | | |
758 | | // ------------------------------------------------------------------------------------------------ |
759 | 3.02k | void DXFImporter::ParseEntities(DXF::LineReader& reader, DXF::FileData& output) { |
760 | | // Push a new block onto the stack. |
761 | 3.02k | output.blocks.emplace_back(); |
762 | 3.02k | DXF::Block& block = output.blocks.back(); |
763 | | |
764 | 3.02k | block.name = AI_DXF_ENTITIES_MAGIC_BLOCK; |
765 | | |
766 | 194k | while( !reader.End() && !reader.Is(0,"ENDSEC")) { |
767 | 191k | if (reader.Is(0,"POLYLINE")) { |
768 | 414 | ParsePolyLine(++reader,output); |
769 | 414 | continue; |
770 | 414 | } |
771 | | |
772 | 191k | else if (reader.Is(0,"INSERT")) { |
773 | 3.28k | ParseInsertion(++reader,output); |
774 | 3.28k | continue; |
775 | 3.28k | } |
776 | | |
777 | 187k | else if (reader.Is(0,"3DFACE") || reader.Is(0,"LINE") || reader.Is(0,"3DLINE")) { |
778 | | //http://sourceforge.net/tracker/index.php?func=detail&aid=2970566&group_id=226462&atid=1067632 |
779 | 12.4k | Parse3DFace(++reader, output); |
780 | 12.4k | continue; |
781 | 12.4k | } |
782 | | |
783 | 175k | else if (reader.Is(0,"POINT")) { |
784 | 660 | ParsePoint(++reader, output); |
785 | 660 | continue; |
786 | 660 | } |
787 | | |
788 | 174k | ++reader; |
789 | 174k | } |
790 | | |
791 | 3.02k | ASSIMP_LOG_VERBOSE_DEBUG( "DXF: got ", block.lines.size()," polylines and ", block.insertions.size(), |
792 | 3.02k | " inserted blocks in ENTITIES" ); |
793 | 3.02k | } |
794 | | |
795 | 3.28k | void DXFImporter::ParseInsertion(DXF::LineReader& reader, DXF::FileData& output) { |
796 | 3.28k | output.blocks.back().insertions.emplace_back(); |
797 | 3.28k | DXF::InsertBlock& bl = output.blocks.back().insertions.back(); |
798 | | |
799 | 7.44k | while( !reader.End() && !reader.Is(0)) { |
800 | 4.16k | switch(reader.GroupCode()) { |
801 | | // name of referenced block |
802 | 679 | case GroupCode_Name: |
803 | 679 | bl.name = reader.Value(); |
804 | 679 | break; |
805 | | |
806 | | // translation |
807 | 159 | case GroupCode_XComp: |
808 | 159 | bl.pos.x = reader.ValueAsFloat(); |
809 | 159 | break; |
810 | 125 | case GroupCode_YComp: |
811 | 125 | bl.pos.y = reader.ValueAsFloat(); |
812 | 125 | break; |
813 | 144 | case GroupCode_ZComp: |
814 | 144 | bl.pos.z = reader.ValueAsFloat(); |
815 | 144 | break; |
816 | | |
817 | | // scaling |
818 | 240 | case 41: |
819 | 240 | bl.scale.x = reader.ValueAsFloat(); |
820 | 240 | break; |
821 | 403 | case 42: |
822 | 403 | bl.scale.y = reader.ValueAsFloat(); |
823 | 403 | break; |
824 | 311 | case 43: |
825 | 311 | bl.scale.z = reader.ValueAsFloat(); |
826 | 311 | break; |
827 | | |
828 | | // rotation angle |
829 | 30 | case 50: |
830 | 30 | bl.angle = reader.ValueAsFloat(); |
831 | 30 | break; |
832 | 4.16k | } |
833 | 4.16k | reader++; |
834 | 4.16k | } |
835 | 3.28k | } |
836 | | |
837 | | static constexpr unsigned int DXF_POLYLINE_FLAG_CLOSED = 0x1; |
838 | | // Currently unused |
839 | | //static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYLINE = 0x8; |
840 | | //static constexpr unsigned int DXF_POLYLINE_FLAG_3D_POLYMESH = 0x10; |
841 | | static constexpr unsigned int DXF_POLYLINE_FLAG_POLYFACEMESH = 0x40; |
842 | | |
843 | | // ------------------------------------------------------------------------------------------------ |
844 | 1.59k | void DXFImporter::ParsePolyLine(DXF::LineReader& reader, DXF::FileData& output) { |
845 | 1.59k | output.blocks.back().lines.push_back(std::make_shared<DXF::PolyLine>()); |
846 | 1.59k | DXF::PolyLine& line = *output.blocks.back().lines.back(); |
847 | | |
848 | 1.59k | unsigned int iguess = 0, vguess = 0; |
849 | 332k | while( !reader.End() && !reader.Is(0,"ENDSEC")) { |
850 | | |
851 | 330k | if (reader.Is(0,"VERTEX")) { |
852 | 85.5k | ParsePolyLineVertex(++reader,line); |
853 | 85.5k | if (reader.Is(0,"SEQEND")) { |
854 | 147 | break; |
855 | 147 | } |
856 | 85.4k | continue; |
857 | 85.5k | } |
858 | | |
859 | 245k | switch(reader.GroupCode()) |
860 | 245k | { |
861 | | // flags --- important that we know whether it is a |
862 | | // polyface mesh or 'just' a line. |
863 | 4.39k | case 70: |
864 | 4.39k | if (!line.flags) { |
865 | 1.80k | line.flags = reader.ValueAsSignedInt(); |
866 | 1.80k | } |
867 | 4.39k | break; |
868 | | |
869 | | // optional number of vertices |
870 | 3.06k | case 71: |
871 | 3.06k | vguess = reader.ValueAsSignedInt(); |
872 | 3.06k | line.positions.reserve(vguess); |
873 | 3.06k | break; |
874 | | |
875 | | // optional number of faces |
876 | 2.60k | case 72: |
877 | 2.60k | iguess = reader.ValueAsSignedInt(); |
878 | 2.60k | line.indices.reserve(iguess); |
879 | 2.60k | break; |
880 | | |
881 | | // 8 specifies the layer on which this line is placed on |
882 | 3.48k | case 8: |
883 | 3.48k | line.layer = reader.Value(); |
884 | 3.48k | break; |
885 | 245k | } |
886 | | |
887 | 245k | reader++; |
888 | 245k | } |
889 | | |
890 | 1.59k | if (vguess && line.positions.size() != vguess) { |
891 | 824 | ASSIMP_LOG_WARN("DXF: unexpected vertex count in polymesh: ", |
892 | 824 | line.positions.size(),", expected ", vguess ); |
893 | 824 | } |
894 | | |
895 | 1.59k | if (line.flags & DXF_POLYLINE_FLAG_POLYFACEMESH ) { |
896 | 1.01k | if (line.positions.size() < 3 || line.indices.size() < 3) { |
897 | 801 | ASSIMP_LOG_WARN("DXF: not enough vertices for polymesh; ignoring"); |
898 | 801 | output.blocks.back().lines.pop_back(); |
899 | 801 | return; |
900 | 801 | } |
901 | | |
902 | | // if these numbers are wrong, parsing might have gone wild. |
903 | | // however, the docs state that applications are not required |
904 | | // to set the 71 and 72 fields, respectively, to valid values. |
905 | | // So just fire a warning. |
906 | 218 | if (iguess && line.counts.size() != iguess) { |
907 | 139 | ASSIMP_LOG_WARN( "DXF: unexpected face count in polymesh: ", line.counts.size(),", expected ", iguess ); |
908 | 139 | } |
909 | 218 | } |
910 | 579 | else if (!line.indices.size() && !line.counts.size()) { |
911 | | // a poly-line - so there are no indices yet. |
912 | | // a polyline is a connected chain of segments, so segment i joins vertex i to vertex i+1. |
913 | 508 | size_t guess = line.positions.size() + (line.flags & DXF_POLYLINE_FLAG_CLOSED ? 1 : 0); |
914 | 508 | line.indices.reserve(guess*2); |
915 | | |
916 | 508 | line.counts.reserve(guess); |
917 | 3.26k | for (unsigned int i = 0; i + 1 < line.positions.size(); ++i) { |
918 | 2.76k | line.indices.push_back(i); |
919 | 2.76k | line.indices.push_back(i+1); |
920 | 2.76k | line.counts.push_back(2); |
921 | 2.76k | } |
922 | | |
923 | | // closed polyline? |
924 | 508 | if (line.flags & DXF_POLYLINE_FLAG_CLOSED) { |
925 | 87 | line.indices.push_back(static_cast<unsigned int>(line.positions.size()-1)); |
926 | 87 | line.indices.push_back(0); |
927 | 87 | line.counts.push_back(2); |
928 | 87 | } |
929 | 508 | } |
930 | 1.59k | } |
931 | | |
932 | 80.3k | #define DXF_VERTEX_FLAG_PART_OF_POLYFACE 0x80 |
933 | | #define DXF_VERTEX_FLAG_HAS_POSITIONS 0x40 |
934 | | |
935 | | // ------------------------------------------------------------------------------------------------ |
936 | 85.5k | void DXFImporter::ParsePolyLineVertex(DXF::LineReader& reader, DXF::PolyLine& line) { |
937 | 85.5k | unsigned int cnti = 0, flags = 0; |
938 | 85.5k | unsigned int indices[4]; |
939 | | |
940 | 85.5k | aiVector3D out; |
941 | 85.5k | aiColor4D clr = AI_DXF_DEFAULT_COLOR; |
942 | | |
943 | 778k | while( !reader.End() ) { |
944 | | |
945 | 777k | if (reader.Is(0)) { // SEQEND or another VERTEX |
946 | 85.3k | break; |
947 | 85.3k | } |
948 | | |
949 | 692k | switch (reader.GroupCode()) { |
950 | 85.4k | case 8: |
951 | | // layer to which the vertex belongs to - assume that |
952 | | // this is always the layer the top-level poly-line |
953 | | // entity resides on as well. |
954 | 85.4k | if(reader.Value() != line.layer) { |
955 | 13.1k | ASSIMP_LOG_WARN("DXF: expected vertex to be part of a poly-face but the 0x128 flag isn't set"); |
956 | 13.1k | } |
957 | 85.4k | break; |
958 | | |
959 | 83.6k | case 70: |
960 | 83.6k | flags = reader.ValueAsUnsignedInt(); |
961 | 83.6k | break; |
962 | | |
963 | | // VERTEX COORDINATES |
964 | 83.9k | case GroupCode_XComp: |
965 | 83.9k | out.x = reader.ValueAsFloat(); |
966 | 83.9k | break; |
967 | | |
968 | 83.2k | case GroupCode_YComp: |
969 | 83.2k | out.y = reader.ValueAsFloat(); |
970 | 83.2k | break; |
971 | | |
972 | 82.4k | case GroupCode_ZComp: |
973 | 82.4k | out.z = reader.ValueAsFloat(); |
974 | 82.4k | break; |
975 | | |
976 | | // POLYFACE vertex indices |
977 | 40.6k | case 71: |
978 | 80.5k | case 72: |
979 | 120k | case 73: |
980 | 121k | case 74: { |
981 | 121k | if (cnti == 4) { |
982 | 307 | ASSIMP_LOG_WARN("DXF: more than 4 indices per face not supported; ignoring"); |
983 | 307 | break; |
984 | 307 | } |
985 | 121k | const int index = reader.ValueAsSignedInt(); |
986 | 121k | if (index >= 0) { |
987 | 119k | indices[cnti++] = static_cast<unsigned int>(index); |
988 | 119k | } else { |
989 | 1.73k | indices[cnti++] = static_cast<unsigned int>(-index); |
990 | 1.73k | } |
991 | 121k | } |
992 | 0 | break; |
993 | | |
994 | | // color |
995 | 49.5k | case 62: |
996 | 49.5k | clr = g_aclrDxfIndexColors[reader.ValueAsUnsignedInt() % AI_DXF_NUM_INDEX_COLORS]; |
997 | 49.5k | break; |
998 | | |
999 | 102k | default: |
1000 | 102k | break; |
1001 | 692k | } |
1002 | | |
1003 | 692k | reader++; |
1004 | 692k | } |
1005 | | |
1006 | 85.5k | if (line.flags & DXF_POLYLINE_FLAG_POLYFACEMESH && !(flags & DXF_VERTEX_FLAG_PART_OF_POLYFACE)) { |
1007 | 2.40k | ASSIMP_LOG_WARN("DXF: expected vertex to be part of a polyface but the 0x128 flag isn't set"); |
1008 | 2.40k | } |
1009 | | |
1010 | | // A triangular polyface is commonly written as a closed quad, repeating either |
1011 | | // the first corner (a,b,c,a) or the last one (a,b,c,c) in group code 74. Left |
1012 | | // as a 4-corner face it triangulates into the real triangle plus a zero-area |
1013 | | // sliver, so collapse it back to a single triangle here. |
1014 | 85.5k | while (cnti > 3 && (indices[cnti-1] == indices[0] || indices[cnti-1] == indices[cnti-2])) { |
1015 | 10 | --cnti; |
1016 | 10 | } |
1017 | | |
1018 | 85.5k | if (cnti) { |
1019 | 40.1k | line.counts.push_back(cnti); |
1020 | 161k | for (unsigned int i = 0; i < cnti; ++i) { |
1021 | | // IMPORTANT NOTE: POLYMESH indices are ONE-BASED |
1022 | 121k | if (indices[i] == 0) { |
1023 | 467 | ASSIMP_LOG_WARN("DXF: invalid vertex index, indices are one-based."); |
1024 | 467 | --line.counts.back(); |
1025 | | // Workaround to fix issue 2229 |
1026 | 467 | if (line.counts.back() == 0) { |
1027 | 74 | line.counts.pop_back(); |
1028 | 74 | } |
1029 | 467 | continue; |
1030 | 467 | } |
1031 | 121k | line.indices.push_back(indices[i]-1); |
1032 | 121k | } |
1033 | 45.4k | } else { |
1034 | 45.4k | line.positions.push_back(out); |
1035 | 45.4k | line.colors.push_back(clr); |
1036 | 45.4k | } |
1037 | 85.5k | } |
1038 | | |
1039 | | // ------------------------------------------------------------------------------------------------ |
1040 | 12.9k | void DXFImporter::Parse3DFace(DXF::LineReader& reader, DXF::FileData& output) { |
1041 | | // (note) this is also used for for parsing line entities, so we |
1042 | | // must handle the vertex_count == 2 case as well. |
1043 | | |
1044 | 12.9k | output.blocks.back().lines.push_back( std::make_shared<DXF::PolyLine>() ); |
1045 | 12.9k | DXF::PolyLine& line = *output.blocks.back().lines.back(); |
1046 | | |
1047 | 12.9k | aiVector3D vip[4]; |
1048 | 12.9k | aiColor4D clr = AI_DXF_DEFAULT_COLOR; |
1049 | | |
1050 | 12.9k | bool b[4] = {false,false,false,false}; |
1051 | 146k | while( !reader.End() ) { |
1052 | | |
1053 | | // next entity with a groupcode == 0 is probably already the next vertex or polymesh entity |
1054 | 146k | if (reader.GroupCode() == 0) { |
1055 | 12.7k | break; |
1056 | 12.7k | } |
1057 | 133k | switch (reader.GroupCode()) { |
1058 | | |
1059 | | // 8 specifies the layer |
1060 | 12.1k | case 8: |
1061 | 12.1k | line.layer = reader.Value(); |
1062 | 12.1k | break; |
1063 | | |
1064 | | // x position of the first corner |
1065 | 7.89k | case 10: |
1066 | 7.89k | vip[0].x = reader.ValueAsFloat(); |
1067 | 7.89k | b[2] = true; |
1068 | 7.89k | break; |
1069 | | |
1070 | | // y position of the first corner |
1071 | 8.17k | case 20: |
1072 | 8.17k | vip[0].y = reader.ValueAsFloat(); |
1073 | 8.17k | b[2] = true; |
1074 | 8.17k | break; |
1075 | | |
1076 | | // z position of the first corner |
1077 | 8.10k | case 30: |
1078 | 8.10k | vip[0].z = reader.ValueAsFloat(); |
1079 | 8.10k | b[2] = true; |
1080 | 8.10k | break; |
1081 | | |
1082 | | // x position of the second corner |
1083 | 8.37k | case 11: |
1084 | 8.37k | vip[1].x = reader.ValueAsFloat(); |
1085 | 8.37k | b[3] = true; |
1086 | 8.37k | break; |
1087 | | |
1088 | | // y position of the second corner |
1089 | 8.08k | case 21: |
1090 | 8.08k | vip[1].y = reader.ValueAsFloat(); |
1091 | 8.08k | b[3] = true; |
1092 | 8.08k | break; |
1093 | | |
1094 | | // z position of the second corner |
1095 | 7.93k | case 31: |
1096 | 7.93k | vip[1].z = reader.ValueAsFloat(); |
1097 | 7.93k | b[3] = true; |
1098 | 7.93k | break; |
1099 | | |
1100 | | // x position of the third corner |
1101 | 9.10k | case 12: |
1102 | 9.10k | vip[2].x = reader.ValueAsFloat(); |
1103 | 9.10k | b[0] = true; |
1104 | 9.10k | break; |
1105 | | |
1106 | | // y position of the third corner |
1107 | 9.08k | case 22: |
1108 | 9.08k | vip[2].y = reader.ValueAsFloat(); |
1109 | 9.08k | b[0] = true; |
1110 | 9.08k | break; |
1111 | | |
1112 | | // z position of the third corner |
1113 | 8.96k | case 32: |
1114 | 8.96k | vip[2].z = reader.ValueAsFloat(); |
1115 | 8.96k | b[0] = true; |
1116 | 8.96k | break; |
1117 | | |
1118 | | // x position of the fourth corner |
1119 | 9.93k | case 13: |
1120 | 9.93k | vip[3].x = reader.ValueAsFloat(); |
1121 | 9.93k | b[1] = true; |
1122 | 9.93k | break; |
1123 | | |
1124 | | // y position of the fourth corner |
1125 | 9.32k | case 23: |
1126 | 9.32k | vip[3].y = reader.ValueAsFloat(); |
1127 | 9.32k | b[1] = true; |
1128 | 9.32k | break; |
1129 | | |
1130 | | // z position of the fourth corner |
1131 | 8.61k | case 33: |
1132 | 8.61k | vip[3].z = reader.ValueAsFloat(); |
1133 | 8.61k | b[1] = true; |
1134 | 8.61k | break; |
1135 | | |
1136 | | // color |
1137 | 1.73k | case 62: |
1138 | 1.73k | clr = g_aclrDxfIndexColors[reader.ValueAsUnsignedInt() % AI_DXF_NUM_INDEX_COLORS]; |
1139 | 1.73k | break; |
1140 | 133k | }; |
1141 | | |
1142 | 133k | ++reader; |
1143 | 133k | } |
1144 | | |
1145 | | // the fourth corner may even be identical to the third, |
1146 | | // in this case we treat it as if it didn't exist. |
1147 | 12.9k | if (vip[3] == vip[2]) { |
1148 | 2.84k | b[1] = false; |
1149 | 2.84k | } |
1150 | | |
1151 | | // sanity checks to see if we got something meaningful |
1152 | 12.9k | if ((b[1] && !b[0]) || !b[2] || !b[3]) { |
1153 | 5.13k | ASSIMP_LOG_WARN("DXF: unexpected vertex setup in 3DFACE/LINE/FACE entity; ignoring"); |
1154 | 5.13k | output.blocks.back().lines.pop_back(); |
1155 | 5.13k | return; |
1156 | 5.13k | } |
1157 | | |
1158 | 7.78k | const unsigned int cnt = (2+(b[0]?1:0)+(b[1]?1:0)); |
1159 | 7.78k | line.counts.push_back(cnt); |
1160 | | |
1161 | 37.1k | for (unsigned int i = 0; i < cnt; ++i) { |
1162 | 29.3k | line.indices.push_back(static_cast<unsigned int>(line.positions.size())); |
1163 | 29.3k | line.positions.push_back(vip[i]); |
1164 | 29.3k | line.colors.push_back(clr); |
1165 | 29.3k | } |
1166 | 7.78k | } |
1167 | | |
1168 | | // ------------------------------------------------------------------------------------------------ |
1169 | 742 | void DXFImporter::ParsePoint(DXF::LineReader& reader, DXF::FileData& output) { |
1170 | | // POINT entities are stored as a PolyLine with a single vertex and a |
1171 | | // single one-index face, which ConvertMeshes() maps to aiPrimitiveType_POINT. |
1172 | 742 | output.blocks.back().lines.push_back(std::make_shared<DXF::PolyLine>()); |
1173 | 742 | DXF::PolyLine& line = *output.blocks.back().lines.back(); |
1174 | | |
1175 | 742 | aiVector3D pos; |
1176 | 742 | aiColor4D clr = AI_DXF_DEFAULT_COLOR; |
1177 | 742 | bool has_position = false; |
1178 | | |
1179 | 2.20k | while( !reader.End() ) { |
1180 | | |
1181 | | // next entity with a groupcode == 0 is probably already the next entity |
1182 | 2.16k | if (reader.GroupCode() == 0) { |
1183 | 692 | break; |
1184 | 692 | } |
1185 | 1.47k | switch (reader.GroupCode()) { |
1186 | | |
1187 | | // 8 specifies the layer |
1188 | 89 | case 8: |
1189 | 89 | line.layer = reader.Value(); |
1190 | 89 | break; |
1191 | | |
1192 | | // x position |
1193 | 324 | case GroupCode_XComp: |
1194 | 324 | pos.x = reader.ValueAsFloat(); |
1195 | 324 | has_position = true; |
1196 | 324 | break; |
1197 | | |
1198 | | // y position |
1199 | 246 | case GroupCode_YComp: |
1200 | 246 | pos.y = reader.ValueAsFloat(); |
1201 | 246 | has_position = true; |
1202 | 246 | break; |
1203 | | |
1204 | | // z position |
1205 | 264 | case GroupCode_ZComp: |
1206 | 264 | pos.z = reader.ValueAsFloat(); |
1207 | 264 | has_position = true; |
1208 | 264 | break; |
1209 | | |
1210 | | // color |
1211 | 24 | case 62: |
1212 | 24 | clr = g_aclrDxfIndexColors[reader.ValueAsUnsignedInt() % AI_DXF_NUM_INDEX_COLORS]; |
1213 | 24 | break; |
1214 | | |
1215 | 526 | default: |
1216 | 526 | break; |
1217 | 1.47k | } |
1218 | | |
1219 | 1.46k | ++reader; |
1220 | 1.46k | } |
1221 | | |
1222 | | // sanity check to see if we got something meaningful |
1223 | 735 | if (!has_position) { |
1224 | 604 | ASSIMP_LOG_WARN("DXF: POINT entity has no position; ignoring"); |
1225 | 604 | output.blocks.back().lines.pop_back(); |
1226 | 604 | return; |
1227 | 604 | } |
1228 | | |
1229 | 131 | line.counts.push_back(1); |
1230 | 131 | line.indices.push_back(0); |
1231 | 131 | line.positions.push_back(pos); |
1232 | 131 | line.colors.push_back(clr); |
1233 | 131 | } |
1234 | | |
1235 | | #endif // !! ASSIMP_BUILD_NO_DXF_IMPORTER |