2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of DAE2MA.
6
Portions of the code are:
7
Copyright (c) 2005-2007 Feeling Software Inc.
8
Copyright (c) 2005-2007 Sony Computer Entertainment America
9
Copyright (c) 2004-2005 Alias Systems Corp.
11
Licensed under the MIT Open Source License,
12
for details please see LICENSE file or the website
13
http://www.opensource.org/licenses/mit-license.php
16
#include "DAE2MAStableHeaders.h"
17
#include "DAE2MADocumentImporter.h"
18
#include "DAE2MAImportOptions.h"
19
#include "DAE2MAMaterialImporter.h"
20
#include "DAE2MAEffectImporter.h"
21
#include "DAE2MAGeometryImporter.h"
22
#include "DAE2MACameraImporter.h"
23
#include "DAE2MALightImporter.h"
24
#include "DAE2MAImageImporter.h"
25
#include "DAE2MAAnimationImporter.h"
26
#include "DAE2MAControllerImporter.h"
27
#include "DAE2MAVisualSceneImporter.h"
28
#include "DAE2MANodeImporter.h"
30
#include "COLLADAFWRoot.h"
31
#include "COLLADAFWAnimationList.h"
32
#include "COLLADAFWScene.h"
37
#include "MayaDMScript.h"
39
#include "COLLADASaxFWLLoader.h"
45
/** This names are reserved. Maya nodes can't have this names! */
46
const size_t DocumentImporter::NUM_RESERVED_NAMES = 43;
47
const String DocumentImporter::RESERVED_NAMES[] =
52
"initialShadingGroup",
53
"initialMaterialInfo",
57
"defaultTextureList1",
68
"hardwareRenderGlobals",
69
"defaultHardwareRenderGlobals",
94
/** The Buffersize for the document to write. */
95
const int DocumentImporter::BUFFERSIZE = 2097152;
98
//---------------------------------
99
DocumentImporter::DocumentImporter (
100
const String& fileName,
101
const String& mayaAsciiFileName,
102
const char* mayaVersion /*= MAYA_VERSION_2009*/ )
103
: mColladaFileName ( fileName )
104
, mMayaAsciiFileURI ( mayaAsciiFileName )
105
, mMayaVersion ( mayaVersion )
106
// , mSaxLoader ( &mSaxParserErrorHandler )
107
, mParseStep ( NO_PARSING )
108
, mVisualScenesList (0)
109
, mLibraryNodesList (0)
112
, mAnimationListsList (0)
115
, mVisualSceneImporter (0)
116
, mGeometryImporter (0)
117
, mMaterialImporter (0)
118
, mEffectImporter (0)
119
, mCameraImporter (0)
122
, mAnimationImporter (0)
123
, mControllerImporter (0)
124
, mNumDocumentParses (0)
125
, mUpAxisType ( COLLADAFW::FileInfo::Y_UP )
126
, mLinearUnitConvertFactor ( 1.0 )
127
, mLinearUnitMayaBindShapeBugConvertFactor ( 1.0 )
128
, mDigitTolerance (FLOAT_TOLERANCE)
130
, mInstanceVisualScene (0)
132
// Maya already use some names for the default maya objects.
133
for ( size_t i=0; i<NUM_RESERVED_NAMES; ++i )
135
mGlobalNodeIdList.addId ( RESERVED_NAMES[i] );
136
mDependNodeIdList.addId ( RESERVED_NAMES[i] );
140
//---------------------------------
141
DocumentImporter::~DocumentImporter()
143
// Close the maya ascii file
144
closeMayaAsciiFile ();
146
// Don't delete the objects earlier, other parts use the elements!
147
delete mInstanceVisualScene;
149
// A copy of the framework's library visual scenes elements.
150
for ( size_t i=0; i< mVisualScenesList.size (); ++i )
152
COLLADAFW::VisualScene* visualScene = mVisualScenesList [i];
155
mVisualScenesList.clear ();
157
// A copy of the framework's library nodes elements.
158
for ( size_t i=0; i< mLibraryNodesList.size (); ++i )
160
COLLADAFW::LibraryNodes* libraryNodes = mLibraryNodesList [i];
163
mLibraryNodesList.clear ();
165
// A copy of the framework's library materials elements.
166
for ( size_t i=0; i< mMaterialsList.size (); ++i )
168
COLLADAFW::Material* material = mMaterialsList [i];
171
mMaterialsList.clear ();
173
// A copy of the framework's library effect elements.
174
for ( size_t i=0; i< mEffectsList.size (); ++i )
176
COLLADAFW::Effect* effect = mEffectsList [i];
179
mEffectsList.clear ();
181
// A copy of the framework's library animationList elements.
182
for ( size_t i=0; i< mAnimationListsList.size (); ++i )
184
COLLADAFW::AnimationList* animationList = mAnimationListsList [i];
185
delete animationList;
187
mAnimationListsList.clear ();
189
// Delete the library elements.
192
// Release the buffer memory
197
//---------------------------------
198
void DocumentImporter::createLibraries()
200
// First release the existing libraries.
203
// Create the libraries.
204
mNodeImporter = new NodeImporter ( this );
205
mVisualSceneImporter = new VisualSceneImporter ( this );
206
mGeometryImporter = new GeometryImporter ( this );
207
mMaterialImporter = new MaterialImporter ( this );
208
mEffectImporter = new EffectImporter ( this );
209
mCameraImporter = new CameraImporter ( this );
210
mLightImporter = new LightImporter ( this );
211
mImageImporter = new ImageImporter (this);
212
mAnimationImporter = new AnimationImporter (this);
213
mControllerImporter = new ControllerImporter (this);
215
// // TODO Initialize the reference manager
216
// ReferenceManager::getInstance()->initialize ();
219
//---------------------------------
220
void DocumentImporter::releaseLibraries()
222
delete mNodeImporter;
223
delete mVisualSceneImporter;
224
delete mGeometryImporter;
225
delete mMaterialImporter;
226
delete mEffectImporter;
227
delete mCameraImporter;
228
delete mLightImporter;
229
delete mImageImporter;
230
delete mAnimationImporter;
231
delete mControllerImporter;
234
//-----------------------------
235
void DocumentImporter::importCurrentScene()
237
// Create the import/export library helpers.
240
// Load the collada document into the collada framework.
241
mParseStep = FIRST_PARSING;
245
COLLADASaxFWL::Loader::SCENE_FLAG |
246
COLLADASaxFWL::Loader::ASSET_FLAG |
247
COLLADASaxFWL::Loader::VISUAL_SCENES_FLAG |
248
COLLADASaxFWL::Loader::LIBRARY_NODES_FLAG |
249
COLLADASaxFWL::Loader::MATERIAL_FLAG |
250
COLLADASaxFWL::Loader::CONTROLLER_FLAG;
251
//mSaxLoader.setObjectFlags ( objectFlags );
253
readColladaDocument();
255
// Close the maya file.
256
closeMayaAsciiFile ();
259
//-----------------------------
260
bool DocumentImporter::createMayaAsciiFile ()
262
String mayaAsciiFileName = mMayaAsciiFileURI.getURIString ();
264
// Check if the file already exist.
265
if ( std::ifstream ( mayaAsciiFileName.c_str () ) )
267
// TODO Open a dialog and ask the user to save the file under an other name.
268
//MGlobal::displayError ( "File already exists!\n" );
269
//MGlobal::doErrorLogEntry ( "File already exists!\n" );
270
std::cerr << "Overwrite existing file!" << std::endl;
273
// Get the current locale value
274
mLocale = setlocale ( LC_NUMERIC, 0 );
275
setlocale ( LC_NUMERIC, "C" );
277
mFile = fopen ( mayaAsciiFileName.c_str (), "w" );
280
std::cerr << "Can't open output file!\n" << std::endl;
285
mBuffer = new char[BUFFERSIZE];
286
bool failed = ( setvbuf ( mFile , mBuffer, _IOFBF, BUFFERSIZE ) != 0 );
291
std::cerr << "Could not set buffer for writing." << std::endl;
298
//-----------------------------
299
void DocumentImporter::closeMayaAsciiFile ()
306
setlocale ( LC_NUMERIC, mLocale.c_str() );
310
//---------------------------------
311
const String& DocumentImporter::getColladaFilename() const
313
return mColladaFileName;
316
//-----------------------------
317
void DocumentImporter::initialize ()
319
// Create the maya file.
320
bool retValue = createMayaAsciiFile ();
322
std::cerr << "Error: could not create output file! " << std::endl;
324
// Initialise the maya default objects.
327
mLightImporter->initialiseDefaultLightObjects ();
331
//-----------------------------
332
void DocumentImporter::cancel ( const String& errorMessage )
334
std::cerr << "Error: " << errorMessage << std::endl;
337
//-----------------------------
338
void DocumentImporter::finish ()
340
// First parse is done.
341
if ( mParseStep <= COPY_ELEMENTS )
343
// The order of the steps here is very important!
344
mParseStep = ELEMENTS_COPIED;
346
// Create the scene graph and map the unique node ids to the framwork node objects.
349
// Import referenced visual scene
350
importVisualScene ();
352
// After the import of the visual scene, we can determine the scale animations.
353
detectScaleAnimations ();
355
// Import morph controllers
356
importMorphControllers ();
358
// First import materials, then effects and after this images.
359
// The order of the import is relevant, about we have to know which effects are used
360
// by this material. After the import of the effects, we know which images we need.
361
// We have to import this before we write the animations in the second parsing, about
362
// to know the animated effects.
367
// Get the minimum and the maximum time values of the animations to get the start
368
// time and the end time of the animation. This times we have to set as the
369
// "playbackOptions" in the "sceneConfigurationScriptNode".
370
importPlaybackOptions ();
372
// Start the next parsing.
373
mParseStep = SECOND_PARSING;
375
// TODO Not active in the current implementation!
377
COLLADASaxFWL::Loader::GEOMETRY_FLAG |
378
COLLADASaxFWL::Loader::EFFECT_FLAG |
379
COLLADASaxFWL::Loader::CAMERA_FLAG |
380
COLLADASaxFWL::Loader::IMAGE_FLAG |
381
COLLADASaxFWL::Loader::LIGHT_FLAG |
382
COLLADASaxFWL::Loader::ANIMATION_FLAG |
383
COLLADASaxFWL::Loader::ANIMATION_LIST_FLAG |
384
COLLADASaxFWL::Loader::SKIN_CONTROLLER_DATA_FLAG;
385
//mSaxLoader.setObjectFlags ( objectFlags );
387
readColladaDocument ();
390
// If the last read is ready, we can write the connections and close the file.
391
--mNumDocumentParses;
392
if ( mNumDocumentParses == 0 )
394
mParseStep = GEOMETRY_IMPORTED;
396
// After we have imported the geometries, we can create the necessary uv-choosers.
397
// We can't create them earlier, about we need to know, if the geometry has more than
398
// one uv-set (texture coordinates).
401
// After the complete read of the collada document,
402
// the connections can be written into the maya file.
403
mParseStep = MAKE_CONNECTIONS;
407
closeMayaAsciiFile ();
409
if( mGeometryImporter && mGeometryImporter->getCount2013Workarounds() > 0 )
410
std::cerr << "Warning: Maya 2013 workaround applied! (duplication of single face geometry!)" << std::endl;
415
//-----------------------------
416
void DocumentImporter::createUvChoosers ()
418
// After we have imported the geometries, we can create the necessary uv-choosers.
419
if ( mParseStep < GEOMETRY_IMPORTED )
421
std::cerr << "Geometries not imported! Can't create the uv-choosers!" << std::endl;
425
// The file must already exist.
428
std::cerr << "DocumentImporter::createUvChoosers(): Cant't import, no maya file exist!" << std::endl;
432
// Create the uv-choosers.
433
mMaterialImporter->createUVChoosers ();
436
//-----------------------------
437
void DocumentImporter::writeConnections ()
439
if ( mParseStep == MAKE_CONNECTIONS )
441
// The file must already exist.
444
std::cerr << "DocumentImporter::writeConnections(): Cant't import, no maya file exist!" << std::endl;
448
// If we have one or more controllers, the material groupIds have to
449
// connect to the geometry object groups on a later index position.
450
mControllerImporter->writeConnections ();
451
mMaterialImporter->writeConnections ();
452
mLightImporter->writeConnections ();
453
mEffectImporter->writeConnections ();
454
mGeometryImporter->writeConnections ();
456
// We have to connect the stored animations.
457
importAnimationLists ();
461
//-----------------------------
462
void DocumentImporter::readColladaDocument ()
464
// See revision 511 (generate new loader object without setting object flags).
465
COLLADASaxFWL::Loader saxLoader ( &mSaxParserErrorHandler );
467
if ( mParseStep == FIRST_PARSING )
468
saxLoader.registerExtraDataCallbackHandler ( &mMayaIdCallbackHandler );
471
COLLADAFW::Root root ( &saxLoader, this );
472
// COLLADAFW::Root root ( &mSaxLoader, this );
473
String filename = getColladaFilename ();
474
String fileUriString = URI::nativePathToUri ( filename );
476
++mNumDocumentParses;
477
root.loadDocument ( fileUriString );
480
//-----------------------------
481
String DocumentImporter::frameworkNameToMayaName ( const String& name )
483
// Replace offending characters by some that are supported within maya:
484
// ':', '|', '-', '!' are replaced by '_'.
486
const char* c = name.c_str ();
487
size_t length = name.length();
488
char* tmp = new char[length + 1];
490
for ( size_t i = 0; i <= length; i++ )
493
if ( d == '.' || d == '-' || d == '|' || d == ':' || d == '/' || d == '\\' || d == '(' || d == ')' || d == '[' || d == ']' )
500
String newName = COLLADABU::Utils::checkNCName ( tmp );
505
//-----------------------------
506
bool DocumentImporter::writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
508
if ( mParseStep >= IMPORT_ASSET )
512
mParseStep = IMPORT_ASSET;
514
// Create the file, if not already done.
526
//String mayaVersion ( MGlobal::mayaVersion ().asChar () );
527
fprintf ( mFile, "//Maya ASCII %s scene\n", mMayaVersion );
528
fprintf ( mFile, "requires maya \"%s\";\n", mMayaVersion );
530
// Get the unit informations.
531
const COLLADAFW::FileInfo::Unit& unit = asset->getUnit ();
532
mLinearUnitConvertFactor = 1.0;
533
mLinearUnitMayaBindShapeBugConvertFactor = 1.0;
535
// Set the default value to centimeters.
536
String linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME;
537
if ( ImportOptions::importUnits () )
539
linearUnitName = unit.getLinearUnitName ();
540
double linearUnitMeter = unit.getLinearUnitMeter ();
542
// Set the valid maya values in depend on the current precision.
543
linearUnitMeter = toMayaUnitValue ( linearUnitMeter );
545
// Set the linear unit in meters.
546
// Maya knows: millimeter, centimeter, meter, foot, inch and yard.
547
switch ( unit.getLinearUnitUnit () )
549
case COLLADAFW::FileInfo::Unit::KILOMETER:
552
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME;
553
mLinearUnitConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_KILOMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER; // 1km = 1000m ==> cf = 1000
554
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_KILOMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1km = 100.000m ==> cf = 100.000
557
case COLLADAFW::FileInfo::Unit::METER:
560
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME;
561
mLinearUnitConvertFactor = 1.0;
562
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1m = 100cm ==> cf = 100
565
case COLLADAFW::FileInfo::Unit::DECIMETER:
567
// Convert to centimeters
568
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME;
569
mLinearUnitConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_DECIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1dm = 10cm ==> cf = 10
570
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_DECIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1dm = 10cm ==> cf = 10
573
case COLLADAFW::FileInfo::Unit::CENTIMETER:
576
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME;
577
mLinearUnitConvertFactor = 1.0;
578
mLinearUnitMayaBindShapeBugConvertFactor = 1.0;
581
case COLLADAFW::FileInfo::Unit::MILLIMETER:
583
// Convert to centimeters
584
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME;
585
mLinearUnitConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_MILLIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1mm = 0.01m ==> cf = 0.1
586
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_MILLIMETER / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1mm = 0.01m ==> cf = 0.1
589
case COLLADAFW::FileInfo::Unit::FOOT:
592
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT_NAME;
593
mLinearUnitConvertFactor = 1.0;
594
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER;
597
case COLLADAFW::FileInfo::Unit::INCH:
600
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH_NAME;
601
mLinearUnitConvertFactor = 1.0;
602
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER;
605
case COLLADAFW::FileInfo::Unit::YARD:
608
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD_NAME;
609
mLinearUnitConvertFactor = 1.0;
610
mLinearUnitMayaBindShapeBugConvertFactor = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER;
615
if ( linearUnitMeter >= COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER )
618
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER_NAME;
619
mLinearUnitConvertFactor = linearUnitMeter / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER; // 1 ? = 1 m
620
mLinearUnitMayaBindShapeBugConvertFactor = linearUnitMeter / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER;
624
// Set to centimeters
625
linearUnitName = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER_NAME;
626
mLinearUnitConvertFactor = linearUnitMeter / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1 ? = 0.01 m
627
mLinearUnitMayaBindShapeBugConvertFactor = linearUnitMeter / COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER; // 1 ? = 0.01 m
634
fprintf ( mFile, "currentUnit -l %s -a %s -t %s;\n",
635
linearUnitName.c_str (), unit.getAngularUnitName ().c_str (), unit.getTimeUnitName ().c_str () );
637
if ( ImportOptions::importUpAxis () )
639
mUpAxisType = asset->getUpAxisType ();
641
switch ( mUpAxisType )
643
case COLLADAFW::FileInfo::Y_UP:
645
case COLLADAFW::FileInfo::Z_UP:
650
// createNode script -name "upAxisScriptNode";
651
// setAttr ".before" -type "string" "string $currentAxis = `upAxis -q -ax`; if ($currentAxis != \"z\") { upAxis -ax \"z\"; viewSet -home persp; }";
652
// setAttr ".scriptType" 2;
653
MayaDM::Script scriptNode ( mFile, SCRIPT_NODE_UP_AXIS );
654
String scriptValue = "string $currentAxis = `upAxis -q -ax`; if ($currentAxis != \\\"" + upAxis + "\\\") { upAxis -ax \\\"" + upAxis + "\\\"; viewSet -home persp; }"; // -rv
656
scriptNode.setBefore ( scriptValue );
657
scriptNode.setScriptType ( 2 );
660
// String application ( MGlobal::executeCommandStringResult ( "about -application" ).asChar () );
661
// fprintf ( mFile, "fileInfo \"application\" \"%s\";\n", application.c_str () );
662
// String product ( MGlobal::executeCommandStringResult ( "about -product" ).asChar () );
663
// fprintf ( mFile, "fileInfo \"product\" \"%s\";\n", product.c_str () );
664
// fprintf ( mFile, "fileInfo \"version\" \"%s\";\n", mayaVersion.c_str () );
665
// String cutIdentifier ( MGlobal::executeCommandStringResult ( "product -cutIdentifier" ).asChar () );
666
// fprintf ( mFile, "fileInfo \"cutIdentifier\" \"%s\";\n", cutIdentifier.c_str () );
667
// String operatingSystemVersion ( MGlobal::executeCommandStringResult ( "product -operatingSystemVersion" ).asChar () );
668
// fprintf ( mFile, "fileInfo \"osv\" \"%s\";\n", operatingSystemVersion.c_str () );
673
//-----------------------------
674
double DocumentImporter::toMayaUnitValue ( double unitValue )
676
if ( COLLADABU::Math::Utils::equalsZero ( unitValue, getTolerance () ) )
678
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_KILOMETER, getTolerance () ) )
679
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_KILOMETER;
680
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER, getTolerance () ) )
681
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_METER;
682
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_DECIMETER, getTolerance () ) )
683
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_DECIMETER;
684
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER, getTolerance () ) )
685
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_CENTIMETER;
686
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT, getTolerance () ) )
687
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_FOOT;
688
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH, getTolerance () ) )
689
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_INCH;
690
else if ( COLLADABU::Math::Utils::equals ( unitValue, COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD, getTolerance () ) )
691
unitValue = COLLADAFW::FileInfo::Unit::LINEAR_UNIT_YARD;
695
//-----------------------------
696
bool DocumentImporter::writeScene ( const COLLADAFW::Scene* scene )
698
// The file must already exist.
701
std::cerr << "DocumentImporter::writeScene(..): Cant't import, no maya file exist!" << std::endl;
705
if ( mParseStep <= COPY_ELEMENTS )
707
// Make a copy of the instantiated visual scene element.
708
mParseStep = COPY_ELEMENTS;
709
mInstanceVisualScene = scene->getInstanceVisualScene ()->clone ();
715
//-----------------------------
716
void DocumentImporter::importNodes ()
718
if ( mParseStep >= ELEMENTS_COPIED )
720
// Get the visual scene element to import.
721
for ( size_t i=0; i<mVisualScenesList.size (); ++i )
723
const COLLADAFW::VisualScene* visualScene = mVisualScenesList [i];
724
if ( mInstanceVisualScene->getInstanciatedObjectId () == visualScene->getUniqueId () )
726
const COLLADAFW::NodePointerArray& nodePointerArray = visualScene->getRootNodes ();
728
// Store the unique node ids in a map to the framework nodes.
729
mNodeImporter->importNodes ( nodePointerArray );
733
// Import the library notes data.
734
for ( size_t i=0; i<mLibraryNodesList.size (); ++i )
736
const COLLADAFW::LibraryNodes* libraryNodes = mLibraryNodesList [i];
737
const COLLADAFW::NodePointerArray& nodePointerArray = libraryNodes->getNodes ();
739
// Store the unique node ids in a map to the framework nodes.
740
mNodeImporter->importNodes ( nodePointerArray );
745
//-----------------------------
746
bool DocumentImporter::writeVisualScene ( const COLLADAFW::VisualScene* visualScene )
748
// The file must already exist.
751
std::cerr << "DocumentImporter::writeScene(..): Cant't import, no maya file exist!" << std::endl;
755
if ( mParseStep <= COPY_ELEMENTS )
757
// Make a copy of the visual scene element and push it into the list of visual scenes.
758
mParseStep = COPY_ELEMENTS;
759
mVisualScenesList.push_back ( new COLLADAFW::VisualScene ( *visualScene ) );
765
//-----------------------------
766
void DocumentImporter::importVisualScene ()
768
if ( mParseStep >= ELEMENTS_COPIED )
770
// The file must already exist.
773
std::cerr << "DocumentImporter::importVisualScene(..): Cant't import, no maya file exist!" << std::endl;
777
// Get the referenced visual scene element to import.
778
for ( size_t i=0; i<mVisualScenesList.size (); ++i )
780
const COLLADAFW::VisualScene* visualScene = mVisualScenesList [i];
781
if ( mInstanceVisualScene->getInstanciatedObjectId () == visualScene->getUniqueId () )
784
mVisualSceneImporter->importVisualScene ( visualScene );
787
mParseStep = VISUAL_SCENE_IMPORTED;
791
//-----------------------------
792
bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes )
794
// The file must already exist.
797
std::cerr << "DocumentImporter::writeLibraryNodes(..): Cant't import, no maya file exist!" << std::endl;
801
if ( mParseStep <= COPY_ELEMENTS )
803
// Make a copy of the library nodes element and push it into the list of library nodes.
804
mParseStep = COPY_ELEMENTS;
805
mLibraryNodesList.push_back ( new COLLADAFW::LibraryNodes ( *libraryNodes ) );
811
// //-----------------------------
812
// void DocumentImporter::importLibraryNodes ()
814
// // The file must already exist.
817
// std::cerr << "DocumentImporter::importLibraryNodes(..): Cant't import, no maya file exist!" << std::endl;
821
// // Import the library notes data.
822
// for ( size_t i=0; i<mLibraryNodesList.size (); ++i )
824
// const COLLADAFW::LibraryNodes* libraryNodes = mLibraryNodesList [i];
825
// mVisualSceneImporter->importLibraryNodes ( libraryNodes );
829
//-----------------------------
830
bool DocumentImporter::writeMaterial ( const COLLADAFW::Material* material )
832
// The file must already exist.
835
std::cerr << "DocumentImporter::writeMaterial(..): Cant't import, no maya file exist!" << std::endl;
839
if ( mParseStep <= COPY_ELEMENTS )
841
// Make a copy of the material element and push it into the list.
842
mParseStep = COPY_ELEMENTS;
843
mMaterialsList.push_back ( new COLLADAFW::Material ( *material ) );
849
//-----------------------------
850
void DocumentImporter::importMaterials ()
852
// The file must already exist.
855
std::cerr << "DocumentImporter::importMaterials(..): Cant't import, no maya file exist!" << std::endl;
859
// Import the materials data.
860
if ( mParseStep >= ELEMENTS_COPIED )
862
for ( size_t i=0; i<mMaterialsList.size (); ++i )
864
const COLLADAFW::Material* material = mMaterialsList [i];
865
mMaterialImporter->importMaterial ( material );
870
//-----------------------------
871
bool DocumentImporter::writeEffect ( const COLLADAFW::Effect* effect )
873
// The file must already exist.
876
std::cerr << "DocumentImporter::writeEffect(..): Cant't import, no maya file exist!" << std::endl;
880
if ( mParseStep <= COPY_ELEMENTS )
882
// Make a copy of the effect element and push it into the list.
883
mParseStep = COPY_ELEMENTS;
884
mEffectsList.push_back ( new COLLADAFW::Effect ( *effect ) );
890
//-----------------------------
891
void DocumentImporter::importEffects ()
893
// The file must already exist.
896
std::cerr << "DocumentImporter::importEffects(): Cant't import, no maya file exist!" << std::endl;
900
// Import the effects data.
901
if ( mParseStep >= ELEMENTS_COPIED )
903
for ( size_t i=0; i<mEffectsList.size (); ++i )
905
const COLLADAFW::Effect* effect = mEffectsList [i];
906
mEffectImporter->importEffect ( effect );
911
//-----------------------------
912
bool DocumentImporter::writeImage ( const COLLADAFW::Image* image )
914
// The file must already exist.
917
std::cerr << "DocumentImporter::writeImage(): Cant't import, no maya file exist!" << std::endl;
921
// We first should copy the images, about it's possible, that we have to create an
922
// image for more than one time. This happens if:
923
// a) one image is referenced from multiple effects
924
// b) one image is referenced in multiple samplers in one effect
925
// c) one effect uses the same sampler multiple times.
926
// We have to dublicate the image, about the possibility to create multiple uv-sets on it.
927
if ( mParseStep <= COPY_ELEMENTS )
929
// Make a copy of the material element and push it into the list.
930
mParseStep = COPY_ELEMENTS;
931
mImageImporter->storeImage ( image );
937
//-----------------------------
938
void DocumentImporter::importImages ()
940
// The file must already exist.
943
std::cerr << "DocumentImporter::importImages(): Cant't import, no maya file exist!" << std::endl;
947
// Import the images data.
948
if ( mParseStep >= ELEMENTS_COPIED )
950
mImageImporter->importImages ();
954
//-----------------------------
955
bool DocumentImporter::writeGeometry ( const COLLADAFW::Geometry* geometry )
957
// The file must already exist.
960
std::cerr << "DocumentImporter::writeGeometry(): Cant't import, no maya file exist!" << std::endl;
964
if ( mParseStep >= SECOND_PARSING )
967
mGeometryImporter->importGeometry ( geometry );
973
//-----------------------------
974
bool DocumentImporter::writeCamera ( const COLLADAFW::Camera* camera )
976
// The file must already exist.
979
std::cerr << "DocumentImporter::writeCamera(): Cant't import, no maya file exist!" << std::endl;
983
if ( mParseStep >= SECOND_PARSING )
986
mCameraImporter->importCamera ( camera );
992
//-----------------------------
993
bool DocumentImporter::writeLight ( const COLLADAFW::Light* light )
995
// The file must already exist.
998
std::cerr << "DocumentImporter::writeLight(): Cant't import, no maya file exist!" << std::endl;
1002
if ( mParseStep >= SECOND_PARSING )
1005
mLightImporter->importLight ( light );
1011
//-----------------------------
1012
bool DocumentImporter::writeAnimation ( const COLLADAFW::Animation* animation )
1014
// The file must already exist.
1017
std::cerr << "DocumentImporter::writeAnimation(): Cant't import, no maya file exist!" << std::endl;
1021
if ( mParseStep >= SECOND_PARSING )
1023
getAnimationImporter ()->importAnimation ( animation );
1024
mParseStep = ANIMATIONS_IMPORTED;
1030
//-----------------------------
1031
bool DocumentImporter::writeAnimationList ( const COLLADAFW::AnimationList* animationList )
1033
// The file must already exist.
1036
std::cerr << "DocumentImporter::writeAnimationList(): Cant't import, no maya file exist!" << std::endl;
1040
// We need the information about scale animations to adjust the physical dimension of a
1041
// scale animation. To get this info, we have to get the transformations of the transform
1042
// animations and have to check for scale animations. Scale animations must have a physical
1043
// dimension number (double) instead of length (distance)!
1044
// The transformations exist after the first parsing, after the visual scene is imported.
1045
// So we have to store the animation lists in the first parsing. After the visual scene
1046
// import we can iterate over the animation lists and determine the scale animations. After
1047
// we know the scale animations, we can import the animations with the correct physical
1048
// dimension. After we have imported all animations, we can write the animation connections
1049
// from the stored animation lists.
1050
// Order of the parse steps:
1052
// VISUAL_SCENE_IMPORTED
1054
// ANIMATIONS_IMPORTED
1058
// On first parsing, we have to store the animation lists.
1059
if ( mParseStep <= COPY_ELEMENTS )
1061
// Make a copy of the visual scene element and push it into the list of visual scenes.
1062
mParseStep = COPY_ELEMENTS;
1063
mAnimationListsList.push_back ( new COLLADAFW::AnimationList ( *animationList ) );
1069
//-----------------------------
1070
void DocumentImporter::importAnimationLists ()
1072
// After we have imported the visual scene, we can detect the scale animations.
1073
if ( mParseStep == MAKE_CONNECTIONS )
1075
std::vector<COLLADAFW::AnimationList*>::const_iterator it = mAnimationListsList.begin ();
1076
while ( it != mAnimationListsList.end () )
1078
const COLLADAFW::AnimationList* animationList = *it;
1079
getAnimationImporter ()->writeConnections ( animationList );
1085
//-----------------------------
1086
void DocumentImporter::detectScaleAnimations ()
1088
// After we have imported the visual scene, we can detect the scale animations.
1089
if ( mParseStep >= VISUAL_SCENE_IMPORTED )
1091
std::vector<COLLADAFW::AnimationList*>::const_iterator it = mAnimationListsList.begin ();
1092
while ( it != mAnimationListsList.end () )
1094
const COLLADAFW::AnimationList* animationList = *it;
1095
getAnimationImporter ()->detectScaleAnimations ( animationList );
1101
//-----------------------------
1102
void DocumentImporter::importPlaybackOptions ()
1104
// The file must already exist.
1107
std::cerr << "DocumentImporter::writePlaybackOptions(): Cant't import, no maya file exist!" << std::endl;
1111
if ( mParseStep >= ANIMATIONS_IMPORTED )
1113
mAnimationImporter->importPlaybackOptions ();
1118
//-----------------------------
1119
bool DocumentImporter::writeSkinControllerData (
1120
const COLLADAFW::SkinControllerData* skinControllerData )
1122
// The file must already exist.
1125
std::cerr << "DocumentImporter::writeSkinControllerData(): Cant't import, no maya file exist!" << std::endl;
1129
if ( mParseStep >= SECOND_PARSING )
1131
mControllerImporter->importSkinControllerData ( skinControllerData );
1137
//-----------------------------
1138
bool DocumentImporter::writeController (
1139
const COLLADAFW::Controller* controller )
1141
// The file must already exist.
1144
std::cerr << "DocumentImporter::writeController(): Cant't import, no maya file exist!" << std::endl;
1148
if ( mParseStep <= COPY_ELEMENTS )
1150
// Make a copy of the controller element and push it into the list.
1151
mParseStep = COPY_ELEMENTS;
1152
mControllerImporter->storeController ( controller );
1158
//-----------------------------
1159
void DocumentImporter::importMorphControllers ()
1161
if ( mParseStep >= ELEMENTS_COPIED )
1163
// The file must already exist.
1166
std::cerr << "DocumentImporter::importMorphControllers(): Cant't import, no maya file exist!" << std::endl;
1170
// Import the morph controllers.
1171
mControllerImporter->importMorphControllers ();
1175
//-----------------------------
1176
bool DocumentImporter::writeFormulas ( const COLLADAFW::Formulas* formulas )
1181
//-----------------------------
1182
bool DocumentImporter::writeKinematicsScene( const COLLADAFW::KinematicsScene* kinematicsScene )
1187
//-----------------------------
1188
const COLLADAFW::Node* DocumentImporter::findNode (
1189
const COLLADAFW::UniqueId& nodeId,
1190
const COLLADAFW::NodePointerArray& nodes )
1192
size_t numNodes = nodes.getCount ();
1193
for ( size_t i=0; i<numNodes; ++i )
1195
const COLLADAFW::Node* node = nodes [i];
1196
if ( nodeId != node->getUniqueId () )
1199
const COLLADAFW::NodePointerArray& childNodes = node->getChildNodes ();
1200
const COLLADAFW::Node* searchedNode = findNode ( nodeId, childNodes );
1201
if ( searchedNode ) return searchedNode;
1208
//-----------------------------
1209
String DocumentImporter::addGlobalNodeId (
1210
const String& newId,
1211
bool returnConverted /*= true*/,
1212
bool alwaysAddNumberSuffix /*= false */ )
1214
return mGlobalNodeIdList.addId ( newId, returnConverted, alwaysAddNumberSuffix );
1217
//-----------------------------
1218
bool DocumentImporter::containsGlobalNodeId ( const String& id )
1220
return mGlobalNodeIdList.containsId ( id );
1223
//-----------------------------
1224
String DocumentImporter::addDependNodeId (
1225
const String& newId,
1226
bool returnConverted /*= true*/,
1227
bool alwaysAddNumberSuffix /*= false */ )
1229
return mDependNodeIdList.addId ( newId, returnConverted, alwaysAddNumberSuffix );
1232
//-----------------------------
1233
bool DocumentImporter::containsDependNodeId ( const String& id )
1235
return mDependNodeIdList.containsId ( id );
1238
//-----------------------------
1239
void DocumentImporter::addDagNodeId ( const String& newId )
1241
mDagNodeIdSet.insert ( newId );
1244
//-----------------------------
1245
bool DocumentImporter::containsDagNodeId ( const String& id )
1247
std::set<String>::const_iterator it = mDagNodeIdSet.find ( id );
1248
if ( it != mDagNodeIdSet.end () ) return true;
1252
//-----------------------------
1253
const COLLADAFW::Material* DocumentImporter::getMaterialById ( const COLLADAFW::UniqueId& materialId )
1255
std::vector<COLLADAFW::Material*>::const_iterator it = mMaterialsList.begin ();
1256
while ( it != mMaterialsList.end () )
1258
if ( materialId == (*it)->getUniqueId () )
1265
//------------------------------
1266
void DocumentImporter::start()
b'\\ No newline at end of file'