scripting and a bunch of rendering fixes

This commit is contained in:
sshumakov3
2021-09-02 02:07:56 +03:00
parent c22a76e55a
commit 9d960b2422
88 changed files with 9210 additions and 125 deletions

42
scripts/clean.lua Normal file
View File

@@ -0,0 +1,42 @@
-- This file is part of Noggit3, licensed under GNU General Public License (version 3).
local clean = brush("Clean");
local def_height = clean:add_real_tag("Default height",-1000,1000,0)
local tex_layer_1 = clean:add_string_tag("Texture layer 1","")
local prop_layer_1 = clean:add_int_tag("Effect layer 1",-2,9999999999,-2)
local tex_layer_2 = clean:add_string_tag("Texture layer 2","")
local prop_layer_2 = clean:add_int_tag("Effect layer 2",-2,9999999999,-2)
local tex_layer_3 = clean:add_string_tag("Texture layer 3","")
local prop_layer_3 = clean:add_int_tag("Effect layer 3",-2,9999999999,-2)
local tex_layer_4 = clean:add_string_tag("Texture layer 4","")
local prop_layer_4 = clean:add_int_tag("Effect layer 4",-2,9999999999,-2)
function clean:on_left_hold(evt)
local sel = select_origin(evt:pos(), evt:outer_radius(), evt:outer_radius())
if(holding_shift()) then
for i,chunk in pairs(sel:chunks()) do
chunk:clear_textures()
chunk:clear_colors()
if tex_layer_1:get() ~= "" then chunk:add_texture(tex_layer_1:get(),prop_layer_1:get()) end
if tex_layer_2:get() ~= "" then chunk:add_texture(tex_layer_2:get(),prop_layer_2:get()) end
if tex_layer_3:get() ~= "" then chunk:add_texture(tex_layer_3:get(),prop_layer_3:get()) end
if tex_layer_4:get() ~= "" then chunk:add_texture(tex_layer_4:get(),prop_layer_4:get()) end
chunk:apply_all()
end
end
if(holding_ctrl()) then
for i,vert in pairs(sel:verts()) do
vert:set_height(def_height:get())
end
end
if(holding_alt()) then
for i,model in pairs(sel:models()) do
model:remove()
end
end
sel:apply()
end

101
scripts/docs/README.md Normal file
View File

