//------------------------------------------------------------------------ EntityEffects::TAttachedEffectId CItem::AttachEffect(int slot, bool attachToAccessory, const char *effectName, const char *helper, const Vec3 &offset, const Vec3 &dir, float scale, bool prime) { if(!g_pGameCVars->i_particleeffects) { return 0; } Vec3 finalOffset(offset); string helperName(helper); if(attachToAccessory) { SEntitySlotInfo slotInfo; QuatT accessoryOffset; accessoryOffset.SetIdentity(); const char* accessoryHelper = ""; const char* accessoryName = NULL; const int numAccessories = m_accessories.size(); for (int curIndex = 0; curIndex < numAccessories; curIndex++) { IEntity* pAccessory = gEnv->pEntitySystem->GetEntity(m_accessories[curIndex].accessoryId); if(pAccessory && pAccessory->GetSlotInfo(slot, slotInfo)) { if(slotInfo.pStatObj) { accessoryOffset.t = slotInfo.pStatObj->GetHelperPos(helper); if(!accessoryOffset.t.IsZero()) { accessoryOffset.q = pAccessory->GetRotation(); accessoryOffset.t += pAccessory->GetPos(); accessoryName = m_accessories[curIndex].pClass->GetName(); break; } } if(slotInfo.pCharacter) { IAttachmentManager *pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(helper); if(pAttachment) { accessoryHelper = GetAccessoryParams(m_accessories[curIndex].pClass)->attach_helper.c_str(); accessoryName = m_accessories[curIndex].pClass->GetName(); accessoryOffset = pAttachment->GetAttAbsoluteDefault(); break; } } } } if(accessoryName) { bool validSlot = GetEntity()->GetSlotInfo(slot, slotInfo) && (slotInfo.pCharacter || slotInfo.pStatObj); if (!validSlot || slotInfo.pStatObj) { if (validSlot) { Matrix34 mtx = GetEntity()->GetSlotLocalTM(slot, false) * Matrix34(accessoryOffset); finalOffset += mtx.GetTranslation(); } EntityEffects::SEffectAttachParams attachParams(finalOffset, dir, scale, prime, eIGS_Last); return m_effectsController.AttachParticleEffect(effectName, attachParams); } else if (slotInfo.pCharacter) // bone attachment { ICharacterInstance *pCharacter = slotInfo.pCharacter; IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = NULL; helperName = string().Format("%s_%s", helper, accessoryName); pAttachment = pAttachmentManager->GetInterfaceByName(helperName.c_str()); if(!pAttachment) { IAttachment* pAccessoryAttachment = pAttachmentManager->GetInterfaceByName(accessoryHelper); if(pAccessoryAttachment) { const char* bone = pCharacter->GetIDefaultSkeleton().GetJointNameByID(pAccessoryAttachment->GetJointID()); pAttachment = pAttachmentManager->CreateAttachment(helperName.c_str(), CA_BONE, bone); if (pAttachment) { QuatT relative = pAccessoryAttachment->GetAttRelativeDefault(); relative = relative * accessoryOffset; relative.t = relative * finalOffset; finalOffset.zero(); pAttachment->SetAttRelativeDefault(relative); } } } } } } EntityEffects::SEffectAttachParams attachParams(finalOffset, dir, scale, prime, eIGS_Last); return m_effectsController.AttachParticleEffect(effectName, slot, helperName, attachParams); }
SpriteFrame::SpriteFrame(const Rectangle& pRectangle, const graphics::TexturePtr& pTexture, bool rotated, const Size2& sourceSize, const Vector2& sourceOffset, const Vector2& pivot) { texture = pTexture; std::vector<uint16_t> indices = {0, 1, 2, 1, 3, 2}; Vector2 textCoords[4]; Vector2 finalOffset(-sourceSize.width * pivot.x + sourceOffset.x, -sourceSize.height * pivot.y + (sourceSize.height - pRectangle.height - sourceOffset.y)); const Size2& textureSize = texture->getSize(); if (!rotated) { Vector2 leftTop(pRectangle.x / textureSize.width, pRectangle.y / textureSize.height); Vector2 rightBottom((pRectangle.x + pRectangle.width) / textureSize.width, (pRectangle.y + pRectangle.height) / textureSize.height); if (texture->isFlipped()) { leftTop.y = 1.0f - leftTop.y; rightBottom.y = 1.0f - rightBottom.y; } textCoords[0] = Vector2(leftTop.x, rightBottom.y); textCoords[1] = Vector2(rightBottom.x, rightBottom.y); textCoords[2] = Vector2(leftTop.x, leftTop.y); textCoords[3] = Vector2(rightBottom.x, leftTop.y); } else { Vector2 leftTop = Vector2(pRectangle.x / textureSize.width, pRectangle.y / textureSize.height); Vector2 rightBottom = Vector2((pRectangle.x + pRectangle.height) / textureSize.width, (pRectangle.y + pRectangle.width) / textureSize.height); if (texture->isFlipped()) { leftTop.y = 1.0f - leftTop.y; rightBottom.y = 1.0f - rightBottom.y; } textCoords[0] = Vector2(leftTop.x, leftTop.y); textCoords[1] = Vector2(leftTop.x, rightBottom.y); textCoords[2] = Vector2(rightBottom.x, leftTop.y); textCoords[3] = Vector2(rightBottom.x, rightBottom.y); } rectangle = Rectangle(finalOffset.x, finalOffset.y, pRectangle.width, pRectangle.height); std::vector<graphics::VertexPCT> vertices = { graphics::VertexPCT(Vector3(finalOffset.x, rectangle.y, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[0]), graphics::VertexPCT(Vector3(finalOffset.x + rectangle.width, rectangle.y, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[1]), graphics::VertexPCT(Vector3(finalOffset.x, rectangle.y + rectangle.height, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[2]), graphics::VertexPCT(Vector3(finalOffset.x + rectangle.width, rectangle.y + rectangle.height, 0.0f), graphics::Color(255, 255, 255, 255), textCoords[3]) }; meshBuffer = sharedEngine->getRenderer()->createMeshBuffer(); meshBuffer->initFromBuffer(indices.data(), sizeof(uint16_t), static_cast<uint32_t>(indices.size()), false, vertices.data(), graphics::VertexPCT::ATTRIBUTES, static_cast<uint32_t>(vertices.size()), true); }