[CSM]Armoreffects/Damaged LOD's Tutorial

Lots of cool and useful tips to mod either serverside or clientside
Post Reply
User avatar
Senshi
Posts: 697
Joined: Sun Oct 18, 2009 1:14 pm
Location: Germany
Contact:

[CSM]Armoreffects/Damaged LOD's Tutorial

Post by Senshi »

[CSM]How to have different meshes for one object in dependancy of hitpoint value

This is a client side modding and cannot be performed serverside. Changes are made to standardmesh.rfa, objects.rfa and optionally texture.rfa

Required: 3DS Max/Gmax with installed Battlefield Tools + BMDT ; basic modding knowledge will be helpful...

This tutorial will explain how to include several meshes for one object/vehicle, which will be visible ingame dependant on the current hitpoints the object has left.
Basic field of application would be to have several visible damagestates for e.g. a tank, the less HP it has, the more smashed up it will look. Of course, there are hundreds of other possible applications, like damagestates for static objects like buildings, damagestates for soldiers (e.g. injured people are visibly injured, bleeding and having torn clothes)


The example vehicle used will be the M10. It is necessary to make BACKUPS of all files altered during this tutorial to be able to quickly reverse to original...
I also assume you have extracted the objects.rfa, standardmesh.rfa and optionally texture.rfa (for those who want to use different textures for their damaged meshes) for easier editing. Working from archives directly is just no good.

These quote boxes are more elaborate explanations on How-Tos, but not needed necessarily for experienced modders
These quote boxes are background explanations, not needed to achieve the desired results, but helpful for understanding the concept of this method

STEP 1: Preparing the intact standardmesh I

This step is pure 3D Modeling.

First, start up Gmax/3DS Max

Use "Model Import", make sure these options are checked: BOUNDING BOX, COLLISION, VISUAL, SHADOW, Scale 100% . Everything else should be unchecked!

Then press IMPORT... and import "m10_hull_m1.sm" This is the standardmesh which includes the hull of the M10, excluding tower and tracks

Now replace "Lod01_m10_hull_m1-1" with a simple box or plane or whatever something that certainly will stay invisible nonetheless and name it exactly the same: "Lod01_m10_hull_m1-1".

Now go into a viewport and use "Select by Name", in the menu opening select the "Lod01_m10_hull_m1-1", click "INVERSE", then "SELECT". Now right-click into a viewport and choose "Hide selection". Now you should only see the main visible LOD mesh

Delete it.

Create a very small "simple primitive plane" and name it exactly "Lod01_m10_hull_m1-1" like the one you just deleted.


Now open "Model Export" in the BF Tool dropdown

Choose "Use object names for export", make sure ALL other options left are UNchecked.

Now reexport it and overwrite the original "m10_hull_m1.sm".

We just removed the LOD01 model from the standardmesh. If you would now startup the game and test the M10, the hull would be invisible when close up (or rather, only the simple plane/box would be shown we replaced it with) and only be visible from greater distance as the LOD02-LOD06 visible models are still included, as well as the collision models.

This is desired, because we are going to add the LOD01 via the Armoreffect-option and thus can make sure to disable the "intact" mesh when we want to replace it with the "damaged" one when the vehicle reaches low hitpoints.




STEP 2: Preparing the intact standardmesh II

This step is pure 3D Modeling.

Open a new project in 3DS Max/Gmax.

Use "Model Import", make sure these options are checked: ONLY MAIN VIS LOD, VISIBLE . Everything else should be unchecked!

Then press "IMPORT..." and import your BACKUP "m10_hull_m1.sm"

Make sure you now only have the model "Lod01_m10_hull_m1-1" selectable

Now export this using "Use object names for export" (make sure ALL other options left are UNchecked) as "m10_hull_intact"

This standardmesh now only includes the LOD01 mesh the standardmesh we made in STEP 1 is missing, so they will be perfect again when united ;) . Only this time they will not be united in a standard mesh, but via our glorious BF42 engine and of course, our glorious object code!


STEP 3: Preparing the damaged standardmesh


This step is pure 3D Modeling.

You can continue from step two here. If not, either you can go nuts modeling a damaged LOD01 mesh yourself and continue here, or make sure you have imported the BACKUP "m10_hull_m1.sm" with the options ONLY MAIN VIS LOD, VISIBLE checked. Everything else should be unchecked!

Now you have a wonderful, single, intact LOD01 mesh.

Single is good, intact is not. We want damage! Badass damage! Just bombard your mesh with whatever skills you got and smack it up pretty good, so it will appear pretty banged up ingame too. Theoretically, there are no limits here!

You are completely free to use custom textures for your damaged mesh, just make sure you set them up properly and put the new textures in your texture.rfa . I won't cover this in this tutorial as this is basic stuff covered in dozens of tutorials

Once you are done, we again export using the previous settings: "Use object names for export", everything else UNCHECKED. Name it "m10_hull_damaged1"

Depending on how many damagestates you want, you now could repeat this step as often as you wish and each time save a new standard mesh, for sake of simplicty call it "m10_hull_damagedx", x is the variable counting up here.


STEP 4: Setting up the geometries.con

Open up the Objects/Vehicles/Land/M10/geometries.con with a text editor.

Now enter this at the bottom:

Code: Select all

GeometryTemplate.create StandardMesh m10_hull_intact
GeometryTemplate.file m10_hull_intact
GeometryTemplate.hasDynamicShadow 1

GeometryTemplate.create StandardMesh m10_hull_damaged1
GeometryTemplate.file m10_hull_damaged1
GeometryTemplate.hasDynamicShadow 1
If you have more damage standardmeshes, just continue this list

Then save&exit

