Skip to content

Commit

Permalink
Merge pull request #466 from fl4re/Fix/Skeleton-skinning
Browse files Browse the repository at this point in the history
Fix/skeleton skinning
  • Loading branch information
RemiArnaud committed Oct 12, 2016
2 parents ab61463 + 5d40a76 commit 9fea0aa
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
3 changes: 2 additions & 1 deletion COLLADAMaya/include/COLLADAMayaControllerExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ namespace COLLADAMaya
*/
void gatherBindMatrices(
SkinController* skinController,
const MObject& controllerNode );
const MObject& controllerNode,
SceneElement* UpperSceneNode);

/**
* Support for joint clusters pipeline.
Expand Down
69 changes: 61 additions & 8 deletions COLLADAMaya/src/COLLADAMayaControllerExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,34 @@ namespace COLLADAMaya
if ( componentCount == 0 ) return ;
}

static SceneElement* searchJointRootElement(SceneElement* sceneElement)
{
bool sceneElementHasJoint = false;
bool sceneParentElementHasJoint = false;

const MDagPath dagPath = sceneElement->getPath();
if (dagPath.hasFn(MFn::kJoint))
sceneElementHasJoint = true;

if (sceneElement->getParentCount())
{
const MDagPath dagParentPath = sceneElement->getParent()->getPath();
if (dagParentPath.hasFn(MFn::kJoint))
sceneParentElementHasJoint = true;
}

if (sceneElementHasJoint && ((sceneElement->getParentCount() && !sceneParentElementHasJoint) || !sceneElement->getParentCount())) return sceneElement;

for (uint i = 0; i<sceneElement->getParentCount(); ++i)
{
SceneElement* parent = sceneElement->getParent(i);
String parentName = parent->getNodeName();
if ((parent = searchJointRootElement(parent)) != NULL) return parent;
}

return NULL;
}

//------------------------------------------------------
void ControllerExporter::exportSkinController(
SceneElement* sceneElement,
Expand Down Expand Up @@ -515,7 +543,9 @@ namespace COLLADAMaya
// Set the joint entry into the other scene element, which use this joints.
MDagPathArray influences = skinController.getInfluences();
unsigned int numInfluences = influences.length();
for ( unsigned int i=0; i<numInfluences; ++i )

SceneElement* JointRootElement;
for ( unsigned int i=0; i<numInfluences; ++i )
{
// Get the scene element.
MDagPath skeletonPath = influences [i];
Expand All @@ -527,7 +557,21 @@ namespace COLLADAMaya

// Get the uri of the current scene
COLLADASW::URI skeletonUri ( visualSceneExporter->getSceneElementURI ( sceneElement, colladaNodeId ) );
sceneElement->addSkeletonURI ( skeletonUri );


bool result = false;
for (unsigned int i = 0; i < numInfluences; ++i)
{
// Get the scene element.
MDagPath skeletonPath = influences[i];
if (sceneElement->containsParentElement(skeletonPath))
{
result = true;
break;
}
}

sceneElement->addSkeletonURI(skeletonUri);

// Set the id on the other instanced nodes.
bool isInstanced = targetDagPath.isInstanced ();
Expand All @@ -537,13 +581,19 @@ namespace COLLADAMaya
for (uint i=0; i<pathes.length(); ++i)
{
SceneElement* foundElement = mDocumentExporter->getSceneGraph()->findElement ( pathes[i] );
if ( foundElement != NULL )
foundElement->addSkeletonURI ( skeletonUri );
if (foundElement != NULL && !result)
{

JointRootElement = searchJointRootElement(sceneElement);
COLLADASW::URI skeletonRootUri(visualSceneExporter->getSceneElementURI(JointRootElement));
foundElement->addSkeletonURI(skeletonRootUri);
}

}
}

// Gather the bind matrices and write them as the bind poses in the target controller object.
gatherBindMatrices ( &skinController, controllerNode );
gatherBindMatrices(&skinController, controllerNode, JointRootElement);

// Collect the vertex weights into the collada skin controller.
collectVertexWeights ( &skinController, controllerNode, outputShape, weightFilters, clusterIndex, numInfluences );
Expand Down Expand Up @@ -687,6 +737,9 @@ namespace COLLADAMaya
}
}




static SceneElement* searchRootElement(SceneElement* sceneElement)
{
if (!sceneElement->getParentCount()) return sceneElement;
Expand Down Expand Up @@ -735,7 +788,8 @@ namespace COLLADAMaya
//------------------------------------------------------
void ControllerExporter::gatherBindMatrices(
SkinController* skinController,
const MObject& controllerNode )
const MObject& controllerNode,
SceneElement* UpperSceneNode)
{
// The list of joints
MDagPathArray& influences = skinController->getInfluences();
Expand All @@ -744,10 +798,9 @@ namespace COLLADAMaya
{
// Retrieve Root
SceneElement* sceneElement = mDocumentExporter->getSceneGraph()->findElement(influences[0]);
SceneElement* rootElement = searchRootElement(sceneElement);

// Parse all childs from Root and add them into influences if not present into.
AddElementToInfluences(influences, rootElement);
AddElementToInfluences(influences, UpperSceneNode);
}

// Request a change in capacity
Expand Down

0 comments on commit 9fea0aa

Please sign in to comment.