1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following conditions are met:
12
13* Redistributions of source code must retain the above
14copyright notice, this list of conditions and the
15following disclaimer.
16
17* Redistributions in binary form must reproduce the above
18copyright notice, this list of conditions and the
19following disclaimer in the documentation and/or other
20materials provided with the distribution.
21
22* Neither the name of the assimp team, nor the names of its
23contributors may be used to endorse or promote products
24derived from this software without specific prior
25written permission of the assimp team.
26
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41/// \file X3DImporter_Texturing.cpp
42/// \brief Parsing data from nodes of "Texturing" 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
51namespace Assimp
52{
53
54// <ImageTexture
55// DEF="" ID
56// USE="" IDREF
57// repeatS="true" SFBool
58// repeatT="true" SFBool
59// url="" MFString
60// />
61// When the url field contains no values ([]), texturing is disabled.
62void X3DImporter::ParseNode_Texturing_ImageTexture()
63{
64 std::string use, def;
65 bool repeatS = true;
66 bool repeatT = true;
67 std::list<std::string> url;
68 CX3DImporter_NodeElement* ne( nullptr );
69
70 MACRO_ATTRREAD_LOOPBEG;
71 MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
72 MACRO_ATTRREAD_CHECK_RET("repeatS", repeatS, XML_ReadNode_GetAttrVal_AsBool);
73 MACRO_ATTRREAD_CHECK_RET("repeatT", repeatT, XML_ReadNode_GetAttrVal_AsBool);
74 MACRO_ATTRREAD_CHECK_REF("url", url, XML_ReadNode_GetAttrVal_AsListS);
75 MACRO_ATTRREAD_LOOPEND;
76
77 // if "USE" defined then find already defined element.
78 if(!use.empty())
79 {
80 MACRO_USE_CHECKANDAPPLY(def, use, ENET_ImageTexture, ne);
81 }
82 else
83 {
84 // create and if needed - define new geometry object.
85 ne = new CX3DImporter_NodeElement_ImageTexture(NodeElement_Cur);
86 if(!def.empty()) ne->ID = def;
87
88 ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatS = repeatS;
89 ((CX3DImporter_NodeElement_ImageTexture*)ne)->RepeatT = repeatT;
90 // Attribute "url" can contain list of strings. But we need only one - first.
91 if(url.size() > 0)
92 ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = url.front();
93 else
94 ((CX3DImporter_NodeElement_ImageTexture*)ne)->URL = "";
95
96 // check for X3DMetadataObject childs.
97 if(!mReader->isEmptyElement())
98 ParseNode_Metadata(ne, "ImageTexture");
99 else
100 NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
101
102 NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
103 }// if(!use.empty()) else
104}
105
106// <TextureCoordinate
107// DEF="" ID
108// USE="" IDREF
109// point="" MFVec3f [inputOutput]
110// />
111void X3DImporter::ParseNode_Texturing_TextureCoordinate()
112{
113 std::string use, def;
114 std::list<aiVector2D> point;
115 CX3DImporter_NodeElement* ne( nullptr );
116
117 MACRO_ATTRREAD_LOOPBEG;
118 MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
119 MACRO_ATTRREAD_CHECK_REF("point", point, XML_ReadNode_GetAttrVal_AsListVec2f);
120 MACRO_ATTRREAD_LOOPEND;
121
122 // if "USE" defined then find already defined element.
123 if(!use.empty())
124 {
125 MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureCoordinate, ne);
126 }
127 else
128 {
129 // create and if needed - define new geometry object.
130 ne = new CX3DImporter_NodeElement_TextureCoordinate(NodeElement_Cur);
131 if(!def.empty()) ne->ID = def;
132
133 ((CX3DImporter_NodeElement_TextureCoordinate*)ne)->Value = point;
134 // check for X3DMetadataObject childs.
135 if(!mReader->isEmptyElement())
136 ParseNode_Metadata(ne, "TextureCoordinate");
137 else
138 NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
139
140 NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
141 }// if(!use.empty()) else
142}
143
144// <TextureTransform
145// DEF="" ID
146// USE="" IDREF
147// center="0 0" SFVec2f [inputOutput]
148// rotation="0" SFFloat [inputOutput]
149// scale="1 1" SFVec2f [inputOutput]
150// translation="0 0" SFVec2f [inputOutput]
151// />
152void X3DImporter::ParseNode_Texturing_TextureTransform()
153{
154 std::string use, def;
155 aiVector2D center(0, 0);
156 float rotation = 0;
157 aiVector2D scale(1, 1);
158 aiVector2D translation(0, 0);
159 CX3DImporter_NodeElement* ne( nullptr );
160
161 MACRO_ATTRREAD_LOOPBEG;
162 MACRO_ATTRREAD_CHECKUSEDEF_RET(def, use);
163 MACRO_ATTRREAD_CHECK_REF("center", center, XML_ReadNode_GetAttrVal_AsVec2f);
164 MACRO_ATTRREAD_CHECK_RET("rotation", rotation, XML_ReadNode_GetAttrVal_AsFloat);
165 MACRO_ATTRREAD_CHECK_REF("scale", scale, XML_ReadNode_GetAttrVal_AsVec2f);
166 MACRO_ATTRREAD_CHECK_REF("translation", translation, XML_ReadNode_GetAttrVal_AsVec2f);
167 MACRO_ATTRREAD_LOOPEND;
168
169 // if "USE" defined then find already defined element.
170 if(!use.empty())
171 {
172 MACRO_USE_CHECKANDAPPLY(def, use, ENET_TextureTransform, ne);
173 }
174 else
175 {
176 // create and if needed - define new geometry object.
177 ne = new CX3DImporter_NodeElement_TextureTransform(NodeElement_Cur);
178 if(!def.empty()) ne->ID = def;
179
180 ((CX3DImporter_NodeElement_TextureTransform*)ne)->Center = center;
181 ((CX3DImporter_NodeElement_TextureTransform*)ne)->Rotation = rotation;
182 ((CX3DImporter_NodeElement_TextureTransform*)ne)->Scale = scale;
183 ((CX3DImporter_NodeElement_TextureTransform*)ne)->Translation = translation;
184 // check for X3DMetadataObject childs.
185 if(!mReader->isEmptyElement())
186 ParseNode_Metadata(ne, "TextureTransform");
187 else
188 NodeElement_Cur->Child.push_back(ne);// add made object as child to current element
189
190 NodeElement_List.push_back(ne);// add element to node element list because its a new object in graph
191 }// if(!use.empty()) else
192}
193
194}// namespace Assimp
195
196#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER
197