• Welcome to SC4 Devotion Forum Archives.

Tutorial: MODding rendered SC4Models

Started by Chrisim, March 09, 2008, 03:00:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chrisim

Imagine you wish to modify a rendered model (a ".SC4Model" file) without re-rendering after changing in Gmax or 3dsMax. In most cases, it will be easier to return to the Gmax model and re-render it. But under certain circumstances, SC4Models can be changed, repaired or improved. For example, when the original Gmax model is lost or Gmax produces corrupt files. And there are a few tricks that can be achieved only with such techniques. However, it is a time-consuming technique- so returning to Gmax and to re-render the model is usually the faster solution.

When I started trying to understand how Sim City 4 custom contents works, I began at the end: analysing existing model, desc, lot and dat files with the Ilive Reader and SC4Tools. Then, I played around and changed certain bits and pieces and over a period of several month, I gained some knowledge that I wish to share with the community. The descibed technique is not new, well known to few experts only and apparently not well known to many and apparently not published as tutorial. I believe that there is much that can be done and hopefully a few of you may catch some of the ideas that will hopefully result in new interesting models for our beloved game.

This is a MODding tutorial for advanced users. It is not for beginners!
It is not B.A.T. tutorial - we already have a rendered model saved in a ".SC4Model" or ".dat" file. It is also not a LOT tutorial.
The Reader and also FiSHMan are required tools for this technique, SC4Tools is useful, too. Being familiar with these tools would be helpful.

When you change the SC4Model of another author, there is a copyright issue. You must always get the permission of the original author before you publish a modified version.

Table of Contents
1. Appetizer
2. Basics about S3D and FSH
3. More on FSH texture files
4. More on S3D Model files
5. Workflow: Scale or shift Models
6. Workflow: Repair Models

Chrisim

#1
Scaling models:
You downloaded a building that, in your opinion, is too large. Simply scale it:
Left: Original Eiffel tower by JEC, 8x8 tiles:
Right: scaled to 75%


The Original is wonderful, but in my opinion a bit too large. With the technique described in this tutorial, N1_2888 from the SFBT scaled it to 6x6 and reduced its height to 75% of the original (for private use, not released to the public)

Incomplete models:
Vienna's Votivkirche by Debussyman was not displayed in zoom 1.

With this technique, zoom 1 was restored (update is available on the LEX)

Model/texture changes:
Extension of Marrast's Avenue Underpasses for trams (GLR)

(not released yet, I am working on more extensions, it will take another few months)

Complex changes to existing models
Example: bending the straight motorway 3D model into a smoothly curved motorway model

This model is just the preview model, only the very first step of many steps that would be necessary to create smoothly curved motorways for the NAM. If there is a SC4 curved motorway fan with both modding and programming experience please contact me.

I believe that further fascinating effects will be possible, like ghost effects by mixing in a modified model for the night view or shifting models partly below the surface.

Chrisim

#2
Before starting to describe the technique of MODding rendered SC4Models, it is necessary to explain some of the basics about S3D and FSH files that are included in SC4Model files.
As example I use the SC4Model file from the SFBT Aral Tankstelle (German petrol station) by Royal, file SFBT_ARAL_Tonnendach-0x5ad0e817_0xd1188252_0x30000.SC4Model

Open this file with the Ilive Reader and click twice on "Instance". This orders all included "files" according to their instance ID.


Look at the sixth digit - it is 0, 1, 2, 3 or 4. This number stand for the zoom level (keys 1 - 5 in the game correspond to numbers 0 - 4).
Look at the seventh digit - it is 0, 1, 2 or 3. This number stands for the view direction.

Click on the S3D file with ID 00030400. The lower right shows a graphical representation.
Get familiar with this display: use the buttons tp zoom in and out, switch night view on/off, and rotate in 3D. Looks funny. Click on the button "Wireframe" and rotate. Click on "Both" and rotate. It becomes obvious that there are several textured triangles that build this model.
Switch group "0", "1" and "2" on and off. Now compare with FSH files 00030400, 00030401 and 00030402. The FSH file contains the texture used by the group.
Compare also with FSH files 00038400, 00038401 and 00038402. These FSH files contain night textures.

Select again the S3D file with ID 00030400. In the upper right part, click on "Mats":


