From a3b863462109f1f72c8cc0dda75a6b2328b8d773 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 1 Jun 2024 14:19:45 +0300 Subject: [PATCH] unit weapon VFX generation --- Assets/Scripts/GameObjects/Units/unitData.lua | 23 ++++++++++- unit.cpp | 41 +++++++++++++++++++ unit.h | 3 ++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 1193310..830d92a 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -53,7 +53,28 @@ structurePrefix = modelPrefix .. "Units/Structures/" units = { { - weapons = {{type = WeaponClass.HITSCAN, rateOfFire = 100, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 50, maxRange = 10}}, + weapons = { + { + type = WeaponClass.HITSCAN, + rateOfFire = 100, + maxRange = 10 + damage = 50, + fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', + fireVfx = { + --[[ + { + model = '', + texture = '', + duration = 20, + pos = {x = 0, y = 0, z = 0}, + rot = {w = 0, x = 0, y = 0, z = 0}, + } + ]]-- + } + hitVfx = { + } + } + }, unitClass = UnitClass.WAR_MECH, unitType = UnitType.LAND, armor = {ArmorType.MECHANIC}, diff --git a/unit.cpp b/unit.cpp index fa743ed..1f6866c 100755 --- a/unit.cpp +++ b/unit.cpp @@ -39,6 +39,13 @@ namespace battleship{ string sfxPath = weaponTable["fireSfx"]; fireSfx = GameObject::prepareSfx(fireSfxBuffer, sfxPath); + initProjectileData(weaponTable); + + initFx(weaponTable, "fireVfx"); + initFx(weaponTable, "hitVfx"); + } + + void Unit::Weapon::initProjectileData(sol::table weaponTable){ string projTableKey = "projectile"; sol::optional proj = weaponTable[projTableKey]; @@ -65,9 +72,43 @@ namespace battleship{ projPos = Vector3(posTable["x"], posTable["y"], posTable["z"]); sol::table rotTable = weaponTable[projTableKey]["rot"]; projRot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]); + } } + vector Unit::Weapon::initFx(sol::table weaponTable, string vfxKey){ + vector vfxNodes; + + sol::table vfxTbl = weaponTable[vfxKey]; + int numVfx = vfxTbl.size(); + + for(int i = 0; i < numVfx; i++){ + Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); + + if((std::optional)vfxTbl["texture"] != sol::nullopt){ + string p[]{vfxTbl["texture"]}; + Texture *tex = new Texture(p, 1, false); + mat->addBoolUniform("texturingEnabled", true); + mat->addTexUniform("diffuseMap[0]", tex, false); + } + else{ + sol::table colorTable = vfxTbl["color"]; + mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["a"])); + mat->addBoolUniform("texturingEnabled", false); + } + + Model *flashModel = new Model((string)vfxTbl["model"]); + flashModel->setMaterial(mat); + unit->getModel()->attachChild(flashModel); + + sol::table posTable = vfxTbl["pos"][i + 1], rotTable = vfxTbl["rot"][i + 1]; + flashModel->setPosition(Vector3(posTable["x"], posTable["y"], posTable["z"])); + flashModel->setOrientation(Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"])); + } + + return vfxNodes; + } + Unit::Weapon::~Weapon(){ if(fireSfx){ fireSfx->stop(); diff --git a/unit.h b/unit.h index 53d78ab..883f588 100755 --- a/unit.h +++ b/unit.h @@ -103,7 +103,10 @@ namespace battleship{ Unit *unit = nullptr; sf::SoundBuffer *fireSfxBuffer; sf::Sound *fireSfx = nullptr; + std::vector fireVfxNodes; + void initProjectileData(sol::table); + std::vector initFx(sol::table, std::string); inline bool canFire(){return vb01::getTime() - lastFireTime > rateOfFire;} };