1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADAMax. 5 6 Portions of the code are: 7 Copyright (c) 2005-2007 Feeling Software Inc. 8 Copyright (c) 2005-2007 Sony Computer Entertainment America 9 10 Based on the 3dsMax COLLADASW Tools: 11 Copyright (c) 2005-2006 Autodesk Media Entertainment 12 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 16 */ 17 18 19 #ifndef __COLLADAMAX_VISUALSCENEEXPORTER_H__ 20 #define __COLLADAMAX_VISUALSCENEEXPORTER_H__ 21 22 #include "COLLADAMaxPrerequisites.h" 23 24 #include "COLLADASWStreamWriter.h" 25 #include "COLLADAMaxEffectExporter.h" 26 #include "COLLADASWLibraryVisualScenes.h" 27 #include "COLLADAMaxDocumentExporter.h" 28 29 namespace COLLADASW 30 { 31 32 class Node; 33 class InstanceMaterialList; 34 } 35 36 namespace COLLADAMax 37 { 38 39 class ExportSceneGraph; 40 41 class ExportNode; 42 43 /** Class to export the visual scene.*/ 44 45 class VisualSceneExporter : public COLLADASW::LibraryVisualScenes 46 { 47 48 public : 49 static const String MATRIX_SID; 50 static const String TRANSLATE_SID; 51 static const String ROTATE_SID; 52 static const String ROTATE_X_SID; 53 static const String ROTATE_Y_SID; 54 static const String ROTATE_Z_SID; 55 static const String ROTATE_SCALE_AXIS_SID; 56 static const String ROTATE_SCALE_AXIS_INVERSE_SID; 57 static const String SCALE_SID; 58 59 static const String MATRIX_PARAMETERS[ 1 ]; 60 static const String TRANSLATION_PARAMETERS[ 3 ]; 61 static const String ROTATION_PARAMETER[ 1 ]; 62 static const String ROTATION_PARAMETERS[ 4 ]; 63 64 65 private: 66 ExportSceneGraph * mExportSceneGraph; 67 68 const EffectMap & mEffectMap; 69 70 /** The id of the visual scene.*/ 71 const String & mVisualSceneId; 72 73 /** Document exporter instance */ 74 DocumentExporter * mDocumentExporter; 75 76 /** The prefix used for node ids.*/ 77 static const String NODE_ID_PRAEFIX; 78 79 /** Name of node containing XRefs (as instance_node elements) 80 that are not bound to any INode. */ 81 82 static const String XREF_NODE_NAME; 83 84 public: 85 /** Constructor 86 @param streamWriter The stream to write the visual seen to. 87 @param exportSceneGraph The scene graph of all the nodes that should be exported. 88 @param sceneId The id of the scene. 89 @param documentExporter 90 */ 91 VisualSceneExporter ( COLLADASW::StreamWriter * streamWriter, ExportSceneGraph * exportSceneGraph, const String & sceneId, DocumentExporter * documentExporter ); ~VisualSceneExporter()92 virtual ~VisualSceneExporter() 93 {} 94 95 ; 96 97 /** Exports the library visual scene.*/ 98 void doExport(); 99 100 /** Fills the two dimensional array @a copy with the values contained in @a original.*/ 101 static void matrix3ToDouble4x4 ( double copy[][ 4 ], const Matrix3 & original ); 102 103 /** Creates an id for the NODE, derived from the node id*/ 104 static String getNodeId(const ExportNode& exportNode); 105 106 /** Returns the world transformation matrix at the animation start time*/ 107 static Matrix3 getWorldTransform(INode* node, TimeValue time); 108 109 110 private: 111 /** Exports the node that instantiates the environment ambient color.*/ 112 void exportEnvironmentAmbientLightNode(); 113 114 /** Exports all the nodes in @a node and all its child nodes.*/ 115 void doExport ( ExportNode* exportNode ); 116 117 /** Exports all the transformations of a node.*/ 118 void exportTransformations ( ExportNode * exportNode, const COLLADASW::Node & colladaNode ); 119 120 /** Fill @a instanceMaterialList with the appropriate elements. 121 @param instanceMaterialList The COLLADASW::InstanceMaterialList to fill 122 @param exportNode The ExportNode which this instance material list is for. */ 123 void fillInstanceMaterialList(COLLADASW::InstanceMaterialList & instanceMaterialList, ExportNode * exportNode); 124 125 void calculateObjectOffsetTransformation(INode* maxNode, Matrix3& tm); 126 127 /** Determines the world transformation of @a node at the animation start time.*/ 128 Matrix3 getWorldTransform(INode* node); 129 130 /** If @a node references a skinned object... 131 @returns True, if the nodes transformation should be exported, false otherwise*/ 132 bool applyFirstInstanceTransform( Matrix3& transformationMatrix, INode* node ); 133 134 }; 135 136 } 137 138 #endif //__COLLADAMAX_VISUALSCENEEXPORTER_H__ 139