Jump to content

Terrain Height, Paint Terrain and Spline Placement scripts (Updated)


WrinkleysRule
 Share

Recommended Posts

  • Wrinkley

I have updated and added some extra functions to the Terrain Height, Spline Placement and Paint Terrain scripts.

All these scripts together with installation instructions are available here

See Updated Spline, CSV, Height, Paint, Place, Scripts – Installation

Link to installation post

 

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

 

Splines

The spline can now be given  any name as long as it includes the name ' spline ' in any part of it i.e. road1_Spline or roadspline01 etc.

Problems will occur if the spline transform or the spline itself does not have the correct rotation, whether in the transform group of the spline or the spline itself . The rotation has to be set at 0,0,0 for any of the scripts to work correctly.

There are a couple of  ways of ensuring this, one is to set up your spline in the position you want and freeze transform only the rotation, the other is to select the S cv of the spline and delete it,  this brings S to the centre (rotating point) of the spline, then just use the E cv to create the rest of the spline so lessening the chance of inadvertently rotating the start of the spline.

 

Terrain Paint

This consists of two scripts

Terrain Paint Set Up

Terrain Paint

To use, create a spline in Giants Editor and align the spline along the terrain to whatever you are intending to paint., the spline does not have to be accurately aligned painting will only occur at the terrain height.

Then with the spline selected,  

 Select –Scripts-- Terrain Paint Set Up

This will create the User Attributes the necessary for the Terrain Paint script and will also print out the terrain layer textures in the Console log in the following format,

Texture No :93:Texture Name : shingle01

Texture No :94:Texture Name : shingle02

Texture No :95:Texture Name : shingle03

Texture No :96:Texture Name : ANIMALMUD

Texture No :97:Texture Name : AS

Texture No :98:Texture Name : ASPHALT

Texture No :99:Texture Name : CONCRETE

Texture No :100:Texture Name : DIRT

User Attributes panel for Terrain Paint

J5YpPvW.png

 

Set Centre Texture Width                           ---Width of the Centre Texture in metres

Set Edge Texture Width                                               ---Width of the Edge Textures in metres (Width set for both edges)

Set Edge Texture Left                                    ---Enter required left edge texture number from Consol log.

Set Centre Texture                                         ---Enter required Centre texture number from Console log

Set Edge Texture Right                                  ---Enter required Right edge texture number from Consol log.

Set Distance Between Textures                                ---How far apart the textures are painted along the spline (default 0.5)

 

Once the User Attributes have been set then,

With the spline selected   Select ---Scripts--- Terrain Paint the textures will then be painted according to the User Attribute settings

A  print out in the GE console log will  detail these settings for reference

Spline name:

Texture Left:  no, name

Texture Centre:  no, name

Texture Right:   no, name

Centre Width :(m), Edge Width: (m), Texture Distance: (m)

If the Set Edge Width Texture is set to zero (0) only the following will be shown in the log

Spline Name,

Texture Centre no,

Centre Width

 Texture Distance

Should you require only the Centre Texture then Set Edge Width Texture to zero (0) and adjust your Centre Width settings accordingly

The image below shows the result with various texture settings using the above values, with a print out of the Texture No and Name showing in the console log on the right of the picture.

aKinDJX.png

 

 

The following image shows how the Set Distance Between Textures setting can be used to create a pothole effect

The first settings were

Set Centre Width –16

Set Center Texture---83 (waterPuddle01)

which painted the water puddle texture over the whole 16m width.

Second settings were

Set Centre Texture Width            -- 16

Set Edge Texture Width                                -- 4

Set Edge Texture Left                    -- 91

Set Centre  Texture                        -- 97

Set Edge Texture Right                  --100

Set Distanced Between Textures -- 1.5

which then painted the DIRT/GRAVEL/GRAVELGRASS texture over the water puddle texture but because the texture distance was set to 1.1 it left holes in the textures so allowing the water puddle texture to show through.

Potholes.png

lRpbA59.png

 

----------------------------------------------------------------------------------------------------------------------------------------------------------

 

Terrain Height

This script is an enhancement of the normal terrain height script which uses a spline to guide the terrain deformation it also allows  the setting of a distance value for Edge Width  (value applies to both sides) and Height / Smoothness  values  to be entered in the TERRAIN HEIGHT  attributes allowing independent control of the height and smoothing on either edges.

Any Edge Width/Height/Smoothness (L/R)  adjustment will have no effect on the  Centre Width setting whose height setting is dependent on the actual spline height or Set Spline Height settings

This also consists of two scripts

Terrain Height Set Up

Terrain Height

To use

