Coverage Report

Created: 2025-06-22 07:30

/src/assimp/code/AssetLib/X3D/X3DImporter_Texturing.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_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
#include "X3DXmlHelper.h"
51
52
namespace Assimp {
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.
62
0
void X3DImporter::readImageTexture(XmlNode &node) {
63
0
    std::string use, def;
64
0
    bool repeatS = true;
65
0
    bool repeatT = true;
66
0
    std::list<std::string> url;
67
0
    X3DNodeElementBase *ne(nullptr);
68
69
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
70
0
    XmlParser::getBoolAttribute(node, "repeatS", repeatS);
71
0
    XmlParser::getBoolAttribute(node, "repeatT", repeatT);
72
0
    X3DXmlHelper::getStringListAttribute(node, "url", url);
73
74
    // if "USE" defined then find already defined element.
75
0
    if (!use.empty()) {
76
0
        ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_ImageTexture, ne);
77
0
    } else {
78
        // create and if needed - define new geometry object.
79
0
        ne = new X3DNodeElementImageTexture(mNodeElementCur);
80
0
        if (!def.empty()) ne->ID = def;
81
82
0
        ((X3DNodeElementImageTexture *)ne)->RepeatS = repeatS;
83
0
        ((X3DNodeElementImageTexture *)ne)->RepeatT = repeatT;
84
        // Attribute "url" can contain list of strings. But we need only one - first.
85
0
        if (!url.empty())
86
0
            ((X3DNodeElementImageTexture *)ne)->URL = url.front();
87
0
        else
88
0
            ((X3DNodeElementImageTexture *)ne)->URL = "";
89
90
        // check for X3DMetadataObject childs.
91
0
        if (!isNodeEmpty(node))
92
0
            childrenReadMetadata(node, ne, "ImageTexture");
93
0
        else
94
0
            mNodeElementCur->Children.push_back(ne); // add made object as child to current element
95
96
0
        NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
97
0
    } // if(!use.empty()) else
98
0
}
99
100
// <TextureCoordinate
101
// DEF=""      ID
102
// USE=""      IDREF
103
// point=""    MFVec3f [inputOutput]
104
// />
105
0
void X3DImporter::readTextureCoordinate(XmlNode &node) {
106
0
    std::string use, def;
107
0
    std::list<aiVector2D> point;
108
0
    X3DNodeElementBase *ne(nullptr);
109
110
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
111
0
    X3DXmlHelper::getVector2DListAttribute(node, "point", point);
112
113
    // if "USE" defined then find already defined element.
114
0
    if (!use.empty()) {
115
0
        ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_TextureCoordinate, ne);
116
0
    } else {
117
        // create and if needed - define new geometry object.
118
0
        ne = new X3DNodeElementTextureCoordinate(mNodeElementCur);
119
0
        if (!def.empty()) ne->ID = def;
120
121
0
        ((X3DNodeElementTextureCoordinate *)ne)->Value = point;
122
        // check for X3DMetadataObject childs.
123
0
        if (!isNodeEmpty(node))
124
0
            childrenReadMetadata(node, ne, "TextureCoordinate");
125
0
        else
126
0
            mNodeElementCur->Children.push_back(ne); // add made object as child to current element
127
128
0
        NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
129
0
    } // if(!use.empty()) else
130
0
}
131
132
// <TextureTransform
133
// DEF=""            ID
134
// USE=""            IDREF
135
// center="0 0"      SFVec2f [inputOutput]
136
// rotation="0"      SFFloat [inputOutput]
137
// scale="1 1"       SFVec2f [inputOutput]
138
// translation="0 0" SFVec2f [inputOutput]
139
// />
140
0
void X3DImporter::readTextureTransform(XmlNode &node) {
141
0
    std::string use, def;
142
0
    aiVector2D center(0, 0);
143
0
    float rotation = 0;
144
0
    aiVector2D scale(1, 1);
145
0
    aiVector2D translation(0, 0);
146
0
    X3DNodeElementBase *ne(nullptr);
147
148
0
    MACRO_ATTRREAD_CHECKUSEDEF_RET(node, def, use);
149
0
    X3DXmlHelper::getVector2DAttribute(node, "center", center);
150
0
    XmlParser::getFloatAttribute(node, "rotation", rotation);
151
0
    X3DXmlHelper::getVector2DAttribute(node, "scale", scale);
152
0
    X3DXmlHelper::getVector2DAttribute(node, "translation", translation);
153
154
    // if "USE" defined then find already defined element.
155
0
    if (!use.empty()) {
156
0
        ne = MACRO_USE_CHECKANDAPPLY(node, def, use, ENET_TextureTransform, ne);
157
0
    } else {
158
        // create and if needed - define new geometry object.
159
0
        ne = new X3DNodeElementTextureTransform(mNodeElementCur);
160
0
        if (!def.empty()) ne->ID = def;
161
162
0
        ((X3DNodeElementTextureTransform *)ne)->Center = center;
163
0
        ((X3DNodeElementTextureTransform *)ne)->Rotation = rotation;
164
0
        ((X3DNodeElementTextureTransform *)ne)->Scale = scale;
165
0
        ((X3DNodeElementTextureTransform *)ne)->Translation = translation;
166
        // check for X3DMetadataObject childs.
167
0
        if (!isNodeEmpty(node))
168
0
            childrenReadMetadata(node, ne, "TextureTransform");
169
0
        else
170
0
            mNodeElementCur->Children.push_back(ne); // add made object as child to current element
171
172
0
        NodeElement_List.push_back(ne); // add element to node element list because its a new object in graph
173
0
    } // if(!use.empty()) else
174
0
}
175
176
} // namespace Assimp
177
178
#endif // !ASSIMP_BUILD_NO_X3D_IMPORTER