vrshoot

view libs/assimp/FBXModel.cpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the
18 following disclaimer in the documentation and/or other
19 materials provided with the distribution.
21 * Neither the name of the assimp team, nor the names of its
22 contributors may be used to endorse or promote products
23 derived from this software without specific prior
24 written permission of the assimp team.
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ----------------------------------------------------------------------
39 */
41 /** @file FBXModel.cpp
42 * @brief Assimp::FBX::Model implementation
43 */
44 #include "AssimpPCH.h"
46 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
48 #include "FBXParser.h"
49 #include "FBXDocument.h"
50 #include "FBXImporter.h"
51 #include "FBXImportSettings.h"
52 #include "FBXDocumentUtil.h"
53 #include "FBXProperties.h"
55 namespace Assimp {
56 namespace FBX {
58 using namespace Util;
60 // ------------------------------------------------------------------------------------------------
61 Model::Model(uint64_t id, const Element& element, const Document& doc, const std::string& name)
62 : Object(id,element,name)
63 , shading("Y")
64 {
65 const Scope& sc = GetRequiredScope(element);
66 const Element* const Shading = sc["Shading"];
67 const Element* const Culling = sc["Culling"];
69 if(Shading) {
70 shading = GetRequiredToken(*Shading,0).StringContents();
71 }
73 if (Culling) {
74 culling = ParseTokenAsString(GetRequiredToken(*Culling,0));
75 }
77 props = GetPropertyTable(doc,"Model.FbxNode",element,sc);
78 ResolveLinks(element,doc);
79 }
82 // ------------------------------------------------------------------------------------------------
83 Model::~Model()
84 {
86 }
89 // ------------------------------------------------------------------------------------------------
90 void Model::ResolveLinks(const Element& element, const Document& doc)
91 {
92 const char* const arr[] = {"Geometry","Material","NodeAttribute"};
94 // resolve material
95 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),arr, 3);
97 materials.reserve(conns.size());
98 geometry.reserve(conns.size());
99 attributes.reserve(conns.size());
100 BOOST_FOREACH(const Connection* con, conns) {
102 // material and geometry links should be Object-Object connections
103 if (con->PropertyName().length()) {
104 continue;
105 }
107 const Object* const ob = con->SourceObject();
108 if(!ob) {
109 DOMWarning("failed to read source object for incoming Model link, ignoring",&element);
110 continue;
111 }
113 const Material* const mat = dynamic_cast<const Material*>(ob);
114 if(mat) {
115 materials.push_back(mat);
116 continue;
117 }
119 const Geometry* const geo = dynamic_cast<const Geometry*>(ob);
120 if(geo) {
121 geometry.push_back(geo);
122 continue;
123 }
125 const NodeAttribute* const att = dynamic_cast<const NodeAttribute*>(ob);
126 if(att) {
127 attributes.push_back(att);
128 continue;
129 }
131 DOMWarning("source object for model link is neither Material, NodeAttribute nor Geometry, ignoring",&element);
132 continue;
133 }
134 }
137 // ------------------------------------------------------------------------------------------------
138 bool Model::IsNull() const
139 {
140 const std::vector<const NodeAttribute*>& attrs = GetAttributes();
141 BOOST_FOREACH(const NodeAttribute* att, attrs) {
143 const Null* null_tag = dynamic_cast<const Null*>(att);
144 if(null_tag) {
145 return true;
146 }
147 }
149 return false;
150 }
153 } //!FBX
154 } //!Assimp
156 #endif