Create the spline in Giants Editor and create/align the spline to whatever area you are intending to terraform.

Then with the spline selected,  

 Select –Scripts-- Terrain Height Set Up

In the User Attributes panel of Giants Editor the necessary User Attributes for the Terrain Height script will be created,as shown below.

52kuciF.png

Set Centre Width            --- Width of centre deformation in metres.

Set Spline Height             -- Height of the start deformation from the spline, can be a negative figure,

                                                      default is 0, ( actual spline position )

Edge Transformation         -- When selected allows independent setting of edge height/ depth, deselected only

                                                      Centre Width deformation

Set Edge  Width                   -- Width of edge deformation on both sides

Set Edge Height  Left          ---Height/Depth of Left Hand deformation

Set Edge Height Right         –-Height/Depth of Right Hand deformation

Set Edge Smooth Right         -- Number is used to factor the amount of smoothing -- lower number less smoothing,

                                                      Higher number greater smoothing (optimal 10)

Set Edge Smooth Left          -- As smoothing Left

Set the relevant User Attributes to your proposed settings and then.

With the Spline selected in GE,  Select---Scripts---Terrain Height

Once the script has been executed a print out will appear in the GE console log detailing these settings for reference

Spline name

Edge Transformation setting

Spline Height

Centre Width :     Edge Width:

Height Left :          Height Right :

 Smoothing Left:    Smoothing Right:

If the Edge Transformation is deselected only the following will be printed

Spline name

Spline Height

Centre Width

Smoothing is carried out much the same way as using the terrain sculpt tool in that it smooths the area down in height so further adjustment of the edge height to match terrain may be required .

Below is an image showing the terrain profiles with various settings (Spline Height set to 4m for clarity).

sTicWmg.png

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  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.

 

Further Example;

abzDjPw.png

The above settings were used as a base for the road in the image below.

To get the desired effect required 4 executions of the script as smoothing was carried out by simply reducing the edge width and heights by one each time the script was executed and finally on the last execution (where Edge Widths and Heights equalled 1, -1 for the right hand edge) by increasing the smoothing factor to 5 for both left and right edges.

 

nGrXfAB.png%20%20%20

 

 

Spline Placement

With this script objects can be placed at various fixed, preset distances,  random distances  and locations away  from or along the spline depending on settings in the script.

The objects will be placed at terrain height along the spline (using their individual point of origin location) from the 'S' cv to the ‘E’ cv and aligned to the to the spline along their "Z" axis (unless random location selected).

e.g.  if you have a hedge that is 4m long and 1m wide ensure the longest section (4m)is  aligned to the 'Z' axis otherwise  rotate it in GE until is aligned along the 'Z' axis and freeze transform rotation also ensure that the point of origin (where the gizmo shows when object is selected) is at the correct point

For best results, open any objects  you intend to place in GE and adjust axis and  origin accordingly, when done , freeze transform all scale/rotation settings  (DO NOT freeze transform translations unless point of origin is relocated) on all the relevant objects.

This also applies to any transform groups containing objects that required to be placed using the transform group itself, select the transform group and Edit—Freeze Transformation—Transformation, Rotation and scale

This script first requires the execution of the Spline Placement Transform script which will create the correct Transform Group (splineObjects) and the relevant sub groups (objectsTo Place and placedObjects),and also create the relevant User Attributes in the User Attributes panel in Giants Editor as shown below

DpMR7om.png

All that is then required is to add a spline (Create-Spline)  CUT/pasted into the splinePlacement transform group and add required objects to the objectsToPlace transform group and insert the relevant Attribute values.

Note. The splinePlacement transform group has to be selected when entering the User Attributes and also when the  Spline Placement script is run.

Script Parameters Explanation

Refer to image above

Set Object Distance                        -- - Sets a fixed  distance between objects along the spline in metres.

Use Distance Table                         ---When selected use the values in the Set Distance Table to set the object distance

      deselected uses distance value in Set Object Distance

Set Distance Table         

Sets a fixed distance between the objects in the objectsToPlace   transform  when  Use Distance Table  selected, number of settings must match number of items in the objectsToPlace transform and be separated by a comma.

The first object in the objectsToPlace transform will always be put at the start of the spline (distance  ‘0’), the entries in the Set Distance Table refer to the distance to the next object from the preceding one.

So in the following example;

A total of 3 objects in the objectsToPlace transform  1,2 and 3

Set Distance Table = 4,8,20   -- value in metres 

object    ‘1’  placed at ‘0’ by default so no reference in distanceTable

object    ‘2 ‘  placed 4m from object ‘1’

                object   ‘3’  placed 8m from object ‘2’