Here is the pointer from the S3D model file to the FSH texture file.

Click on "Prim" :


All groups are of type triangle, and the first group consists of 39 vertices in this case.

Click on "Indx" and the + before the first group:


Each triangle is defined by three vertices, and each vertex is named by an index.

Click on "Vert" and the + before the first group:


For each vertex, there are two sets of coordinates: x, y, z, and u,v
x, y, z correspond to the 3D display below.

Double-click into the z- cell of vertex 11, enter 0 and hit return. You have just deformed the model:


Don't click the button Apply. On the left, click any other file. The Reader will ask a question (warning you that you have not clicked Apply). Click "Yes".

Select again the S3D file with ID 00030400. In the upper right part, click on "UV map". Select the first material name


The image on the upper right displays the texture (the referenced FSH file). Move the cursor onto the image and U and V values will be displayed. These values are in the range 0 - 1.

There are blue dots. Try to select one. You may have to drag the mouse over it while pressing the mouse button, which opens a white box. When you stop pressing the mouse button, the blue point gets selected (gets a white border). Click the point and move it somewhere. Watch the 3D display below!


You deformed the roof of the filling station.
Again, don't click the button Apply. On the left, click any other file. The Reader will ask a question (warning you that you have not clicked Apply). Click "Yes".
Obviously, the x, y, z coordinate of the 3D model is related to the u, v coordinate of the texture.

The number for Prim (39 in this case) refers to the 39 points under Index (13 indices times 3 vertices building a triangle). Prim is also related to Anim, as you can easily see for yourself. Triangles must be defined counterclockwise (thanks to ArkenbergeJoe for this hint!).

This is one set of parameters that we can change with the Reader. Well, most changes do not make any sense, but there are a few possible meaningful changes that we may use for modding.





EDIT: I have turned the pics into direct links, for the sake of better reading and following the tutorial. I hope it is ok ;) - jeronij -

Chrisim

#3
Continuing with the Aral Petrol Station Model, click the "Filters" button at the very top, select FSH files only, refresh and click twice on "Instance" to order according to instance ID.
Using a 000304xx FSH texture, on the right, try out each of the options "Color only", "Alpha Only", "Alpha blended".


The game does blend the alpha blended texture onto the city.
Try also the three options for night textures. Corresponding day and night textures are obviously similar. The game does blend day and night textures (4 textures!) together during night view.

This opens more possibilities for modding. We can export FSH texture, change them with graphic software and import them back.
Furthermore, we can introduce "Ghost" effects by deliberately introducing differences on the night texture. A building may look differently at night.

FSH texture export:
Select one or several FSH files in the Reader and click "Save selected file(s)". I do always rename the files to "fxxxx.fsh", with xxxx for the last four digits of the instance ID.
Open FiSHMan, open a FSH file, right-click on "#1" and select "Export-Color".


A file selection box opens, don't forget to change to a graphics format like PNG or BMP. Repeat this for "Export-Alpha".

FSH texture import:
Open FiSHMan, open any FSH file, right-click on "#1" and select "Remove". Right-click on "Bitmaps" and select "Import Bitmaps". The "Insert new bitmap" window opens.


Enter file names for Bitmap (color) and Alpha map and don't forget to select the FSH bitmap type "DXT3 Compressed, with Alpha". After "OK", back in the main FiSHMan window, select "#1" and look at it. Switch the options "Color only", "Alpha Only" and "Alpha blended" to make sure that everything is right. Use "File - Save as" to save the new FSH file.
In the Reader, select the files that you wish to replace and right-click "Remove file". Right-click "Insert & Compress file" and select your new FSH file(s). In the new window, enter "FSH file" as file type. The FSH file is loaded.
Now you only need to set proper group and instance ID (select the file, click "File info" and then "Edit"). The Reader does not update the display immediately. On the very left, change to "Blank dat" and back to your file and the display is updated.
Save the SC4Model file before any further clicking, otherwise you risk a crash of the Reader.




EDIT: I have turned the pics into direct links, for the sake of better reading and following the tutorial. I hope it is ok ;) - jeronij -

Chrisim

#4
Continuing with Aral Petrol Station Model, click the "Filters" button at the very top, select S3D files only, refresh and click twice on "Instance" to order according to instance ID.


