1/*
2Open Asset Import Library (assimp)
3----------------------------------------------------------------------
4
5Copyright (c) 2006-2017, assimp team
6
7All rights reserved.
8
9Redistribution and use of this software in source and binary forms,
10with or without modification, are permitted provided that the
11following 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
27THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
39----------------------------------------------------------------------
40*/
41
42/** @file FBXNoteAttribute.cpp
43 * @brief Assimp::FBX::NodeAttribute (and subclasses) implementation
44 */
45
46#ifndef ASSIMP_BUILD_NO_FBX_IMPORTER
47
48#include "FBXParser.h"
49#include "FBXDocument.h"
50#include "FBXImporter.h"
51#include "FBXDocumentUtil.h"
52
53namespace Assimp {
54namespace FBX {
55
56using namespace Util;
57
58// ------------------------------------------------------------------------------------------------
59Deformer::Deformer(uint64_t id, const Element& element, const Document& doc, const std::string& name)
60 : Object(id,element,name)
61{
62 const Scope& sc = GetRequiredScope(element);
63
64 const std::string& classname = ParseTokenAsString(GetRequiredToken(element,2));
65 props = GetPropertyTable(doc,"Deformer.Fbx" + classname,element,sc,true);
66}
67
68
69// ------------------------------------------------------------------------------------------------
70Deformer::~Deformer()
71{
72
73}
74
75
76// ------------------------------------------------------------------------------------------------
77Cluster::Cluster(uint64_t id, const Element& element, const Document& doc, const std::string& name)
78: Deformer(id,element,doc,name)
79, node()
80{
81 const Scope& sc = GetRequiredScope(element);
82
83 const Element* const Indexes = sc["Indexes"];
84 const Element* const Weights = sc["Weights"];
85
86 const Element& Transform = GetRequiredElement(sc,"Transform",&element);
87 const Element& TransformLink = GetRequiredElement(sc,"TransformLink",&element);
88
89 transform = ReadMatrix(Transform);
90 transformLink = ReadMatrix(TransformLink);
91
92 // it is actually possible that there be Deformer's with no weights
93 if (!!Indexes != !!Weights) {
94 DOMError("either Indexes or Weights are missing from Cluster",&element);
95 }
96
97 if(Indexes) {
98 ParseVectorDataArray(indices,*Indexes);
99 ParseVectorDataArray(weights,*Weights);
100 }
101
102 if(indices.size() != weights.size()) {
103 DOMError("sizes of index and weight array don't match up",&element);
104 }
105
106 // read assigned node
107 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Model");
108 for(const Connection* con : conns) {
109 const Model* const mod = ProcessSimpleConnection<Model>(*con, false, "Model -> Cluster", element);
110 if(mod) {
111 node = mod;
112 break;
113 }
114 }
115
116 if (!node) {
117 DOMError("failed to read target Node for Cluster",&element);
118 }
119}
120
121
122// ------------------------------------------------------------------------------------------------
123Cluster::~Cluster()
124{
125
126}
127
128
129// ------------------------------------------------------------------------------------------------
130Skin::Skin(uint64_t id, const Element& element, const Document& doc, const std::string& name)
131: Deformer(id,element,doc,name)
132, accuracy( 0.0f ) {
133 const Scope& sc = GetRequiredScope(element);
134
135 const Element* const Link_DeformAcuracy = sc["Link_DeformAcuracy"];
136 if(Link_DeformAcuracy) {
137 accuracy = ParseTokenAsFloat(GetRequiredToken(*Link_DeformAcuracy,0));
138 }
139
140 // resolve assigned clusters
141 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Deformer");
142
143 clusters.reserve(conns.size());
144 for(const Connection* con : conns) {
145
146 const Cluster* const cluster = ProcessSimpleConnection<Cluster>(*con, false, "Cluster -> Skin", element);
147 if(cluster) {
148 clusters.push_back(cluster);
149 continue;
150 }
151 }
152}
153
154
155// ------------------------------------------------------------------------------------------------
156Skin::~Skin()
157{
158
159}
160
161}
162}
163
164#endif
165
166