void CFlowConvoyNode::DiscoverConvoyCoaches(IEntity *pEntity) { m_coaches.resize(0); while (pEntity) { SConvoyCoach tc; ICharacterInstance *pCharacterInstance = pEntity->GetCharacter(0); ISkeletonPose *pSkeletonPose = pCharacterInstance ? pCharacterInstance->GetISkeletonPose() : NULL; ICharacterModelSkeleton* pICharacterModelSkeleton = pCharacterInstance ? pCharacterInstance->GetICharacterModel()->GetICharacterModelSkeleton() : NULL; IPhysicalEntity* pPhysics = pEntity->GetPhysics(); if(!pPhysics) { // don't need physics here, but need it later, so don't use entity if it's not physicalized GameWarning("Convoy entity [%s] is not physicalized", pEntity->GetName()); break; } AABB bbox; pEntity->GetLocalBounds(bbox); //tc.m_coachOffset = (bbox.max.y - bbox.min.y) * .5f; tc.m_coachOffset = 10.0f; tc.m_frontWheelBase = pICharacterModelSkeleton ? pICharacterModelSkeleton->GetJointIDByName("wheel_base1") : -1; tc.m_backWheelBase = pICharacterModelSkeleton ? pICharacterModelSkeleton->GetJointIDByName("wheel_base2") : -1; if (tc.m_frontWheelBase >=0 && tc.m_backWheelBase >= 0) { QuatT qt1 = pSkeletonPose->GetRelJointByID(tc.m_frontWheelBase); QuatT qt2 = pSkeletonPose->GetRelJointByID(tc.m_backWheelBase); tc.m_wheelDistance = qt1.t.GetDistance(qt2.t) * .5f; } else { // Fallback for entities that don't have wheel_base joints if ( m_bXAxisFwd ) tc.m_wheelDistance = (bbox.max.x - bbox.min.x) * .5f; else tc.m_wheelDistance = (bbox.max.y - bbox.min.y) * .5f; } tc.m_pEntity = pEntity; // pEntity->SetConvoyEntity(); //for (int i = 0; i < pEntity->GetChildCount(); i++) // pEntity->GetChild(i)->SetConvoyEntity(); //tc.m_pEntitySoundsProxy = (IEntitySoundProxy*) tc.m_pEntity->CreateProxy(ENTITY_PROXY_SOUND); //assert(tc.m_pEntitySoundsProxy); m_coaches.push_back(tc); IEntityLink *pEntityLink = pEntity->GetEntityLinks(); pEntity = pEntityLink ? gEnv->pEntitySystem->GetEntity(pEntityLink->entityId) : NULL; } }
//------------------------------------------------------------------------ const Matrix33 &CItem::GetSlotHelperRotation(int slot, const char *helper, bool worldSpace, bool relative) { static Matrix33 rotation; rotation.SetIdentity(); IEntity* pEntity = GetEntity(); if(!pEntity) return rotation; SEntitySlotInfo info; if (pEntity->GetSlotInfo(slot, info)) { if (info.pStatObj) { IStatObj *pStatObj = info.pStatObj; rotation = Matrix33(pStatObj->GetHelperTM(helper)); rotation.OrthonormalizeFast(); rotation = Matrix33(GetEntity()->GetSlotLocalTM(slot, false))*rotation; } else if (info.pCharacter) { ICharacterInstance *pCharacter = info.pCharacter; if(!pCharacter) return rotation; IAttachment* pAttachment = pCharacter->GetIAttachmentManager()->GetInterfaceByName(helper); if(pAttachment) { rotation = Matrix33(worldSpace ? pAttachment->GetAttWorldAbsolute().q : pAttachment->GetAttModelRelative().q); return rotation; } else { ICharacterModelSkeleton* pICharacterModelSkeleton = pCharacter->GetICharacterModel()->GetICharacterModelSkeleton(); ISkeletonPose* pSkeletonPose = pCharacter->GetISkeletonPose(); int16 id = pICharacterModelSkeleton->GetJointIDByName(helper); if (id > -1) { rotation = relative ? Matrix33(pSkeletonPose->GetRelJointByID(id).q) : Matrix33(pSkeletonPose->GetAbsJointByID(id).q); } } if (!relative) { rotation = Matrix33(pEntity->GetSlotLocalTM(slot, false)) * rotation; } } } if (worldSpace) { rotation = Matrix33(pEntity->GetWorldTM()) * rotation; } return rotation; }
//------------------------------------------------------------------------ Vec3 CItem::GetSlotHelperPos(int slot, const char *helper, bool worldSpace, bool relative) const { Vec3 position(0,0,0); SEntitySlotInfo info; if (GetEntity()->GetSlotInfo(slot, info)) { if (info.pStatObj) { IStatObj *pStatsObj = info.pStatObj; position = pStatsObj->GetHelperPos(helper); position = GetEntity()->GetSlotLocalTM(slot, false).TransformPoint(position); } else if (info.pCharacter) { ICharacterInstance *pCharacter = info.pCharacter; IAttachment* pAttachment = pCharacter->GetIAttachmentManager()->GetInterfaceByName(helper); if (pAttachment) { position = worldSpace ? pAttachment->GetAttWorldAbsolute().t : pAttachment->GetAttModelRelative().t; return position; } else { ICharacterModelSkeleton* pICharacterModelSkeleton = pCharacter->GetICharacterModel()->GetICharacterModelSkeleton(); ISkeletonPose* pSkeletonPose = pCharacter->GetISkeletonPose(); int16 id = pICharacterModelSkeleton->GetJointIDByName(helper); if (id > -1) { position = relative ? pSkeletonPose->GetRelJointByID(id).t : pSkeletonPose->GetAbsJointByID(id).t; } } if (!relative) { position = GetEntity()->GetSlotLocalTM(slot, false).TransformPoint(position); } } } if (worldSpace) { position = GetWorldTM().TransformPoint(position); } return position; }
QuatT CScriptbind_Entity::GetJointRelative(IEntity *pEntity, mono::string jointName, int characterSlot) { if(ICharacterInstance *pCharacter = pEntity->GetCharacter(characterSlot)) { const IDefaultSkeleton *pDefaultSkeleton = &pCharacter->GetIDefaultSkeleton(); ISkeletonPose *pSkeletonPose = pCharacter->GetISkeletonPose(); if (pSkeletonPose != nullptr) { int16 id = pDefaultSkeleton->GetJointIDByName(ToCryString(jointName)); if (id > -1) return pSkeletonPose->GetRelJointByID(id); } } return QuatT(); }
//------------------------------------------------------------------------ void CVehiclePartAnimated::InitGeometry() { if (!m_pSharedParameters->m_filename.empty()) { m_slot = GetEntity()->LoadCharacter(m_slot, m_pSharedParameters->m_filename.c_str()); m_pCharInstance = GetEntity()->GetCharacter(m_slot); if (m_pCharInstance) { if (m_pCharInstance->GetIMaterial() && !GetEntity()->GetMaterial()) { SetMaterial(m_pCharInstance->GetIMaterial()); } ISkeletonAnim* pSkeletonAnim = m_pCharInstance->GetISkeletonAnim(); ISkeletonPose* pSkeletonPose = m_pCharInstance->GetISkeletonPose(); IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton(); if (pSkeletonAnim) pSkeletonAnim->StopAnimationsAllLayers(); if (m_hideCount == 0) GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) | ENTITY_SLOT_RENDER); else GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) & ~(ENTITY_SLOT_RENDER | ENTITY_SLOT_RENDER_NEAREST)); #if ENABLE_VEHICLE_DEBUG if (IsDebugParts()) { CryLog("joint transformations for %s", m_pCharInstance->GetFilePath()); for (int i = 0; i < rIDefaultSkeleton.GetJointCount(); ++i) { VehicleUtils::LogMatrix(rIDefaultSkeleton.GetJointNameByID(i), Matrix34(pSkeletonPose->GetRelJointByID(i))); } } #endif } if (!m_pCharInstanceDestroyed && !m_pSharedParameters->m_filenameDestroyed.empty()) m_pCharInstanceDestroyed = gEnv->pCharacterManager->CreateInstance(m_pSharedParameters->m_filenameDestroyed.c_str()); if (m_pCharInstanceDestroyed) { m_pCharInstanceDestroyed->AddRef(); #if ENABLE_VEHICLE_DEBUG if (IsDebugParts()) { CryLog("joint transformations for %s", m_pCharInstanceDestroyed->GetFilePath()); ISkeletonPose* pSkeletonDestroyed = m_pCharInstanceDestroyed->GetISkeletonPose(); IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstanceDestroyed->GetIDefaultSkeleton(); for (int i = 0; i < rIDefaultSkeleton.GetJointCount(); ++i) { VehicleUtils::LogMatrix(rIDefaultSkeleton.GetJointNameByID(i), Matrix34(pSkeletonDestroyed->GetRelJointByID(i))); } } #endif } } if (m_pSharedParameters->m_isPhysicalized && m_slot > -1) GetEntity()->UnphysicalizeSlot(m_slot); if (m_pCharInstance) { m_pCharInstance->GetISkeletonAnim()->StopAnimationsAllLayers(); if (m_hideCount == 0) GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) | ENTITY_SLOT_RENDER); else GetEntity()->SetSlotFlags(m_slot, GetEntity()->GetSlotFlags(m_slot) & ~(ENTITY_SLOT_RENDER | ENTITY_SLOT_RENDER_NEAREST)); } // Disable hand-placed (static) decals on vehicles GetEntity()->SetFlags(GetEntity()->GetFlags() | ENTITY_FLAG_NO_DECALNODE_DECALS); }