diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 99f4c5a78..7dbac9f3f 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -336,7 +336,7 @@ void UnitAttackBoostEffect::applyLoadedAttackBoostParticles(UnitParticleSystemTy upst->setValues(ups); ups->setPos(unit->getCurrVectorForParticlesystems()); ups->setRotation(unit->getRotation()); - ups->setUnitModel(unit->getCurrentModelPtr()); + unit->setMeshPosInParticleSystem(ups); if (unit->getFaction()->getTexture()) { ups->setFactionColor(unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0, 0)); } @@ -2449,7 +2449,7 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( getCurrVectorForParticlesystems()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); - currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); if (getFaction()->getTexture()) { currentAttackBoostOriginatorEffect. @@ -2562,7 +2562,7 @@ void Unit::updateAttackBoostProgress(const Game* game) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos( getCurrVectorForParticlesystems()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); - currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); if (getFaction()->getTexture()) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setFactionColor( @@ -2751,14 +2751,14 @@ bool Unit::update() { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrVectorForParticlesystems()); (*it)->setRotation(getRotation()); - (*it)->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(*it); } } for(UnitParticleSystems::iterator it= damageParticleSystems.begin(); it != damageParticleSystems.end(); ++it) { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrVectorForParticlesystems()); (*it)->setRotation(getRotation()); - (*it)->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(*it); } } @@ -2766,7 +2766,7 @@ bool Unit::update() { if(Renderer::getInstance().validateParticleSystemStillExists((*it),rsGame) == true) { (*it)->setPos(getCurrMidHeightVector()); (*it)->setRotation(getRotation()); - (*it)->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(*it); } } @@ -2778,7 +2778,7 @@ bool Unit::update() { if(particleValid == true) { effect->ups->setPos(getCurrVectorForParticlesystems()); effect->ups->setRotation(getRotation()); - effect->ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(effect->ups); } //printf("i = %d particleValid = %d\n",i,particleValid); @@ -2793,7 +2793,7 @@ bool Unit::update() { if(particleValid == true) { currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setPos(getCurrVectorForParticlesystems()); currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setRotation(getRotation()); - currentAttackBoostOriginatorEffect.currentAppliedEffect->ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(currentAttackBoostOriginatorEffect.currentAppliedEffect->ups); } } } @@ -2850,7 +2850,7 @@ void Unit::updateTimedParticles() { pst->setValues(ups); ups->setPos(getCurrVectorForParticlesystems()); ups->setRotation(getRotation()); - ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(ups); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); @@ -2993,7 +2993,7 @@ bool Unit::applyAttackBoost(const AttackBoost *boost, const Unit *source) { effect->upst->setValues(effect->ups); effect->ups->setPos(getCurrVectorForParticlesystems()); effect->ups->setRotation(getRotation()); - effect->ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(effect->ups); if(getFaction()->getTexture()) { effect->ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -4138,7 +4138,7 @@ void Unit::checkCustomizedUnitParticleListTriggers(const UnitParticleSystemTypes pst->setValues(ups); ups->setPos(getCurrVectorForParticlesystems()); ups->setRotation(getRotation()); - ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(ups); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -4168,6 +4168,36 @@ void Unit::queueTimedParticles(const UnitParticleSystemTypes &unitParticleSystem } } +void Unit::setMeshPosInParticleSystem(UnitParticleSystem *ups){ + if(ups->getMeshName()!=""){ + string meshName=ups->getMeshName(); + Model *model= getCurrentModelPtr(); + model->updateInterpolationVertices(getAnimProgressAsFloat(), isAlive() && !isAnimProgressBound()); + + bool foundMesh=false; + for(unsigned int i=0; igetMeshCount() ; i++){ + //printf("meshName=%s\n",unitModel->getMesh(i)->getName().c_str()); + if(model->getMesh(i)->getName()==meshName){ + const InterpolationData *data=model->getMesh(i)->getInterpolationData(); + const Vec3f *verticepos=data->getVertices(); + ups->setMeshPos(Vec3f(verticepos->x,verticepos->y,verticepos->z)); + foundMesh=true; + break; + } + } + if( foundMesh == false ) { + string meshesFound=""; + for(unsigned i=0; igetMeshCount() ; i++){ + meshesFound+= model->getMesh(i)->getName()+", "; + } + + string errorString = "Warning: Particle system is trying to find mesh'"+meshName+"', but just found:\n'"+meshesFound+"' in file:\n'"+model->getFileName()+"'\n"; + //throw megaglest_runtime_error(errorString); + printf("%s",errorString.c_str()); + } + } +} + void Unit::checkCustomizedUnitParticleTriggers() { if(currSkill != NULL) { checkCustomizedUnitParticleListTriggers(currSkill->unitParticleSystemTypes,false); @@ -4265,7 +4295,7 @@ void Unit::checkCustomizedParticleTriggers(bool force) { pst->setValues(ups); ups->setPos(getCurrVectorForParticlesystems()); ups->setRotation(getRotation()); - ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(ups); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -4296,7 +4326,7 @@ void Unit::startDamageParticles() { pst->setValues(ups); ups->setPos(getCurrVectorForParticlesystems()); ups->setRotation(getRotation()); - ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(ups); if(getFaction()->getTexture()) { ups->setFactionColor(getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0)); } @@ -4329,7 +4359,7 @@ void Unit::startDamageParticles() { ups->setColor(Vec4f(0.115f, 0.115f, 0.115f, 0.22f)); ups->setPos(getCurrBurnVector()); ups->setRotation(getRotation()); - ups->setUnitModel(getCurrentModelPtr()); + setMeshPosInParticleSystem(ups); ups->setBlendMode(ups->strToBlendMode("black")); ups->setOffset(Vec3f(0,2,0)); ups->setDirection(Vec3f(0,1,-0.2f)); diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 2aec01562..05a169b14 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -789,6 +789,7 @@ public: inline void setUsePathfinderExtendedMaxNodes(bool value) { usePathfinderExtendedMaxNodes = value; } void updateTimedParticles(); + void setMeshPosInParticleSystem(UnitParticleSystem *ups); virtual string getUniquePickName() const; void saveGame(XmlNode *rootNode); diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index a7d9fff56..1b1b0c102 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -377,6 +377,7 @@ public: float gravity; float rotation; const Model *unitModel; + Vec3f meshPos; string meshName; bool isVisibleAtNight; bool isVisibleAtDay; @@ -425,7 +426,8 @@ public: void setSizeNoEnergy(float sizeNoEnergy) {this->sizeNoEnergy= sizeNoEnergy;} void setGravity(float gravity) {this->gravity= gravity;} void setRotation(float rotation); - const void setUnitModel(const Model* unitModel) {this->unitModel= unitModel;} + void setMeshPos(Vec3f meshPos) {this->meshPos=meshPos;} + string getMeshName() {return meshName;} void setMeshName(string meshName) {this->meshName= meshName;} void setRelative(bool relative) {this->relative= relative;} void setRelativeDirection(bool relativeDirection) {this->relativeDirection= relativeDirection;} diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index c1a59d513..0fccd6227 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -1054,6 +1054,7 @@ UnitParticleSystem::UnitParticleSystem(int particleCount) : endTime = 1; unitModel=NULL; meshName=""; + meshPos=Vec3f(0,0,0); radiusBasedStartenergy = false; } @@ -1182,36 +1183,17 @@ void UnitParticleSystem::initParticle(Particle *p, int particleIndex){ p->pos.z = truncateDecimal(p->pos.z,6); } - else {// rotate it according to rotation + else { Vec3f combinedOffset=Vec3f(offset); - if(meshName!="" && unitModel!=NULL){ - //printf("meshName set unitModel given\n"); - bool foundMesh=false; - for(unsigned int i=0; igetMeshCount() ; i++){ - //printf("meshName=%s\n",unitModel->getMesh(i)->getName().c_str()); - if(unitModel->getMesh(i)->getName()==meshName){ - const InterpolationData *data=unitModel->getMesh(i)->getInterpolationData(); - const Vec3f *verticepos=data->getVertices(); - //printf("verticepos %f %f %f\n",verticepos->x,verticepos->y,verticepos->z); - combinedOffset.x+=verticepos->x; - combinedOffset.y+=verticepos->y; - combinedOffset.z+=verticepos->z; - foundMesh=true; - break; - } - } - if( foundMesh == false ) { - string meshesFound=""; - for(unsigned i=0; igetMeshCount() ; i++){ - meshesFound+= unitModel->getMesh(i)->getName()+", "; - } - - string errorString = "Warning: Particle system is trying to find mesh'"+meshName+"', but just found:\n'"+meshesFound+"' in file:\n'"+unitModel->getFileName()+"'\n"; - //throw megaglest_runtime_error(errorString); - printf("%s",errorString.c_str()); + if(meshName!=""){ + combinedOffset.x+=meshPos.x; + combinedOffset.y+=meshPos.y; + combinedOffset.z+=meshPos.z; + if(meshPos.x==0 && meshPos.y==0 && meshPos.z==0) { + printf("meshPosFail\n"); } } - + // rotate it according to rotation #ifdef USE_STREFLOP p->pos= Vec3f(pos.x+x+combinedOffset.z*streflop::sinf(static_cast(rad))+combinedOffset.x*streflop::cosf(static_cast(rad)), pos.y+random.randRange(-radius/2, radius/2)+combinedOffset.y, pos.z+y+(combinedOffset.z*streflop::cosf(static_cast(rad))-combinedOffset.x*streflop::sinf(static_cast(rad)))); #else @@ -1397,9 +1379,13 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { unitParticleSystemNode->addAttribute("cRotation",cRotation.getString(), mapTagReplacements); // Vec3f fixedAddition; unitParticleSystemNode->addAttribute("fixedAddition",fixedAddition.getString(), mapTagReplacements); -// Vec3f oldPosition; +// Vec3f oldPosition; unitParticleSystemNode->addAttribute("oldPosition",oldPosition.getString(), mapTagReplacements); -// bool energyUp; +// Vec3f meshPos; + unitParticleSystemNode->addAttribute("meshPos",meshPos.getString(), mapTagReplacements); +// string meshName; + unitParticleSystemNode->addAttribute("meshName",meshName, mapTagReplacements); +// bool energyUp; unitParticleSystemNode->addAttribute("energyUp",intToStr(energyUp), mapTagReplacements); // float startTime; unitParticleSystemNode->addAttribute("startTime",floatToStr(startTime,6), mapTagReplacements); @@ -1409,7 +1395,7 @@ void UnitParticleSystem::saveGame(XmlNode *rootNode) { unitParticleSystemNode->addAttribute("relative",intToStr(relative), mapTagReplacements); // bool relativeDirection; unitParticleSystemNode->addAttribute("relativeDirection",intToStr(relativeDirection), mapTagReplacements); -// bool fixed; +// bool fixed; unitParticleSystemNode->addAttribute("fixed",intToStr(fixed), mapTagReplacements); // Shape shape; unitParticleSystemNode->addAttribute("shape",intToStr(shape), mapTagReplacements); @@ -1461,6 +1447,14 @@ void UnitParticleSystem::loadGame(const XmlNode *rootNode) { fixedAddition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("fixedAddition")->getValue()); // Vec3f oldPosition; oldPosition = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("oldPosition")->getValue()); + // Vec3f meshPos; + if(unitParticleSystemNode->hasAttribute("meshPos")){ + meshPos = Vec3f::strToVec3(unitParticleSystemNode->getAttribute("meshPos")->getValue()); + } + // Vec3f meshName; + if(unitParticleSystemNode->hasAttribute("meshName")){ + meshName = unitParticleSystemNode->getAttribute("meshName")->getValue(); + } // bool energyUp; energyUp = unitParticleSystemNode->getAttribute("energyUp")->getIntValue() != 0; // float startTime;