/src/assimp/code/AssetLib/X3D/X3DImporter_Shape.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2019, assimp team |
6 | | |
7 | | All rights reserved. |
8 | | |
9 | | Redistribution and use of this software in source and binary forms, |
10 | | with or without modification, are permitted provided that the |
11 | | following conditions are met: |
12 | | |
13 | | * Redistributions of source code must retain the above |
14 | | copyright notice, this list of conditions and the |
15 | | following disclaimer. |
16 | | |
17 | | * Redistributions in binary form must reproduce the above |
18 | | copyright notice, this list of conditions and the |
19 | | following disclaimer in the documentation and/or other |
20 | | materials provided with the distribution. |
21 | | |
22 | | * Neither the name of the assimp team, nor the names of its |
23 | | contributors may be used to endorse or promote products |
24 | | derived from this software without specific prior |
25 | | written permission of the assimp team. |
26 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | |
39 | | ---------------------------------------------------------------------- |
40 | | */ |
41 | | /// \file X3DImporter_Shape.cpp |
42 | | /// \brief Parsing data from nodes of "Shape" set of X3D. |
43 | | /// \date 2015-2016 |
44 | | /// \author smal.root@gmail.com |
45 | | |
46 | | #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER |
47 | | |
48 | | #include "X3DImporter.hpp" |
49 | | #include "X3DImporter_Macro.hpp" |
50 | | #include "X3DXmlHelper.h" |
51 | | |
52 | | namespace Assimp { |
53 | | |
54 | 0 | void X3DImporter::readShape(XmlNode &node) { |
55 | 0 | std::string use, def; |
56 | 0 | X3DNodeElementBase *ne(nullptr); |
57 | |
|
58 | 0 | MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use); |
59 | | |
60 | | // if "USE" defined then find already defined element. |
61 | 0 | if (!use.empty()) { |
62 | 0 | ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Shape, ne); |
63 | 0 | } else { |
64 | | // create and if needed - define new geometry object. |
65 | 0 | ne = new X3DNodeElementShape(mNodeElementCur); |
66 | 0 | if (!def.empty()) ne->ID = def; |
67 | | |
68 | | // check for child nodes |
69 | 0 | if (!isNodeEmpty(node)) { |
70 | 0 | ParseHelper_Node_Enter(ne); |
71 | 0 | for (auto currentChildNode : node.children()) { |
72 | 0 | const std::string ¤tChildName = currentChildNode.name(); |
73 | | // check for appearance node |
74 | 0 | if (currentChildName == "Appearance") readAppearance(currentChildNode); |
75 | | // check for X3DGeometryNodes |
76 | 0 | else if (currentChildName == "Arc2D") |
77 | 0 | readArc2D(currentChildNode); |
78 | 0 | else if (currentChildName == "ArcClose2D") |
79 | 0 | readArcClose2D(currentChildNode); |
80 | 0 | else if (currentChildName == "Circle2D") |
81 | 0 | readCircle2D(currentChildNode); |
82 | 0 | else if (currentChildName == "Disk2D") |
83 | 0 | readDisk2D(currentChildNode); |
84 | 0 | else if (currentChildName == "Polyline2D") |
85 | 0 | readPolyline2D(currentChildNode); |
86 | 0 | else if (currentChildName == "Polypoint2D") |
87 | 0 | readPolypoint2D(currentChildNode); |
88 | 0 | else if (currentChildName == "Rectangle2D") |
89 | 0 | readRectangle2D(currentChildNode); |
90 | 0 | else if (currentChildName == "TriangleSet2D") |
91 | 0 | readTriangleSet2D(currentChildNode); |
92 | 0 | else if (currentChildName == "Box") |
93 | 0 | readBox(currentChildNode); |
94 | 0 | else if (currentChildName == "Cone") |
95 | 0 | readCone(currentChildNode); |
96 | 0 | else if (currentChildName == "Cylinder") |
97 | 0 | readCylinder(currentChildNode); |
98 | 0 | else if (currentChildName == "ElevationGrid") |
99 | 0 | readElevationGrid(currentChildNode); |
100 | 0 | else if (currentChildName == "Extrusion") |
101 | 0 | readExtrusion(currentChildNode); |
102 | 0 | else if (currentChildName == "IndexedFaceSet") |
103 | 0 | readIndexedFaceSet(currentChildNode); |
104 | 0 | else if (currentChildName == "Sphere") |
105 | 0 | readSphere(currentChildNode); |
106 | 0 | else if (currentChildName == "IndexedLineSet") |
107 | 0 | readIndexedLineSet(currentChildNode); |
108 | 0 | else if (currentChildName == "LineSet") |
109 | 0 | readLineSet(currentChildNode); |
110 | 0 | else if (currentChildName == "PointSet") |
111 | 0 | readPointSet(currentChildNode); |
112 | 0 | else if (currentChildName == "IndexedTriangleFanSet") |
113 | 0 | readIndexedTriangleFanSet(currentChildNode); |
114 | 0 | else if (currentChildName == "IndexedTriangleSet") |
115 | 0 | readIndexedTriangleSet(currentChildNode); |
116 | 0 | else if (currentChildName == "IndexedTriangleStripSet") |
117 | 0 | readIndexedTriangleStripSet(currentChildNode); |
118 | 0 | else if (currentChildName == "TriangleFanSet") |
119 | 0 | readTriangleFanSet(currentChildNode); |
120 | 0 | else if (currentChildName == "TriangleSet") |
121 | 0 | readTriangleSet(currentChildNode); |
122 | | // check for X3DMetadataObject |
123 | 0 | else if (!checkForMetadataNode(currentChildNode)) |
124 | 0 | skipUnsupportedNode("Shape", currentChildNode); |
125 | 0 | } |
126 | |
|
127 | 0 | ParseHelper_Node_Exit(); |
128 | 0 | } // if (!isNodeEmpty(node)) |
129 | 0 | else { |
130 | 0 | mNodeElementCur->Children.push_back(ne); // add made object as child to current element |
131 | 0 | } |
132 | |
|
133 | 0 | NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph |
134 | 0 | } // if(!use.empty()) else |
135 | 0 | } |
136 | | |
137 | | // <Appearance |
138 | | // DEF="" ID |
139 | | // USE="" IDREF |
140 | | // > |
141 | | // <!-- AppearanceChildContentModel --> |
142 | | // "Child-node content model corresponding to X3DAppearanceChildNode. Appearance can contain FillProperties, LineProperties, Material, any Texture node and |
143 | | // any TextureTransform node, in any order. No more than one instance of these nodes is allowed. Appearance may also contain multiple shaders (ComposedShader, |
144 | | // PackagedShader, ProgramShader). |
145 | | // A ProtoInstance node (with the proper node type) can be substituted for any node in this content model." |
146 | | // </Appearance> |
147 | 0 | void X3DImporter::readAppearance(XmlNode &node) { |
148 | 0 | std::string use, def; |
149 | 0 | X3DNodeElementBase *ne(nullptr); |
150 | |
|
151 | 0 | MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use); |
152 | | |
153 | | // if "USE" defined then find already defined element. |
154 | 0 | if (!use.empty()) { |
155 | 0 | ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Appearance, ne); |
156 | 0 | } else { |
157 | | // create and if needed - define new geometry object. |
158 | 0 | ne = new X3DNodeElementAppearance(mNodeElementCur); |
159 | 0 | if (!def.empty()) ne->ID = def; |
160 | | |
161 | | // check for child nodes |
162 | 0 | if (!isNodeEmpty(node)) { |
163 | 0 | ParseHelper_Node_Enter(ne); |
164 | 0 | for (auto currentChildNode : node.children()) { |
165 | 0 | const std::string ¤tChildName = currentChildNode.name(); |
166 | 0 | if (currentChildName == "Material") |
167 | 0 | readMaterial(currentChildNode); |
168 | 0 | else if (currentChildName == "ImageTexture") |
169 | 0 | readImageTexture(currentChildNode); |
170 | 0 | else if (currentChildName == "TextureTransform") |
171 | 0 | readTextureTransform(currentChildNode); |
172 | | // check for X3DMetadataObject |
173 | 0 | else if (!checkForMetadataNode(currentChildNode)) |
174 | 0 | skipUnsupportedNode("Appearance", currentChildNode); |
175 | 0 | } |
176 | 0 | ParseHelper_Node_Exit(); |
177 | 0 | } // if(!isNodeEmpty(node)) |
178 | 0 | else { |
179 | 0 | mNodeElementCur->Children.push_back(ne); // add made object as child to current element |
180 | 0 | } |
181 | |
|
182 | 0 | NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph |
183 | 0 | } // if(!use.empty()) else |
184 | 0 | } |
185 | | |
186 | | // <Material |
187 | | // DEF="" ID |
188 | | // USE="" IDREF |
189 | | // ambientIntensity="0.2" SFFloat [inputOutput] |
190 | | // diffuseColor="0.8 0.8 0.8" SFColor [inputOutput] |
191 | | // emissiveColor="0 0 0" SFColor [inputOutput] |
192 | | // shininess="0.2" SFFloat [inputOutput] |
193 | | // specularColor="0 0 0" SFColor [inputOutput] |
194 | | // transparency="0" SFFloat [inputOutput] |
195 | | // /> |
196 | 0 | void X3DImporter::readMaterial(XmlNode &node) { |
197 | 0 | std::string use, def; |
198 | 0 | float ambientIntensity = 0.2f; |
199 | 0 | float shininess = 0.2f; |
200 | 0 | float transparency = 0; |
201 | 0 | aiColor3D diffuseColor(0.8f, 0.8f, 0.8f); |
202 | 0 | aiColor3D emissiveColor(0, 0, 0); |
203 | 0 | aiColor3D specularColor(0, 0, 0); |
204 | 0 | X3DNodeElementBase *ne(nullptr); |
205 | |
|
206 | 0 | MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use); |
207 | 0 | XmlParser::getFloatAttribute(node, "ambientIntensity", ambientIntensity); |
208 | 0 | XmlParser::getFloatAttribute(node, "shininess", shininess); |
209 | 0 | XmlParser::getFloatAttribute(node, "transparency", transparency); |
210 | 0 | X3DXmlHelper::getColor3DAttribute(node, "diffuseColor", diffuseColor); |
211 | 0 | X3DXmlHelper::getColor3DAttribute(node, "emissiveColor", emissiveColor); |
212 | 0 | X3DXmlHelper::getColor3DAttribute(node, "specularColor", specularColor); |
213 | | |
214 | | // if "USE" defined then find already defined element. |
215 | 0 | if (!use.empty()) { |
216 | 0 | ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_Material, ne); |
217 | 0 | } else { |
218 | | // create and if needed - define new geometry object. |
219 | 0 | ne = new X3DNodeElementMaterial(mNodeElementCur); |
220 | 0 | if (!def.empty()) ne->ID = def; |
221 | |
|
222 | 0 | ((X3DNodeElementMaterial *)ne)->AmbientIntensity = ambientIntensity; |
223 | 0 | ((X3DNodeElementMaterial *)ne)->Shininess = shininess; |
224 | 0 | ((X3DNodeElementMaterial *)ne)->Transparency = transparency; |
225 | 0 | ((X3DNodeElementMaterial *)ne)->DiffuseColor = diffuseColor; |
226 | 0 | ((X3DNodeElementMaterial *)ne)->EmissiveColor = emissiveColor; |
227 | 0 | ((X3DNodeElementMaterial *)ne)->SpecularColor = specularColor; |
228 | | // check for child nodes |
229 | 0 | if (!isNodeEmpty(node)) |
230 | 0 | childrenReadMetadata(node, ne, "Material"); |
231 | 0 | else |
232 | 0 | mNodeElementCur->Children.push_back(ne); // add made object as child to current element |
233 | |
|
234 | 0 | NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph |
235 | 0 | } // if(!use.empty()) else |
236 | 0 | } |
237 | | |
238 | | } // namespace Assimp |
239 | | |
240 | | #endif // !ASSIMP_BUILD_NO_X3D_IMPORTER |