Select "Wireframe" and click on some other S3D models. You will see that for smaller zooms (xxxxx0xx - xxxxx3xx), the S3D model is very simple.


They consist of six triangles defined by seven vertices.

Furthermore you can easily verify that for a given view (e.g. xxxxxx20), all S3D models are (almost) identical for zooms xxxxx0xx to xxxxx3xx. Only model xxxxx4xx is complex.
The reason for my wording "almost" is due to the reference to textures (under "Mats"). S3D model 00030320 points to FSH texture 00030320, etc.

This conclusion of S3D models being (almost) identical is important, because it opens several possibilities for modding. The conclusion seems to be a valid statement for most models, but not for all.

Copying S3D files inside the Reader is straightforward: select S3D file, cntrl-C, cntrl-V. Remember to change the instance ID and the reference to FSH textures under "Mats" (or do not change it, depending on what you wish to do). Save the SC4Model file often, because the risk of crashing the Reader is high.

Exporting and importing S3D files
The Reader allows to export and import .s3d and .3ds files. These are binary formats.

There is a trick that allows exporting and importing some of the data to MS Excel or OpenOffice Calc. This is described in the workflow in chapter 5.





EDIT: I have turned the pics into direct links, for the sake of better reading and following the tutorial. I hope it is ok ;) - jeronij -

Chrisim

#5
Scaling S3D models is straightforward. Manual editing is possible when all 20 models (for each zoom and each view direction) are simple, i.e., consist of few triangles only. Simply edit the values for x, y, z as described in chapter 2. I created the SFBT BSC updated Marrast street underpasses in this way.

For most models, manual editing is not feasible, because the S3D model for the most detailed zoom usually has too many triangles. Then you can apply the following workflow, that was tested for the Eiffel tower (see the images in chapter 1).

Open MS Excel or OpenOffice Calc (empty file)
In the Reader, select the S3D file. Click on "Vert" and each + before the groups.


Select all values x, y, z, and click Cntrl-C for copy.
In Excel or OpenOffice Calc, click Cntrl-V. Use formulas to scale all values (for our test, we scaled the Eiffel tower by 0.75, from 8x8 to 6x6 tiles). Mark and copy all new values with Cntrl-C.
In the Reader under "Vert", select the uppermost cell for x and press Cntrl-V.
Click Apply and save the file. Don't forget to update the model sizes in the building exemplar (Desc-File).

You can also shift models, to center a building or to move parts of your model underground. Or you invert a model: flipped pyramids. Many possibilities for modding ...
The smoothly curved motorway preview model (see chapter 1) was created in a very similar way, although the operations inside OpenOffice Calc are slightly more complex than simple scaling.





EDIT: I have turned the pics into direct links, for the sake of better reading and following the tutorial. I hope it is ok ;) - jeronij -

Chrisim

Imagine you have an incomplete or corrupt SC4Model file. Under certain conditions, you can repair it.

