2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADAMax.
6
Portions of the code are:
7
Copyright (c) 2005-2007 Feeling Software Inc.
8
Copyright (c) 2005-2007 Sony Computer Entertainment America
10
Based on the 3dsMax COLLADASW Tools:
11
Copyright (c) 2005-2006 Autodesk Media Entertainment
13
Licensed under the MIT Open Source License,
14
for details please see LICENSE file or the website
15
http://www.opensource.org/licenses/mit-license.php
19
#include "COLLADAMaxStableHeaders.h"
20
#include "COLLADAMaxExtraDataHandler.h"
21
#include "generated14/COLLADASaxFWLColladaParserAutoGen14Attributes.h"
23
#include "GeneratedSaxParserUtils.h"
29
static const char* MAX_EXTRA_ATTRIBUTE_SKYLIGHT = "skylight";
30
static const char* MAX_EXTRA_ATTRIBUTE_CAST_SHADOWS = "cast_shadows";
31
static const char* MAX_EXTRA_ATTRIBUTE_COLOR_MAP_AMOUNT = "color_map_amount";
32
static const char* MAX_EXTRA_ATTRIBUTE_COLOR_MAP_ON = "color_map_on";
33
static const char* MAX_EXTRA_ATTRIBUTE_INTENSITY_ON = "intensity_on";
34
static const char* MAX_EXTRA_ATTRIBUTE_MODE = "mode";
35
static const char* MAX_EXTRA_ATTRIBUTE_MULTIPLIER = "multiplier";
36
static const char* MAX_EXTRA_ATTRIBUTE_RAY_BIAS = "ray_bias";
37
static const char* MAX_EXTRA_ATTRIBUTE_RAYS_PER_SAMPLE = "rays_per_sample";
40
static const char* MAX_EXTRA_ATTRIBUTE_BUMP = "bump";
41
static const char* MAX_EXTRA_ATTRIBUTE_TEXTURE = "texture";
44
//------------------------------
45
ExtraDataHandler::ExtraDataHandler(DocumentImporter* colladaImporter)
46
: ImporterBase(colladaImporter)
48
, mExtraTagType(EXTRA_TAG_TYPE_UNKNOWN)
49
, mCurrentElementUniqueId()
54
//------------------------------
55
ExtraDataHandler::~ExtraDataHandler()
61
//------------------------------
62
bool ExtraDataHandler::elementBegin( const COLLADASaxFWL::ParserChar* elementName, const GeneratedSaxParser::xmlChar** attributes )
65
switch ( mExtraTagType )
67
case EXTRA_TAG_TYPE_UNKNOWN:
69
if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_SKYLIGHT) == 0 )
71
mExtraTagType = EXTRA_TAG_TYPE_SKYLIGHT;
72
mExtraParameters.skyLightParameters.castShadows = false;
73
mExtraParameters.skyLightParameters.colorMapAmount = 100;
74
mExtraParameters.skyLightParameters.colorMapOn = true;
75
mExtraParameters.skyLightParameters.intensityOn = true;
76
mExtraParameters.skyLightParameters.mode = 1.0f;
77
mExtraParameters.skyLightParameters.multiplier = 1.0f;
78
mExtraParameters.skyLightParameters.rayBias = 0.004999995f;
79
mExtraParameters.skyLightParameters.raysPerSample = 20;
82
else if( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_BUMP) == 0 )
84
determineBumpType(attributes);
85
if( mExtraParameters.bumpParameters.bumpType != BUMP_TYPE_INVALID )
87
mExtraTagType = EXTRA_TAG_TYPE_BUMP;
88
mExtraParameters.bumpParameters.textureAttributes = 0;
93
case EXTRA_TAG_TYPE_BUMP:
94
if( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_TEXTURE) == 0 )
96
determineBumpTextureSamplerAndTexCoord(attributes);
102
//------------------------------
103
bool ExtraDataHandler::elementEnd( const COLLADASaxFWL::ParserChar* elementName )
106
switch ( mExtraTagType )
108
case EXTRA_TAG_TYPE_SKYLIGHT:
110
if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_SKYLIGHT) == 0 )
112
mExtraTagType = EXTRA_TAG_TYPE_UNKNOWN;
113
addUniqueIdSkyLightParametersPair(mCurrentElementUniqueId, mExtraParameters.skyLightParameters);
115
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_CAST_SHADOWS) == 0 )
117
bool val = GeneratedSaxParser::Utils::toBool(mTextBuffer.c_str(), failed);
120
mExtraParameters.skyLightParameters.castShadows = val;
123
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_COLOR_MAP_AMOUNT) == 0 )
125
float val = GeneratedSaxParser::Utils::toFloat(mTextBuffer.c_str(), failed);
128
mExtraParameters.skyLightParameters.colorMapAmount = val;
131
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_COLOR_MAP_ON) == 0 )
133
bool val = GeneratedSaxParser::Utils::toBool(mTextBuffer.c_str(), failed);
136
mExtraParameters.skyLightParameters.colorMapOn = val;
139
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_INTENSITY_ON) == 0 )
141
bool val = GeneratedSaxParser::Utils::toBool(mTextBuffer.c_str(), failed);
144
mExtraParameters.skyLightParameters.castShadows = val;
147
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_MODE) == 0 )
149
float val = GeneratedSaxParser::Utils::toFloat(mTextBuffer.c_str(), failed);
152
mExtraParameters.skyLightParameters.mode = val;
155
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_MULTIPLIER) == 0 )
157
float val = GeneratedSaxParser::Utils::toFloat(mTextBuffer.c_str(), failed);
160
mExtraParameters.skyLightParameters.multiplier = val;
163
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_RAY_BIAS) == 0 )
165
float val = GeneratedSaxParser::Utils::toFloat(mTextBuffer.c_str(), failed);
168
mExtraParameters.skyLightParameters.rayBias = val;
171
else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_RAYS_PER_SAMPLE) == 0 )
173
int val = GeneratedSaxParser::Utils::toSint32(mTextBuffer.c_str(), failed);
176
mExtraParameters.skyLightParameters.raysPerSample = val;
181
case EXTRA_TAG_TYPE_BUMP:
183
if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_BUMP) == 0 )
185
mExtraTagType = EXTRA_TAG_TYPE_UNKNOWN;
186
addUniqueIdEffectBumpMapParametersPair(mCurrentElementUniqueId, mExtraParameters.bumpParameters);
188
//else if ( strcmp(elementName, MAX_EXTRA_ATTRIBUTE_...) == 0 )
198
//------------------------------
199
bool ExtraDataHandler::textData( const COLLADASaxFWL::ParserChar* text, size_t textLength )
201
mTextBuffer.append(text, textLength);
205
//------------------------------
206
bool ExtraDataHandler::parseElement( const COLLADASaxFWL::ParserChar* profileName, const COLLADASaxFWL::StringHash& elementHash
207
, const COLLADAFW::UniqueId& uniqueId, COLLADAFW::Object* object )
209
mCurrentElementUniqueId = uniqueId;
211
if( object != 0 && object->getUniqueId() == mCurrentElementUniqueId )
212
mCurrentObject = object;
214
switch ( elementHash )
216
case COLLADASaxFWL14::HASH_ELEMENT_LIGHT:
217
case COLLADASaxFWL14::HASH_ELEMENT_TECHNIQUE:
218
if ( strcmp(profileName, "OpenCOLLADA3dsMax") == 0)
231
//------------------------------
232
void ExtraDataHandler::determineBumpType( const GeneratedSaxParser::xmlChar** attributes )
234
mExtraParameters.bumpParameters.bumpType = BUMP_TYPE_INVALID;
238
const GeneratedSaxParser::xmlChar* attributeKey = attributes[index++];
239
const GeneratedSaxParser::xmlChar* attributeValue = 0;
240
while( attributeKey != 0 )
242
attributeValue = attributes[index++];
243
if( strcmp(attributeKey, "bumptype") == 0 && attributeValue != 0 )
245
if( strcmp(attributeValue, "HEIGHTFIELD") == 0 )
246
mExtraParameters.bumpParameters.bumpType = BUMP_TYPE_HEIGHTFIELD;
250
attributeKey = attributes[index++];
254
//------------------------------
255
void ExtraDataHandler::determineBumpTextureSamplerAndTexCoord( const GeneratedSaxParser::xmlChar** attributes )
257
mExtraParameters.bumpParameters.textureAttributes = 0;
261
if( COLLADAFW::COLLADA_TYPE::EFFECT == mCurrentObject->getClassId() )
263
COLLADAFW::Effect* effect = (COLLADAFW::Effect*)mCurrentObject;
264
mExtraParameters.bumpParameters.textureAttributes = effect->createExtraTextureAttributes();
268
if( mExtraParameters.bumpParameters.textureAttributes == 0 )
273
const GeneratedSaxParser::xmlChar* attributeKey = attributes[index++];
274
const GeneratedSaxParser::xmlChar* attributeValue = 0;
275
while( attributeKey != 0 )
277
attributeValue = attributes[index++];
278
if( strcmp(attributeKey, "texture") == 0 && attributeValue != 0 )
280
if( mExtraParameters.bumpParameters.textureAttributes )
281
mExtraParameters.bumpParameters.textureAttributes->textureSampler = attributeValue;
283
else if( strcmp(attributeKey, "texcoord") == 0 && attributeValue != 0 )
285
if( mExtraParameters.bumpParameters.textureAttributes )
286
mExtraParameters.bumpParameters.textureAttributes->texCoord = attributeValue;
289
attributeKey = attributes[index++];