Jump to content

Export a Spline from Giants Editor into Blender to Create Roads/Railways (Updated)


WrinkleysRule
 Share

Recommended Posts

  • Wrinkley

There are two parts to this tutorial, the first part deals with creating a 2D spline in Giants Editor and using the

Spline CSV  Creator scripts to create a new spline aligned to the terrain with more cv's at a chosen set distance along it.

Also created is a CSV (Comma Separated Variable  ) file for use in Blender 2.79 (Only)  to create a road mesh .i3d aligned to the map terrain.

The following scripts are also used in this tutorial.

Spline CSV  Creator Set Up

Terrain Paint Set Up,

Terrain Paint

 Terrain Height Set Up

Terrain Height

The second part, the Blender section deals with creating a new mesh from the CSV data and using it to create a road layout i3d aligned to the terrain of your map for import into Giants Editor.

Note:Blender 2.79 is only used to create the CSV mesh as no viable updated version of the csv mesh  importer  script used is available at the moment. Hopefully a Geometry node that accepts CSV inputs will become available in the future.

Whilst at first the tutorial may seem a little complicated once run through a couple of times it will seem quite easy.

All the scripts used in this tutorial, together  with the installation instructions are available here.

Link to updated scripts

https://farmerboysmodding.com/index.php?/topic/2412-updated-spline-csv-height-paint-place-scripts/ 

 

GIANTS EDITOR

 

Spline CSV  Creator Set Up

Creates in the Giants Editor User Attributes panel the required User Attributes for the Spline CSV Creator

T0rYI2Z.png

The script is executed simply by Selecting –Scripts -- Spline CSV  Creator Set Up in GE --and must be initiated before executing the Spline CSV  Creator script.

Spline CSV Creator

Creates a new Spline_CSV.i3d from an existing spline aligned to the terrain with the CSV distance set by the

CSV Distance attribute in the User Attributes panel,  also created is a Spline_ CSV data .txt both are placed in the

new  CSVdata  folder created In the root folder of your map.

The CSV data is automatically converted from the Giants Editor transform axis to the Blender format, X(Z) axis, Y(X) axis,  Z(Y) axis, (Giants in brackets) to use with the csv Importer script in Blender 2.79

The script allows for the original spline to be created in 2D with less cv’s and away from the terrain, the new spline created can easily be used in any of the Spline Height/Paint/ Placement  scripts.

Create a spline and align it to the road/rail network you wish to model, naming it accordingly.

The spline can be called any name as long as it has the word spline in it i.e. road01_spline,  spline_2 etc,

the name chosen will also be the name of the spline.i3d and spline_CSVdata.txt  created in the CSVdata folder in your map root folder.

 

 

 

In Giants Editor --Select  Scripts—Spline CSV Creator  Set Up which will then create the User Attributes required by the Spline CSV Creator script  a ‘ ‘SplineNameCSV Creator Attributes Created ‘ message will appear in the consol log,  then,

 

 

 

Insert your map name in the (b).Map Name attribute   

The full name of your map ( root folder name) must be entered (Case Sensitive) in the (b). Map Name attribute in order for the CSVdata folder to be place in the correct position (map Root Folder)

Insert the required value to the (c).CSV Distance attribute.

The lower the number the more cv’s and greater accuracy in alignment in Blender or when used with the Spline Placement script

In the example image below its set to 5, generally  a value of 5 for roads and 10 or more for train tracks (gives a smoother incline) should be sufficient, but bear in mind that this distance will be the size of your individual road/rail sections in Blender.

 

 

 

With the spline selected Select –Scripts --Spline CSV Creator

A new Spline.i3d  with your chosen Spline name will be placed in a newly created CSVdata folder in the map root folder along with a Spline_CSVdata.txt file.

The message ‘New Spline: road01_spline_CSV.i3d and  road01_CSVdata.txt created in Manor Farm / CSVdata Folder’ will also appear in the consol log, in this example the spline has been named road01_spline and map name is ‘Manor Farm.

The new road01_spline.i3d can be imported directly into the map in GE by selecting File-Import and navigating to the map CSVdata folder in the map root folder and selecting the road01_spline_CSV.i3d which will then appear at the correct location in your map.

The road01_CSVdata .txt  is for use with the csv_importer script in Blender 2.79(only at the moment) and can be referenced in Blender directly from the CSVdata folder.

 

 

 

