Ejemplo n.º 1
0
//------------------------------------------------------------------------
bool CItem::SetGeometry(int slot, const ItemString& name, const ItemString& material, bool useParentMaterial, const Vec3& poffset, const Ang3& aoffset, float scale, bool forceReload)
{
    assert(slot >= 0 && slot < eIGS_Last);

    bool changedfp=false;
    switch(slot)
        {
        case eIGS_Owner:
            break;
        case eIGS_FirstPerson:
        case eIGS_ThirdPerson:
        default:
        {
            if (name.empty() || forceReload)
                {
                    GetEntity()->FreeSlot(slot);
#ifndef ITEM_USE_SHAREDSTRING
                    m_geometry[slot].resize(0);
#else
                    m_geometry[slot].reset();
#endif
                }

            DestroyAttachmentHelpers(slot);

            if (!name.empty())
                {
                    if (m_geometry[slot] != name)
                        {
                            const char* ext = PathUtil::GetExt(name.c_str());
                            if ((stricmp(ext, "chr") == 0) || (stricmp(ext, "cdf") == 0) || (stricmp(ext, "cga") == 0) )
                                GetEntity()->LoadCharacter(slot, name.c_str(), 0);
                            else
                                GetEntity()->LoadGeometry(slot, name.c_str(), 0, 0);

                            changedfp=slot==eIGS_FirstPerson;
                        }

                    CreateAttachmentHelpers(slot);
                }

            /*			if (slot == eIGS_FirstPerson)
            			{
            				ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson);
            				if (pCharacter)
            				{
            					pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE));
            				}
            			}
                  else */if (slot == eIGS_Destroyed)
                DrawSlot(eIGS_Destroyed, false);
        }
        break;
        }

    Matrix34 slotTM;
    slotTM = Matrix34::CreateRotationXYZ(aoffset);
    slotTM.ScaleColumn(Vec3(scale, scale, scale));
    slotTM.SetTranslation(poffset);
    GetEntity()->SetSlotLocalTM(slot, slotTM);

    if (changedfp && m_stats.mounted)
        {
            if (m_sharedparams->pMountParams && !m_sharedparams->pMountParams->pivot.empty())
                {
                    Matrix34 tm=GetEntity()->GetSlotLocalTM(eIGS_FirstPerson, false);
                    Vec3 pivot = GetSlotHelperPos(eIGS_FirstPerson, m_sharedparams->pMountParams->pivot.c_str(), false);
                    tm.AddTranslation(pivot);

                    GetEntity()->SetSlotLocalTM(eIGS_FirstPerson, tm);
                }

            GetEntity()->InvalidateTM();
        }

    m_geometry[slot] = name ? name : ItemString();

    ReAttachAccessories();

    IEntity* pParentEntity = gEnv->pEntitySystem->GetEntity(GetParentId());
    IMaterial* pOverrideMaterial = 0;
    if (!material.empty())
        {
            pOverrideMaterial = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material.c_str());
        }
    else if (useParentMaterial && pParentEntity)
        {
            ICharacterInstance* pParentCharacter = pParentEntity->GetCharacter(slot);
            IEntityRenderProxy* pParentRenderProxy = static_cast<IEntityRenderProxy*>(pParentEntity->GetProxy(ENTITY_PROXY_RENDER));
            if (pParentCharacter)
                pOverrideMaterial = pParentCharacter->GetIMaterial();
            else if (pParentRenderProxy)
                pOverrideMaterial = pParentRenderProxy->GetSlotMaterial(slot);
        }
    if (pOverrideMaterial)
        {
            ICharacterInstance* pCharacter = GetEntity()->GetCharacter(slot);
            IEntityRenderProxy* pRenderProxy = static_cast<IEntityRenderProxy*>(GetEntity()->GetProxy(ENTITY_PROXY_RENDER));
            OverrideAttachmentMaterial(pOverrideMaterial, this, slot);
            if (pCharacter)
                pCharacter->SetIMaterial_Instance(pOverrideMaterial);
            else if (pRenderProxy)
                pRenderProxy->SetSlotMaterial(slot, pOverrideMaterial);
        }

    if(slot == eIGS_FirstPerson && IsSelected())
        {
            CActor* pOwnerActor = GetOwnerActor();
            IActionController *pActionController = GetActionController();
            if(pActionController && pOwnerActor && pOwnerActor->IsClient())
                {
                    UpdateScopeContexts(pActionController);
                }
        }

    return true;
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------
bool CVehiclePartTread::Init(IVehicle* pVehicle, const CVehicleParams& table, IVehiclePart* parent, CVehicle::SPartInitInfo& initInfo, int partType)
{
	if (!CVehiclePartBase::Init(pVehicle, table, parent, initInfo, eVPT_Tread))
		return false;

	CVehicleParams subTable = table.findChild("Tread"); // Tread subtable
	if (!subTable)
		return false;

	string filename = subTable.getAttr("filename");
	if (filename.empty())
		return false;

	subTable.getAttr("uvSpeedMultiplier", m_uvSpeedMultiplier);

	if (table.haveAttr("component"))
	{
		if (CVehicleComponent* pComponent = static_cast<CVehicleComponent*>(m_pVehicle->GetComponent(table.getAttr("component"))))
			pComponent->AddPart(this);
	}

	m_slot = GetEntity()->LoadCharacter(m_slot, filename);

	m_pCharInstance = GetEntity()->GetCharacter(m_slot);
	if (!m_pCharInstance)
		return false;

	if (subTable.haveAttr("materialName"))
	{
		string materialName = subTable.getAttr("materialName");
		materialName.MakeLower();

		IMaterial* pMaterial = 0;
		const char* subMtlName = 0;
		int subMtlSlot = -1;

		// find tread material
		IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)GetEntity()->GetProxy(ENTITY_PROXY_RENDER);
		if (pRenderProxy)
		{
			pMaterial = pRenderProxy->GetRenderMaterial(m_slot);
			if (pMaterial)
			{
				// if matname doesn't fit, look in submaterials
				if (string(pMaterial->GetName()).MakeLower().find(materialName) == string::npos)
				{
					for (int i=0; i < pMaterial->GetSubMtlCount(); ++i)
					{
						if (string(pMaterial->GetSubMtl(i)->GetName()).MakeLower().find(materialName) != string::npos)
						{
							subMtlName = pMaterial->GetSubMtl(i)->GetName();
							subMtlSlot = i;
							break;
						}
					}
				}
			}
		}

		if (pMaterial)
		{
			// clone
			IMaterial *pCloned = pMaterial->GetMaterialManager()->CloneMultiMaterial(pMaterial, subMtlName);
			if (pCloned)
			{
				pRenderProxy->SetSlotMaterial(m_slot, pCloned);
				pMaterial = pCloned;
				m_pMaterial = pMaterial;
			}

			if (subMtlSlot > -1)
				m_pShaderResources = pMaterial->GetShaderItem(subMtlSlot).m_pShaderResources;
			else
				m_pShaderResources = pMaterial->GetShaderItem().m_pShaderResources;
		}

		if (m_pShaderResources)
		{
			for (int i = 0; i < EFTT_MAX; ++i)
			{
				if (!m_pShaderResources->GetTexture(i))
					continue;

				SEfTexModificator& modif = *m_pShaderResources->GetTexture(i)->AddModificator();

				modif.SetMember("m_eMoveType[0]", 1.0f);  // ETMM_Fixed: u = m_OscRate[0] + sourceU

				modif.SetMember("m_OscRate[0]", 0.0f);
			}
		}
	}

	char wheelName[256];

	IDefaultSkeleton& rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton();
	for (int i=0; i<rIDefaultSkeleton.GetJointCount(); ++i)
	{
		const char* boneName = rIDefaultSkeleton.GetJointNameByID(i);
		if (0 != boneName)
		{
			// extract wheel name
			const size_t len = strcspn(boneName, "_");
			if (len < strlen(boneName) && len < sizeof(wheelName))
			{
				cry_strcpy(wheelName, boneName, len);

				CVehiclePartSubPartWheel* pWheel = (CVehiclePartSubPartWheel*)m_pVehicle->GetPart(wheelName);
				if (pWheel)
				{
					SWheelInfo wheelInfo;
					wheelInfo.slot = pWheel->m_slot;
					wheelInfo.jointId = i;
					wheelInfo.pWheel = pWheel;
					m_wheels.push_back(wheelInfo);

					m_lastWheelIndex = pWheel->GetWheelIndex();
				}
			}
		}
	}

	m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);

	m_state = eVGS_Default;
	return true;
}