Example #1
0
/*---------------------------------------------------------------------------*/
NiNodeRef NifPrepareUtility::parse4Armor(NiNodeRef pNode, BSLightingShaderPropertyRef pShaderTmpl)
{
	vector<NiAVObjectRef>	childList(pNode->GetChildren());

	//  unlink children
	pNode->ClearChildren();

	//  iterate over children
	for (auto pIter(childList.begin()), pEnd(childList.end()); pIter != pEnd; pIter++)
	{
		//  NiTriShape => remodel BSLightingShaderProperty
		if (DynamicCast<NiTriShape>(*pIter) != NULL)
		{
			NiTriShapeRef				pShape  (DynamicCast<NiTriShape>(*pIter));
			BSDismemberSkinInstanceRef	pSkin   (DynamicCast<BSDismemberSkinInstance>(pShape->GetSkinInstance()));
			vector<NiPropertyRef>		propList(pShape->GetProperties());

			//  part of skin data? => modify skin code
			if (pSkin != NULL)
			{
				vector<BodyPartList>	bPartList(pSkin->GetPartitions());

				for (auto pIter(bPartList.begin()), pEnd(bPartList.end()); pIter != pEnd; pIter++)
				{
					if (_bodyPartMap.count(pIter->bodyPart) > 0)
					{
						pIter->bodyPart = (BSDismemberBodyPartType) _bodyPartMap[pIter->bodyPart];
					}
				}  //  for (auto pIter(bPartList.begin()), pEnd(bPartList.end()); pIter != pEnd; pIter++)

				//  set modified parts
				pSkin->SetPartitions(bPartList);

			}  //  if (pSkin != NULL)

			//  remove all properties
			pShape->ClearProperties();

			//  create new BSLightingShaderProperty if template given
			if (pShaderTmpl != NULL)
			{
				//  check properties
				for (auto pIterProp(propList.begin()), pEnd(propList.end()); pIterProp != pEnd; pIterProp++)
				{
					//  convert BSShaderPPLightingProperty to BSLightingShaderProperty
					if (DynamicCast<BSShaderPPLightingProperty>(*pIterProp) != NULL)
					{
						BSShaderPPLightingProperty*	pPProp(DynamicCast<BSShaderPPLightingProperty>(*pIterProp));
						BSLightingShaderProperty*	pLProp(new BSLightingShaderProperty());

						//  move texture set
						pLProp->SetTextureSet(pPProp->GetTextureSet());
						pPProp->SetTextureSet(NULL);

						pLProp->SetShaderFlags1       (pShaderTmpl->GetShaderFlags1());
						pLProp->SetShaderFlags2       (pShaderTmpl->GetShaderFlags2());
						pLProp->SetEmissiveMultiple   (pShaderTmpl->GetEmissiveMultiple());
						pLProp->SetEmissiveColor      (pShaderTmpl->GetEmissiveColor());
						pLProp->SetLightingEffect1    (pShaderTmpl->GetLightingEffect1());
						pLProp->SetLightingEffect2    (pShaderTmpl->GetLightingEffect2());
						pLProp->SetEnvironmentMapScale(pShaderTmpl->GetEnvironmentMapScale());
						pLProp->SetSkyrimShaderType   (pShaderTmpl->GetSkyrimShaderType());
						pLProp->SetSpecularColor      (pShaderTmpl->GetSpecularColor());
						pLProp->SetSpecularStrength   (pShaderTmpl->GetSpecularStrength());
						pLProp->SetTextureClampMode   (pShaderTmpl->GetTextureClampMode());
						pLProp->SetUnknownFloat2      (pShaderTmpl->GetUnknownFloat2());
						pLProp->SetGlossiness         (pShaderTmpl->GetGlossiness());

						//  add property to shape
						pShape->SetBSProperty(0, pLProp);
					}
				}  //  for (auto pIterProp(propList.begin()), pEnd(propList.end()); pIterProp != pEnd; pIterProp++)
			}  //  if (pShaderTmpl != NULL)

			//  add shape to node
			pNode->AddChild(*pIter);
		}
		//  NiNode (and derived classes?) => iterate subnodes
		else if (DynamicCast<NiNode>(*pIter) != NULL)
		{
			pNode->AddChild(&(*parse4Armor(DynamicCast<NiNode>(*pIter), pShaderTmpl)));
		}
	}  //  for (auto pIter(childList.begin()), pEnd(childList.end()); pIter != pEnd; pIter++)

	return pNode;
}