The following image shows the Attributes and log messages created when selecting --

Spline CSV Creator  Set Up                                                                                   Spline CSV Creator

XTgCXPA.png

finally showing the imported road01_spline_CSV, note that the imported road01_spline_CSV translation is now set at 0,0,0 not at the road01_spline settings

 

Setting Up the map

 

Navigate to the CSVdata  folder (in your map Root folder) and import the new --your name spline_CSV.i3d

The next step is to paint the terrain along the road01_spline_CSV spline.

Whilst this is not strictly necessary there are two reasons to do it, the first is to paint the terrain under any road mesh with a high AI value texture such as Asphalt or Gravel, although this probably won’t be seen, it means that an AI spline need not be created along any road mesh route not covered by the main traffic or AI splines, the second is purely for indication of road and edge size when setting the terrain height along this spline (settings should roughly reference to final Blender road width).

It can also gives a performance advantage by allowing a lower clip distance on the road mesh without any visual loss when viewed from a distance.

 

First  Select—Scripts -- Terrain Paint Set Up  this will create the User Attributes necessary for the Terrain Paint script and also print out the terrain layers textures in the Console log.

In this example the Attributes have been sets as

Set Centre Texture Width           5m 

Set Edge Texture Width               3m (both edges)

Set Edge Texture Left                    102  --see print out in Console Log for GRASS

Set TextureCentre                          98 --see print out in Console Log for ASPHALT

Set Edge Texture Right                  102  --see print out in Console Log for GRASS

Set Distance Between Textures  0.5 --textures painted every 0.5m

Select—Scripts-- Terrain Paint and the terrain will be painted with the chosen textures the following entry is printed out in the Console log detailing the settings.

Spline Name : road01_spline _CSV

Texture Left :- 93 -- GRASS

Texture Centre :- 89 -- ASPHALT

Texture Right :- 93 -- GRASS

Centre Width : 5.0 m : Edge Width : 3.0 m :

Texture Distance: 0.5

Result shown in following image.

6DSf4Jf.png

 

To ensure any new road mesh created using this CSV spline as a base fits the terrain it is necessary to provisionally adjust the terrain height along the length of the spline using the Terrain Height scripts. Terrain height may need to be adjusted when road mesh finally completed due to relaxing/smoothing of csv mesh.

Before executing the Terrain  Height script ensure that you save the map and make a backup copy of your map_dem.png in case of any problems.

m7e2K2S.png

 

Select  Scripts - Terrain Height Set Up 

This will create the necessary User Attributes used by the Terrain Height script.

In the image above, the inset shows the original terrain profile with a sharp drop on the right hand side and raised terrain on the left hand side so the settings below have taken this into account this allows easier blending of either edge with GE terrain tools once the Terrain Height script has been executed.

Also note that the Terrain Paint User Attributes are also shown the  User Attributes window this is because the map was saved before the Terrain Height Set Up script was executed so the Terrain Paint User attributes were saved in the normal way and can still be used to adjust terrain textures  using this road01_spline _CSV spline.

User Attribute values,

Set CentreWidth     6  (m)             -- size dependant on final mesh size in Blender in this case a 6m roadbed with 2m

    Edges  giving a 1m adjustment for final blending in GE after placement.

Set SplineHeight      0  (m)            --spline aligned to terrain

Edge Transformation                      ‘selected’  --allows independent height and smoothing to either edge

Set EdgeWidth          3 (m)             3m edge width either side of the CentreWidth

Set Edge Height Left                       4 (m)   raises the left hand edge by 4m to match left hand terrain.

Set Edge Height Right                    -4 (m)   lowers right hand edge by-4m to match right hand terrain

Set Edge Smooth Left    10            factors the amount of smoothing on the left hand edge

Set Edge Smooth Right  10           factors the amount of smoothing on the right hand edge

Select Scripts—Terrain Height

The effects of these values are shown in the main window of the image above also printed in the Console log is a reference detailing the settings used together with the name of the spline, in this case

Spline Name : road01_spline _CSV

Offset:'True'

Spline Height: 0.0

Centre Width: 7.0 m :Edge Width: 4.0 m :

Height Left: 4 :Height Right: -4 :

Smoothing Left: 8 Smoothing Right:8 

Shown bottom right in the above image

 Further smoothing of the edge area can be made by reducing the EdgeWidth , HeightLeft and HeightRight by 1 and re executing the script until the EdgeWidth is ‘0’ (CentreWidth value not changed during this operation)