object    ‘1’   placed 20m from object ‘3’

and so on until the end of the spline.

A distance of ‘0’ will mean that two objects will be placed at the same location on the spline (e.g lamp post ,hedge )

Any incorrect entries in the Set Distance Table will result in a DISTANCE TABLE ERROR in the Console log.

Stay Upright                          ---- When selected all item remains upright, specifically for trees, poles, lights etc

          deselected reverts to spline 'X'rotation and original object rotation at the placement

          point.

Random Scale                      -- -When selected allows random object scale between the parameters set by Scale Low,

                 Scale High values.If an item is already scaled then it has to be freeze transformed

                (Scale) for this to work correctly, deselected'  retains original size.

Set ScaleLow                                     --- value of the minimum random scale parameter, the value set applies to all

                 scale axis (x, y, z) at the same time

Set Scale High                                   --- value of the maximum random scale parameter, the value set applies to all

                scale axis (x, y, z) at the same time

Random Y Rotation                         -- -When selected' objects randomly rotated on the 'Y'axis

                 deselected' Y’ axis rotation as original object

Random Order                                  -- -When selected allows a random order of objects along the spline

                deselected retains the order set in the objectsToBePlaced transform group.

Random Object Distance              —When selected sets a random distance between objects along the spline

                                                                     deselected distance set by Object Distance or Distance Table

Set Random Object Distance Seed     -- percentage factor used to calculate randomObjectDistance

Random Placement                      -- When selected places the object away from the spline by the Random Placement

     Distance, deselected                 objects placed along the spline.

Set Random Placement Distance      -- maximum displacement distance from the spline, displacement varies

                                                                           between 0 and number chosen.

Set Fixed Distance                          -- When selected allows a set distance for objects to be placed either to the left or

    right of  the spline depending on value set in Distance Fixed.

   If selected and Distance Fixed value set this is also the distance around which

    Random Placement will start.

Set DistanceFixed                           -- Distance objects to be placed to the left or right of the spline in metres,

   positive number to the left negative to the right viewed from 'S' cv.

Note:  The spline is not moved so the set distance between the objects will increase depending on value set (like the spokes on a bicycle wheel from the hub to the rim). Objects will be placed at 90 degrees to the spline on the ‘Z’ axis at the relevant spline point.

 

Whilst this next section is not strictly necessary it can help in creating splines and accurate placement when using the Spline Placement script

Creating splines for use with this script.

Whilst this step is optional (depending on your spline layout) if used will help in creating a spline aligned to the terrain with a large number of cv’s ensuring accurate placement of any object.

As the script works by placing object(s) at their point of origin at set distances along or around the spline, aligned to the terrain height and spline rotation at that particular point, for accurate placement it means the spline must have a large number of cv’s (in this case suggest one every metre) to ensure correct alignment to the terrain.

Obviously this would be very time consuming, a quick way is to roughly create the spline path as required without paying much attention to height settings (in fact it can go underground without affecting the final created spline).

When satisfied with the spline layout  in GE, Select ---Scripts-  Spline CSV Creator Set Up,  set User Attributes as follows,

(b).Map Name – Insert  your Full map (root folder) name  (Note: Case sensitive)

(c.).CSV Distance to  ‘1’

With the spline selected Select -- Spline CSV Creator in the Scripts dropdown, the new spline will be created in the CSVdata  folder (one will be created if not already there) in your map root folder. A  Your Name spline_CSVdata.txt file will also be created in the same folder should you wish to use the spline data for creating a road/rail mesh.

Import it into your map by File—Import and navigate to where the CSvdata folder is located (map root folder)and select the spline, the spline will have its original name with the suffix _CSV.

It will then appear at the location of your original spline, aligned to the terrain at 1 metre intervals

In the following image the Attributes have been set with the Farm Name, in this case Manor Farm and CSV Distance to 1 and the new spline01_CSV  imported into GE. Console log also shows the relevant information regarding creation of the new items.

It also shows the original spline01 (as just a straight line) and the new spline01_CSV with the  cv’s aligned to the terrain at 1 metre intervals.

Note: the new spline translations will have been reset to zero.

E2NLGMM.png

 

Another method of setting objects away from the spline

The following method will only work satisfactorily if the spline hasn’t been Freeze Transformed – Translate.

Because the objects are placed on the ‘Z’ axis away from the spline, another way of placing objects at a set distance from the first spline and retaining the distance between the objects is to make a copy of the first spline and adjust the ‘Z’ transformation to the required -/+ distance, replacing the first spline in the splineTransform group with the new spline and executing the script, ideal for fences /hedges alongside roads etc.

