[FS19] Multi Terrain Angle

Your forum for all discussions around Modding.
TracMaxx
Posts: 60
Joined: Mon Mar 11, 2013 11:41 am

Re: [FS19] Multi Terrain Angle

Post by TracMaxx »

@Oddbob
1. ModMap.lua: numAdditionalAngleChannels = 4
3. map.i3d: numDensityMapChannels: 17, combinedValuesChannels "0 3 0:6 6 0:3 3 1"

I am satisfied with 2 additional channels resulting in angles of mlutiples of 11.25° (this I have tested and it works - thanks to all contributors of this thread *thumbsup* :hi: ), 4 additional channels will result in 2.8° angles (not tested by myself). Please let us know if it works, because 17 channels are one more as two bytes (16 channels), I wonder if this gdm can be converted into png.

Greetings TracMax
Oddbob
Posts: 105
Joined: Wed Nov 21, 2018 12:03 pm

Re: [FS19] Multi Terrain Angle

Post by Oddbob »

TracMaxx wrote: Mon May 13, 2019 12:25 pm @Oddbob
1. ModMap.lua: numAdditionalAngleChannels = 4
3. map.i3d: numDensityMapChannels: 17, combinedValuesChannels "0 3 0:6 6 0:3 3 1"

I am satisfied with 2 additional channels resulting in angles of mlutiples of 11.25° (this I have tested and it works - thanks to all contributors of this thread *thumbsup* :hi: ), 4 additional channels will result in 2.8° angles (not tested by myself). Please let us know if it works, because 17 channels are one more as two bytes (16 channels), I wonder if this gdm can be converted into png.