@@ -0,0 +1,101 @@
# Scripting
[API Documentation](api/modules.md)
This version of Noggit has support for scriptable brushes, meaning you can use the Lua programming language (version 5.1) to customize your own workflow.
Script brushes should be placed in the `scripts` subdirectory in your Noggit installation. Script brushes can be loaded inside Noggit from the scripting tool (book icon) in the menu to the left.
**Warning**: Scripts are created by third party developers and are not maintained by Noggit. Scripts downloaded from the internet might contain malicious code.
## Hello World
This example illustrates a simple working script brush that you can load in the scripting tool.
```lua
-- We create a new script brush that becomes
local my_brush = brush("My Brush")
-- We register an event for when this brush clicks on the ground
function my_brush:on_left_click(evt)
print("Hello world!")
end
```
## Script Parameters
Script brushes can register custom settings that the user can configure without editing the script.
```lua
local parameter_brush = brush("Parameter Brush")
-- Editable string
local string_param = parameter_brush:add_string_tag("Parameter Name","default value")
-- Integer between 1 and 50, default value of 5
local int_param = parameter_brush:add_int_tag("Int Tag",1,50,5)
-- Real between 0.0005 and 1, default value of 0.001 and at most 5 decimal points.
local real_param = parameter_brush:add_real_tag("Real Tag",0.0005,1.0,0.001,5)
-- Checkbox
local bool_param = parameter_brush:add_bool_tag("Bool Tag",false)
function parameter_brush:on_left_click(evt)
-- We can now access the tag values from the brush event
print("String: " .. string_param:get())
print("Bool: " .. bool_param:get())
print("Int: " .. int_param:get())
print("Real: " .. real_param:get())
-- And we can access the special radius settings from the event parameter
print("Outer brush radius:" .. evt:outer_radius())
print("Inner brush radius" .. evt:inner_radius())
end
```
## Selections
Most noggit operations involve some kind of selection using the Noggit API.
The following code illustrates how we can iterate various data in Noggit:
```lua
local selection_brush = brush("Selection Brush")
function selection_brush:on_left_click(evt)
-- Creates a square selection at the clicked position
-- containing the entire outer brush circle
local sel = select_origin(evt:pos(), evt:outer_radius())
-- iterate selected chunks
for i,chunk in pairs(sel:chunks()) do
-- do something to the chunk here
end
-- iterate selected vertices
for i,vert in pairs(sel:verts()) do
-- do something to the vertex here
end
-- iterate selected texture units
for i,tex in pairs(sel:tex()) do
-- do something to the texture unit here
end
-- iterate selected models (m2 and wmo)
for i,model in pairs(sel:model()) do
-- do something to the model here
end
end
```
## Noggit API
To see all the predefined functions you can call from scripts, see the [API documentation](api/modules.md).
### File System Permissions
The functions [image::save](api/classes/image####save) and [write_file](api/modules.md####write_file) can be used to write to the users file systems. By default, when a script tries to call either of these functions the user will be prompted with a popup to confirm they wish to write to that file. If they answer no, an exception will be thrown and stop execution of the script, and if they answer yes the file will be written, and can be written to again without asking until Noggit is restarted.
This default behavior can be disabled in the Noggit settings under `Allow scripts to write to any file`.

View File

@@ -0,0 +1,309 @@
# Class: chunk
Represents a chunk in the world
## Table of contents
### Constructors
- [constructor](chunk.md#constructor)
### Methods
- [add\_texture](chunk.md#add_texture)
- [apply](chunk.md#apply)
- [apply\_all](chunk.md#apply_all)
- [apply\_heightmap](chunk.md#apply_heightmap)
- [apply\_textures](chunk.md#apply_textures)
- [apply\_vertex\_color](chunk.md#apply_vertex_color)
- [clear\_colors](chunk.md#clear_colors)
- [clear\_textures](chunk.md#clear_textures)
- [get\_area\_id](chunk.md#get_area_id)
- [get\_effect](chunk.md#get_effect)
- [get\_tex](chunk.md#get_tex)
- [get\_texture](chunk.md#get_texture)
- [get\_texture\_count](chunk.md#get_texture_count)
- [get\_vert](chunk.md#get_vert)
- [remove\_texture](chunk.md#remove_texture)
- [set\_area\_id](chunk.md#set_area_id)
- [set\_effect](chunk.md#set_effect)
- [set\_hole](chunk.md#set_hole)
- [set\_impassable](chunk.md#set_impassable)
- [to\_selection](chunk.md#to_selection)
## Constructors
### constructor
\+ **new chunk**(): [*chunk*](chunk.md)
**Returns:** [*chunk*](chunk.md)
## Methods
### add\_texture
**add_texture**(`texture`: *string*, `effect`: *number*): *number*
Adds a new texture at the current topmost layer.
**`note`** A chunk can hold at most 4 texture layers.
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`texture` | *string* | |
`effect` | *number* | effect id to add - -2 (default): does not change effect - -1: clears current effect index - 0+: change to this effect index |
**Returns:** *number*
texture index added to
___
### apply
**apply**(): *void*
Same as apply_all
**Returns:** *void*
___
### apply\_all
**apply_all**(): *void*
Applies all changes in this chunk
**Returns:** *void*
___
### apply\_heightmap
**apply_heightmap**(): *void*
Applies all changes to the heightmap in this chunk
**Returns:** *void*
___
### apply\_textures
**apply_textures**(): *void*
Applies all changes to texture alphamaps in this chunk
**Returns:** *void*
___
### apply\_vertex\_color
**apply_vertex_color**(): *void*
Applies all changes to vertex colors in this chunk
**Returns:** *void*
___
### clear\_colors
**clear_colors**(): *void*
Removes all vertex colors in this chunk
**Returns:** *void*
___
### clear\_textures
**clear_textures**(): *void*
Removes all texture layers in this chunk
**Returns:** *void*
___
### get\_area\_id
**get_area_id**(): *number*
Returns the area id of a chunk
**Returns:** *number*
___
### get\_effect
**get_effect**(`layer`: *number*): *number*
Returns the effect id at a texture layer
#### Parameters:
Name | Type |
:------ | :------ |
`layer` | *number* |
**Returns:** *number*
___
### get\_tex
**get_tex**(`index`: *number*): [*tex*](tex.md)
Returns a texel by index in this chunk
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`index` | *number* | valid in range [0-4095] |
**Returns:** [*tex*](tex.md)
___
### get\_texture
**get_texture**(`index`: *number*): *string*
Returns the name of the texture at the specified layer.
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
**Returns:** *string*
___
### get\_texture\_count
**get_texture_count**(): *number*
Returns the amount of textures on this chunk
**Returns:** *number*
___
### get\_vert
**get_vert**(`index`: *number*): [*vert*](vert.md)
Returns a vertex by index in this chunk
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`index` | *number* | valid in range [0-144] |
**Returns:** [*vert*](vert.md)
___
### remove\_texture
**remove_texture**(`index`: *number*): *void*
Removes a texture layer from this chunk
and decreases the texture ids of all higher layers by 1
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
**Returns:** *void*
___
### set\_area\_id
**set_area_id**(`value`: *number*): *void*
Changes the area id of a chunk
#### Parameters:
Name | Type |
:------ | :------ |
`value` | *number* |
**Returns:** *void*
___
### set\_effect
**set_effect**(`layer`: *number*, `effect`: *number*): *any*
Changes the effect id at a texture layer
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`layer` | *number* | |
`effect` | *number* | effect id to set (-1 to remove effects) |
**Returns:** *any*
___
### set\_hole
**set_hole**(`hole`: *boolean*): *void*
Creates or removes a hole in this chunk
#### Parameters:
Name | Type |
:------ | :------ |
`hole` | *boolean* |
**Returns:** *void*
___
### set\_impassable
**set_impassable**(`impassable`: *boolean*): *void*
Sets whether this chunk should be impassable for players or not
#### Parameters:
Name | Type |
:------ | :------ |
`impassable` | *boolean* |
**Returns:** *void*
___
### to\_selection
**to_selection**(): [*selection*](selection.md)
Returns a selection spanning this chunk
**`note`** - iterating will include border vert/texels
**Returns:** [*selection*](selection.md)

View File

@@ -0,0 +1,209 @@
# Class: image
Represents a bitmap image
images can be created from create_image or load_png
## Table of contents
### Constructors
- [constructor](image.md#constructor)
### Methods
- [get\_alpha](image.md#get_alpha)
- [get\_blue](image.md#get_blue)
- [get\_green](image.md#get_green)
- [get\_pixel](image.md#get_pixel)
- [get\_red](image.md#get_red)
- [gradient\_scale](image.md#gradient_scale)
- [height](image.md#height)
- [save](image.md#save)
- [set\_pixel](image.md#set_pixel)
- [set\_pixel\_floats](image.md#set_pixel_floats)
- [width](image.md#width)
## Constructors
### constructor
\+ **new image**(): [*image*](image.md)
**Returns:** [*image*](image.md)
## Methods
### get\_alpha
**get_alpha**(`x`: *number*, `y`: *number*): *number*
Returns the alpha channel (between 0-1) at an image coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
**Returns:** *number*
___
### get\_blue
**get_blue**(`x`: *number*, `y`: *number*): *number*
Returns the blue channel (between 0-1) at an image coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
**Returns:** *number*
___
### get\_green
**get_green**(`x`: *number*, `y`: *number*): *number*
Returns the green channel (between 0-1) at an image coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
**Returns:** *number*
___
### get\_pixel
**get_pixel**(`x`: *number*, `y`: *number*): *number*
Returns the pixel value at a coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
**Returns:** *number*
___
### get\_red
**get_red**(`x`: *number*, `y`: *number*): *number*
Returns the red channel (between 0-1) at an image coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
**Returns:** *number*
___
### gradient\_scale
**gradient_scale**(`rel`: *number*): *number*
Returns the pixel value at a relative horizontal coordinate
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`rel` | *number* | horizontal relative position (between 0-1) |
**Returns:** *number*
___
### height
**height**(): *number*
Returns the height of this image
**Returns:** *number*
___
### save
**save**(`filename`: *string*): *any*
Saves this image to a file
#### Parameters:
Name | Type |
:------ | :------ |
`filename` | *string* |
**Returns:** *any*
___
### set\_pixel
**set_pixel**(`x`: *number*, `y`: *number*, `value`: *number*): *void*
Sets the pixel value at an image coordinate
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
`value` | *number* |
**Returns:** *void*
___
### set\_pixel\_floats
**set_pixel_floats**(`x`: *number*, `y`: *number*, `r`: *number*, `g`: *number*, `b`: *number*, `a`: *number*): *void*
Sets the pixel value at an image coordinate
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`x` | *number* | |
`y` | *number* | |
`r` | *number* | should be between 0-1 |
`g` | *number* | should be between 0-1 |
`b` | *number* | should be between 0-1 |
`a` | *number* | should be between 0-1 |
**Returns:** *void*
___
### width
**width**(): *number*
Returns the width of this image
**Returns:** *number*

View File

@@ -0,0 +1,149 @@
# Class: model
Represents a model in the world. Can represent both an m2 and wmo model.
## Table of contents
### Constructors
- [constructor](model.md#constructor)
### Methods
- [get\_filename](model.md#get_filename)
- [get\_pos](model.md#get_pos)
- [get\_rot](model.md#get_rot)
- [get\_scale](model.md#get_scale)
- [get\_uid](model.md#get_uid)
- [has\_filename](model.md#has_filename)
- [remove](model.md#remove)
- [replace](model.md#replace)
- [set\_pos](model.md#set_pos)
- [set\_rot](model.md#set_rot)
- [set\_scale](model.md#set_scale)
## Constructors
### constructor
\+ **new model**(): [*model*](model.md)
**Returns:** [*model*](model.md)
## Methods
### get\_filename
**get_filename**(): *string*
**Returns:** *string*
___
### get\_pos
**get_pos**(): [*vector\_3d*](vector_3d.md)
**Returns:** [*vector\_3d*](vector_3d.md)
___
### get\_rot
**get_rot**(): [*vector\_3d*](vector_3d.md)
**Returns:** [*vector\_3d*](vector_3d.md)
___
### get\_scale
**get_scale**(): *number*
**Returns:** *number*
___
### get\_uid
**get_uid**(): *number*
**Returns:** *number*
___
### has\_filename
**has_filename**(`name`: *string*): *boolean*
#### Parameters:
Name | Type |
:------ | :------ |
`name` | *string* |
**Returns:** *boolean*
___
### remove
**remove**(): *void*
**Returns:** *void*
___
### replace
**replace**(`filename`: *string*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`filename` | *string* |
**Returns:** *any*
___
### set\_pos
**set_pos**(`pos`: [*vector\_3d*](vector_3d.md)): *void*
#### Parameters:
Name | Type |
:------ | :------ |
`pos` | [*vector\_3d*](vector_3d.md) |
**Returns:** *void*
___
### set\_rot
**set_rot**(`pos`: [*vector\_3d*](vector_3d.md)): *void*
#### Parameters:
Name | Type |
:------ | :------ |
`pos` | [*vector\_3d*](vector_3d.md) |
**Returns:** *void*
___
### set\_scale
**set_scale**(`scale`: *number*): *void*
#### Parameters:
Name | Type |
:------ | :------ |
`scale` | *number* |
**Returns:** *void*

View File

@@ -0,0 +1,96 @@
# Class: noisemap
Represents a map of floats values, typically use with a
noise generator.
## Table of contents
### Constructors
- [constructor](noisemap.md#constructor)
### Methods
- [get](noisemap.md#get)
- [height](noisemap.md#height)
- [is\_highest](noisemap.md#is_highest)
- [set](noisemap.md#set)
- [width](noisemap.md#width)
## Constructors
### constructor
\+ **new noisemap**(): [*noisemap*](noisemap.md)
**Returns:** [*noisemap*](noisemap.md)
## Methods
### get
**get**(`pos`: [*vector\_3d*](vector_3d.md)): *number*
Returns the float value at a specific 3d position.
**`note`** The 'y' value of pos is ignored by this operation.
#### Parameters:
Name | Type |
:------ | :------ |
`pos` | [*vector\_3d*](vector_3d.md) |
**Returns:** *number*
___
### height
**height**(): *number*
**Returns:** *number*
___
### is\_highest
**is_highest**(`pos`: [*vector\_3d*](vector_3d.md), `check_radius`: *number*): *boolean*
Returns true if the float value at a 3d position
is the highest position within a given range.
This is typically used for object placement.
#### Parameters:
Name | Type |
:------ | :------ |
`pos` | [*vector\_3d*](vector_3d.md) |
`check_radius` | *number* |
**Returns:** *boolean*
___
### set
**set**(`x`: *number*, `y`: *number*, `value`: *number*): *void*
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
`value` | *number* |
**Returns:** *void*
___
### width
**width**(): *number*
**Returns:** *number*

View File

@@ -0,0 +1,41 @@
# Class: procedures\_class
Contains some general-purpose procedures that don't fit anywhere else.
Access these functions through the global singleton "procedures".
## Table of contents
### Constructors
- [constructor](procedures_class.md#constructor)
### Methods
- [paint\_texture](procedures_class.md#paint_texture)
## Constructors
### constructor
\+ **new procedures_class**(): [*procedures\_class*](procedures_class.md)
**Returns:** [*procedures\_class*](procedures_class.md)
## Methods
### paint\_texture
**paint_texture**(`sel`: [*selection*](selection.md), `img`: [*image*](image.md), `layer`: *number*, `pressure`: *number*, `angle`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`sel` | [*selection*](selection.md) |
`img` | [*image*](image.md) |
`layer` | *number* |
`pressure` | *number* |
`angle` | *number* |
**Returns:** *any*

View File

@@ -0,0 +1,52 @@
# Class: random
Represents a random generator and its state.
## Table of contents
### Constructors
- [constructor](random.md#constructor)
### Methods
- [integer](random.md#integer)
- [real](random.md#real)
## Constructors
### constructor
\+ **new random**(): [*random*](random.md)
**Returns:** [*random*](random.md)
## Methods
### integer
**integer**(`low`: *number*, `high`: *number*): *number*
#### Parameters:
Name | Type |
:------ | :------ |
`low` | *number* |
`high` | *number* |
**Returns:** *number*
___
### real
**real**(`low`: *number*, `high`: *number*): *number*
#### Parameters:
Name | Type |
:------ | :------ |
`low` | *number* |
`high` | *number* |
**Returns:** *number*

View File

@@ -0,0 +1,233 @@
# Class: script\_brush
Represents a script brush in the script window.
## Table of contents
### Constructors
- [constructor](script_brush.md#constructor)
### Properties
- [on\_left\_click](script_brush.md#on_left_click)
- [on\_left\_hold](script_brush.md#on_left_hold)
- [on\_left\_release](script_brush.md#on_left_release)
- [on\_right\_click](script_brush.md#on_right_click)
- [on\_right\_hold](script_brush.md#on_right_hold)
- [on\_right\_release](script_brush.md#on_right_release)
### Methods
- [add\_bool\_tag](script_brush.md#add_bool_tag)
- [add\_description](script_brush.md#add_description)
- [add\_int\_tag](script_brush.md#add_int_tag)
- [add\_null\_tag](script_brush.md#add_null_tag)
- [add\_real\_tag](script_brush.md#add_real_tag)
- [add\_string\_list\_tag](script_brush.md#add_string_list_tag)
- [add\_string\_tag](script_brush.md#add_string_tag)
- [get\_name](script_brush.md#get_name)
- [set\_name](script_brush.md#set_name)
## Constructors
### constructor
\+ **new script_brush**(): [*script\_brush*](script_brush.md)
**Returns:** [*script\_brush*](script_brush.md)
## Properties
### on\_left\_click
**on\_left\_click**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The function to call when the user left clicks
the world with this brush
___
### on\_left\_hold
**on\_left\_hold**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The funciton to call when the user holds the left mouse button
in the world with this brush
___
### on\_left\_release
**on\_left\_release**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The function to call when the user releases the left moues button
in the world with this brush
___
### on\_right\_click
**on\_right\_click**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The function to call when the user right clicks
the world with this brush
___
### on\_right\_hold
**on\_right\_hold**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The funciton to call when the user holds the right mouse button
in the world with this brush
___
### on\_right\_release
**on\_right\_release**: [*callback*](../modules.md#callback)<(`brush`: [*script\_brush*](script_brush.md), `event`: [*script\_brush\_event*](script_brush_event.md)) => *void*\>
The function to call when the user releases the right mouse button
in the world with this brush
## Methods
### add\_bool\_tag
**add_bool_tag**(`item`: *string*, `def`: *boolean*): [*tag*](tag.md)<boolean\>
Adds a bool tag to the settings panel
#### Parameters:
Name | Type |
:------ | :------ |
`item` | *string* |
`def` | *boolean* |
**Returns:** [*tag*](tag.md)<boolean\>
___
### add\_description
**add_description**(`text`: *string*): *any*
Adds a description row to the brush window
#### Parameters:
Name | Type |
:------ | :------ |
`text` | *string* |
**Returns:** *any*
___
### add\_int\_tag
**add_int_tag**(`item`: *string*, `low`: *number*, `high`: *number*, `def`: *number*): [*tag*](tag.md)<number\>
Adds an integer tag to the settings panel
#### Parameters:
Name | Type |
:------ | :------ |
`item` | *string* |
`low` | *number* |
`high` | *number* |
`def` | *number* |
**Returns:** [*tag*](tag.md)<number\>
___
### add\_null\_tag
**add_null_tag**(): *any*
Adds an empty tag, typically used to create empty lines in the settings panel
**Returns:** *any*
___
### add\_real\_tag
**add_real_tag**(`item`: *string*, `low`: *number*, `high`: *number*, `def`: *number*): [*tag*](tag.md)<number\>
Adds a real (i.e. float) tag to the settings panel
#### Parameters:
Name | Type |
:------ | :------ |
`item` | *string* |
`low` | *number* |
`high` | *number* |
`def` | *number* |
**Returns:** [*tag*](tag.md)<number\>
___
### add\_string\_list\_tag
**add_string_list_tag**(`item`: *string*, ...`values`: *string*[]): [*tag*](tag.md)<string\>
Adds a dropdown menu to the settings panel
#### Parameters:
Name | Type |
:------ | :------ |
`item` | *string* |
`...values` | *string*[] |
**Returns:** [*tag*](tag.md)<string\>
___
### add\_string\_tag
**add_string_tag**(`item`: *string*, `def`: *string*): [*tag*](tag.md)<string\>
Adds a string tag to the settings panel
#### Parameters:
Name | Type |
:------ | :------ |
`item` | *string* |
`def` | *string* |
**Returns:** [*tag*](tag.md)<string\>
___
### get\_name
**get_name**(): *string*
Returns the current name of this script brush
**Returns:** *string*
___
### set\_name
**set_name**(`name`: *string*): *void*
Changes the name of this script brush
#### Parameters:
Name | Type |
:------ | :------ |
`name` | *string* |
**Returns:** *void*

View File

@@ -0,0 +1,99 @@
# Class: script\_brush\_event
Represents the event context passed to brush click events.
## Table of contents
### Constructors
- [constructor](script_brush_event.md#constructor)
### Methods
- [dt](script_brush_event.md#dt)
- [inner\_radius](script_brush_event.md#inner_radius)
- [outer\_radius](script_brush_event.md#outer_radius)
- [pos](script_brush_event.md#pos)
- [set\_inner\_radius](script_brush_event.md#set_inner_radius)
- [set\_outer\_radius](script_brush_event.md#set_outer_radius)
## Constructors
### constructor
\+ **new script_brush_event**(): [*script\_brush\_event*](script_brush_event.md)
**Returns:** [*script\_brush\_event*](script_brush_event.md)
## Methods
### dt
**dt**(): *number*
Returns the delta-time since the last update frame
**Returns:** *number*
___
### inner\_radius
**inner_radius**(): *number*
Returns the current inner radius configured in the settings panel
**Returns:** *number*
___
### outer\_radius
**outer_radius**(): *number*
Returns the current outer radius configured in the settings panel
**Returns:** *number*
___
### pos
**pos**(): [*vector\_3d*](vector_3d.md)
Returns world position of this click event.
i.e. the world position where the user clicked, held or released a mouse button
**Returns:** [*vector\_3d*](vector_3d.md)
___
### set\_inner\_radius
**set_inner_radius**(`value`: *number*): *any*
Sets the outer radius in the settings panel for this brush
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`value` | *number* | should be between 0-1 |
**Returns:** *any*
___
### set\_outer\_radius
**set_outer_radius**(`value`: *number*): *any*
Sets the outer radius in the settings panel for this brush
#### Parameters:
Name | Type |
:------ | :------ |
`value` | *number* |
**Returns:** *any*

View File

@@ -0,0 +1,143 @@
# Class: selection
Represents a rectangular selection in the world and provides
iterators for heightmap vertices, texture units, chunks and models within it.
## Table of contents
### Constructors
- [constructor](selection.md#constructor)
### Methods
- [apply](selection.md#apply)
- [center](selection.md#center)
- [chunks](selection.md#chunks)
- [make\_noise](selection.md#make_noise)
- [max](selection.md#max)
- [min](selection.md#min)
- [models](selection.md#models)
- [size](selection.md#size)
- [tex](selection.md#tex)
- [verts](selection.md#verts)
## Constructors
### constructor
\+ **new selection**(): [*selection*](selection.md)
**Returns:** [*selection*](selection.md)
## Methods
### apply
**apply**(): *void*
Applies all changes made inside this selection.
You almost always want to call this function when you're done
with a selection.
**Returns:** *void*
___
### center
**center**(): [*vector\_3d*](vector_3d.md)
Returns the center point of this selection
**Returns:** [*vector\_3d*](vector_3d.md)
___
### chunks
**chunks**(): [*chunk*](chunk.md)[]
Creates and returns an iterator for all chunks inside this selection
**Returns:** [*chunk*](chunk.md)[]
___
### make\_noise
**make_noise**(`frequency`: *number*, `algorithm`: *string*, `seed`: *string*): [*noisemap*](noisemap.md)
Creates a noisemap matching the location of this selection
#### Parameters:
Name | Type |
:------ | :------ |
`frequency` | *number* |
`algorithm` | *string* |
`seed` | *string* |
**Returns:** [*noisemap*](noisemap.md)
___
### max
**max**(): [*vector\_3d*](vector_3d.md)
Returns the highest point of this selection
**Returns:** [*vector\_3d*](vector_3d.md)
___
### min
**min**(): [*vector\_3d*](vector_3d.md)
Returns the smallest point of this selection
**Returns:** [*vector\_3d*](vector_3d.md)
___
### models
**models**(): [*model*](model.md)[]
Creates and returns an iterator for all models inside this selection
**Returns:** [*model*](model.md)[]
___
### size
**size**(): [*vector\_3d*](vector_3d.md)
Returns a vector representing the size of this selection on each axis.
**`note`** for iterators, only x and z values are respected. y (height) is ignored.
**Returns:** [*vector\_3d*](vector_3d.md)
___
### tex
**tex**(): [*tex*](tex.md)[]
Creates and returns an iterator for all texture units inside this selection
**Returns:** [*tex*](tex.md)[]
___
### verts
**verts**(): [*vert*](vert.md)[]
Creates and returns an iterator for all vertices inside this selection
**Returns:** [*vert*](vert.md)[]

View File

@@ -0,0 +1,43 @@
# Class: tag<T\>
Represents a settings tag that can be accessed at any time by a script.
## Type parameters
Name |
:------ |
`T` |
## Table of contents
### Constructors
- [constructor](tag.md#constructor)
### Methods
- [get](tag.md#get)
## Constructors
### constructor
\+ **new tag**<T\>(): [*tag*](tag.md)<T\>
#### Type parameters:
Name |
:------ |
`T` |
**Returns:** [*tag*](tag.md)<T\>
## Methods
### get
**get**(): T
Returns the current value of this tag in the settings panel.
**Returns:** T

View File

@@ -0,0 +1,64 @@
# Class: tex
Represents a single texture unit in the worlds texture layers.
A texture unit represents the smallest area where it's possible to
affect textures alpha layers. This is much smaller than the areas made
up by heightmap vertices.
## Table of contents
### Constructors
- [constructor](tex.md#constructor)
### Methods
- [get\_alpha](tex.md#get_alpha)
- [get\_pos\_2d](tex.md#get_pos_2d)
- [set\_alpha](tex.md#set_alpha)
## Constructors
### constructor
\+ **new tex**(): [*tex*](tex.md)
**Returns:** [*tex*](tex.md)
## Methods
### get\_alpha
**get_alpha**(`index`: *number*): *number*
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
**Returns:** *number*
___
### get\_pos\_2d
**get_pos_2d**(): [*vector\_3d*](vector_3d.md)
**Returns:** [*vector\_3d*](vector_3d.md)
___
### set\_alpha
**set_alpha**(`index`: *number*, `alpha`: *number*): *void*
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
`alpha` | *number* |
**Returns:** *void*

View File

@@ -0,0 +1,42 @@
# Class: vector\_3d
Represents a 3-dimensional vector.
Most functions do not use the 'y' (height) value at all
## Table of contents
### Constructors
- [constructor](vector_3d.md#constructor)
### Properties
- [x](vector_3d.md#x)
- [y](vector_3d.md#y)
- [z](vector_3d.md#z)
## Constructors
### constructor
\+ **new vector_3d**(): [*vector\_3d*](vector_3d.md)
**Returns:** [*vector\_3d*](vector_3d.md)
## Properties
### x
**x**: *number*
___
### y
**y**: *number*
___
### z
**z**: *number*

View File

@@ -0,0 +1,190 @@
# Class: vert
Represents a single heightmap vertex in the world.
Changes to this vertex takes visible effect in Noggit after you call
"apply" on the chunk or selection that contains it.
## Table of contents
### Constructors
- [constructor](vert.md#constructor)
### Methods
- [add\_height](vert.md#add_height)
- [get\_alpha](vert.md#get_alpha)
- [get\_pos](vert.md#get_pos)
- [is\_water\_aligned](vert.md#is_water_aligned)
- [set\_alpha](vert.md#set_alpha)
- [set\_color](vert.md#set_color)
- [set\_height](vert.md#set_height)
- [set\_hole](vert.md#set_hole)
- [set\_water](vert.md#set_water)
- [sub\_height](vert.md#sub_height)
## Constructors
### constructor
\+ **new vert**(): [*vert*](vert.md)
**Returns:** [*vert*](vert.md)
## Methods
### add\_height
**add_height**(`y`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`y` | *number* |
**Returns:** *any*
___
### get\_alpha
**get_alpha**(`index`: *number*): *any*
Returns the average alpha of all texture units closest to this vertex.
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
**Returns:** *any*
___
### get\_pos
**get_pos**(): [*vector\_3d*](vector_3d.md)
Returns the full position of this vertex
**Returns:** [*vector\_3d*](vector_3d.md)
___
### is\_water\_aligned
**is_water_aligned**(): *boolean*
Returns true if this vertex is aligned with water tiles.
**Returns:** *boolean*
___
### set\_alpha
**set_alpha**(`index`: *number*, `alpha`: *number*): *void*
Sets a texture alpha layer of all texture units closest to this vertex.
#### Parameters:
Name | Type |
:------ | :------ |
`index` | *number* |
`alpha` | *number* |
**Returns:** *void*
___
### set\_color
**set_color**(`red`: *number*, `green`: *number*, `blue`: *number*): *void*
Changes the vertex color that this vertex blends with the
underlying texture. Values generally range between 0-1, but can
also go higher.
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`red` | *number* | How much red should be used (default: 1) |
`green` | *number* | How much green should be used (default: 1) |
`blue` | *number* | How much blue should be used (default: 1) |
**Returns:** *void*
___
### set\_height
**set_height**(`y`: *number*): *any*
Changes the height of this vertex
#### Parameters:
Name | Type |
:------ | :------ |
`y` | *number* |
**Returns:** *any*
___
### set\_hole
**set_hole**(`has_hole`: *boolean*): *void*
Sets whether this vertex should be a hole, but only if the
vertex is aligned with hole tiles. If the vertex is not aligned
with a hole tile, this function does nothing.
#### Parameters:
Name | Type |
:------ | :------ |
`has_hole` | *boolean* |
**Returns:** *void*
___
### set\_water
**set_water**(`type`: *number*, `height`: *number*): *void*
Changes the water type on this vertex, but only if the vertex is
aligned with water tiles. If the vertex is not aligned
with a water tile, this function does nothing.
**`note`** The C++ function backing this operation is very slow for the moment.
use with care.
#### Parameters:
Name | Type |
:------ | :------ |
`type` | *number* |
`height` | *number* |
**Returns:** *void*
___
### sub\_height
**sub_height**(`y`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`y` | *number* |
**Returns:** *any*

932
scripts/docs/api/modules.md Normal file
View File

@@ -0,0 +1,932 @@
#
## Table of contents
### Classes
- [chunk](classes/chunk.md)
- [image](classes/image.md)
- [model](classes/model.md)
- [noisemap](classes/noisemap.md)
- [procedures\_class](classes/procedures_class.md)
- [random](classes/random.md)
- [script\_brush](classes/script_brush.md)
- [script\_brush\_event](classes/script_brush_event.md)
- [selection](classes/selection.md)
- [tag](classes/tag.md)
- [tex](classes/tex.md)
- [vector\_3d](classes/vector_3d.md)
- [vert](classes/vert.md)
### Type aliases
- [brush\_callback](modules.md#brush_callback)
- [callback](modules.md#callback)
- [nil](modules.md#nil)
### Variables
- [procedures](modules.md#procedures)
### Functions
- [abs](modules.md#abs)
- [acos](modules.md#acos)
- [acosh](modules.md#acosh)
- [add\_m2](modules.md#add_m2)
- [add\_wmo](modules.md#add_wmo)
- [append\_file](modules.md#append_file)
- [asin](modules.md#asin)
- [asinh](modules.md#asinh)
- [atan](modules.md#atan)
- [atanh](modules.md#atanh)
- [brush](modules.md#brush)
- [cam\_pitch](modules.md#cam_pitch)
- [cam\_yaw](modules.md#cam_yaw)
- [camera\_pos](modules.md#camera_pos)
- [cbrt](modules.md#cbrt)
- [ceil](modules.md#ceil)
- [cos](modules.md#cos)
- [cosh](modules.md#cosh)
- [create\_image](modules.md#create_image)
- [dist\_2d](modules.md#dist_2d)
- [dist\_2d\_compare](modules.md#dist_2d_compare)
- [exp](modules.md#exp)
- [floor](modules.md#floor)
- [get\_area\_id](modules.md#get_area_id)
- [get\_chunk](modules.md#get_chunk)
- [get\_map\_id](modules.md#get_map_id)
- [holding\_alt](modules.md#holding_alt)
- [holding\_ctrl](modules.md#holding_ctrl)
- [holding\_left\_mouse](modules.md#holding_left_mouse)
- [holding\_right\_mouse](modules.md#holding_right_mouse)
- [holding\_shift](modules.md#holding_shift)
- [holding\_space](modules.md#holding_space)
- [lerp](modules.md#lerp)
- [load\_png](modules.md#load_png)
- [log](modules.md#log)
- [log10](modules.md#log10)
- [make\_noise](modules.md#make_noise)
- [path\_exists](modules.md#path_exists)
- [pow](modules.md#pow)
- [print](modules.md#print)
- [random\_from\_seed](modules.md#random_from_seed)
- [random\_from\_time](modules.md#random_from_time)
- [read\_file](modules.md#read_file)
- [rotate\_2d](modules.md#rotate_2d)
- [round](modules.md#round)
- [select\_between](modules.md#select_between)
- [select\_origin](modules.md#select_origin)
- [sin](modules.md#sin)
- [sinh](modules.md#sinh)
- [sqrt](modules.md#sqrt)
- [tan](modules.md#tan)
- [tanh](modules.md#tanh)
- [vec](modules.md#vec)
- [write\_file](modules.md#write_file)
## Type aliases
### brush\_callback
Ƭ **brush\_callback**: [*callback*](modules.md#callback)<(`brush`: [*script\_brush*](classes/script_brush.md), `event`: [*script\_brush\_event*](classes/script_brush_event.md)) => *void*\>
The type of callback used for brush events.
**`note`** In lua, the first argument becomes "self" argument if using colon notation
___
### callback
Ƭ **callback**<T\>: T \| [*nil*](modules.md#nil)
Callback functions are unassigned by default, but may be assigned to
by the user
#### Type parameters:
Name |
:------ |
`T` |
___
### nil
Ƭ **nil**: *undefined*
This is the documentation for the Noggit scripting API.
Functions not connected to a class are global and can be called from
anywhere in a script.
## Variables
### procedures
`Const` **procedures**: [*procedures\_class*](classes/procedures_class.md)
singleton
## Functions
### abs
**abs**(`arg`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`arg` | *number* |
**Returns:** *any*
___
### acos
**acos**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### acosh
**acosh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### add\_m2
**add_m2**(`filename`: *string*, `pos`: [*vector\_3d*](classes/vector_3d.md), `scale`: *number*, `rotation`: [*vector\_3d*](classes/vector_3d.md)): *void*
Spawns an m2 model in the world.
#### Parameters:
Name | Type |
:------ | :------ |
`filename` | *string* |
`pos` | [*vector\_3d*](classes/vector_3d.md) |
`scale` | *number* |
`rotation` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** *void*
___
### add\_wmo
**add_wmo**(`filename`: *string*, `pos`: [*vector\_3d*](classes/vector_3d.md), `rot`: [*vector\_3d*](classes/vector_3d.md)): *void*
Spawns a wmo model in the world.
**`note`** wmo models cannot be scaled.
#### Parameters:
Name | Type |
:------ | :------ |
`filename` | *string* |
`pos` | [*vector\_3d*](classes/vector_3d.md) |
`rot` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** *void*
___
### append\_file
**append_file**(`file`: *string*, `content`: *string*): *void*
Appends text to a file
**`note`** This operation REQUIRES explicit permission from the user,
or it will throw an error.
#### Parameters:
Name | Type |
:------ | :------ |
`file` | *string* |
`content` | *string* |
**Returns:** *void*
___
### asin
**asin**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### asinh
**asinh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### atan
**atan**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### atanh
**atanh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### brush
**brush**(`name`: *string*): [*script\_brush*](classes/script_brush.md)
Creates a new script brush
#### Parameters:
Name | Type |
:------ | :------ |
`name` | *string* |
**Returns:** [*script\_brush*](classes/script_brush.md)
___
### cam\_pitch
**cam_pitch**(): *number*
Returns the cameras pitch rotation (the one you almost NEVER want)
**Returns:** *number*
___
### cam\_yaw
**cam_yaw**(): *number*
Returns the cameras yaw rotation (the one you almost ALWAYS want)
**Returns:** *number*
___
### camera\_pos
**camera_pos**(): [*vector\_3d*](classes/vector_3d.md)
Returns the current camera position
**Returns:** [*vector\_3d*](classes/vector_3d.md)
___
### cbrt
**cbrt**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### ceil
**ceil**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### cos
**cos**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### cosh
**cosh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### create\_image
**create_image**(`width`: *number*, `height`: *number*): [*image*](classes/image.md)
Creates a new blank image
#### Parameters:
Name | Type |
:------ | :------ |
`width` | *number* |
`height` | *number* |
**Returns:** [*image*](classes/image.md)
___
### dist\_2d
**dist_2d**(`from`: [*vector\_3d*](classes/vector_3d.md), `to`: [*vector\_3d*](classes/vector_3d.md)): *any*
Returns the 2d distance (ignoring y) between two vectors
#### Parameters:
Name | Type |
:------ | :------ |
`from` | [*vector\_3d*](classes/vector_3d.md) |
`to` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** *any*
___
### dist\_2d\_compare
**dist_2d_compare**(`from`: [*vector\_3d*](classes/vector_3d.md), `to`: [*vector\_3d*](classes/vector_3d.md), `dist`: *number*): *number*
Compares the 2d distance (ignoring y value) between two vectors to a given distance.
This operation is significantly faster than manually comparing to the result of dist_2d
#### Parameters:
Name | Type |
:------ | :------ |
`from` | [*vector\_3d*](classes/vector_3d.md) |
`to` | [*vector\_3d*](classes/vector_3d.md) |
`dist` | *number* |
**Returns:** *number*
___
### exp
**exp**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### floor
**floor**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### get\_area\_id
**get_area_id**(`pos`: [*vector\_3d*](classes/vector_3d.md)): *number*
Returns the area id at a specific position.
The 'y' value is ignored for this operation.
#### Parameters:
Name | Type |
:------ | :------ |
`pos` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** *number*
___
### get\_chunk
**get_chunk**(`position`: [*vector\_3d*](classes/vector_3d.md)): [*chunk*](classes/chunk.md)
Returns the chunk at a given position.
The tile at the position must be loaded into memory for the
operation to be successful.
#### Parameters:
Name | Type |
:------ | :------ |
`position` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** [*chunk*](classes/chunk.md)
___
### get\_map\_id
**get_map_id**(): *number*
Returns the id of the currently open map
**Returns:** *number*
___
### holding\_alt
**holding_alt**(): *boolean*
Returns true if the user is currently pressing the alt key
**Returns:** *boolean*
___
### holding\_ctrl
**holding_ctrl**(): *boolean*
Returns true if the user is currently pressing the ctrl key
**Returns:** *boolean*
___
### holding\_left\_mouse
**holding_left_mouse**(): *boolean*
Returns true if the user is currently pressing the left mouse button
**Returns:** *boolean*
___
### holding\_right\_mouse
**holding_right_mouse**(): *boolean*
Returns true if the user is currently pressing the right mouse button
**Returns:** *boolean*
___
### holding\_shift
**holding_shift**(): *boolean*
Returns true if the user is currently pressing the shift key
**Returns:** *boolean*
___
### holding\_space
**holding_space**(): *boolean*
Returns true if the user is currently pressing the spacebar
**Returns:** *boolean*
___
### lerp
**lerp**(`from`: *number*, `to`: *number*, `ratio`: *number*): *number*
Returns the value at some percentage between two values.
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`from` | *number* | the minimum range value |
`to` | *number* | the maximum range value |
`ratio` | *number* | the percentage to take (typically between 0-1) |
**Returns:** *number*
___
### load\_png
**load_png**(`path`: *string*): [*image*](classes/image.md)
Loads a png file into an in-memory image.
#### Parameters:
Name | Type |
:------ | :------ |
`path` | *string* |
**Returns:** [*image*](classes/image.md)
___
### log
**log**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### log10
**log10**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### make\_noise
**make_noise**(`start_x`: *number*, `start_y`: *number*, `width`: *number*, `height`: *number*, `frequency`: *number*, `algorithm`: *string*, `seed`: *string*): *any*
Creates a new noisemap
#### Parameters:
Name | Type |
:------ | :------ |
`start_x` | *number* |
`start_y` | *number* |
`width` | *number* |
`height` | *number* |
`frequency` | *number* |
`algorithm` | *string* |
`seed` | *string* |
**Returns:** *any*
___
### path\_exists
**path_exists**(`path`: *string*): *boolean*
Returns true if a pathname exists already
#### Parameters:
Name | Type |
:------ | :------ |
`path` | *string* |
**Returns:** *boolean*
___
### pow
**pow**(`a1`: *number*, `a2`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a1` | *number* |
`a2` | *number* |
**Returns:** *any*
___
### print
**print**(): *void*
**Returns:** *void*
**print**(...`args`: *any*[]): *any*
Prints out a message to the script window.
(sometimes, with errors, print messages will be suppressed)
#### Parameters:
Name | Type |
:------ | :------ |
`...args` | *any*[] |
**Returns:** *any*
___
### random\_from\_seed
**random_from_seed**(`seed`: *string*): [*random*](classes/random.md)
Creates a new random generator from a specific seed.
#### Parameters:
Name | Type |
:------ | :------ |
`seed` | *string* |
**Returns:** [*random*](classes/random.md)
___
### random\_from\_time
**random_from_time**(): [*random*](classes/random.md)
Creates a new random generator from the current system time.
**Returns:** [*random*](classes/random.md)
___
### read\_file
**read_file**(`file`: *string*): *string*
Reads a file from the file system.
**`note`** This operation does NOT require explicit permission from the user.
#### Parameters:
Name | Type |
:------ | :------ |
`file` | *string* |
**Returns:** *string*
___
### rotate\_2d
**rotate_2d**(`point`: [*vector\_3d*](classes/vector_3d.md), `origin`: [*vector\_3d*](classes/vector_3d.md), `angle`: *number*): [*vector\_3d*](classes/vector_3d.md)
Returns a 3d point around an origin, ignoring the y value.
#### Parameters:
Name | Type |
:------ | :------ |
`point` | [*vector\_3d*](classes/vector_3d.md) |
`origin` | [*vector\_3d*](classes/vector_3d.md) |
`angle` | *number* |
**Returns:** [*vector\_3d*](classes/vector_3d.md)
___
### round
**round**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### select\_between
**select_between**(`point1`: [*vector\_3d*](classes/vector_3d.md), `point2`: [*vector\_3d*](classes/vector_3d.md)): [*selection*](classes/selection.md)
Makes and returns a rectangular selection between two points.
#### Parameters:
Name | Type |
:------ | :------ |
`point1` | [*vector\_3d*](classes/vector_3d.md) |
`point2` | [*vector\_3d*](classes/vector_3d.md) |
**Returns:** [*selection*](classes/selection.md)
___
### select\_origin
**select_origin**(`origin`: [*vector\_3d*](classes/vector_3d.md), `xRadius`: *number*, `zRadius`: *number*): [*selection*](classes/selection.md)
Makes and returns a rectangular selection around an origin point
#### Parameters:
Name | Type | Description |
:------ | :------ | :------ |
`origin` | [*vector\_3d*](classes/vector_3d.md) | The center point of the selection |
`xRadius` | *number* | |
`zRadius` | *number* | |
**Returns:** [*selection*](classes/selection.md)
selection
___
### sin
**sin**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### sinh
**sinh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### sqrt
**sqrt**(`arg`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`arg` | *number* |
**Returns:** *any*
___
### tan
**tan**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### tanh
**tanh**(`a`: *number*): *any*
#### Parameters:
Name | Type |
:------ | :------ |
`a` | *number* |
**Returns:** *any*
___
### vec
**vec**(`x`: *number*, `y`: *number*, `z`: *number*): [*vector\_3d*](classes/vector_3d.md)
Creates a new vector from its components
#### Parameters:
Name | Type |
:------ | :------ |
`x` | *number* |
`y` | *number* |
`z` | *number* |
**Returns:** [*vector\_3d*](classes/vector_3d.md)
___
### write\_file
**write_file**(`file`: *string*, `content`: *string*): *void*
Writes text to a file
**`note`** This operation REQUIRES explicit permission from the user,
or it will throw an error.
#### Parameters:
Name | Type |
:------ | :------ |
`file` | *string* |
`content` | *string* |
**Returns:** *void*

867
scripts/global.d.ts vendored Normal file
View File

@@ -0,0 +1,867 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
/**
* This is the documentation for the Noggit scripting API.
* Functions not connected to a class are global and can be called from
* anywhere in a script.
*/
// While the language in this file is TypeScript,
// everything here applies to lua as well.
type nil = undefined;
/**
* Callback functions are unassigned by default, but may be assigned to
* by the user
*/
type callback<T> = T|nil
/**
* The type of callback used for brush events.
*
* @note In lua, the first argument becomes "self" argument if using colon notation
*/
type brush_callback = callback<((brush: script_brush, event: script_brush_event) => void)>;
/**
* Represents a 3-dimensional vector.
* Most functions do not use the 'y' (height) value at all
*/
declare class vector_3d {
x: number;
y: number;
z: number;
}
/**
* Represents the event context passed to brush click events.
*/
declare class script_brush_event {
/**
* Sets the outer radius in the settings panel for this brush
* @param value
*/
set_outer_radius(value: number);
/**
* Sets the outer radius in the settings panel for this brush
* @param value - should be between 0-1
*/
set_inner_radius(value: number);
/**
* Returns the current outer radius configured in the settings panel
*/
outer_radius(): number;
/**
* Returns the current inner radius configured in the settings panel
*/
inner_radius(): number;
/**
* Returns the delta-time since the last update frame
*/
dt(): number;
/**
* Returns world position of this click event.
* i.e. the world position where the user clicked, held or released a mouse button
*/
pos(): vector_3d;
}
/**
* Represents a script brush in the script window.
*/
declare class script_brush {
/**
* Changes the name of this script brush
* @param name
*/
set_name(name: string): void;
/**
* Returns the current name of this script brush
*/
get_name(): string;
/**
* Adds an empty tag, typically used to create empty lines in the settings panel
*/
add_null_tag();
/**
* Adds a description row to the brush window
* @param text
*/
add_description(text: string);
/**
* Adds an integer tag to the settings panel
* @param item
* @param low
* @param high
* @param def
*/
add_int_tag(item: string, low: number, high: number, def: number): tag<number>;
/**
* Adds a real (i.e. float) tag to the settings panel
* @param item
* @param low
* @param high
* @param def
*/
add_real_tag(item: string, low: number, high: number, def: number): tag<number>;
/**
* Adds a string tag to the settings panel
* @param item
* @param def
*/
add_string_tag(item: string, def: string): tag<string>;
/**
* Adds a bool tag to the settings panel
* @param item
* @param def
*/
add_bool_tag(item: string, def: boolean): tag<boolean>;
/**
* Adds a dropdown menu to the settings panel
* @param item
* @param values
*/
add_string_list_tag(item: string, ...values: string[]): tag<string>;
/**
* The function to call when the user left clicks
* the world with this brush
*/
on_left_click: brush_callback;
/**
* The funciton to call when the user holds the left mouse button
* in the world with this brush
*/
on_left_hold: brush_callback;
/**
* The function to call when the user releases the left moues button
* in the world with this brush
*/
on_left_release: brush_callback;
/**
* The function to call when the user right clicks
* the world with this brush
*/
on_right_click: brush_callback;
/**
* The funciton to call when the user holds the right mouse button
* in the world with this brush
*/
on_right_hold: brush_callback;
/**
* The function to call when the user releases the right mouse button
* in the world with this brush
*/
on_right_release: brush_callback;
}
/**
* Creates a new script brush
* @param name
*/
declare function brush(name: string): script_brush;
/**
* Represents a chunk in the world
*/
declare class chunk {
/**
* Removes a texture layer from this chunk
* and decreases the texture ids of all higher layers by 1
* @param index
*/
remove_texture(index: number): void;
/**
* Returns the name of the texture at the specified layer.
* @param index
*/
get_texture(index: number): string;
/**
* Returns the amount of textures on this chunk
*/
get_texture_count(): number
/**
* Adds a new texture at the current topmost layer.
*
* @param texture
* @param effect - effect id to add
* - -2 (default): does not change effect
* - -1: clears current effect index
* - 0+: change to this effect index
* @note A chunk can hold at most 4 texture layers.
* @return texture index added to
*/
add_texture(texture: string, effect: number): number;
/**
* Changes the effect id at a texture layer
* @param layer
* @param effect - effect id to set (-1 to remove effects)
*/
set_effect(layer: number, effect: number)
/**
* Returns the effect id at a texture layer
* @param layer
*/
get_effect(layer: number): number
/**
* Removes all texture layers in this chunk
*/
clear_textures(): void;
/**
* Creates or removes a hole in this chunk
* @param hole
*/
set_hole(hole: boolean): void;
/**
* Removes all vertex colors in this chunk
*/
clear_colors(): void;
/**
* Applies all changes to texture alphamaps in this chunk
*/
apply_textures(): void;
/**
* Applies all changes to the heightmap in this chunk
*/
apply_heightmap(): void;
/**
* Applies all changes to vertex colors in this chunk
*/
apply_vertex_color(): void;
/**
* Applies all changes in this chunk
*/
apply_all(): void;
/**
* Same as apply_all
*/
apply(): void;
/**
* Sets whether this chunk should be impassable for players or not
*/
set_impassable(impassable: boolean): void;
/**
* Returns the area id of a chunk
*/
get_area_id(): number;
/**
* Changes the area id of a chunk
* @param value
*/
set_area_id(value: number): void;
/**
* Returns a selection spanning this chunk
*
* @note - iterating will include border vert/texels
*/
to_selection(): selection;
/**
* Returns a texel by index in this chunk
* @param index valid in range [0-4095]
*/
get_tex(index: number): tex;
/**
* Returns a vertex by index in this chunk
* @param index valid in range [0-144]
*/
get_vert(index: number): vert;
}
/**
* Writes text to a file
* @param file
* @param content
*
* @note This operation REQUIRES explicit permission from the user,
* or it will throw an error.
*/
declare function write_file(file: string, content: string): void;
/**
* Appends text to a file
* @param file
* @param content
*
* @note This operation REQUIRES explicit permission from the user,
* or it will throw an error.
*/
declare function append_file(file: string, content: string): void;
/**
* Reads a file from the file system.
* @param file
* @note This operation does NOT require explicit permission from the user.
*/
declare function read_file(file: string): string;
/**
* Returns true if a pathname exists already
* @param path
*/
declare function path_exists(path: string): boolean;
/**
* Creates a new vector from its components
* @param x
* @param y
* @param z
*/
declare function vec(x: number, y: number, z: number): vector_3d;
/**
* Returns the current camera position
*/
declare function camera_pos(): vector_3d;
/**
* Spawns an m2 model in the world.
*
* @param filename
* @param pos
* @param scale
* @param rotation
*/
declare function add_m2(filename: string
, pos: vector_3d
, scale: number
, rotation: vector_3d
): void
/**
* Spawns a wmo model in the world.
*
* @param filename
* @param pos
* @param rot
*
* @note wmo models cannot be scaled.
*/
declare function add_wmo( filename: string
, pos: vector_3d
, rot: vector_3d
): void
/**
* Returns the id of the currently open map
*/
declare function get_map_id(): number
/**
* Returns the area id at a specific position.
*
* The 'y' value is ignored for this operation.
*/
declare function get_area_id(pos: vector_3d): number
/**
* Returns the cameras pitch rotation (the one you almost NEVER want)
*/
declare function cam_pitch(): number
/**
* Returns the cameras yaw rotation (the one you almost ALWAYS want)
*/
declare function cam_yaw(): number
/**
* Returns true if the user is currently pressing the alt key
*/
declare function holding_alt(): boolean
/**
* Returns true if the user is currently pressing the shift key
*/
declare function holding_shift(): boolean
/**
* Returns true if the user is currently pressing the ctrl key
*/
declare function holding_ctrl(): boolean
/**
* Returns true if the user is currently pressing the spacebar
*/
declare function holding_space(): boolean
/**
* Returns true if the user is currently pressing the left mouse button
*/
declare function holding_left_mouse(): boolean
/**
* Returns true if the user is currently pressing the right mouse button
*/
declare function holding_right_mouse(): boolean
/**
* Prints out a message to the script window.
* (sometimes, with errors, print messages will be suppressed)
* @param args
*/
declare function print(...args: any[])
/**
* Represents a bitmap image
*
* images can be created from create_image or load_png
*/
declare class image {
/**
* Returns the pixel value at a coordinate
* @param x
* @param y
*/
get_pixel(x: number, y: number): number;
/**
* Returns the blue channel (between 0-1) at an image coordinate
* @param x
* @param y
*/
get_blue(x: number, y: number): number;
/**
* Returns the alpha channel (between 0-1) at an image coordinate
* @param x
* @param y
*/
get_alpha(x: number, y: number): number;
/**
* Returns the red channel (between 0-1) at an image coordinate
* @param x
* @param y
*/
get_red(x: number, y: number): number;
/**
* Returns the green channel (between 0-1) at an image coordinate
* @param x
* @param y
*/
get_green(x: number, y: number): number;
/**
* Returns the pixel value at a relative horizontal coordinate
* @param rel horizontal relative position (between 0-1)
*/
gradient_scale(rel: number): number;
/**
* Sets the pixel value at an image coordinate
* @param x
* @param y
* @param value
*/
set_pixel(x: number, y: number, value: number): void;
/**
* Sets the pixel value at an image coordinate
* @param x
* @param y
* @param r - should be between 0-1
* @param g - should be between 0-1
* @param b - should be between 0-1
* @param a - should be between 0-1
*/
set_pixel_floats(x: number, y: number, r: number, g: number, b: number, a: number): void;
/**
* Saves this image to a file
* @param filename
*/
save(filename: string);
/**
* Returns the width of this image
*/
width(): number;
/**
* Returns the height of this image
*/
height(): number;
}
/**
* Creates a new blank image
* @param width
* @param height
*/
declare function create_image(width: number, height: number): image;
/**
* Loads a png file into an in-memory image.
* @param path
*/
declare function load_png(path: string): image;
declare function round(a: number);
declare function pow(a1: number, a2: number)
declare function log10(a: number);
declare function log(a: number);
declare function ceil(a: number);
declare function floor(a: number);
declare function exp(a: number);
declare function cbrt(a: number);
declare function acosh(a: number);
declare function asinh(a: number);
declare function atanh(a: number);
declare function cosh(a: number);
declare function sinh(a: number);
declare function tanh(a: number);
declare function acos(a: number);
declare function asin(a: number);
declare function atan(a: number);
declare function cos(a: number);
declare function sin(a: number);
declare function tan(a: number);
declare function sqrt(arg: number);
declare function abs(arg: number);
/**
* Returns the value at some percentage between two values.
*
* @param from - the minimum range value
* @param to - the maximum range value
* @param ratio - the percentage to take (typically between 0-1)
*/
declare function lerp(from: number, to: number, ratio: number): number;
/**
* Returns the 2d distance (ignoring y) between two vectors
* @param from
* @param to
*/
declare function dist_2d(from: vector_3d, to: vector_3d);
/**
* Compares the 2d distance (ignoring y value) between two vectors to a given distance.
* This operation is significantly faster than manually comparing to the result of dist_2d
*
* @param from
* @param to
* @param dist
*/
declare function dist_2d_compare(from: vector_3d, to:vector_3d, dist: number): number
/**
* Returns a 3d point around an origin, ignoring the y value.
* @param point
* @param origin
* @param angle
*/
declare function rotate_2d(point: vector_3d, origin: vector_3d, angle: number): vector_3d
/**
* Represents a model in the world. Can represent both an m2 and wmo model.
*/
declare class model {
get_pos(): vector_3d;
set_pos(pos: vector_3d): void;
get_rot(): vector_3d;
set_rot(pos: vector_3d): void;
get_scale(): number;
set_scale(scale: number): void;
get_uid(): number;
remove(): void;
get_filename(): string;
has_filename(name: string): boolean;
replace(filename: string);
}
/**
* Represents a map of floats values, typically use with a
* noise generator.
*/
declare class noisemap {
/**
* Returns the float value at a specific 3d position.
* @param pos
* @note The 'y' value of pos is ignored by this operation.
*/
get(pos: vector_3d): number;
/**
* Returns true if the float value at a 3d position
* is the highest position within a given range.
*
* This is typically used for object placement.
*
* @param pos
* @param check_radius
*/
is_highest(pos: vector_3d, check_radius: number): boolean
set(x: number, y: number, value: number): void;
width(): number;
height(): number;
}
/**
* Creates a new noisemap
* @param start_x
* @param start_y
* @param width
* @param height
* @param frequency
* @param algorithm
* @param seed
*/
declare function make_noise(start_x: number, start_y: number, width: number, height: number, frequency: number, algorithm: string, seed: string)
/**
* Represents a random generator and its state.
*/
declare class random {
integer(low: number, high: number): number;
real(low: number, high: number): number;
}
/**
* Creates a new random generator from a specific seed.
* @param seed
*/
declare function random_from_seed(seed: string): random;
/**
* Creates a new random generator from the current system time.
*/
declare function random_from_time(): random;
/**
* Represents a rectangular selection in the world and provides
* iterators for heightmap vertices, texture units, chunks and models within it.
*/
declare class selection {
/**
* Creates a noisemap matching the location of this selection
*
* @param frequency
* @param algorithm
* @param seed
*/
make_noise(frequency: number, algorithm: string, seed: string): noisemap
/**
* Returns the center point of this selection
*/
center(): vector_3d;
/**
* Returns the smallest point of this selection
*/
min(): vector_3d;
/**
* Returns the highest point of this selection
*/
max(): vector_3d;
/**
* Returns a vector representing the size of this selection on each axis.
* @note for iterators, only x and z values are respected. y (height) is ignored.
*/
size(): vector_3d;
/**
* Creates and returns an iterator for all models inside this selection
*/
models(): model[];
/**
* Creates and returns an iterator for all vertices inside this selection
*/
verts(): vert[];
/**
* Creates and returns an iterator for all texture units inside this selection
*/
tex(): tex[];
/**
* Creates and returns an iterator for all chunks inside this selection
*/
chunks(): chunk[];
/**
* Applies all changes made inside this selection.
* You almost always want to call this function when you're done
* with a selection.
*/
apply(): void;
}
/**
* Makes and returns a rectangular selection between two points.
* @param point1
* @param point2
*/
declare function select_between(point1: vector_3d, point2: vector_3d): selection;
/**
* Makes and returns a rectangular selection around an origin point
*
* @param origin - The center point of the selection
* @param xRadius
* @param zRadius
* @returns selection
*/
declare function select_origin(origin: vector_3d, xRadius: number, zRadius: number): selection;
/**
* Returns the chunk at a given position.
* The tile at the position must be loaded into memory for the
* operation to be successful.
* @param position
*/
declare function get_chunk(position: vector_3d): chunk
/**
* Represents a settings tag that can be accessed at any time by a script.
*/
declare class tag<T> {
/**
* Returns the current value of this tag in the settings panel.
*/
get(): T;
}
/**
* Represents a single texture unit in the worlds texture layers.
*
* A texture unit represents the smallest area where it's possible to
* affect textures alpha layers. This is much smaller than the areas made
* up by heightmap vertices.
*/
declare class tex {
set_alpha(index: number, alpha: number): void;
get_alpha(index: number): number;
get_pos_2d(): vector_3d;
}
/**
* Represents a single heightmap vertex in the world.
*
* Changes to this vertex takes visible effect in Noggit after you call
* "apply" on the chunk or selection that contains it.
*/
declare class vert {
/**
* Returns the full position of this vertex
*/
get_pos(): vector_3d;
/**
* Changes the height of this vertex
*/
set_height(y: number);
add_height(y: number);
sub_height(y: number);
/**
* Changes the vertex color that this vertex blends with the
* underlying texture. Values generally range between 0-1, but can
* also go higher.
*
* @param red - How much red should be used (default: 1)
* @param green - How much green should be used (default: 1)
* @param blue - How much blue should be used (default: 1)
*/
set_color(red: number, green: number, blue: number): void;
/**
* Changes the water type on this vertex, but only if the vertex is
* aligned with water tiles. If the vertex is not aligned
* with a water tile, this function does nothing.
*
* @param type
* @param height
*
* @note The C++ function backing this operation is very slow for the moment.
* use with care.
*/
set_water(type: number, height: number): void;
/**
* Sets whether this vertex should be a hole, but only if the
* vertex is aligned with hole tiles. If the vertex is not aligned
* with a hole tile, this function does nothing.
*
* @param has_hole
*/
set_hole(has_hole: boolean): void;
/**
* Sets a texture alpha layer of all texture units closest to this vertex.
*
* @param index
* @param alpha
*/
set_alpha(index: number, alpha: number): void;
/**
* Returns the average alpha of all texture units closest to this vertex.
* @param index
*/
get_alpha(index: number);
/**
* Returns true if this vertex is aligned with water tiles.
*/
is_water_aligned(): boolean;
}
/**
* Contains some general-purpose procedures that don't fit anywhere else.
*
* Access these functions through the global singleton "procedures".
*/
declare class procedures_class {
paint_texture(sel: selection, img: image, layer: number, pressure: number, angle: number);
}
/**
* singleton
*/
declare const procedures: procedures_class;

27
scripts/height_noise.lua Normal file
View File

@@ -0,0 +1,27 @@
-- This file is part of Noggit3, licensed under GNU General Public License (version 3).
local noise_brush = brush("Height Noise")
local algo = noise_brush:add_string_tag("Algorithm","HgANAAUAAAAAAABAEAAAAAA/CAAAAACAPwAAAAA/AAAAAAABEwBI4RpAGwANAAMAAAAAAABACAAAAAAAPwAAAAAAAI/C9Tw=")
local seed = noise_brush:add_string_tag("Seed","noggit")
local frequency = noise_brush:add_real_tag("Frequency",0.0005,1.0,0.001,5)
local amplitude = noise_brush:add_real_tag("Amplitude",1.0,1000.0,410.0,2)
function noise_brush:on_left_hold(evt)
local sel = select_origin(
evt:pos(),
evt:outer_radius(),
evt:outer_radius()
)
local map = sel:make_noise(
frequency:get(),
algo:get(),
seed:get()
)
for i,vert in pairs(sel:verts()) do
local height = map:get(
vert:get_pos()
) * amplitude:get()
vert:set_height(height)
end
sel:apply()
end

38
scripts/image_brush.lua Normal file
View File

@@ -0,0 +1,38 @@
-- This file is part of Noggit3, licensed under GNU General Public License (version 3).
local painter_brush = brush("Image Painter")
local image_path = painter_brush:add_string_tag("Filename", "")
function painter_brush:on_left_click(evt)
local img = load_png(
image_path:get()
)
local origin = evt:pos()
local width = img:width()
local height = img:height()
local half_width = width / 2
local half_height = height / 2
local sel = select_origin(origin, width, height)
for i,vert in pairs(sel:verts()) do
local angle = cam_yaw() - 90
local pos = rotate_2d(
vert:get_pos(),
origin,
angle
)
local local_x = round((pos.x - origin.x) + half_width)
local local_z = round((pos.z - origin.z) + half_height)
if local_x >= 0
and local_x < width
and local_z >= 0
and local_z < height
and img:get_alpha(local_x,local_z)>0.5 then
local red = img:get_red(local_x, local_z)
local green = img:get_green(local_x, local_z)
local blue = img:get_blue(local_x, local_z)
vert:set_color(red, green, blue)
end
end
sel:apply()
end

88
scripts/prop_placer.lua Normal file
View File

@@ -0,0 +1,88 @@
-- This file is part of Noggit3, licensed under GNU General Public License (version 3).
local prop_placer = brush("Prop Placer")
local seed = prop_placer:add_string_tag("Seed","noggit")
local dist = prop_placer:add_int_tag("Distance",1,50,5)
local delete_all = prop_placer:add_bool_tag("Delete all models",false)
local circle_brush = prop_placer:add_bool_tag("Circle brush",false)
function Prop(index)
local prop = {}
prop.model_name = prop_placer:add_string_tag("Prop "..index)
prop.min_scale = prop_placer:add_real_tag("Prop "..index.." Min Scale",0.001,10,0.7,2)
prop.max_scale = prop_placer:add_real_tag("Prop "..index.." Max Scale",0.001,10,0.7,2)
return prop
end
prop_placer:add_null_tag()
local prop1 = Prop(1);
prop_placer:add_null_tag();
local prop2 = Prop(2);
prop_placer:add_null_tag();
local prop3 = Prop(3);
local props = {prop1,prop2,prop3}
function prop_placer:on_left_hold(evt)
local cur_props = {}
local count = 0
for _,v in pairs(props) do
if string.len(v.model_name:get())>0 then
table.insert(cur_props,v)
count = count + 1
end
end
if count == 0 then
print("No models selected")
return
end
local sel = select_origin(evt:pos(),evt:outer_radius(),evt:outer_radius())
for _,v in pairs(cur_props) do
for i,model in pairs(sel:models()) do
if(
(delete_all:get() or model:has_filename(v))
and
((not circle_brush:get())
or dist_2d(
model:get_pos()
, evt:pos()) < evt:outer_radius())
) then
model:remove()
end
end
end
local map = make_noise(
sel:min().x-dist:get()
, sel:min().z-dist:get()
, sel:size().x+2*dist:get()
, sel:size().z+2*dist:get()
, 1
, "SIMPLEX"
, seed:get()
)
for i,vert in pairs(sel:verts()) do
if (not circle_brush:get()) or dist_2d(
vert:get_pos(),
evt:pos()
) < evt:outer_radius() then
local loc = vert:get_pos()
if map:is_highest(loc,dist:get()) then
local rnd = random_from_seed(seed:get().." "..loc.x.." "..loc.z)
local index = rnd:integer(1,count+1)
local prop = cur_props[index]
local size = rnd:real(prop.min_scale:get(),prop.max_scale:get())
local rot = rnd:real(0,360.0)
add_m2(prop.model_name:get(),loc,size,vec(0,rot,0))
end
end
end
sel:apply()
end

23
scripts/texture_brush.lua Normal file
View File

@@ -0,0 +1,23 @@
local texture_brush = brush("Texture Brush")
texture_brush:add_description("<b>Description</b>:")
texture_brush:add_description("- Uses a black / white texture to paint alpha layers. ")
texture_brush:add_description("- The painting is only additive at the moment,")
texture_brush:add_description(" meaning it cannot paint layers from \"underneath\"")
texture_brush:add_description(" another layer.")
local texture = texture_brush:add_string_tag("Brush Texture", "")
local pressure = texture_brush:add_real_tag("Pressure", 0, 1000, 1, 2)
local index = texture_brush:add_int_tag("Texture Index", 1, 3, 1)
texture_brush.on_left_hold = function(brush, evt)
local image = load_png(
texture:get()
)
local sel = select_origin(
evt:pos(),
evt:outer_radius(),
evt:outer_radius()
)
procedures:paint_texture(sel,image,index:get(),pressure:get(),cam_yaw()-90)
sel:apply()
end

View File

@@ -0,0 +1,26 @@
local texture_printer = brush("Texture Printer");
texture_printer:add_description("<b>Description</b>:")
texture_printer:add_description("Prints out texture paths and effect ids ")
texture_printer:add_description("in the clicked chunk.")
texture_printer:add_null_tag()
function texture_printer:on_left_click(evt)
local sel = select_origin(evt:pos(), 1, 1)
for i,chunk in pairs(sel:chunks()) do
if chunk:get_texture_count() == 0 then
print("Chunk has no textures")
end
print("== Chunk Textures ==")
for i=0,chunk:get_texture_count()-1 do
local tex = chunk:get_texture(i)
local eff = chunk:get_effect(i)
print("Layer "..i..":")
print(" Texture: "..tex)
print(" Effect: "..eff)
end
print("")
end
end

21
scripts/tsconfig.json Normal file
View File

@@ -0,0 +1,21 @@
/**
* This file has a working configuration to write
* script brushes with TypeScriptToLua
* (https://github.com/TypeScriptToLua/TypeScriptToLua)
*/
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"outDir": "./_tsbuild",
"forceConsistentCasingInFileNames": true
},
"tstl": {
"luaTarget": "5.1",
"luaPlugins": [],
"noImplicitSelf": true,
}
}