vrshoot

view libs/assimp/FBXMaterial.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 FBXMaterial.cpp
42 * @brief Assimp::FBX::Material and Assimp::FBX::Texture 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 Material::Material(uint64_t id, const Element& element, const Document& doc, const std::string& name)
62 : Object(id,element,name)
63 {
64 const Scope& sc = GetRequiredScope(element);
66 const Element* const ShadingModel = sc["ShadingModel"];
67 const Element* const MultiLayer = sc["MultiLayer"];
69 if(MultiLayer) {
70 multilayer = !!ParseTokenAsInt(GetRequiredToken(*MultiLayer,0));
71 }
73 if(ShadingModel) {
74 shading = ParseTokenAsString(GetRequiredToken(*ShadingModel,0));
75 }
76 else {
77 DOMWarning("shading mode not specified, assuming phong",&element);
78 shading = "phong";
79 }
81 std::string templateName;
83 const char* const sh = shading.c_str();
84 if(!strcmp(sh,"phong")) {
85 templateName = "Material.FbxSurfacePhong";
86 }
87 else if(!strcmp(sh,"lambert")) {
88 templateName = "Material.FbxSurfaceLambert";
89 }
90 else {
91 DOMWarning("shading mode not recognized: " + shading,&element);
92 }
94 props = GetPropertyTable(doc,templateName,element,sc);
96 // resolve texture links
97 const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
98 BOOST_FOREACH(const Connection* con, conns) {
100 // texture link to properties, not objects
101 if (!con->PropertyName().length()) {
102 continue;
103 }
105 const Object* const ob = con->SourceObject();
106 if(!ob) {
107 DOMWarning("failed to read source object for texture link, ignoring",&element);
108 continue;
109 }
111 const Texture* const tex = dynamic_cast<const Texture*>(ob);
112 if(!tex) {
113 DOMWarning("source object for texture link is not a texture, ignoring",&element);
114 continue;
115 }
117 const std::string& prop = con->PropertyName();
118 if (textures.find(prop) != textures.end()) {
119 DOMWarning("duplicate texture link: " + prop,&element);
120 }
122 textures[prop] = tex;
123 }
124 }
127 // ------------------------------------------------------------------------------------------------
128 Material::~Material()
129 {
130 }
133 // ------------------------------------------------------------------------------------------------
134 Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name)
135 : Object(id,element,name)
136 , uvScaling(1.0f,1.0f)
137 {
138 const Scope& sc = GetRequiredScope(element);
140 const Element* const Type = sc["Type"];
141 const Element* const FileName = sc["FileName"];
142 const Element* const RelativeFilename = sc["RelativeFilename"];
143 const Element* const ModelUVTranslation = sc["ModelUVTranslation"];
144 const Element* const ModelUVScaling = sc["ModelUVScaling"];
145 const Element* const Texture_Alpha_Source = sc["Texture_Alpha_Source"];
146 const Element* const Cropping = sc["Cropping"];
148 if(Type) {
149 type = ParseTokenAsString(GetRequiredToken(*Type,0));
150 }
152 if(FileName) {
153 fileName = ParseTokenAsString(GetRequiredToken(*FileName,0));
154 }
156 if(RelativeFilename) {
157 relativeFileName = ParseTokenAsString(GetRequiredToken(*RelativeFilename,0));
158 }
160 if(ModelUVTranslation) {
161 uvTrans = aiVector2D(ParseTokenAsFloat(GetRequiredToken(*ModelUVTranslation,0)),
162 ParseTokenAsFloat(GetRequiredToken(*ModelUVTranslation,1))
163 );
164 }
166 if(ModelUVScaling) {
167 uvScaling = aiVector2D(ParseTokenAsFloat(GetRequiredToken(*ModelUVScaling,0)),
168 ParseTokenAsFloat(GetRequiredToken(*ModelUVScaling,1))
169 );
170 }
172 if(Cropping) {
173 crop[0] = ParseTokenAsInt(GetRequiredToken(*Cropping,0));
174 crop[1] = ParseTokenAsInt(GetRequiredToken(*Cropping,1));
175 crop[2] = ParseTokenAsInt(GetRequiredToken(*Cropping,2));
176 crop[3] = ParseTokenAsInt(GetRequiredToken(*Cropping,3));
177 }
178 else {
179 // vc8 doesn't support the crop() syntax in initialization lists
180 // (and vc9 WARNS about the new (i.e. compliant) behaviour).
181 crop[0] = crop[1] = crop[2] = crop[3] = 0;
182 }
184 if(Texture_Alpha_Source) {
185 alphaSource = ParseTokenAsString(GetRequiredToken(*Texture_Alpha_Source,0));
186 }
188 props = GetPropertyTable(doc,"Texture.FbxFileTexture",element,sc);
189 }
192 Texture::~Texture()
193 {
195 }
197 } //!FBX
198 } //!Assimp
200 #endif