Adding weights to bones (C++ SDK)

Adding weights to bones (C++ SDK)

Anonymous
Not applicable
896 Views
1 Reply
Message 1 of 2

Adding weights to bones (C++ SDK)

Anonymous
Not applicable

Hello,

 

I am trying to import rigging datas from my own software. Once I have created all the bones and the hierarchy, I try to add weights for each vertex of my model. However, the "AddWeights" method from ISkinImportData returns false each time I try to add weights on an extreme bone.

Here is how create the bones: 

 

// itBone is an iterator on a map <size_t, myBoneStructure>
// node is the node corresponding to my model in 3dsMax
Modifier* skin = (Modifier*)CreateInstance(SClass_ID(OSM_CLASS_ID), SKIN_CLASSID);
ISkinImportData* skinInterface = (ISkinImportData*)skin->GetInterface(I_SKINIMPORTDATA);
GetCoreInterface12()->AddModifier(*node, *skin);
std::map<size_t, INode*> bonePerId; for (auto itBone = xstObj->skinningData_.GetSkinningBoneData()->Begin(); itBone != xstObj->skinningData_.GetSkinningBoneData()->End(); ++itBone) { Object* pBone = (Object*)ip->CreateInstance(GEOMOBJECT_CLASS_ID, BONE_OBJ_CLASSID); INode* boneNode = ip->CreateObjectNode(pBone); std::string boneName = "Bone_" + boost::lexical_cast<std::string>(mySkeletonIndex); boneName += boost::lexical_cast<std::string>(itBone->first); std::wstring wideBoneName = std::wstring(boneName.begin(), boneName.end()); const wchar_t* result = wideBoneName.c_str(); const MCHAR* nodeName(result); boneNode->SetName(nodeName); bonePerId[itBone->first] = boneNode; }

 Here is how I create my hierarchy:

 

for (auto itBone = meshObj->skinningData_.GetSkinningBoneData()->Begin(); 
		itBone != meshObj->skinningData_.GetSkinningBoneData()->End(); ++itBone)
	{
		const size_t &parentBoneId(itBone->first);
		const SkinningBone &parentBone(itBone->second);

		INode &parentMaxNode(*bonePerId[parentBoneId]);

		const std::vector<size_t> &childIds = parentBone.GetChildIds();
		// For each child
		for (auto childIt(childIds.begin()); childIt != childIds.end(); ++childIt)
		{
			// Attach it to the parent
			const size_t &childId(*childIt);
			SkinningBone & childBone =
				meshObj->skinningData_.GetSkinningBoneData()->GetSkinningBone(childId);
			INode &childMaxNode(*bonePerId[childId]);
			parentMaxNode.AttachChild(&childMaxNode);

			// Position and rotate it
			Point3 posDelta = childBone.GetBonePosition() - parentBone.GetBonePosition();
			posDelta = msg->tsf_ * posDelta * 40;
			const Point3 posDeltaMax(posDelta.x, posDelta.y, posDelta.z);
			Matrix3 mat;
			mat.SetTranslate(posDeltaMax);
			childMaxNode.SetNodeTM(0, mat);
		}
	}

And finally here is how I add the weights :

 

 

for (auto itWeights = weightsPerBonePerVertice.begin(); itWeights != weightsPerBonePerVertice.end(); ++itWeights)
	{
		Tab<INode*> tabNodes;
		Tab<float> tabWeights;
		int count = (int)itWeights->second.size();
		tabNodes.SetCount(count);
		tabWeights.SetCount(count);
		size_t index = 0;
		for (auto itBone = (itWeights->second).begin(); itBone != (itWeights->second).end(); ++itBone)
		{
			float weightForBone = (float)itBone->second;
			tabNodes[index] = bonePerId[itBone->first];
			tabWeights[index] = weightForBone;
			index++;
		}

		bool addedWeights = skinInterface->AddWeights(node, (int)itWeights->first, tabNodes, tabWeights);
	}

Say my model is a tree with 5 bones, the 4th is the end of a branch and the 5th is the end of the trunk. Then, when AddWeights tries to add some weights on either of those two bones, the method returns false.

What did I do wrong ? Why does it returns false and refuses to add weights to those bones ?
Thank you !

 

 

0 Likes
Accepted solutions (1)
897 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

No wonder, not registering them in the ISkinImportData made it impossible to attach weights to them...

0 Likes