These lines of code make sure BF42 loads the sm-files we created when the M10 is used on a map and labels them for usage in the objects.con. This is a basic necessity whenever you want to add geometries to an object. Setting DynamicShadow 1 is required as we have a vehicle which will be moved, so it obviously will have a moving/dynamic shadow too, unlike buildings.


STEP 5: Setting up the Simple Objects

Open up the Objects/Vehicles/Land/M10/objects.con with a text editor.

Enter this at the bottom:

Code: Select all

ObjectTemplate.create SimpleObject M10Intact
ObjectTemplate.geometry m10_hull_intact

ObjectTemplate.create SimpleObject M10Damaged1
ObjectTemplate.geometry m10_hull_damaged1
Again, expand as required if you have more damagestate meshes.

Save&exit or continue with step 6.

Really, really basic, but necessary stuff. Not much else to say...


STEP 6: Setting up the armoreffects

Only if you do not continue from step 5: Open up the Objects/Vehicles/Land/M10/objects.con with a text editor.

Search for

Code: Select all

ObjectTemplate.addArmorEffect 50 e_PanzDamage 0/1/-1.4
Should be pretty much at the top.

Now replace all ObjectTemplate.addArmorEffect lines with this segment:

Code: Select all

ObjectTemplate.addArmorEffect 100 M10Intact 0/0/0
ObjectTemplate.addArmorEffect 50 M10Intact 0/0/0
ObjectTemplate.addArmorEffect 50 e_PanzDamage 0/1/-1.4
ObjectTemplate.addArmorEffect 30 M10Damaged1 0/0/0
ObjectTemplate.addArmorEffect 30 e_PanzDamage 0/1/-1.4
ObjectTemplate.addArmorEffect 12 e_PanzFire 0/1/-1.4
ObjectTemplate.addArmorEffect 12 M10Damaged1 0/0/0
ObjectTemplate.addArmorEffect 0 e_ExplGas 0/0/0
ObjectTemplate.addArmorEffect 0 e_scrapmetal 0/0/0
ObjectTemplate.addArmorEffect -1 WaterWaterExplosion 0/0/0

Explanation of code parameters: ObjectTemplate.addArmorEffect 100 M10Intact 0/0/0
ObjectTemplate.addArmorEffect HP_value Name_of_object/effect Relative_position_from_center_in_X/Y/Z


Use a HP value of your choice to engage damaged meshes, make sure to use 0/0/0 coordinates. If you have multiple damagestate meshes, set them also up as it pleases.

Save&Exit

The M10 has 100 hitpoints, so when we add an armor effect at 100 HP, it will be visible right from the moment it spawns. It is important you use the exact same hitpoints value as the object initially has! Look it up a few lines above at

Code: Select all

ObjectTemplate.hitpoints 100
As we basically add the LOD01 mesh we of course want it to blend perfectly with the model, so we obviously choose 0/0/0 coordinates.

A basic function of ArmorEffects are that previous armoreffects are disengaged when a new one is started. So when our M10 reaches 50 hitpoints, normally it starts having light grey smoke (e_PanzDamage) on the top back (0/1/-1.4).
Normally, now the M10intact effect would disengage and the hull would become invisble again. To keep the hull, we have to reengage M10Intact, as effects which are launched simulatenously at the same HP value stay :) .

In our example i want the M10Damaged1 mesh to appear when the M10 only has 30 HP left, meaning it's pretty battered up already. So there is the M10Damaged1 effect! Now this would disengage the grey smoke, so we reengage e_panzdamage again simulatenously.
At 12 HP the tank starts to catch fire and becomes immobile (look up ObjectTemplate.criticalDamage 12 to get this value), and as this is clearly another effect (e_Panzfire), we have to reengage M10Damaged1 again.
Now when the M10 has 0 HP left there are two effects (e_Explgas and e_scrapmetal), but when a vehicle reaches 0 HP automatically the Wreck standardmesh is used, so obviously there's no need to reengange our M10Damaged1.[/i][/color]

STEP 7: Wrapping things up

Well, the usual. Pack your things up in nice and tight rfas! Remember you can use patchfiles for standardmesh.rfa and texture.rfa (e.g. standardmesh_00x.rfa , x=variable natural number, count up from 0).

That's it! Now you are good to go and should do ingame tests to see if it really works and dance in joy. ;)


Addendum: Theoretical Possibilities
The addArmorEffect is not limited to effects and staticmeshes, so it is possible to code in pretty much whatever you want and position it relative to the vehicle, e.g. small objects falling off...of course, as long as these objects have no mobilephysics, they are bound to their relative position with the tank! But for adding a nice extra touch there are almost endless possibilites. Of course this only makes sense if you need something dependant on a certain HP value.

Also this method only makes changes to the visual model, no matter how much you change that, the Collision models are the same, as are the armor materials etc., so if you have an extremly distorted or elaborate damage standardmesh this won't fit in that well. If you alter the first steps a bit you can of course also include the COL-models into your armor effect-meshes. Just replace it along with the LOD01 during step1, import it together with the LOD01 in step02 and resave it together with the LOD01 seperatly. Now do this for step03 too and of course, you could alter the COL-models there along with your LOD-mesh.
Of course you also could simply add "ObjectTemplate.setHasCollisionPhysics 1" to the simpleobject you create, but that would cause high extra perfomance drop as BF42 would have to render the elaborate high-poly-LOD01 mesh for collisions too instead of the very low-poly extra COL-model.

Of course, there's all sorts of completely useless but funny crap you can do with these possibilites too, but I leave that to the crazy guys and try to focus on possible practical uses ;)
Credits go to mrhowdoimod for the glorious intial idea of using armoreffects for this and me, Senshi, for working out his idea to full usability and writing this tutorial ;)
Post Reply