Occasionally alterations to the ‘X’ axis may be required as well on the new spline to get the perfect alignment.

This trick can also be used for traffic/AI splines BUT the spline must be ‘freeze transformed Translate’ before use as a traffic /AI spline.

Example.

DkDLxL1.png

 

The images below shows examples of the various settings used in the Spline Placement attributes to achieve different results

Should you need to delete the objects in the placedObjects transform (eg. Resetting settings or just adding objects) then with the splinePlacement transform selected execute the Spline Placement Delete script.

NOTE: The Spline Placement Delete script will delete ALL objects in the placedObjects transform so if doing multiple runs of the Spline Placement script copy paste the placedObjects transform directly into the Scenegraph.

Note. The splinePlacement transform group has to be selected when entering the User Attributes and also when the  Spline Placement script is run otherwise warnings will appear in the Console log.

Using  a fence from the in game Farm Fence placeable.

YMVdehs.png

In the following image the script has been run twice, the first time to place the pole upright and the second to align the rotation of the panel to the terrain, setting used are highlighted in red.

x7sPkhi.png

 

There is no need to delete the poles from the placedObjects transform before running the script for a second time the panels will be placed in the same transform. Note; object Distance is used to set the distance in this case

Some of the fence panels will need a slight adjustment to align correctly, which can easily be done by selecting the relevant panel and adjusting as necessary.

NOTE: When placing a Transform Group with objects inside it, first select the Transform Group and Freeze Transform --Translate/Scale/Rotation settings before adding it to the objectsToPlace transform.

Examples of other settings using the road mesh and splines image from the Blender CSV Road/Rail tutorial

Example Image

9ULLgvP.png

 

splinePlace_Right

To create this particular placement I have first moved the m4m hedge point of origin to the centre of the hedge to allow for better placement on bends, an example of the difference after placement can be seen in inset 2 above.

To do this simply select the m4m hedge in the objectsToPlace transform group and set the ‘Z’ translation to -2 and Edit—Freeze Transform—Translation.

Creating a 4m fence section

phYJbdz.png

 

Create new transform group

copy/paste a pole ( pole02) and duplicate twice so you have three poles

copy/paste a panel (panel01)and duplicate once

Transform Group should look like this

4mFence

                pole02

                panel01

                panel01

                pole02

                pole02

select second panel01 and translate 'Z' -2

select second pole02 and translate 'Z' -2

select thirdpole02 and translate 'Z' 2

with the first pole02 selected (pole02 Transform group)

Edit --Freeze Transformations --Translate

now all items in that transform group are aligned at zero with reference to the centre pole

to use copy/paste the pole02 transform group into the objectsToPlace transform

The 4mFence_Section now has the same point of origin as the hedge.

The poly count of this 4m fence section can also be reduced by deleting all the collisions for each item and replacing with a new collision made in the following way

 Create—Primitive –cube

Cut/paste cube into the 4mFence_Section transform and scale to fit when done Freeze Transform –Translate and Scale.

Set the Rigid body tab and in the shape tab select Cast Shadowmap,  Receive Shadowmap, Non Renderable and Distance Blending.

Whilst this only saves a poly count of 48 for each section it can make a large difference over a whole map for example a 400m fence will have a poly count of 80,800 with the new collision as opposed to the original poly count of 85,600

 

Now with the objectsToPlace transform set up as in the Example Image the Spline Placement script attributes can be set up as follows and executed by selecting Scripts—Spline Placement

BVZYV8E.png

 

 

splinePlace_Left  

To get the desired effect shown in the Example Image using the splinePlace_Left spline, the script was executed four times with various settings in the script and replacing the items in the objectsTo Place transform with new ones.  

The image below shows the various objectsToPlace transform entry’s and Spline Placement attributes settings.

The image below shows the various objectsToPlace transform entry’s and splinePlacement script settings for each execution/run of the script.

CK8DY38.png

 

The lightPoleLarge01 object on the first run had to be rotated on the ‘Y’ axis by 90 degrees and Edit -Freeze Transform --Rotate to get the correct alignment for placing along the spline and matching the road layout.

On completion of the four runs of the script the placedObjects transform group will now have all the above items from the various executions in it, if you are happy with the result then this can then be cut pasted and renamed as another transform group.

The Distance Fixed value of -15m in the fourth run of the script means that objects will be placed that far away from the spline and random placement will be based on that figure so in order for the trees to not spawn on the road the  Random Placement Distance  was set to the lower figure of 10.  

Note:

If you execute the Spline Placement Delete script at any time with the splinePlacement  transform selected it will delete ALL items in your placedObjects transform group.

  • Thanks 1
Link to comment
Share on other sites

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