Also note that the Terrain Paint User Attributes are also shown the  User Attributes window this is because the map was saved before the Terrain Height Set Up script was executed .

Note:

Once executed this terrain deformation cannot normally be undone, but provided you haven’t saved the map after executing the script the terrain can be reset back to previous levels by selecting the Reload i3d file:///C:\Users\ccrjs\AppData\Local\Temp\msohtmlclip1\01\clip_image002.gif icon in the toolbar( under the Create tab) then re adjusting script values as required.

If the map has been saved then the only way of redoing the terrain is to Copy/Paste your backup map_dem.png into the map data folder.

Once happy with the results save the map.

 

BLENDER

Unfortunately there doesn’t seem to be a viable alternative available of the csv_mesh_importer, hopefully a Geometry node that allows inputs of CSV data will appear at some point or better still the ability to export a spline either as a Nurbs Curve or Obj mesh from Giants Editor

In the meantime,

If you haven't got a copy of Blender 2.79 then you can download one from the https://www.blender.org/

select Download-- Previous Versions, in the All Previous versions box select download in next window scroll down till you find

Blender2.79/                                       29-Jul-2019 13:11

Stand alone Zip version is the better option

Download and install the csv_mesh_importer v0_7alpha.zip.

Available here

https://blenderartists.org/t/a-script-to-import-a-csv-file-and-create-meshes-for-blender-2-5x-or-later/501410

 

Install Plugin

Close Blender if active

The script cannot be installed from zip as there is no init file.

If using a standalone version then navigate to where you unzipped the Blender file i.e. D:\blender-2.79b-windows-x64\blender-2.79b-windows-x64\2.79\scripts\addons and copy paste the csv_mesh_importer.py into addons.

Otherwise navigate to Windows(C:)—Programm Files—Blender Foundation—Blender—2.79 (the script only works with 2.79 version of Blender)—scripts—addons  and copy paste the csv_mesh_importer.py into addons.

 

CSV Importer

Open Blender --Select File—User Preferences—Import Export,  locate and select the checkbox next to CSV Mesh Importer then Save as Default.

 

 

 

Select the CSV Mesh Importer panel, and set up as follows  

 

 

 

Select ‘Point list containing X.Y,Z column’s in File Type menu

Select the folder icon at the end of the .csv File Path: selection box and browse to where the road01_CSVdata .txt is located (map root folder)and click Accept (top right)

Ensure that comma[,] is selected in the Delimiter section

Click the Add Button and in the configuration box below

Select Create vertices only and in the pop up box select “Create vertices and edges (single line)”

The X,Y,Z column details can be left as is (the script has already allowed for the axis labelling).

In Object Name put the name of your spline.

Select Import

The csv Spline mesh will appear in the Scene panel at the top,  select this and zoom out till you can see it

(it will be at the same  world location as it was in your map, hence the high camera clip distance ‘End 10km’ in the view menu). Do not change the location of this mesh as it will cause problems when aligning the finished road in GE.

 

 

 

Save the file as a .blend file and close Blender 2.79.

The following image shows the setup and final mesh position in Blender

D70E2AB.png

 

Blender 3.2 and above  (other versions may differ in Menu’s and settings)

 

Open Blender and in Object Mode, Select   File ---Append, navigate to where you have saved the Blender2.79 .blend file and double click on the file, this will open a list of folders contained in that .blend file, double click the Object file, double click the name of your spline mesh, the spline csv mesh will appear in the Collections panel and in the 3D window at the location it is in your map. Do NOT change this location; if it is changed then problems will occur in placement when exporting final road mesh.

(Quick way of getting the mesh in view is with the mesh selected, in the Collections panel, select decimal point on the Keypad)

In Edit Mode ,with the mesh selected open the Tools Panel ‘N’ and select Edit – Loop Tools – Relax (arrow to left of word Relax)

In the dropdown

InterpolationLinearInput

Iterations ‘ 1 ‘       Note: High values will result in straightening out of curves  

Regular Selected

And select Relax

This will relax the mesh giving a smoother line along the whole mesh.

Change to Object Mode, with the mesh selected –Select , Object—Convert—Curve , this converts the mesh to a curve ready for use with the Curve Tools.

Select the Curve Icon in the Scene panel (green semi circle) to open the Curve Tools Panel

 

With the curve still selected change to Edit Mode