Greetings TracMax
Thank you for this. I actually got it working on a fresh start of the map I was working on, with numAdditionalAngleChannels = 3 and numDensityMapChannels: 16, combinedValuesChannels "0 3 0:6 5 0:3 3 1" and 31/32 in the groundshaderxml. Someone else on another site or maybe YouTube (can't remember) showed that, and I went with it, and am satisfied with it.

However thank you very much for the info provided as maybe in the future I will change to that.
canons
Posts: 4
Joined: Sun Oct 31, 2010 7:09 pm

Re: [FS19] Multi Terrain Angle

Post by canons »

Hi, I followed the tutorial step by step to apply the "Multi terrain angle" in the beautiful "Hof Bergmann" map, but when I try to start it I get this kind of error:

2019-06-01 11:16 Error: Running LUA method 'update'.
2019-06-01 11:16 dataS/scripts/BaseMission.lua(57) : attempt to index local 'missionCollaborators' (a nil value)
2019-06-01 11:16 Error: Running LUA method 'update'.
2019-06-01 11:16 dataS/scripts/events.lua(31) : attempt to index global 'g_currentMission' (a nil value)
2019-06-01 11:16 Error: Running LUA method 'update'.
2019-06-01 11:16 dataS/scripts/events.lua(38) : attempt to index global 'g_currentMission' (a nil value)
2019-06-01 11:16 Error: Running LUA method 'update'.
2019-06-01 11:16 dataS/scripts/events.lua(53) : attempt to index global 'g_currentMission' (a nil value)

what could it depend on? Thank you
TracMaxx
Posts: 60
Joined: Mon Mar 11, 2013 11:41 am

Re: [FS19] Multi Terrain Angle

Post by TracMaxx »

@canons
I never got this error in combination with the multi terrain angle. So I suggest something else got wrong or you have a typewriter error either in modDesc.xml or ModMap.lua.
For comparison an extract of my modDesc.xml

Code: Select all

    <maps>
        <map id="MapNonnenthal" className="ModMap" filename="scripts/ModMap.lua" configFilename="maps/Nonnenthal.xml" defaultVehiclesXMLFilename="defaultVehicles.xml" defaultItemsXMLFilename="defaultItems.xml">
            <title>
				<en>blank 4x Map</en>
				<de>Nonnenthal</de>
            </title>
            <description>
                <en>A simple blank map to get you started.</en>
                <de>Eine schöne Map in Süddeutschland</de>
            </description>
            <iconFilename>map_previewNT.png</iconFilename>
        </map>
    </maps>
and the ModMap.lua I use

Code: Select all

--- Thanks to [Team LTW] kingkalle
--- https://forum.giants-software.com/viewtopic.php?f=884&t=103797&start=90

ModMap = {}
local ModMap_mt = Class(ModMap, Mission00)

function ModMap:new(baseDirectory, customMt, missionCollaborators)
    local mt = customMt
    if mt == nil then
        mt = ModMap_mt
    end
    local self = ModMap:superClass():new(baseDirectory, mt, missionCollaborators)

    -- Number of additional channels that are used compared to the original setting (2)
    -- two additional channels give 16 directions and an angle of 11.25°
    local numAdditionalAngleChannels = 2;

    self.terrainDetailAngleNumChannels = self.terrainDetailAngleNumChannels + numAdditionalAngleChannels;
    self.terrainDetailAngleMaxValue = (2^self.terrainDetailAngleNumChannels) - 1;

    self.sprayLevelFirstChannel = self.sprayLevelFirstChannel + numAdditionalAngleChannels;

    self.plowCounterFirstChannel = self.plowCounterFirstChannel + numAdditionalAngleChannels;
    self.limeCounterFirstChannel = self.limeCounterFirstChannel + numAdditionalAngleChannels;

    return self
end
Hope it helps
TracMax
PellaR
Posts: 5
Joined: Thu Dec 14, 2017 5:35 pm

Re: [FS19] Multi Terrain Angle

Post by PellaR »

when i'm opening the map in GE to make the new cultivator_density.gdm. i get the warning Warning: Missing texture 'blendMap2' in 'groundDetail_mat' (G:/Dropbox/Privat/FS 19/Local/Mods Edit/Map Edit/FS19_The_Valley_The_Old_farm/shaders/groundShader.xml). what i'm i doing wrong? i have tried to copy the cultivator_density.gdm from another map. but then i get some taxture issues.
User avatar
Phantoms
Posts: 408
Joined: Thu Sep 17, 2015 6:37 pm
Location: Georgia, USA

Re: [FS19] Multi Terrain Angle

Post by Phantoms »

I got Multi Terrain Angle working on New Woodshire (v1.0), unfortunately it requires a new game save.

I got it working by following the tutorial at https://www.youtube.com/watch?v=e18ysh3LtcI.
Only thing different is using the names from the map you're trying to add it to (New Woodshire is mapUS), but the className has to be "ModMap". Here's what it looks like in my modDesc.xml:

Code: Select all

<map id="SampleModMap" className="ModMap" filename="maps/mapUS.lua" configFilename="maps/mapUS.xml"

And here's what it looks like in game.

Image
Playing on PC
PellaR
Posts: 5
Joined: Thu Dec 14, 2017 5:35 pm

Re: [FS19] Multi Terrain Angle

Post by PellaR »

Hi. i have followed the turtorial both in the video and in the thread. but when i open the maop in GE i get this warning: Warning: Missing texture 'blendMap2' in 'groundDetail_mat' (C:/Users/Pette/Desktop/Ny mappe/FS19_Jonsboda/maps/shaders/groundShader.xml). any pointer on what is wrong? i have also tried to use a groundShader.xml from a map with MTA but still the same warning
Eische
Posts: 3773
Joined: Thu Oct 18, 2018 5:17 pm

Re: [FS19] Multi Terrain Angle

Post by Eische »

PellaR wrote: Fri Jan 29, 2021 3:19 pm Hi. i have followed the turtorial both in the video and in the thread. but when i open the maop in GE i get this warning: Warning: Missing texture 'blendMap2' in 'groundDetail_mat' (C:/Users/Pette/Desktop/Ny mappe/FS19_Jonsboda/maps/shaders/groundShader.xml). any pointer on what is wrong? i have also tried to use a groundShader.xml from a map with MTA but still the same warning
Never had that issue.
Check your groundshader.xml
Quite at the beginning of the file there should be the textures section. Ir should look like this:

Code: Select all

<Textures>
      <Texture group="terrainDetail" name="blendMap"                             defaultColorProfile="linearRGB" />
      <Texture group="terrainDetail" name="blendMap2"                            defaultColorProfile="linearRGB" />
      <Texture group="terrainDetail" name="noiseMap"                             defaultColorProfile="linearRGB" defaultFilename="$data/shared/noise.png"/>
      <Texture group="terrainDetail" name="baseMap"               type="2dArray" />
      <Texture group="terrainDetail" name="normalMap"             type="2dArray" />
      <Texture group="terrainDetail" name="groundLayerDiffuseMap" type="2dArray" defaultColorProfile="sRGB" defaultFilename="$data/maps/textures/terrain/ground/groundLayer_diffuse.png"/>
Playing on PC - Win10
Ryzen 3600
RX 5500XT
16GB Ram
How to post log file
How to upload pictures
Please report bugs for FS22 using the bugtracker
buck2202
Posts: 5
Joined: Tue Sep 15, 2020 10:58 pm

Re: [FS19] Multi Terrain Angle

Post by buck2202 »

I was digging into the bit-level meanings of the gdm/png files for preserving heaps on the ground when heighttypes are increased, and it occurred to me that the same would be applicable for preserving work-angles, plow state, fertilization count, etc in updating for more terrain angles. For example, some of the youtube walkthroughs for this process mention that plow state is lost when you use the density map from a savegame.

Crudely, a pixel in the density for the default 2 angle channels has values

Code: Select all

AAAABBCC|DDDDDDDD|DDDDDDDD
red     |green   |blue
where A contains the current ground state (cultivated, seeded, ...), B seems to be assorted spray states (fert/herb, manure, lime, chopped straw, ...), C is the work angle, and D is other stuff (fertilization level, plow "counter") and a lot of unused bits.

If we add one angle channel in groundshader.xml and the map i3d file, and then load an fewer-angle png in giants editor, the data is read through our new bitmask

Code: Select all

AAAABBCC|CDDDDDDD|DDDDDDDD
but the data wasn't written in that format. The fert level/plow counter and anything but a pure 0 degree work angle will be misinterpreted.

To preserve it, you can insert a processing step between using the GRLE converter and loading in giants editor. When adding a single angle channel, we convert the data to

Code: Select all

AAAABB0C|CDDDDDDD|DDDDDDDD
just prepending the appropriate number of zeros to the original angle data, and shifting all of D to the right (dropping some thankfully-unused bits).


I wrote a quick python script to do this, and thought I'd share it in case anyone else might find it useful. I wrote it to be used from the command line in linux, but the update_pixel function should be easily adaptable to other workflows.

Code: Select all

#!/usr/bin/python3

import sys,argparse
from os.path import exists
from PIL import Image

def update_pixel(p,inchan,outchan):
	pixel = p[0] + (256 * p[1]) + (65536 * p[2])
	
	outpixel = (
		(pixel & 0x3F) |							#ground state. red masked by [00111111]
		( (pixel & ~0x3F) << (outchan-inchan) ) )	#rest of data shifted left by #channels added, starting at bit 7 (maintains fert level, plow counter, etc)
													#keeps old angle data at most-significant bits to save old angle data
	
	return (outpixel % 256, outpixel // 256, outpixel // 65536)


def main(argv):
	parser = argparse.ArgumentParser(description='Converts cultivator density map between # terrain angles without data loss')
	
	parser.add_argument('-i', '--inchannels',	action='store', type=int, default=2,	dest='inchannels',					help='# angle channels in input png')
	parser.add_argument('-o', '--outchannels',	action='store', type=int, 				dest='outchannels', required=True,	help='# angle channels in output png')
	parser.add_argument('-I', '--inpng',		action='store', 						dest='infile',		required=True,	help='input png (output from GRLE converter)')
	parser.add_argument('-O', '--outpng',		action='store',							dest='outfile',		required=True,	help='file to write')
	args = parser.parse_args()
	
	print(args)
	print("in channels:", args.inchannels)
	print("out channels:", args.outchannels)
	print("in file:", args.infile)
	print("out file:", args.outfile)
	
	addchannels = args.outchannels - args.inchannels
	if not exists(args.infile):
		print("in file missing")
		sys.exit(1)
	elif exists(args.outfile):
		print("out file exists. won't overwrite")
		sys.exit(1)
	elif args.inchannels < 2:
		print("inchannels invalid")
		sys.exit(1)
	elif addchannels == 0:
		print("nothing to do")
		sys.exit(0)
	elif addchannels < 0:
		print("inchannels > outchannels. why?")
		sys.exit(1)
		
	
	img = Image.open(args.infile)
	pixels = list(img.getdata())
	new_pixels = [update_pixel(p,args.inchannels,args.outchannels) for p in pixels]
	img.putdata(new_pixels)
	img.save(args.outfile)
	
		
if __name__ == "__main__":
   main(sys.argv[1:])
I haven't examined it exhaustively on a long-running save, but spotchecks in giants editor seem ok. To be clear, you would use the grle converter as before, run this script on its output, and then copy this script's result into the mapDE or mapUS folder (all other steps still required). There's unlikely to be any need for this extra step if you're working from the original cultivator_density.gdm provided with a map.

(related post for max height-types here: viewtopic.php?f=1014&t=155894&start=30#p1415818)
Post Reply