vrshoot

annotate libs/assimp/FBXAnimation.cpp @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40
nuclear@0 41 /** @file FBXAnimation.cpp
nuclear@0 42 * @brief Assimp::FBX::AnimationCurve, Assimp::FBX::AnimationCurveNode,
nuclear@0 43 * Assimp::FBX::AnimationLayer, Assimp::FBX::AnimationStack
nuclear@0 44 */
nuclear@0 45 #include "AssimpPCH.h"
nuclear@0 46
nuclear@0 47 #ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
nuclear@0 48
nuclear@0 49 #include "FBXParser.h"
nuclear@0 50 #include "FBXDocument.h"
nuclear@0 51 #include "FBXImporter.h"
nuclear@0 52 #include "FBXImportSettings.h"
nuclear@0 53 #include "FBXDocumentUtil.h"
nuclear@0 54 #include "FBXProperties.h"
nuclear@0 55
nuclear@0 56 namespace Assimp {
nuclear@0 57 namespace FBX {
nuclear@0 58
nuclear@0 59 using namespace Util;
nuclear@0 60
nuclear@0 61 // ------------------------------------------------------------------------------------------------
nuclear@0 62 AnimationCurve::AnimationCurve(uint64_t id, const Element& element, const std::string& name, const Document& doc)
nuclear@0 63 : Object(id, element, name)
nuclear@0 64 {
nuclear@0 65 const Scope& sc = GetRequiredScope(element);
nuclear@0 66 const Element& KeyTime = GetRequiredElement(sc,"KeyTime");
nuclear@0 67 const Element& KeyValueFloat = GetRequiredElement(sc,"KeyValueFloat");
nuclear@0 68
nuclear@0 69 ParseVectorDataArray(keys, KeyTime);
nuclear@0 70 ParseVectorDataArray(values, KeyValueFloat);
nuclear@0 71
nuclear@0 72 if(keys.size() != values.size()) {
nuclear@0 73 DOMError("the number of key times does not match the number of keyframe values",&KeyTime);
nuclear@0 74 }
nuclear@0 75
nuclear@0 76 // check if the key times are well-ordered
nuclear@0 77 if(!std::equal(keys.begin(), keys.end() - 1, keys.begin() + 1, std::less<KeyTimeList::value_type>())) {
nuclear@0 78 DOMError("the keyframes are not in ascending order",&KeyTime);
nuclear@0 79 }
nuclear@0 80
nuclear@0 81 const Element* KeyAttrDataFloat = sc["KeyAttrDataFloat"];
nuclear@0 82 if(KeyAttrDataFloat) {
nuclear@0 83 ParseVectorDataArray(attributes, *KeyAttrDataFloat);
nuclear@0 84 }
nuclear@0 85
nuclear@0 86 const Element* KeyAttrFlags = sc["KeyAttrFlags"];
nuclear@0 87 if(KeyAttrFlags) {
nuclear@0 88 ParseVectorDataArray(flags, *KeyAttrFlags);
nuclear@0 89 }
nuclear@0 90 }
nuclear@0 91
nuclear@0 92
nuclear@0 93 // ------------------------------------------------------------------------------------------------
nuclear@0 94 AnimationCurve::~AnimationCurve()
nuclear@0 95 {
nuclear@0 96
nuclear@0 97 }
nuclear@0 98
nuclear@0 99
nuclear@0 100 // ------------------------------------------------------------------------------------------------
nuclear@0 101 AnimationCurveNode::AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc,
nuclear@0 102 const char* const * target_prop_whitelist /*= NULL*/, size_t whitelist_size /*= 0*/)
nuclear@0 103 : Object(id, element, name)
nuclear@0 104 , target()
nuclear@0 105 , doc(doc)
nuclear@0 106 {
nuclear@0 107 const Scope& sc = GetRequiredScope(element);
nuclear@0 108
nuclear@0 109 // find target node
nuclear@0 110 const char* whitelist[] = {"Model","NodeAttribute"};
nuclear@0 111 const std::vector<const Connection*>& conns = doc.GetConnectionsBySourceSequenced(ID(),whitelist,2);
nuclear@0 112
nuclear@0 113 BOOST_FOREACH(const Connection* con, conns) {
nuclear@0 114
nuclear@0 115 // link should go for a property
nuclear@0 116 if (!con->PropertyName().length()) {
nuclear@0 117 continue;
nuclear@0 118 }
nuclear@0 119
nuclear@0 120 if(target_prop_whitelist) {
nuclear@0 121 const char* const s = con->PropertyName().c_str();
nuclear@0 122 bool ok = false;
nuclear@0 123 for (size_t i = 0; i < whitelist_size; ++i) {
nuclear@0 124 if (!strcmp(s, target_prop_whitelist[i])) {
nuclear@0 125 ok = true;
nuclear@0 126 break;
nuclear@0 127 }
nuclear@0 128 }
nuclear@0 129
nuclear@0 130 if (!ok) {
nuclear@0 131 throw std::range_error("AnimationCurveNode target property is not in whitelist");
nuclear@0 132 }
nuclear@0 133 }
nuclear@0 134
nuclear@0 135 const Object* const ob = con->DestinationObject();
nuclear@0 136 if(!ob) {
nuclear@0 137 DOMWarning("failed to read destination object for AnimationCurveNode->Model link, ignoring",&element);
nuclear@0 138 continue;
nuclear@0 139 }
nuclear@0 140
nuclear@0 141 // XXX support constraints as DOM class
nuclear@0 142 //ai_assert(dynamic_cast<const Model*>(ob) || dynamic_cast<const NodeAttribute*>(ob));
nuclear@0 143 target = ob;
nuclear@0 144 if(!target) {
nuclear@0 145 continue;
nuclear@0 146 }
nuclear@0 147
nuclear@0 148 prop = con->PropertyName();
nuclear@0 149 break;
nuclear@0 150 }
nuclear@0 151
nuclear@0 152 if(!target) {
nuclear@0 153 DOMWarning("failed to resolve target Model/NodeAttribute/Constraint for AnimationCurveNode",&element);
nuclear@0 154 }
nuclear@0 155
nuclear@0 156 props = GetPropertyTable(doc,"AnimationCurveNode.FbxAnimCurveNode",element,sc,false);
nuclear@0 157 }
nuclear@0 158
nuclear@0 159
nuclear@0 160 // ------------------------------------------------------------------------------------------------
nuclear@0 161 AnimationCurveNode::~AnimationCurveNode()
nuclear@0 162 {
nuclear@0 163
nuclear@0 164 }
nuclear@0 165
nuclear@0 166
nuclear@0 167 // ------------------------------------------------------------------------------------------------
nuclear@0 168 const AnimationCurveMap& AnimationCurveNode::Curves() const
nuclear@0 169 {
nuclear@0 170 if(curves.empty()) {
nuclear@0 171 // resolve attached animation curves
nuclear@0 172 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"AnimationCurve");
nuclear@0 173
nuclear@0 174 BOOST_FOREACH(const Connection* con, conns) {
nuclear@0 175
nuclear@0 176 // link should go for a property
nuclear@0 177 if (!con->PropertyName().length()) {
nuclear@0 178 continue;
nuclear@0 179 }
nuclear@0 180
nuclear@0 181 const Object* const ob = con->SourceObject();
nuclear@0 182 if(!ob) {
nuclear@0 183 DOMWarning("failed to read source object for AnimationCurve->AnimationCurveNode link, ignoring",&element);
nuclear@0 184 continue;
nuclear@0 185 }
nuclear@0 186
nuclear@0 187 const AnimationCurve* const anim = dynamic_cast<const AnimationCurve*>(ob);
nuclear@0 188 if(!anim) {
nuclear@0 189 DOMWarning("source object for ->AnimationCurveNode link is not an AnimationCurve",&element);
nuclear@0 190 continue;
nuclear@0 191 }
nuclear@0 192
nuclear@0 193 curves[con->PropertyName()] = anim;
nuclear@0 194 }
nuclear@0 195 }
nuclear@0 196
nuclear@0 197 return curves;
nuclear@0 198 }
nuclear@0 199
nuclear@0 200
nuclear@0 201 // ------------------------------------------------------------------------------------------------
nuclear@0 202 AnimationLayer::AnimationLayer(uint64_t id, const Element& element, const std::string& name, const Document& doc)
nuclear@0 203 : Object(id, element, name)
nuclear@0 204 , doc(doc)
nuclear@0 205 {
nuclear@0 206 const Scope& sc = GetRequiredScope(element);
nuclear@0 207
nuclear@0 208 // note: the props table here bears little importance and is usually absent
nuclear@0 209 props = GetPropertyTable(doc,"AnimationLayer.FbxAnimLayer",element,sc, true);
nuclear@0 210 }
nuclear@0 211
nuclear@0 212
nuclear@0 213 // ------------------------------------------------------------------------------------------------
nuclear@0 214 AnimationLayer::~AnimationLayer()
nuclear@0 215 {
nuclear@0 216
nuclear@0 217 }
nuclear@0 218
nuclear@0 219
nuclear@0 220 // ------------------------------------------------------------------------------------------------
nuclear@0 221 AnimationCurveNodeList AnimationLayer::Nodes(const char* const * target_prop_whitelist /*= NULL*/,
nuclear@0 222 size_t whitelist_size /*= 0*/) const
nuclear@0 223 {
nuclear@0 224 AnimationCurveNodeList nodes;
nuclear@0 225
nuclear@0 226 // resolve attached animation nodes
nuclear@0 227 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"AnimationCurveNode");
nuclear@0 228 nodes.reserve(conns.size());
nuclear@0 229
nuclear@0 230 BOOST_FOREACH(const Connection* con, conns) {
nuclear@0 231
nuclear@0 232 // link should not go to a property
nuclear@0 233 if (con->PropertyName().length()) {
nuclear@0 234 continue;
nuclear@0 235 }
nuclear@0 236
nuclear@0 237 const Object* const ob = con->SourceObject();
nuclear@0 238 if(!ob) {
nuclear@0 239 DOMWarning("failed to read source object for AnimationCurveNode->AnimationLayer link, ignoring",&element);
nuclear@0 240 continue;
nuclear@0 241 }
nuclear@0 242
nuclear@0 243 const AnimationCurveNode* const anim = dynamic_cast<const AnimationCurveNode*>(ob);
nuclear@0 244 if(!anim) {
nuclear@0 245 DOMWarning("source object for ->AnimationLayer link is not an AnimationCurveNode",&element);
nuclear@0 246 continue;
nuclear@0 247 }
nuclear@0 248
nuclear@0 249 if(target_prop_whitelist) {
nuclear@0 250 const char* s = anim->TargetProperty().c_str();
nuclear@0 251 bool ok = false;
nuclear@0 252 for (size_t i = 0; i < whitelist_size; ++i) {
nuclear@0 253 if (!strcmp(s, target_prop_whitelist[i])) {
nuclear@0 254 ok = true;
nuclear@0 255 break;
nuclear@0 256 }
nuclear@0 257 }
nuclear@0 258 if(!ok) {
nuclear@0 259 continue;
nuclear@0 260 }
nuclear@0 261 }
nuclear@0 262 nodes.push_back(anim);
nuclear@0 263 }
nuclear@0 264
nuclear@0 265 return nodes; // pray for NRVO
nuclear@0 266 }
nuclear@0 267
nuclear@0 268 // ------------------------------------------------------------------------------------------------
nuclear@0 269 AnimationStack::AnimationStack(uint64_t id, const Element& element, const std::string& name, const Document& doc)
nuclear@0 270 : Object(id, element, name)
nuclear@0 271 {
nuclear@0 272 const Scope& sc = GetRequiredScope(element);
nuclear@0 273
nuclear@0 274 // note: we don't currently use any of these properties so we shouldn't bother if it is missing
nuclear@0 275 props = GetPropertyTable(doc,"AnimationStack.FbxAnimStack",element,sc, true);
nuclear@0 276
nuclear@0 277 // resolve attached animation layers
nuclear@0 278 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"AnimationLayer");
nuclear@0 279 layers.reserve(conns.size());
nuclear@0 280
nuclear@0 281 BOOST_FOREACH(const Connection* con, conns) {
nuclear@0 282
nuclear@0 283 // link should not go to a property
nuclear@0 284 if (con->PropertyName().length()) {
nuclear@0 285 continue;
nuclear@0 286 }
nuclear@0 287
nuclear@0 288 const Object* const ob = con->SourceObject();
nuclear@0 289 if(!ob) {
nuclear@0 290 DOMWarning("failed to read source object for AnimationLayer->AnimationStack link, ignoring",&element);
nuclear@0 291 continue;
nuclear@0 292 }
nuclear@0 293
nuclear@0 294 const AnimationLayer* const anim = dynamic_cast<const AnimationLayer*>(ob);
nuclear@0 295 if(!anim) {
nuclear@0 296 DOMWarning("source object for ->AnimationStack link is not an AnimationLayer",&element);
nuclear@0 297 continue;
nuclear@0 298 }
nuclear@0 299 layers.push_back(anim);
nuclear@0 300 }
nuclear@0 301 }
nuclear@0 302
nuclear@0 303
nuclear@0 304 // ------------------------------------------------------------------------------------------------
nuclear@0 305 AnimationStack::~AnimationStack()
nuclear@0 306 {
nuclear@0 307
nuclear@0 308 }
nuclear@0 309
nuclear@0 310 } //!FBX
nuclear@0 311 } //!Assimp
nuclear@0 312
nuclear@0 313 #endif