L3DT users' community
Large 3D terrain generator

Trying to work with scripts

Got a problem or need advice?

Trying to work with scripts

Postby noremac407 » Thu May 12, 2016 1:09 am

Hi,

I've been using L3DT for a while now. But now I'm finding there are some specific needs that I need, so I want to create a few of my own scripts.

The documentation on scripts seems to be a little bit light, and I'm having trouble figure out how to use a certain function.

I'm trying to use 'SetPixel' to alter certain areas of my height map.

The fourth variable in this function requires an "hvar hValue" which I cannot figure out what it is.

I've tried just defining something, like "hvar FOO" but I get an error that it is an invalid value type (var was /0).

What type do I need? How do I set it / define it? I'm trying to set a pixel on a heightmap, so I also tried an int, but that also came back with an error.

How do I use this function? I've searched all of the example scripts that came with my install (garage games torque version) and also search the website and forums, but I can't find an example of this function being used.

Any help?
noremac407
New member
 
Posts: 2
Joined: Thu May 12, 2016 1:03 am

Re: Trying to work with scripts

Postby Aaron » Thu May 12, 2016 12:44 pm

Hi noremac407,

Welcome to the forum, thanks for the question, and sorry for the poor documentation and general design of ZeoScript.

The map.GetPixel function in ZeoScript is a bit of a throwback to the C programming language, with which I am most familiar, and which was used to write the ZeoScript compiler. Since C is strongly typed, ZeoScript is too. This means that functions like map.SetPixel are a bit tricky, because they need to take pixel arguments with different data types when used with different map types (floats for heightfields, RGB colours for colour maps, bytes for mask maps, etc.) Either I would have had to write a set of functions (one for each data type), or else write one function that took a generic handle to a variable (the usual approach in C). I chose the latter option. Anyhow, 'hvar' is just a generic handle to a variable of any data type, much like a void* in C can be treated as a pointer to any data type. You use it like this:

Code: Select all
// get a handle to the heightfield
hvar hMap
set hMap <GetMap "HF">

float ExampleFloat // declare a float
set ExampleFloat 20 // set the float value

// set pixel x=125, y=456 to value given by ExampleFloat
map.SetPixel hMap 123 456 &ExampleFloat


Note the use of the ampersand operator in '&ExampleFloat', which gets the handle to ExampleFloat as a hvar (just like C).

I've uploaded an example script (see here) that uses these functions to generate a sinusoidal heightfield like this:

HF_SineDemo.png


Please let me know if you find any further problems or have additional questions.

Please also note that ZeoScript can be a little slow for pixel-by-pixel calculations. Although you can do it (as in the above example), ZeoScript is more suited to being the glue between calls to native functions (from L3DT or plugins) which can access map data much more quickly. However, if you're performing an operation that can't be expressed in terms of the available function calls, then ZeoScript (though slow) may be easier than writing a full-blown plugin. It really depends on how large a map you want to process, and how often you want to run the calculation. I'm happy to provide assistance in making a plugin, if that's necessary.

Best regards,
Aaron.
User avatar
Aaron
Site Admin
 
Posts: 3696
Joined: Sun Nov 20, 2005 2:41 pm
Location: Melbourne, Australia

Re: Trying to work with scripts

Postby noremac407 » Thu May 12, 2016 6:33 pm

Wow! Thank you for the fast and very detailed reply!

I tested it and it works! Thank you!

My script is for placing a road. In Torque (my game engine) I use a decal road to create roads, since you can generally get a better looking road than with painting the terrain alone. However I always paint a 'dirt' terrain type underneath the decal for a really nice effect. As I have done this, I have noticed that roads look a lot better when they are both level, and slightly indented into the terrain.

My script is going to take an exported paint layer from torque (just a png with white over black showing where I have 'painted' my under-road texture) and is going to slightly indent all of those areas on the height map. Or at least that is the goal.

I'll let you know how it turns out!
noremac407
New member
 
Posts: 2
Joined: Thu May 12, 2016 1:03 am


Return to Help and support

Who is online

Users browsing this forum: No registered users and 7 guests

cron