For example, I restored zoom 1 (and two nightlight zooms) for Debussyman's wonderful Votivkirche (see image in chapter 1) using the following workflow.
Zoom 1 (the S3D models and FSH textures with ID's xxxxx0xx) were corrupt. I removed all corrupt S3D models and FSH textures for this zoom.
I verified the textures and wireframes of the S3D models for zoom 2. They were all correct and simple (basically a box).
So, I simply copied the S3D models of zoom 2 (ID's xxxxx1xx) and gave them ID's for zoom 1 (xxxxx0xx). Internally, these new S3D files still point to the textures of zoom2 which is fine.
Finally, I changed the AppearanceZoomsFlag in the Prop Exemplar to 1F to activate the display for all zooms. It seemed to work.

Well, I was not sure whether this would be really fine. For consistency, I actually changed the "Mat"-References in the new zoom 1 S3D to textures of zoom 1 (xxxxx0xx). I created these textures by exporting the zoom 2 FSH textures, scaling the image size to 50% with Irfanview (very quick with few mouse clicks) and re-importing (and setting proper instance ID's). This process took 15 minutes extra and I am unsure whether it was really required, but the model is consistent and I do not have to fear any surprises.

That's it. I hope somebody will find this tutorial useful and will produce wonderful models that I may then use in my cities ...  ;)

RippleJet

Thank you Chrisim for an excellent tutorial! &apls

BAT rendering errors have sometimes resulted in model files where the u-coordinates are scaled.
I've got two such examples that have been fixed in accordance with 5. Workflow: Scale or Shift Models:

- Glenni's Mehelia Taarnet
- Superstar's Key Tower

You can also renumber mats (give new IID's for textures) to avoid conflicts like the ones in Superstar's Triangle Tower.

jeronij

Excellent tutorial  :thumbsup:

Thanks for sharing all this knowledge with us  ;)
I am currently not active - Please, contact Tarkus for any site related matter. Thanks for enjoying SC4D :D


Autism Awareness;  A Father Shares
Mallorca My Mayor Diary


RippleJet

Xannepan's JENX Rue du Renard 4 was rendered offset.
However, shifting the x- and z-coordinates of the LOD boxes, it was easier to fix it in Reader than to rerender. :thumbsup:

As you can see below, the original model had z-coordinates between -20.122684 and +11.817574.
Had the bat model been centered before rendering, the average of these would have been close to 0.
The average of these extreme coordinates gives the center point: (-20.122684+11.817574)/2 = -4.152555.
In other words, changing all z-coordinates +4.15 m should correct the offset rendering:



For the other rotations you need to verify whether it's the x- or z-coordinates you need to either increase ir decrease.
Using Excel for the correction is extremely helpful though! :)
Note however, that if your national settings use a decimal comma instead of a decimal point,
you need to change this in the Excel file (Tools -> Alternatives -> International) before being able to copy from/to a s3d file.

Naturally, the same technique can be used to change a centered model into one rendered offset. ::)

Chrisim

A nice example - and I like the animation of your gif file  :)
Quote from: RippleJet on March 11, 2008, 04:21:13 AM
Note however, that if your national settings use a decimal comma instead of a decimal point,
you need to change this in the Excel file (Tools -> Alternatives -> International) before being able to copy from/to a s3d file.
I know, that's annoying. I thought that only the Germans have this problem. In OpenOffice Calc, you can select Extras - Options - Language settings - Language. The other possible solution is a change under XP's regional settings.

SimFox

#11
Quote from: Chrisim on March 09, 2008, 03:58:08 PM
Imagine you have an incomplete or corrupt SC4Model file. Under certain conditions, you can repair it.

For example, I restored zoom 1 (and two nightlight zooms) for Debussyman's wonderful Votivkirche (see image in chapter 1) using the following workflow.
Zoom 1 (the S3D models and FSH textures with ID's xxxxx0xx) were corrupt. I removed all corrupt S3D models and FSH textures for this zoom.
I verified the textures and wireframes of the S3D models for zoom 2. They were all correct and simple (basically a box).
So, I simply copied the S3D models of zoom 2 (ID's xxxxx1xx) and gave them ID's for zoom 1 (xxxxx0xx). Internally, these new S3D files still point to the textures of zoom2 which is fine.
Finally, I changed the AppearanceZoomsFlag in the Prop Exemplar to 1F to activate the display for all zooms. It seemed to work.

Well, I was not sure whether this would be really fine. For consistency, I actually changed the "Mat"-References in the new zoom 1 S3D to textures of zoom 1 (xxxxx0xx). I created these textures by exporting the zoom 2 FSH textures, scaling the image size to 50% with Irfanview (very quick with few mouse clicks) and re-importing (and setting proper instance ID's). This process took 15 minutes extra and I am unsure whether it was really required, but the model is consistent and I do not have to fear any surprises.

That's it. I hope somebody will find this tutorial useful and will produce wonderful models that I may then use in my cities ...  ;)

Unfortunately, strictly speaking this method doesn't work. Zoom1 differs from Zoom2 by more that just scale (even that isn't 50%) there is a significant difference in camera angle as well... Of course one may say that something better then nothing at all, though...
But all-in-all this could be useful if for some reason some of the stages of the export process fail. If that is the case separate view of this particular zoom level could be made and manually inserted.

One very interesting point (for me at least) is about moving part of model below ground,... Would it be possible to get more info on that?

RippleJet

Quote from: SimFox on May 20, 2008, 06:53:44 AM
One very interesting point (for me at least) is about moving part of model below ground,... Would it be possible to get more info on that?

Don't think there's anything special about that. As little special as there is with rendering a bat partly below y=0.
Those parts won't appear in the game though if the lot's tile has got a base texture.

Normally you would create a custom foundation instead of extending the model beneath ground level. :thumbsup:

Take a look at Cockatoo's post here to see how a model rendered beneath ground level can be used e.g. for underwater structures though.

bap

Hi There,

Thanks for the great tutorial!
I am trying to reduce the height of a building with the techniques you described. I copied the 'y' column in the vert tab of the s3d file in ilive Reader's to Excel and scaled all values by 0.75, and copied the scaled values back to the s3d file and saved. It kind of work, but some of the vertices of the triangles (some of the borders/edges of the building) do not scale correctly and became distorted. I am keeping the full 6 digits precision in the conversion. Any idea of what I am doing wrong? Or, it this not the right way to change the height of a building?
Thanks,
Bap

MandelSoft

What is shown here is the way how I modd the Maxis Highways in the HRS-Project  ;)!
Lurk mode: ACTIVE

RippleJet

Quote from: bap on June 14, 2008, 03:44:00 PM
I am trying to reduce the height of a building with the techniques you described. I copied the 'y' column in the vert tab of the s3d file in ilive Reader's to Excel and scaled all values by 0.75, and copied the scaled values back to the s3d file and saved. It kind of work, but some of the vertices of the triangles (some of the borders/edges of the building) do not scale correctly and became distorted. I am keeping the full 6 digits precision in the conversion. Any idea of what I am doing wrong? Or, it this not the right way to change the height of a building?

You were doing the correct thing! :)