The new curve first needs to be aligned along the correct axis for the road, to do this you can either select

Control Points—Tilt and type 90 or simply (Ctrl ) -- T -- 90

In the Shape panel of the Curve Tools, select 3D, Fill Mode 'Half',  Curve Deform 'Radius Selected', all other settings can be left as is.

Open the Geometry and Bevel Tabs

Geometry Tab

 Extrude  ‘ 3 ‘        ---this equates to a road bed width of 6 metres , half the desired width

Offset  ‘ 0 ‘            ---value can be left at 0 as this just raises or lowers the mesh by +-1m

Bevel Tab

Select   -- Profile

Depth   ‘ 2             -- this figure is the width of the road edges in metres, in this case 2 for 2m

Resoloution – ‘ 0 ’ --This figure sets the number of subdivisions in the edge mesh should you wish to create

         your  own custom or preset profile.

 

 

You will note that after entering the figure in the Depth box the curve point of origin  is now aligned to the bottom of the edges, this change will need to be catered for when the mesh is finally imported into GE.

The following image shows the result of these transformations.

YeCcivE.png

 

Once you are happy with the basic shape, the curve deformations can now be turned into an editable mesh.

With the curve selected

Object Mode – Object –Convert --- Mesh

The mesh can now be edited in the normal way for example adjusting the bends in the road to be smoother and adding white lines (see Enhancements at the end of the tutorial).

 

Texture

Add the texture you are going to use in the normal way

One quick method I use is in the example below,

Edit mode     –with all the road bed faces selected

UV –Reset     -- adjust the UV map to fit the road bed texture (inset 1 shows full road texture )

Do the same for each of the road edges then,

Edit Mode—Edge Select – and select both outside road edges and raise to a shallower angle (inset 2)

ZYnPyX5.png

 

Finally Export as an i3d either using the .blend filename or creating your own in File Location

iHXZSU2.png

 

Open your map in GE and import the road mesh i3d (in this case it is road01_splineCSV)

Rotate the ‘Y’ axis by -90 and adjust the ‘Y’ Translation of the road mesh to match the  flattened terrain.

Further adjustments (texturing/terrain height) of the road area can now be carried out.

The image below shows the road imported and adjusted, the inset shows a magnified image of the road placement at the indicated location.

pITlYHj.png

 

Note: To enable the AI to work better with the new road mesh, the Collision Mask (Hex) should be set up as follows,

1SAlrMg.png

Where

0: "DEFAULT: The default bit",
1: "STATIC_WORLD: Collision with terrain, terrainHeight and static objects",
2: "STATIC_WORLD_WITHOUT_DELTA: Deprecated in FS22: Do not use it anymore!",
3: "STATIC_OBJECTS: Collision with static objects",
4: "STATIC_OBJECT: A static object",
Deselected is 5: "AI_BLOCKING: Blocks the AI",
6: "TRACTOR: Deprecated in FS22: Do not use it anymore!",
7: "COMBINE: Deprecated in FS22: Do not use it anymore!",
18: "AI_DRIVABLE: AI can drive over this node",

 

The above settings are taken from the base game road mesh , although numbers 2,6, and 7 state that they are no longer used it would be prudent to include them anyway as the collision masks may have changed in later game patches.

 

ENHANCEMENTS

 

Adjusting and smoothing blocky curves/bends

Example; Navigate to a curve section you want to adjust in the viewport

Edit Mode

Select the outer edges of the road sections in the bend (3 in this case) and subdivide, number of subdivisions will be dependent on smoothness required.

Open the Tools Panel ‘N’ and select Edit – Loop Tools – Relax (arrow to left of word Relax)

In the dropdown

InterpolationLinear- Projects vertices on straight line, Cubic uses a natural cubic spline to project the vertices

Input Parallel (all) --This will also modify any parallel vertices at the same time, if in doubt select,  Section, only

          selected modified.

Iterations ‘ 1 ‘          – No of times tool is run, higher number gives smoother results but straightens out the curve

Regular Selected –When selected vertices spread evenly along the loop

Select the vertices along the edge of the curve Section, and select Relax

Further smoothing can be carried out by repeating the above process on the relevant section

Finally select all the vertices along one edge of the whole road mesh and then select Relax

This will smooth out the whole road mesh

 

Image below shows the various stages and images 1 and 3 show the before and after result.

GcTpcNX.png

 

