1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2021, assimp team
6 
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
12 following 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 
43 /** @file  FBXModel.cpp
44  *  @brief Assimp::FBX::Model implementation
45  */
46 
47 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
48 
49 #include "FBXDocument.h"
50 #include "FBXDocumentUtil.h"
51 #include "FBXImporter.h"
52 #include "FBXMeshGeometry.h"
53 #include "FBXParser.h"
54 
55 namespace Assimp {
56 namespace FBX {
57 
58 using namespace Util;
59 
60 // ------------------------------------------------------------------------------------------------
Model(uint64_t id,const Element & element,const Document & doc,const std::string & name)61 Model::Model(uint64_t id, const Element &element, const Document &doc, const std::string &name) :
62         Object(id, element, name), shading("Y") {
63     const Scope &sc = GetRequiredScope(element);
64     const Element *const Shading = sc["Shading"];
65     const Element *const Culling = sc["Culling"];
66 
67     if (Shading) {
68         shading = GetRequiredToken(*Shading, 0).StringContents();
69     }
70 
71     if (Culling) {
72         culling = ParseTokenAsString(GetRequiredToken(*Culling, 0));
73     }
74 
75     props = GetPropertyTable(doc, "Model.FbxNode", element, sc);
76     ResolveLinks(element, doc);
77 }
78 
79 // ------------------------------------------------------------------------------------------------
~Model()80 Model::~Model() {
81 }
82 
83 // ------------------------------------------------------------------------------------------------
ResolveLinks(const Element &,const Document & doc)84 void Model::ResolveLinks(const Element&, const Document &doc) {
85     const char *const arr[] = { "Geometry", "Material", "NodeAttribute" };
86 
87     // resolve material
88     const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), arr, 3);
89 
90     materials.reserve(conns.size());
91     geometry.reserve(conns.size());
92     attributes.reserve(conns.size());
93     for (const Connection *con : conns) {
94 
95         // material and geometry links should be Object-Object connections
96         if (con->PropertyName().length()) {
97             continue;
98         }
99 
100         const Object *const ob = con->SourceObject();
101         if (!ob) {
102             DOMWarning("failed to read source object for incoming Model link, ignoring", &element);
103             continue;
104         }
105 
106         const Material *const mat = dynamic_cast<const Material *>(ob);
107         if (mat) {
108             materials.push_back(mat);
109             continue;
110         }
111 
112         const Geometry *const geo = dynamic_cast<const Geometry *>(ob);
113         if (geo) {
114             geometry.push_back(geo);
115             continue;
116         }
117 
118         const NodeAttribute *const att = dynamic_cast<const NodeAttribute *>(ob);
119         if (att) {
120             attributes.push_back(att);
121             continue;
122         }
123 
124         DOMWarning("source object for model link is neither Material, NodeAttribute nor Geometry, ignoring", &element);
125         continue;
126     }
127 }
128 
129 // ------------------------------------------------------------------------------------------------
IsNull() const130 bool Model::IsNull() const {
131     const std::vector<const NodeAttribute *> &attrs = GetAttributes();
132     for (const NodeAttribute *att : attrs) {
133 
134         const Null *null_tag = dynamic_cast<const Null *>(att);
135         if (null_tag) {
136             return true;
137         }
138     }
139 
140     return false;
141 }
142 
143 } // namespace FBX
144 } // namespace Assimp
145 
146 #endif
147