Dynamic attachment

#1
I need to dynamically (f.e. during animation) attach some objects to the empty attachment slot. How can i do this in C++? Or maybe somehow by proc. clip?

The only solution, that I came up with is to previously attach objects in character editor and show/hide them on demand:

Code: Select all

auto *pCharacter = GetEntity()->GetCharacter(CPlayer::eGeometry_ThirdPerson); auto *pAttachment = pCharacter->GetIAttachmentManager()->GetInterfaceByName(attName); pAttachment->HideAttachment(1);
But it seems to be very bad practice.

Re: Dynamic attachment

#2
To attach an entity at runtime you can do this:

Code: Select all

CEntityAttachment* pEntityAttachment = new CEntityAttachment(); pEntityAttachment->SetEntityId(GetEntity()->GetId()); pAttachment->AddBinding(pEntityAttachment);
To attach a simple CGF object:

Code: Select all

CCGFAttachment* pCGFAttachment = new CCGFAttachment(); pCGFAttachment->pObj = gEnv->p3DEngine->LoadStatObj("Objects/Default/primitive_cube.cgf"); pAttachment->AddBinding(pCGFAttachment);
To attach a light:

Code: Select all

CDLight light; light.SetLightColor(ColorF(30.f, 35.f, 40.f, 1.0f)); light.SetSpecularMult(0.5f); light.m_fRadius = 40.f; light.m_Flags |= DLF_CASTSHADOW_MAPS | DLF_POINT; ... CLightAttachment* pLightAttachment = new CLightAttachment(); pLightAttachment ->LoadLight(light); pAttachment->AddBinding(pLightAttachment );
To set position, orientation etc.

Code: Select all

QuatT q = pAttachment->GetAttAbsoluteDefault(); q.SetTranslation(Vec3(0,0,2); pAttachment->SetAttAbsoluteDefault(q);
To detach:

Code: Select all

pAttachment->ClearBinding();
Last edited by gshot on Sun Feb 26, 2017 3:36 pm, edited 1 time in total.

Who is online

Users browsing this forum: No registered users and 1 guest

cron