Development post #8
A lot of information in this post. I'll try my best to not turn it into a saga (it took me over 3 hours to write, had to take a day break before finishing it up too lol). I'd say this part in the process will be the most interesting to many seeing as its damage and its visually spectacular in terms of what the player sees. As cars crash and flip over eachother the car itself is transformed from a pristine body to a crumpled up wreck. The cost of getting working damage for a mod is pretty tedious and to make it more realistic looking requires a lot more coding work as well to hook it all up. One fun fact is the above screenshots from my last dev post actually had working damage in the build. I never showed any cars crashing of course but I was working on damage while typing out the LOD post actually.
The first thing I had to do was take my L1 (Lod 1) body and copy it. I make this copy my new 'damage model'. Before I can make any damage I need to split up the body into more pieces though. Any pieces I want removed after extreme damage or removed by the pit crew these need to be separated from the rest of the body. I've color coded all the separate parts so you can see what it looks like. I also attached the inner shell body to each piece so when they are removed those go with it:
Each piece I had to rename as well to something standard. Every part will need to be referenced in the code several times so it is best to name all the parts something easy to copy and also replace certain keywords for the other damage LODs later on. If you setup clean code and naming conventions it goes a long way when you have to copy/paste multiple lines over and over replacing certain words and dong quick edit to a single piece of the car if a change is made. I do this same practice with my folders and model names when I 3D model in-case I need to pull one out or replace a certain model with an older/newer version.
While not shown, I copied all the interior pieces as well and renamed them to something damage related as well. Since the car will wreck and pieces come off the interior sections like the rear and engine area will be more visible so its important these follow the damaged body and are not clipping through them.
Once I have all my new models separated how I like its time to begin applying damage. There are two ways I know of doing this. One way is to copy again my damage meshes and then mess around with the topology on every model making it look damaged. This way I have a damaged piece and a non-damage piece that are the same exact topology. The other way, how Cosmin did it for his mods is using a lattice modifier and using keyframes between a non-damaged and damaged state of the same mesh between frame 0 and frame 1 on the timeline. If find the lattice approach way easier since its a live modifier I can edit and adjust over time.
To do this I just select my models I wish to be damaged and apply a FFD box modifier in 3ds max to them. I raise the control points up higher so there are a lot more of them as well so you have a cage of points around your model like this:
I'm pretty familiar with lattice effect from when I used to use Maya as my primary 3d application. By moving the control points your mesh pieces will follow them depending on where you push and pull the points. Lattices are a great way to bend, morph, and contort a mesh that would be a lot more difficult to do by manually moving each very by hand. Before I start messing the model up I have to set my keyframe to auto mode and move to frame 1 on the timeline. If I don't then changes will be made to the model on frame 0 and I don't want that. Frame 0 is where the model will retain its original shape and frame 1 is where all the changes to the shape of the meshes will occur. This way I have created a destination between the same mesh. Once I am ready I just move around the model pieces on frame 1 until I have something like this on every part:
I probably made it look simple but it takes some time researching car body damage, being creative in how you want it to look 'crushed', and also double checking no interior parts are clipping through the outer body. I actually ran into a dumb problem as well with 3ds max 8 that wasted nearly a full day where the lattice performance was so slow I couldn't edit much without extreme viewport lag. Since Max 8 is a very old program its not very good using new pc hardware. Thankfully I found the issue and it turned out the viewport renderer had to be set to software mode instead of using direct X 9. I bring this up because many would run into an issue like this and then just say "welp fun while it lasted, guess the program doesn't work, time to give up". You must not do that, look into the program, search for help, look at the tool settings, try different settings, or try alternative tools to get the results you want then import it into the older program version. I had come too far and had the perfect models set up with the lattice ready to edit to just give up and assume there was nothing I could have done about it. I can guarantee in all years of modding some of the biggest roadblocks you hit when making a mod for every game turns out the be the stupidest things that seem impossible to fix but then you find the 'fix' and it is usually some very tiny dumb setting or process and everything becomes unblocked again. I once had a weapon animation issue in Fallout 4 that took me a week to figure out and it turned out to be a single node of the characters hand that I needed to parent to another bone on the skeleton and everything finally worked as expected. All I am trying to say here is if you really care and want to make a mod push through adversity and find a solution or workaround. You'll not only feel great when you get things working but also be more confident and better equipped when the next issue arises and eventually each issue you hit is just going through the motions of mod making.
Back on topic through once I have the damaged state done I ended up either something like this between both frames:
That is all great but this is just the visual representation of what I want the car to look like as it gets damaged for the mod. Now I have to do the code to tell the game this is what each piece will look like. I also have to signify in the code where each piece belongs and as the car is being contacted by walls and other cars the game knows where the car should start taking damage while also not being damaged in the other sections. Next I have to clarify in the code several parts that I want to fall off from extreme damage or to be eventually removed by the pit crew if the damage is bad enough. If that is not enough I then need to redo the work for all of the other damage LODs as well. To top it off for that extra flair and realism I need to add visual damage like scrapes and tire doughnut marks to the sides of the car so it looks like it actually hit something and paint is worn off. That is not all though, throughout this entire process a lot of crash testing is needed in-game to ensure the parts deform as expected but also performance is retained.
To start in the code I need to call each mesh from my scene and define what it is. For this example lets use the hood:
Code:
make0_hood_L1_ud: MESH maxCars make0_hood_L1_d frame 0
make0_hood_L1_d: MESH maxCars make0_hood_L1_d frame 1
The first line is my non-damaged hood mesh, as it sits frame 0 in my 3ds max timeline. The second line of code is the damaged mesh which sits on frame 1. The same mesh is used twice (hence why you see it referenced in each line of code). Other than the frame difference between each line I call each line a different name for the same mesh. I used 'ud' at the end of the first line (for me its an abbreviation of 'undamaged'). Then for line 2 I add just 'd' at the end (for damaged). You can name your meshes anything you want, I just made it something simple and easy to understand. I Also added in the name the Lod level which in this case is L1 so when I do the other lods I can easily replace L1 with any other lod level.
Once the meshes are called and I've given them a 'name' the code understands I now have to tell them what this mesh actually is how to be damaged. For that I use a damage morph. The damage morph is a line of code that sets a source mesh (the undamged) to a destination mesh (the damaged one). This way the mesh will transition from undamaged to damaged. Next I need to tell the code this is a hood:
Code:
L1_make0_hood_damaged: REGION_MORPH make0_hood_L1_ud Destination make0_hood_L1_d Regions (hood_bbox hood_damage 8 0)
As you can see in the code above I called this morph L1_make0_hood_damaged for my make 1 body and its at lod level 1. Again, you can name you morphs whatever you want, I highly recommend making them easy to remember and also displaying any vital info (important to you) so you know what you are looking at in the code of your mod so when you see something go wrong in the game you know exactly what line of code in your file might be the culprit. No one else (unless you are on a mod making team) is going to see this code so as long as you know what you are looking at with a quick glance that will suffice. If you can't remember what in your code is "model_660_damage_part_2_section10" because you did poor naming conventions then you are in for a world of hurt and wasting a ton of time. Clean code is just as important as making good models and textures even if no one sees the code.
After I gave it a name you can see the next section as REGION_MORPH make0_hood_L1_ud Destination make0_hood_L1_d using the region morph I first put my undamaged mesh frame and after the destination put my damaged mesh name. This tells the code that the mesh morph will transition from the ud (undamaged) to the d (damaged) mesh. The last part I have to do is clarify the region this mesh belongs to on the car along with its corresponding bounding box. Regions (hood_bbox hood_damage 8 0) Here I say the region used in parenthesis is my hood bounding box (hood_bbox) and it will go with the hood_damage at 8 0. The numbers at the end are hardcoded and cannot be changed. Every section of the car has a different number code, you can find this along with a full damage tutorial over at The Pits.com. The bounding boxes are literally just cubes in my 3ds scene that encompass each section of the car, they define the region of the different car parts.
After this the hood will now technically damage as you ram into other cars or walls fast enough. Also if its not damaged enough the pit crew can repair it. Ever been on pit road with your car and noticed the damaged hood slowly start to mold back to a repaired state? That is the damage morph working in real time right in front of you. The game is pretty much telling the hood to go back to its original state until 'repairs' are complete.
This is not all that is needed for the hood though, we need an extra line of code to now tell it we want this piece (the hood) to not only receive damage but also come off when its gets damaged too much. To do this we need this code next:
Code:
L1_make0_hood_damaged_removed: STATE_SWITCH VAR hood_removed ( 0 L1_make0_hood_damaged, 0.9 )
Here we create a state switch variable which says to remove the hood section of our damage hood region morph. I gave this line of code the name of L1_make0_hood_damaged_removed while the damage is named L1_make0_hood_damaged without the _removed at the end. So now I have the damage and a removable piece. The 0.9 I believe states when this piece reached .9 damage it will be removable. This number is hardcoded and can't be changed, every removable piece uses 0.9 so its easy to remember. You can make as many (or less) pieces on your mod come off. If for some reason you wanted the entire roof to fall off you could. I kept mine realistic and only made the hood, front, corners, and rear piece fall off. Every other section will just get really damaged but will never come off the car.
After this its just the same process for every single other piece. For my mod there are 18 separate meshes which equals 36 damaged + undamaged versions between the frame 0 and frame 1 just for LOD 1. So much fun coding is ahead. I pretty much clarified what each piece is, where it belongs on the car, is it removable or not and also what bounding box it belongs with. You can use multiple car sections in a region as well to share between a piece. For example on the rear I can have it take damage from the rend_damage region and the chassis_damage if I want. As long as you set up your regions correctly and it looks good in game its up to you. The main thing you want to avoid is like if your car's hood hits a wall but the rear end never touches it and that section just doesn't morph into a damaged state for no reason.
After every single piece is clarified you then need to group them into a LOD 1 group just like I would for the non-damaged LODs:
Code:
L1_make0_DAM: GROUP ( lf, rf, rr, lr, flaps_roof_lod, shared_hood_flaps_removed, flaps_deck_lod,
L1_make0_hood_damaged,
L1_make0_rear_end_damaged,
L1_make0_decklid_damaged,
L1_make0_front_bumper_damaged,
L1_make0_LF_damaged,
L1_make0_RF_damaged,
L1_make0_LR_damaged,
L1_make0_RR_damaged,
L1_make0_body_damaged,
L1_make0_body_top_damaged,
L1_make0_banner_damaged,
L1_make0_parts_damaged,
L1_make0_engine_damaged,
L1_make0_rollcage_damaged,
L1_make0_chassis_damaged,
L1_make0_windows_damaged,
L1_make0_interior_damaged,
L1_make0_interior_top_damaged,
L1_vis_dmg_left_damaged,
L1_vis_dmg_right_damaged,
L1_vis_dmg_roof_damaged,
L1_vis_dmg_rear_damaged)
L1_make0_DAM2: GROUP ( lf, rf, rr, lr, flaps_roof_lod, shared_hood_flaps_removed, flaps_deck_lod,
L1_make0_hood_damaged_removed,
L1_make0_rear_end_damaged_removed,
L1_make0_decklid_damaged,
L1_make0_front_bumper_damaged_removed,
L1_make0_LF_damaged_removed,
L1_make0_RF_damaged_removed,
L1_make0_LR_damaged_removed,
L1_make0_RR_damaged_removed,
L1_make0_body_damaged,
L1_make0_body_top_damaged,
L1_make0_banner_damaged,
L1_make0_parts_damaged,
L1_make0_engine_damaged,
L1_make0_rollcage_damaged,
L1_make0_chassis_damaged,
L1_make0_windows_damaged,
L1_make0_interior_damaged,
L1_make0_interior_top_damaged,
L1_vis_dmg_left_damaged,
L1_vis_dmg_right_damaged,
L1_vis_dmg_roof_damaged,
L1_vis_dmg_rear_damaged_removed)
You will notice I have 2 similar looking LOD groups. The main difference is the bottom one I have replaced the damaged pieces with their 'removed' variable. This will tell the game if any piece is removed then use this LOD group so the piece will no longer appear in the LOD. If this was not done then when you see AI cars have parts removed they wouldn't actually disappear because they are still using a LOD group that contains the visible mesh still. This same process needs to be done for L3, L5, L7 and L9 lods.
///A 'quick' sidestep about LODs for the damaged mod///
As I mentioned previously LODs still need to be made for the damage pieces. My previous dev post I go over LODs, I do a similar thing where I lower the mesh resolution for each damaged lod state. The main difference with the damage meshes is I keep more parts at farther distances since you will see the inner section more due to damage. Also, these lods need the lattice modifier still applied between frame 0 and 1 so they have damage. Its pretty much a ton of copy and pasting making sure each model is named the same thing except for the lod it signifies. Here are all the lods for damage in my 3ds max scene I had to make. Yes, every single piece had to have a unique name, had to be lowered in resolution for each lod and has the lattice modifier applied:
I couldn't even get a screenshot that fits all of the un-collapsed groups, it only went to L5 before getting cut off but you get the point. This is a LOT of work and this is only for make0 of the mod. I hope this one screenshot really shows you the gravity of the situation when it comes to how much is really needed and what those modders went through when making you a mod. Its honestly boring work for the most part. For you though, when making a mod, boring is good. It means you at least know what to do and that is always a far better situation than being stuck not knowing how to making a mod. Anyways lets get back to where we were now that you know LODs are also a crucial step with the damage meshes as well.
///ok back to the code continued///
Last but not least we have to tell the code where this all fits in after we've done every LOD:
Code:
Exterior_make0_DAM: STATIC_LOD ( 0 L1_make0_DAM,
2.0 L3_make0_DAM,
4.5 L3_make0_DAM,
6.8 L5_make0_DAM,
9.2 L5_make0_DAM,
12.3 L7_make0_DAM,
16.4 L7_make0_DAM,
20.0 L9_make0_DAM,
30.5 L9_make0_DAM,
48.2 Exterior_make0_L11,
70.0 Exterior_make0_L11
)
Exterior_make0_DAM2: STATIC_LOD ( 0 L1_make0_DAM2,
2.0 L3_make0_DAM2,
4.5 L3_make0_DAM2,
6.8 L5_make0_DAM2,
9.2 L5_make0_DAM2,
12.3 L7_make0_DAM2,
16.4 L7_make0_DAM2,
20.0 L9_make0_DAM2,
30.5 L9_make0_DAM2,
48.2 Exterior_make0_L11,
70.0 Exterior_make0_L11
)
Again, we have 2 LOD groups because one contains all the LOD states for each lod level with all the damaged parts. The other contains all the damaged parts with the removed damaged pieces. One thing to point out is I didn't need a L11 for damage because the car is so far away you can't see it anyways so I just used my L11 non-damaged LOD again. This saved a bit of time which was nice. After this we now we contain our LOD groups into the damage state switch variable:
Code:
Make0DAM: STATE_SWITCH VAR damaged (0 Exterior_make0, 1 Exterior_make0_DAM, 2 Exterior_make0_DAM2, 2.9)
This switch tells the game the moment your car hits another car or object hard enough to switch from the undamaged meshes to the damaged. Then if pieces will fall off or are removed by your pit crew to switch to the damaged removed LOD group. If you have ever been racing and tapped a wall slightly but just hard enough to incur damage you might have noticed a slight shift in lighting or mesh shape to the car if you were racing on like the hood cam really close to the car. What you just witnessed was this state switch in action telling the game "ok this joker hit the wall, switch his/her car model from the undamaged version to a damaged one". I remember seeing this as far back as Nascar Racing 2 but until making a mod myself never actually understood what the 'magic' was happening under the hood (no pun intended). Game creation is all about magic really. Its making things appear one way or another and having code create those 'effects' pretty much. This above switch I just need one for now but as I make the bodies for make 1, 2, and 3 I will need a state switch and damage for all of them to group into as well.
After this we finally reach the final output for our damage and group it to the state switch that tells this game this is our exterior view models when you use the hotkeys in game to switch to anything other than cockpit view. We used the same thing for the non-damaged model except now that I have damage models contained in this exterior view code as well:
Code:
extViewB: STATE_SWITCH VAR carMakeIdx (0 Make0DAM, 1 Make0DAM, 2 Make0DAM, 3 Make0DAM, 4)
extView: GROUP (extViewB)
The numbers signify the different car makes. Because I just have one now I've copied my Make0DAm to 1, 2, 3 and 4 car bodies. If I didn't the if you created a car for the other body types no car would appear in the game. As I get the other car bodies in game they will replace the make0 for the other numbered slots.
Now hold on sunshine, I know what you are thinking: "its time to see that damage in the game!" but not yet. I still have one final thing to do which is create visual damage on the car body so it looks like it has paint scrapes and tire marks. While this isn't required the mod looks so much better and realistic with it and most mods have these included so I'm not about to skip out on that feature. In most people's code from the modders that have shared theirs with me I see they call it 'scrapers'. Scrapers is simply a slight of hand trick where when the mod goes to a damaged state you slip a mesh on the sides, roof, and rear (or wherever else you may want it) to the car. These are just simple mesh planes that will contain a texture that looks like damage. At first these meshes don't appear but as the car gets more damaged and the car body crumples inward more the damaged scrape meshes will appear. Here are the 'scrapers' or as I like to call mine vis_dmg (visual_damage) meshes look like:
As you can see I made one for the sides, roof, and rear of the car. They are just flat plane meshes that I UV unwrapped on a single texture so I can paint the damage effects on them.
To make the textures I just created them from plain layers in affinity photo like I did with most of my textures for this mod. For the paint scratches I painted long paint lines. Then using several filters such as motion blur, displacement, and dust/scratches I gave it that scratched look. For the doughnut marks I made a circle layer and again used several filters to give it that tire mark look. For the extra touch I erased section of it and then duplicated it and rotated it around a bit so there were multiple different looking tire marks. The layer is transparent as well so any sections the scratches and tire marks don't appear you will be able to see the original paint scheme. Without transparency on here is what it looks like applied to the car:
You can see how I have treated my visual damage mesh the same as the car body and applied a lattice to it so it conforms to the shape of the damaged car. This ensures that as the car shape changes from damage the visual damage mesh never appears like its floating away from the car. Also for the rear section since this gets removed I had to also put in the code that this is removable and should go with the rear end when it falls off. If I didn't then you'd see no rear end piece but floating scrapes.
Thankfully I didn't really run into any major errors when compiling the first time. I hit one snag where I accidentally referenced my visual damage mesh for every lod instead of sharing it for all of them but other than that it went smoothly. Now that it is all done and said its finally time to go in the game and see the results what I am sure you've all been waiting for:
This section of the mod was the part where the code really got heavy. Before adding any damage my code for just one non-damaged body and was a little over 1000 lines. Now that I have damage for that same single body the code is 2600+ lines. Once I add the other bodies in its probably going to be anywhere from 8000 to over 10,000 lines. Along with the code getting larger the list of bugs found also increased:
I've fixed everything at this point minus one little cosmetic deal that isn't that important right now. Still lots of issues and all sorts of different type of issues have arisen already in development. Things may look like they are always going smooth from these posts but there is always something to fix even when making the mod in progress. I have no doubt the list of bugs will increase as I add the 3 other makes in.
At this point this pretty much concludes make0 for the exterior, it has all the functional workings needed for a 'complete' car in a mod pretty much. The next step that I've already began is modeling the front noses of the 3 other makes and almost starting over the entire process. I'll save the details of the other 3 car makes for another post. This damage one is already so huge.