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