Adding Custom road markings.

 

Select all the road bed faces (Shift-Alt held - select face) of your finished road mesh, change to Edge select, again with Shift-Alt held deselect left and right hand edges and Subdivide ' 1 '.

Select the new centre edge (Shift-Alt held - select edge) and Shift-D to copy ' P ' Selection to separate from main road mesh, with the new edge mesh selected

Object mode

Object--Convert--Curve

Curve Tools panel --Shape-- Geometry and set Extrude to ‘ 0.2 ‘ (Extrude value dependent on the width of the road marking texture used)

Edit mode Ctrl 'T ' -90 to correct the axis.

Object mode -- Object--Convert--Mesh

Add texture as normal not forgetting alpha channel settings in Blender

Edit mode -Face select --select all

UV—Reset   -- adjust UV mesh to fit texture

Texture may need to be adjust on the bends but that is easily done in the UV editing window

Finally when satisfied export as i3d.

To do the edge markings (if required), select the left hand or right hand edge and Shift-D to copy ' P ' Selection to separate from main road mesh and continue as above, doing the same for the other edge.

Example below

BaJm5nr.png

 

The previous tutorial showed two ways of creating the road mesh from the CSV mesh but I think the above  method is the quickest and easiest way to get the best results.

 

As it is possible to  create a spline in Blender 3.2 and export it as an i3d you can create a set of splines aligned to the road mesh to use in  the Spline Placement script and also for traffic/railway splines

Using the finished road mesh as an example

For Spline Placement

In Edit mode, Edge Select

Shift-Alt select the left or right hand road edge so all the edges are selected.

Shift ‘ D ‘ to copy

With the edge still selected ‘ P ‘ Selection to separate

Object Mode

With the edge selected -- Object –Convert—Curve

Edit Mode

Curve –Set Spline Type – NURBS

Object mode

Open i3d exporter Export Tab and ensure that Nurbs Curves and Shapes are selected

Set up filename and File Location in the Output tab

Export the i3d

Import into map set ‘ Y ‘ rotation to -90 and Edit-- Freeze Transformation –Rotate Only (leave preserve instances selected) height settings do not matter as objects will be placed on the terrain at their point of origin.

Replace any splines in the splinePlacement transform with this new spline and set up the script parameters accordingly.

Example before selecting Object mode and exporting

5n804Tz.png

 

For traffic/railway splines

 

Select all the road bed faces (Shift-Alt held - select face) of your finished road mesh, change to Edge select, again with Shift-Alt held deselect left and right hand edges and Subdivide '3 '. If creating a railroad spline then Subdivide ' 1 '

Subdivide ‘ 3’ is necessary to get the correct location for the traffic splines (midway between centre and edge).

The centre edge line can be used, if required, as a new roadSpline01_CSV to adjust any terrain height after smoothing of road mesh (slight straightening of bends etc).

1ugYW0B.png

 

Shift-Alt select edge to the left of the centre of the road mesh so all the edges are selected and continue as above for the splineUtilsPlace adding a further step after the ‘With the edge still selected ‘ P ‘ Selection to separate’ of renaming the mesh to traffic01_left for clarity and continue the method above.

Repeat the procedure for the right hand edge.

Image showing both sets of splines.

UgNPqvT.png

 

Once the traffic splines are imported the Translation/Rotation needs to be set up as follows

Translate ‘ X ‘ and ‘ Z ‘ to‘ 0 ‘

Translate ‘Y ‘  to  a suitable value to align it just above the road mesh, in this case -1.9

Rotate ‘ X ‘ and  ‘ Z ‘ to ‘ 0 ‘

Rotate ‘Y ‘  to  -90

Once done freeze (Edit-Freeze Transformation) the Transformation/Rotation settings.

As both traffic splines, after importing are in the same direction, traffic direction can be set by selecting the relevant spline and pressing the ‘ R ‘ key on your keyboard.

All the splines once imported into the map can be edited/ expanded in the normal way.

Note: Regardless of the filename you have given the spline in Blender the name in the scenegraph of GE will be the

name in the Collections Panel of Blender with the suffix.001 in this case road01_splineCSV.001

Below is an example showing the road mesh, markings,  together with the various splines and also objects that have been placed using the Spline Placement script (see Terrain Height, Paint Terrain and Spline Placement scripts (Updated) for details of placement).

KAAdSMg.png

  • Thanks 3
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share