Skip to content
Browse files

support morph controller as skin target

  • Loading branch information...
1 parent 8acb7f7 commit 8d0d3ed758224dbcdf060ae05e5823ece80d0ca7 @opencollada-sebastian opencollada-sebastian committed May 26, 2009
View
18 COLLADAMax/include/COLLADAMaxDocumentImporter.h
@@ -29,6 +29,7 @@ for details please see LICENSE file or the website
#include "COLLADAFWInstanceGeometry.h"
#include "COLLADAFWController.h"
#include "COLLADAFWMorphController.h"
+#include "COLLADAFWSkinController.h"
#include <list>
@@ -146,6 +147,9 @@ namespace COLLADAMax
/** Maps Unique ids of morph controllers to the morph controller.*/
typedef std::map< COLLADAFW::UniqueId /* Controller data*/, const COLLADAFW::MorphController* > UniqueIdMorphControllerMap;
+ /** Maps Unique ids of skin controllers to the skin controller.*/
+ typedef std::map< COLLADAFW::UniqueId /* Controller data*/, const COLLADAFW::SkinController* > UniqueIdSkinControllerMap;
+
struct FileInfo
{
COLLADABU::URI absoluteFileUri;
@@ -261,6 +265,13 @@ namespace COLLADAMax
/** Maps Unique ids of all morph controllers found during the first pass to the morph controller.*/
UniqueIdMorphControllerMap mUniqueIdMorphControllersMap;
+ /** Maps the unique ids of morph controllers that are NOT instantiated in the scene graph but
+ used as source by a skin controller to the INode that references this skin controller.*/
+ UniqueIdINodeMap mMorphUniqueIdINodeMap;
+
+ /** Maps Unique ids of all skin controllers found during the first pass to the skin controller.*/
+ UniqueIdSkinControllerMap mUniqueIdSkinControllersMap;
+
// TODO check if we need this map
/** Maps unique ids of skin controller to the INode that references the controller.*/
UniqueIdINodeMap mSkinControllerINodeMap;
@@ -469,9 +480,16 @@ namespace COLLADAMax
/** Maps Unique ids of all morph controllers found during the first pass to the morph controller.*/
UniqueIdMorphControllerMap& getUniqueIdMorphControllerMap() { return mUniqueIdMorphControllersMap; }
+ /** Maps Unique ids of all skin controllers found during the first pass to the skin controller.*/
+ UniqueIdSkinControllerMap& getUniqueIdSkinControllerMap() { return mUniqueIdSkinControllersMap; }
+
/** Maps unique ids of skin controller to the INode that references the controller.*/
UniqueIdINodeMap& getSkinControllerINodeMap() { return mSkinControllerINodeMap; }
+ /** Maps the unique ids of morph controllers that are NOT instantiated in the scene graph but
+ used as source by a skin controller to the INode that references this skin controller.*/
+ UniqueIdINodeMap& getMorphUniqueIdINodeMap() { return mMorphUniqueIdINodeMap; }
+
/** Functors used to convert values from frame work units into max units.*/
const UnitConversionFunctors& getUnitConversionFunctors() const { return mUnitConversionFunctors; }
View
15 COLLADAMax/include/COLLADAMaxImporterBase.h
@@ -261,12 +261,27 @@ namespace COLLADAMax
be deleted at the end of the import.*/
void addMorphController( const COLLADAFW::MorphController* morphController );
+ /** Returns the skin controller with unique id @a skinControllerUniqueId. Null if not found. */
+ const COLLADAFW::SkinController* getSkinControllerByUniqueId( const COLLADAFW::UniqueId& skinControllerUniqueId ) const;
+
+ /** Adds @a skinController to map of all skin controllers found during the first pass. The skin controller will
+ be deleted at the end of the import.*/
+ void addSkinController( const COLLADAFW::SkinController* skinController );
+
/** Maps unique ids of controller data to the corresponding controller.*/
INode* getINodeBySkinController( const COLLADAFW::UniqueId& skinController ) const { return mDocumentImporter->getSkinControllerINodeMap()[skinController]; }
/** Adds the pair @a controllerData, @a controller to the UniqueIdControllerMultiMap.*/
void addSkinControllerINodePair( const COLLADAFW::UniqueId& skinController, INode* inode) { mDocumentImporter->getSkinControllerINodeMap()[skinController] = inode;}
+ /** Maps the unique ids of morph controllers that are NOT instantiated in the scene graph but
+ used as source by a skin controller to the INode that references this skin controller.*/
+ const DocumentImporter::UniqueIdINodeMap& getMorphUniqueIdINodeMap( ) const { return mDocumentImporter->getMorphUniqueIdINodeMap(); }
+
+ /** Maps the unique ids of morph controllers that are NOT instantiated in the scene graph but
+ used as source by a skin controller to the INode that references this skin controller.*/
+ void addMorphControllerINodePair( const COLLADAFW::UniqueId& morphController, INode* inode) { mDocumentImporter->getMorphUniqueIdINodeMap()[morphController] = inode;}
+
/** Returns informations about the entire file being loaded.*/
const DocumentImporter::FileInfo& getFileInfo() const { return mDocumentImporter->getFileInfo(); }
View
2 COLLADAMax/include/COLLADAMaxMorphControllerCreator.h
@@ -55,6 +55,8 @@ namespace COLLADAMax
/** Disable default assignment operator. */
const MorphControllerCreator& operator= ( const MorphControllerCreator& pre );
+ /** Creates a morph controller (modifier) using the data in @a morphController and assigns the to
+ @a referencingINode.*/
bool createMorphController( const COLLADAFW::MorphController* morphController, INode* referencingINode );
/** Sets the vertex data of the morph channel. This is required for channels that use geometries not
View
5 COLLADAMax/include/COLLADAMaxSceneGraphCreator.h
@@ -112,9 +112,12 @@ namespace COLLADAMax
nodes with reference the same object and transformation controller.*/
bool recursivelyCloneINode( ImpNode* parentImportNode, INode* nodeToClone );
- /** Store the information about material bindings of @a instanceGeometry attached to max node @a node*/
+ /** Store the information about material bindings of @a instanceGeometry attached to max node @a node.*/
void storeMaterialBindings( INode* node, COLLADAFW::InstanceGeometry* instanceGeometry);
+ /** Store the information about material bindings of @a instanceController attached to max node @a node. */
+ void postProcessInstanceController( INode* node, COLLADAFW::InstanceController* instanceController );
+
private:
View
9 COLLADAMax/src/COLLADAMaxControllerImporter.cpp
@@ -46,13 +46,18 @@ namespace COLLADAMax
const COLLADAFW::UniqueId& controllerDataUniqueId = skinController->getSkinControllerData();
if ( controllerDataUniqueId.isValid() )
{
- addUniqueIdControllerPair(controllerDataUniqueId, new COLLADAFW::SkinController(*skinController));
+ COLLADAFW::SkinController* clonedSkinController = new COLLADAFW::SkinController(*skinController);
+ addUniqueIdControllerPair(controllerDataUniqueId, clonedSkinController);
+ // clonedSkinController will be deleted by ImporterBase after import
+ addSkinController( clonedSkinController );
}
}
else if ( mController->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_MORPH )
{
const COLLADAFW::MorphController* morphController = (const COLLADAFW::MorphController*)mController;
- addMorphController( new COLLADAFW::MorphController(*morphController) );
+ COLLADAFW::MorphController* clonedMorphController = new COLLADAFW::MorphController(*morphController);
+ // clonedMorphController will be deleted by ImporterBase after import
+ addMorphController( clonedMorphController );
}
return true;
View
2 COLLADAMax/src/COLLADAMaxDocumentImporter.cpp
@@ -88,7 +88,7 @@ namespace COLLADAMax
delete it->second;
// Delete all the controllers
- for ( UniqueIdControllerMultiMap::const_iterator it = mUniqueIdControllerMap.begin(); it != mUniqueIdControllerMap.end(); ++it)
+ for ( UniqueIdSkinControllerMap::const_iterator it = mUniqueIdSkinControllersMap.begin(); it != mUniqueIdSkinControllersMap.end(); ++it)
delete it->second;
// Delete all the controllers
View
21 COLLADAMax/src/COLLADAMaxImporterBase.cpp
@@ -427,6 +427,27 @@ namespace COLLADAMax
}
}
+ //------------------------------
+ void ImporterBase::addSkinController( const COLLADAFW::SkinController* skinController )
+ {
+ mDocumentImporter->getUniqueIdSkinControllerMap().insert(std::make_pair(skinController->getUniqueId(), skinController));
+ }
+
+ //------------------------------
+ const COLLADAFW::SkinController* ImporterBase::getSkinControllerByUniqueId( const COLLADAFW::UniqueId& skinControllerUniqueId ) const
+ {
+ const DocumentImporter::UniqueIdSkinControllerMap& map = mDocumentImporter->getUniqueIdSkinControllerMap();
+ DocumentImporter::UniqueIdSkinControllerMap::const_iterator it = map.find( skinControllerUniqueId );
+ if ( it == map.end() )
+ {
+ return 0;
+ }
+ else
+ {
+ return it->second;
+ }
+ }
+
//------------------------------
const COLLADAFW::AnimationList* ImporterBase::getAnimationList( const COLLADAFW::Animatable* animatable )
View
24 COLLADAMax/src/COLLADAMaxMorphControllerCreator.cpp
@@ -39,6 +39,7 @@ namespace COLLADAMax
//------------------------------
bool MorphControllerCreator::create()
{
+ // create all the morph controller that are instantiated in the scene graph
DocumentImporter::UniqueIdINodeMultiMapConstIterator firstInstance = getUniqueIdObjectINodesBegin();
DocumentImporter::UniqueIdINodeMultiMapConstIterator lastInstance = getUniqueIdObjectINodesEnd();
for ( DocumentImporter::UniqueIdINodeMultiMapConstIterator it = firstInstance; it != lastInstance; ++it )
@@ -55,6 +56,24 @@ namespace COLLADAMax
}
}
}
+
+ // create all the morph controller that are the source of a skin controller
+ const DocumentImporter::UniqueIdINodeMap& morphControllers = getMorphUniqueIdINodeMap();
+ for ( DocumentImporter::UniqueIdINodeMap::const_iterator it = morphControllers.begin(); it != morphControllers.end(); ++it )
+ {
+ const COLLADAFW::UniqueId& morphControllerUniqueId = it->first;
+ INode* referencingINode = it->second;
+
+ const COLLADAFW::MorphController* morphController = getMorphControllerByUniqueId( morphControllerUniqueId );
+ if ( morphController )
+ {
+ if ( !createMorphController( morphController, referencingINode) )
+ {
+ return false;
+ }
+ }
+ }
+
return true;
}
@@ -162,6 +181,7 @@ namespace COLLADAMax
referencingINode->SetObjectRef(mDerivedObject);
}
+ addUniqueIdObjectPair( morphController->getUniqueId(), mDerivedObject );
return true;
}
@@ -178,11 +198,11 @@ namespace COLLADAMax
MNMesh* polyMesh = 0;
Mesh* triangleMesh = 0;
- if ( geometryObjectClassId == EPOLYOBJ_CLASS_ID )
+ if ( (geometryObjectClassId == EPOLYOBJ_CLASS_ID) || (geometryObjectClassId.PartA() == POLYOBJ_CLASS_ID) )
{
polyMesh = &((PolyObject*)geometryObject)->GetMesh();
}
- else if ( geometryObjectClassId.PartA() == TRIOBJ_CLASS_ID )
+ else if ( (geometryObjectClassId.PartA() == TRIOBJ_CLASS_ID) || (geometryObjectClassId.PartA() == EDITTRIOBJ_CLASS_ID ) )
{
triangleMesh = &((TriObject*)geometryObject)->GetMesh();
}
View
23 COLLADAMax/src/COLLADAMaxSceneGraphCreator.cpp
@@ -187,7 +187,7 @@ namespace COLLADAMax
//------------------------------
bool SceneGraphCreator::importInstanceControllers( const COLLADAFW::InstanceControllerPointerArray& instanceControllerArray, ImpNode* parentImportNode )
{
- return importInstances<COLLADAFW::InstanceController, &SceneGraphCreator::storeMaterialBindings>(instanceControllerArray, parentImportNode);
+ return importInstances<COLLADAFW::InstanceController, &SceneGraphCreator::postProcessInstanceController>(instanceControllerArray, parentImportNode);
}
//------------------------------
@@ -257,7 +257,7 @@ namespace COLLADAMax
//------------------------------
ImpNode* SceneGraphCreator::importInstanceController( const COLLADAFW::Node* node, INode* parentINode )
{
- return importInstance<COLLADAFW::InstanceController, &COLLADAFW::Node::getInstanceControllers, &SceneGraphCreator::storeMaterialBindings>(node, parentINode);
+ return importInstance<COLLADAFW::InstanceController, &COLLADAFW::Node::getInstanceControllers, &SceneGraphCreator::postProcessInstanceController>(node, parentINode);
}
//------------------------------
@@ -357,6 +357,25 @@ namespace COLLADAMax
}
}
+ //------------------------------
+ void SceneGraphCreator::postProcessInstanceController( INode* node, COLLADAFW::InstanceController* instanceController )
+ {
+ storeMaterialBindings( node, instanceController );
+
+ const COLLADAFW::UniqueId& controllerUniqueId = instanceController->getInstanciatedObjectId();
+
+ const COLLADAFW::SkinController* skinController = getSkinControllerByUniqueId( controllerUniqueId );
+
+ if ( skinController )
+ {
+ const COLLADAFW::UniqueId& skinSource = skinController->getSource();
+ if ( skinSource.getClassId() == COLLADAFW::MorphController::ID() )
+ {
+ addMorphControllerINodePair( skinSource, node);
+ }
+ }
+
+ }
} // namespace COLLADAMax
View
12 COLLADAMax/src/COLLADAMaxSkinControllerDataImporter.cpp
@@ -79,8 +79,16 @@ namespace COLLADAMax
if ( !mSkinModifier )
return true;
- //probably we need to check if object is already a derived object
- mDerivedObject = CreateDerivedObject(object);
+ if ( (object->ClassID() == derivObjClassID) || (object->ClassID() == WSMDerivObjClassID) )
+ {
+ // Object is a derived object, just attach ourselves to it
+ mDerivedObject = (IDerivedObject*) object;
+ }
+ else
+ {
+ // Create the derived object for the target and the modifier
+ mDerivedObject = CreateDerivedObject(object);
+ }
mDerivedObject->AddModifier(mSkinModifier);

0 comments on commit 8d0d3ed

Please sign in to comment.
Something went wrong with that request. Please try again.