When copying the values from Excel back into Reader, make sure that you do get all values transfered.
Be especially careful when copying values belonging to two separate groups.

nerdly_dood

#16
How would I add another poly into a S3D in Reader? My police car mods (link in my sig) use the same S3D as the Maxis luxury sedan with a different FSH texture - and as such the light bars are 2D and just look painted on - I'd like to know how to add a lightbar without uisng a 3D modeling program which I have been consistently unable to install on my computer.

I mean that I want to add a lightbar of a reasonable size... not huge and not tiny. I would also like to know how I can use a similar method to add a fake beacon light in the center for my Michigan state police car using the same sort of + shape as the lights on Swamper77's Euro ambulance (available on the LEX - creator=Swamper77) and also to make a V-shaped light bar like the NYPD and California Highway Patrol have on their cars...

I've used my knowledge of S3Ds shown in Reader in wireframe view to guess the number of polys each would add:
Standard light bar: 6 rectangles, 12 polys
Beacon light: 2 rectangles, 4 polys
V-light: 45 rectangles, 90 polys! (unless I cheat somehow)

Those all assume that a single rectangle is made of 2 triangles joined together.


This involves adding polys, not modifying the location of existing vertices.
My days here are numbered. It's been great and I've had a lot of fun, but I've moved on to bigger and better things.
—   EGO  VOBIS  VADELICO   —
Glory be unto the modder and unto the fun and unto the city game!

Chrisim

Yes, you can create a lightbar inside the S3D module of the Reader. First, you must learn and understand the Anim, Mats, Prim, Indx and Vert sections and how they relate.
There is a tutorial by ArkenbergeJoe, unfortunately for you in German language, here. However, there are pictures, maybe you can understand it after having translated it with Google or Yahoo.
The key is the Anim section, it references the other sections. Look at various existing S3D files and try to understand them. Then, you can add new points, groups, etc via right mouse click inside these sections.

Jonathan

I'm not sure if this falls into this topic,
I need to flip a model on the y axis (in the reader it is the z axis)I think it is, that is True3D, so it is a network piece.
But just changing positive/negatives to their opposite(in excel the formula is =A1-A1*2) makes the piece show up incorrectly, because of backface culling.
If I turn this off in the mats tab then there is a serious shadow problem. Usually I solve this on symetrical models, by changing the positive/negative of the X axis, but because it isn't symmetrical I can't.

Jonathan


Swamper77

Jonathan,

In addition to flipping the coordinates, you will also have to edit the Index groups. These tell the game how the individual triangles are associated to each other. You would be best to use a program such as MilkShape 3D which can flip the polygons and rearrange the vertex order so the model is right-side out.

-Jan
You can call me Jan, if you want to.
Pagan and Proud!