Permalink
Browse files

export option visible/invisible nodes

  • Loading branch information...
1 parent 088ac74 commit bc78efd5eb145080b89a56b6a23bceeeeb860f09 @opencollada-sebastian opencollada-sebastian committed Apr 30, 2009
View
1 COLLADAMaya/TODO.TXT
@@ -14,7 +14,6 @@
- path animation export
- skew/shear animation import/export
(possible solution could be the animation formula from collada 1.5)
- - effect colors animation import
- clip animation import
- Controller
View
3 COLLADAMaya/include/COLLADAMayaControllerExporter.h
@@ -100,6 +100,9 @@ namespace COLLADAMaya
/** List of controllerIds from the already exported controllers. */
std::vector<String> mExportedControllers;
+ /** A list of the exported controller scene elements. */
+ std::vector<SceneElement*> mExportedControllerSceneElements;
+
public:
/**
View
6 COLLADAMaya/include/COLLADAMayaGeometryExporter.h
@@ -99,11 +99,17 @@ namespace COLLADAMaya
*/
const String findColladaGeometryId ( const String& mayaGeometryId );
+ /** Handle the geometry in depend on it is a controller or not. */
+ void exportControllerOrGeometry ( SceneElement* sceneElement );
+
private:
/** Exports the current scene element and all it's children. */
void exportGeometries ( SceneElement* sceneElement );
+ /** Handle controller geometries. */
+ void handleControllers ( SceneElement* sceneElement );
+
/** Exports the geometry data of the current object, if it is a valid mesh object to export. */
bool exportGeometry ( SceneElement* sceneElement );
View
56 COLLADAMaya/src/COLLADAMayaCameraExporter.cpp
@@ -61,27 +61,51 @@ namespace COLLADAMaya
//---------------------------------------------------------------
void CameraExporter::exportCameras ( SceneElement* sceneElement )
{
- // If we have a external reference, we don't need to export the data here.
+ // If we have a external reference or an export node, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
+ if ( !sceneElement->getIsExportNode () ) return;
- // Get the current dag path
- MDagPath dagPath = sceneElement->getPath();
-
- // Check for instance
- bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
-
- // Check if it is a camera and an export node
- if ( sceneElement->getType() == SceneElement::CAMERA &&
- sceneElement->getIsExportNode() && !isInstance )
+ // Check if it is a camera
+ SceneElement::Type sceneElementType = sceneElement->getType();
+ if ( sceneElementType == SceneElement::CAMERA )
{
- // Export the geometry
- bool exported = exportCamera ( dagPath );
+ // Get the current dag path
+ MDagPath dagPath = sceneElement->getPath();
- // Push it in the list of exported elements.
- if ( exported )
- mDocumentExporter->getSceneGraph()->addExportedElement( sceneElement );
- }
+ // Check for instance
+ bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
+ // If the original instanced element isn't already exported, we have to export it now.
+ if ( isInstance )
+ {
+ // Get the original instanced element.
+ MDagPath instancedPath;
+ dagPath.getPath ( instancedPath, 0 );
+
+ // Check if the original instanced element is already exported.
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ SceneElement* exportedElement = sceneGraph->findExportedElement ( instancedPath );
+ if ( exportedElement == 0 )
+ {
+ // Export the original instanced element and push it in the exported scene graph.
+ if ( exportCamera ( instancedPath ) )
+ {
+ SceneElement* instancedSceneElement = sceneGraph->findElement ( instancedPath );
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ sceneGraph->addExportedElement( instancedSceneElement );
+ }
+ }
+ }
+ else
+ {
+ // Export the element and push it in the exported scene graph.
+ if ( exportCamera ( dagPath ) )
+ {
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ sceneGraph->addExportedElement( sceneElement );
+ }
+ }
+ }
// Recursive call for all the child elements
for ( uint i=0; i<sceneElement->getChildCount(); ++i )
View
63 COLLADAMaya/src/COLLADAMayaControllerExporter.cpp
@@ -87,19 +87,60 @@ namespace COLLADAMaya
{
// If we have a external reference, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
-
- // Get the current dag path
- MDagPath dagPath = sceneElement->getPath();
-
- // Check for instance
- bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
+ if ( !sceneElement->getIsExportNode () ) return;
// Check if it is a mesh and an export node
- if ( sceneElement->getType() == SceneElement::MESH &&
- sceneElement->getIsExportNode() && !isInstance )
+ SceneElement::Type sceneElementType = sceneElement->getType();
+ if ( sceneElementType == SceneElement::MESH )
{
- // Create a skin/morph transform object and export the controller.
- bool exported = exportController ( sceneElement );
+ // Get the current dag path
+ MDagPath dagPath = sceneElement->getPath();
+
+ // Check if the current element is an instance.
+ // We don't need to export instances, because we export the original instanced element.
+ bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
+
+ // If the original instanced element isn't already exported, we have to export it now.
+ if ( isInstance )
+ {
+ // Get the original instanced element.
+ MDagPath instancedPath;
+ dagPath.getPath ( instancedPath, 0 );
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ SceneElement* instancedSceneElement = sceneGraph->findElement ( instancedPath );
+
+ // Check if the geometry of original instanced element is already exported.
+ SceneElement* exportedGeometryElement = sceneGraph->findExportedElement ( instancedPath );
+ if ( exportedGeometryElement == 0 )
+ {
+ // Export the original instanced element and push it in the exported list.
+ GeometryExporter* geometryExporter = mDocumentExporter->getGeometryExporter ();
+ geometryExporter->exportControllerOrGeometry ( instancedSceneElement );
+ }
+
+ // Check if the controller of the original instanced element is already exported.
+ std::vector<SceneElement*>::const_iterator controllerIter;
+ controllerIter = find ( mExportedControllerSceneElements.begin (), mExportedControllerSceneElements.end (), instancedSceneElement );
+ if ( controllerIter == mExportedControllerSceneElements.end () )
+ {
+ // Create a skin/morph transform object and export the controller for the
+ // the original instanced element.
+ if ( exportController ( instancedSceneElement ) )
+ {
+ // Push the scene element in the list of exported controller elements.
+ mExportedControllerSceneElements.push_back ( instancedSceneElement );
+ }
+ }
+ }
+ else
+ {
+ // Create a skin/morph transform object and export the controller.
+ if ( exportController ( sceneElement ) )
+ {
+ // Push the scene element in the list of exported controller elements.
+ mExportedControllerSceneElements.push_back ( sceneElement );
+ }
+ }
}
// Recursive call for all the child elements
@@ -113,8 +154,8 @@ namespace COLLADAMaya
//------------------------------------------------------
bool ControllerExporter::exportController( SceneElement* sceneElement )
{
+ // Get the current dag path
MDagPath dagPath = sceneElement->getPath();
- if ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 ) return false;
// Get the current mesh node.
MObject meshNode = dagPath.node();
View
198 COLLADAMaya/src/COLLADAMayaGeometryExporter.cpp
@@ -83,99 +83,40 @@ namespace COLLADAMaya
{
// If we have a external reference, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
+ if ( !sceneElement->getIsExportNode () ) return;
- // Get the current dag path
- MDagPath dagPath = sceneElement->getPath();
-
- // Get the scene graph
- SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
-
- // Check for instance
- bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
-
- // Check if it is a mesh and an export node
- SceneElement::Type type = sceneElement->getType();
- if ( type == SceneElement::MESH &&
- sceneElement->getIsExportNode() && !isInstance )
+ SceneElement::Type sceneElementType = sceneElement->getType();
+ if ( sceneElementType == SceneElement::MESH )
{
- bool exported = false;
-
- // Get the controller library
- ControllerExporter* controller = mDocumentExporter->getControllerExporter();
+ // Get the current dag path
+ MDagPath dagPath = sceneElement->getPath();
- // Add the controller and/or geometry to our libraries
- bool hasSkinController =
- ExportOptions::exportJointsAndSkin() &&
- controller->hasSkinController ( dagPath.node() );
- bool hasMorphController = controller->hasMorphController ( dagPath.node() );
+ // Check if the current element is an instance.
+ // We don't need to export instances, because we export the original instanced element.
+ bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
- // Handle the controllers
- if ( hasSkinController || hasMorphController )
+ // If the original instanced element isn't already exported, we have to export it now.
+ if ( isInstance )
{
- // The stacks of the controllers for the affected nodes.
- ControllerStack stack;
- ControllerMeshStack meshStack;
-
- // Iterate upstream finding all the nodes which affect the mesh.
- if ( !ControllerExporter::findAffectedNodes( dagPath.node(), stack, meshStack ) ) return;
-
-// // Disable the blend shape influences.
-// ControllerExporter::disableBlendShape( stack );
- // Disable any effects on the nodes.
- ControllerExporter::setControllerNodeStatesToNoEffect ( stack );
- // Set all meshes as visible and not intermediate.
- ControllerExporter::setValidMeshParameters ( meshStack );
-
- // Export the geometry
- exported = exportGeometry ( sceneElement );
-
- // Push it in the list of exported elements.
- if ( exported )
- sceneGraph->addExportedElement( sceneElement );
-
- // Export the controllerStack items
- for ( size_t i=0; i<meshStack.size(); ++i )
+ // Get the original instanced element.
+ MDagPath instancedPath;
+ dagPath.getPath ( instancedPath, 0 );
+
+ // Check if the original instanced element is already exported.
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ SceneElement* exportedElement = sceneGraph->findExportedElement ( instancedPath );
+ if ( exportedElement == 0 )
{
- ControllerMeshItem item = meshStack[i];
- MDagPath currentDagPath = MDagPath::getAPathTo ( item.mesh );
- MFnDagNode dagFn ( currentDagPath );
- bool isIntermediate = dagFn.isIntermediateObject();
- String currentPath = currentDagPath.fullPathName().asChar();
-
- if ( sceneGraph->findExportedElement( currentDagPath ) == NULL )
- {
- SceneElement* meshSceneElement = sceneGraph->findElement( currentDagPath );
- if ( meshSceneElement != NULL && meshSceneElement->getHasJoint() )
- {
- // Export the geometry
- exportGeometry ( meshSceneElement );
-
- // Push it in the list of exported elements.
- if ( exported )
- sceneGraph->addExportedElement( meshSceneElement );
- }
- }
+ // Export the original instanced element.
+ SceneElement* instancedSceneElement = sceneGraph->findElement ( instancedPath );
+ exportControllerOrGeometry ( instancedSceneElement );
}
-
- // Reset all the controller node states.
- ControllerExporter::resetControllerNodeStates ( stack );
-// // Enable the blend shape influences.
-// ControllerExporter::enableBlendShape ( stack );
- // Reset the meshes as visible and not intermediate.
- ControllerExporter::resetMeshParameters ( meshStack );
- // Delete the controller stack items and clear the stack.
- ControllerExporter::deleteControllerStackItems ( stack );
}
else
{
- // Export the geometry
- exported = exportGeometry ( sceneElement );
-
- // Push it in the list of exported elements.
- if ( exported )
- sceneGraph->addExportedElement( sceneElement );
+ // Handle the geometry in depend on it is a controller or not.
+ exportControllerOrGeometry ( sceneElement );
}
-
}
// Recursive call for all the child elements
@@ -187,6 +128,35 @@ namespace COLLADAMaya
}
// --------------------------------------------------------
+ void GeometryExporter::exportControllerOrGeometry (
+ SceneElement* sceneElement )
+ {
+ // Get the controller library
+ ControllerExporter* controller = mDocumentExporter->getControllerExporter();
+
+ // Get the current node element.
+ MObject node = sceneElement->getPath ().node();
+
+ // Add the controller and/or geometry to our libraries
+ bool hasSkinController = ExportOptions::exportJointsAndSkin() && controller->hasSkinController ( node );
+ bool hasMorphController = controller->hasMorphController ( node );
+ if ( hasSkinController || hasMorphController )
+ {
+ // Handle the controllers
+ handleControllers ( sceneElement );
+ }
+ else
+ {
+ // Export the element and push it in the exported scene graph.
+ if ( exportGeometry ( sceneElement ) )
+ {
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ sceneGraph->addExportedElement( sceneElement );
+ }
+ }
+ }
+
+ // --------------------------------------------------------
bool GeometryExporter::exportGeometry ( SceneElement* sceneElement )
{
if ( !ExportOptions::exportPolygonMeshes() ) return false;
@@ -1469,4 +1439,68 @@ namespace COLLADAMaya
return COLLADABU::Utils::EMPTY_STRING;
}
+ // ------------------------------------
+ void GeometryExporter::handleControllers (
+ SceneElement* sceneElement )
+ {
+ // Get the scene graph
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+
+ // Get the current dag path
+ MDagPath dagPath = sceneElement->getPath();
+
+ // The stacks of the controllers for the affected nodes.
+ ControllerStack stack;
+ ControllerMeshStack meshStack;
+
+ // Iterate upstream finding all the nodes which affect the mesh.
+ if ( !ControllerExporter::findAffectedNodes( dagPath.node(), stack, meshStack ) ) return;
+
+// // Disable the blend shape influences.
+// ControllerExporter::disableBlendShape( stack );
+ // Disable any effects on the nodes.
+ ControllerExporter::setControllerNodeStatesToNoEffect ( stack );
+ // Set all meshes as visible and not intermediate.
+ ControllerExporter::setValidMeshParameters ( meshStack );
+
+ // Export the element and push it in the exported scene graph.
+ if ( exportGeometry ( sceneElement ) )
+ {
+ sceneGraph->addExportedElement( sceneElement );
+ }
+
+ // Export the controllerStack items
+ for ( size_t i=0; i<meshStack.size(); ++i )
+ {
+ ControllerMeshItem item = meshStack[i];
+ MDagPath currentDagPath = MDagPath::getAPathTo ( item.mesh );
+ MFnDagNode dagFn ( currentDagPath );
+ bool isIntermediate = dagFn.isIntermediateObject();
+ String currentPath = currentDagPath.fullPathName().asChar();
+
+ if ( sceneGraph->findExportedElement( currentDagPath ) == NULL )
+ {
+ SceneElement* meshSceneElement = sceneGraph->findElement( currentDagPath );
+ if ( meshSceneElement != NULL && meshSceneElement->getHasJoint() )
+ {
+ // Export the geometry
+ if ( exportGeometry ( meshSceneElement ) )
+ {
+ // Push it in the list of exported elements.
+ sceneGraph->addExportedElement( meshSceneElement );
+ }
+ }
+ }
+ }
+
+ // Reset all the controller node states.
+ ControllerExporter::resetControllerNodeStates ( stack );
+// // Enable the blend shape influences.
+// ControllerExporter::enableBlendShape ( stack );
+ // Reset the meshes as visible and not intermediate.
+ ControllerExporter::resetMeshParameters ( meshStack );
+ // Delete the controller stack items and clear the stack.
+ ControllerExporter::deleteControllerStackItems ( stack );
+ }
+
}
View
3 COLLADAMaya/src/COLLADAMayaImageExporter.cpp
@@ -33,8 +33,7 @@ namespace COLLADAMaya
{
// export the images
ImageMap::const_iterator it = imageMap->begin();
-
- for ( ; it != imageMap->end(); ++it )
+ for ( ; it!=imageMap->end(); ++it )
{
// Create a new image structure
COLLADASW::Image* colladaImage = it->second;
View
56 COLLADAMaya/src/COLLADAMayaLightExporter.cpp
@@ -64,23 +64,49 @@ namespace COLLADAMaya
{
// If we have a external reference, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
+ if ( !sceneElement->getIsExportNode () ) return;
- // Get the current dag path
- MDagPath dagPath = sceneElement->getPath();
-
- // Check for instance
- bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
-
- // Check if it is a mesh and an export node
- if ( sceneElement->getType() == SceneElement::LIGHT &&
- sceneElement->getIsExportNode() && !isInstance )
+ // Check if it is a light.
+ SceneElement::Type sceneElementType = sceneElement->getType();
+ if ( sceneElementType == SceneElement::LIGHT )
{
- // Export the geometry
- bool exported = exportLight ( dagPath );
-
- // Push it in the list of exported elements.
- if ( exported )
- mDocumentExporter->getSceneGraph()->addExportedElement( sceneElement );
+ // Get the current dag path
+ MDagPath dagPath = sceneElement->getPath();
+
+ // Check if the current element is an instance.
+ // We don't need to export instances, because we export the original instanced element.
+ bool isInstance = ( dagPath.isInstanced() && dagPath.instanceNumber() > 0 );
+
+ // If the original instanced element isn't already exported, we have to export it now.
+ if ( isInstance )
+ {
+ // Get the original instanced element.
+ MDagPath instancedPath;
+ dagPath.getPath ( instancedPath, 0 );
+
+ // Check if the original instanced element is already exported.
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ SceneElement* exportedElement = sceneGraph->findExportedElement ( instancedPath );
+ if ( exportedElement == 0 )
+ {
+ // Export the original instanced element and push it in the exported scene graph.
+ if ( exportLight ( instancedPath ) )
+ {
+ SceneElement* instancedSceneElement = sceneGraph->findElement ( instancedPath );
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ sceneGraph->addExportedElement( instancedSceneElement );
+ }
+ }
+ }
+ else
+ {
+ // Export the element and push it in the exported scene graph.
+ if ( exportLight ( dagPath ) )
+ {
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ sceneGraph->addExportedElement( sceneElement );
+ }
+ }
}
View
7 COLLADAMaya/src/COLLADAMayaMaterialExporter.cpp
@@ -129,7 +129,8 @@ namespace COLLADAMaya
for ( size_t i = 0; i < length; ++i )
{
SceneElement* sceneElement = ( *exportNodesTree ) [i];
- const MDagPath dagPath = sceneElement->getPath();
+ if ( !sceneElement->getIsLocal() ) continue;
+ if ( !sceneElement->getIsExportNode () ) continue;
size_t childCount = sceneElement->getChildCount();
for ( size_t i=0; i<childCount; ++i )
@@ -146,10 +147,10 @@ namespace COLLADAMaya
{
// If we have a external reference, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
+ if ( !sceneElement->getIsExportNode () ) return;
// Check if it is a mesh object and an export node
- if ( sceneElement->getType() == SceneElement::MESH &&
- sceneElement->getIsExportNode() )
+ if ( sceneElement->getType() == SceneElement::MESH )
{
MDagPath dagPath = sceneElement->getPath();
View
8 COLLADAMaya/src/COLLADAMayaSceneGraph.cpp
@@ -329,9 +329,10 @@ namespace COLLADAMaya
}
// --------------------------------------------------------------------
- bool SceneGraph::getIsExportNode ( const MDagPath& dagPath,
- bool& isForced,
- bool& isVisible )
+ bool SceneGraph::getIsExportNode (
+ const MDagPath& dagPath,
+ bool& isForced,
+ bool& isVisible )
{
// Does this dagPath already exist? If so, only recurse if FollowInstancedChildren() is set.
MFnDagNode dagFn ( dagPath );
@@ -366,6 +367,7 @@ namespace COLLADAMaya
// Check for visibility
if ( !ExportOptions::exportInvisibleNodes() && !isVisible )
{
+ // Check if the visibility of the element is animated.
AnimationSampleCache* animationCache = mDocumentExporter->getAnimationCache();
if ( !AnimationHelper::isAnimated ( animationCache, dagPath.node(), ATTR_VISIBILITY ) )
{
View
4 COLLADAMaya/src/COLLADAMayaVisualSceneExporter.cpp
@@ -1125,8 +1125,8 @@ namespace COLLADAMaya
uint instanceNumber = 0;
if ( dagPath.isInstanced() )
{
- SceneElement* exportedElement =
- mDocumentExporter->getSceneGraph()->findExportedElement( dagPath );
+ SceneGraph* sceneGraph = mDocumentExporter->getSceneGraph();
+ SceneElement* exportedElement = sceneGraph->findElement( dagPath );
dagPath = exportedElement->getPath();
}

0 comments on commit bc78efd

Please sign in to comment.