From abdefde25c2fd2ce302f00d20d4c1ad4a88a0c1a Mon Sep 17 00:00:00 2001 From: Dmitry Kostenko Date: Sun, 31 Jan 2021 04:23:18 +0100 Subject: [PATCH] Add cylinder shape --- init.lua | 27 +++++++++++++++++++++++++- textures/terraform_shape_cylinder.png | Bin 0 -> 870 bytes 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 textures/terraform_shape_cylinder.png diff --git a/init.lua b/init.lua index e088154..7b7c92e 100644 --- a/init.lua +++ b/init.lua @@ -188,7 +188,8 @@ terraform:register_tool("brush", { "label[0.2,0.5; Shape:]".. "image_button[0,1;1,1;"..selection("terraform_shape_sphere.png",settings:get_string("shape") == "sphere")..";shape_sphere;]".. "image_button[1,1;1,1;"..selection("terraform_shape_cube.png", settings:get_string("shape") == "cube")..";shape_cube;]".. - "image_button[2,1;1,1;"..selection("terraform_shape_plateau.png",settings:get_string("shape") == "plateau")..";shape_plateau;]".. + "image_button[2,1;1,1;"..selection("terraform_shape_cylinder.png", settings:get_string("shape") == "cylinder")..";shape_cylinder;]".. + "image_button[0,2;1,1;"..selection("terraform_shape_plateau.png",settings:get_string("shape") == "plateau")..";shape_plateau;]".. "container_end[]".. @@ -235,6 +236,10 @@ terraform:register_tool("brush", { settings:set_string("shape", "plateau") refresh = true end + if fields.shape_cylinder ~= nil then + settings:set_string("shape", "cylinder") + refresh = true + end if fields.search ~= nil then settings:set_string("search", fields.search) refresh = true @@ -355,6 +360,26 @@ terraform:register_tool("brush", { end, } end, + cylinder = function() + return { + get_bounds = function(self, player, target_pos, size_3d) + return vector.subtract(target_pos, vector.new(size_3d.x, 0, size_3d.z)), vector.add(target_pos, size_3d) + end, + paint = function(self, data, a, target_pos, minp, maxp, ctx) + for i in a:iter(minp.x, minp.y, minp.z, maxp.x, maxp.y, maxp.z) do + local ip = a:position(i) + local epsilon = 0.3 + local delta = { x = ip.x - target_pos.x, z = ip.z - target_pos.z } + delta = { x = delta.x / (ctx.size_3d.x + epsilon), z = delta.z / (ctx.size_3d.z + epsilon) } + delta = { x = delta.x^2, z = delta.z^2 } + + if 1 > delta.x + delta.z and ctx.in_mask(data[i]) then + data[i] = ctx.get_paint() + end + end + end, + } + end, plateau = function() return { get_bounds = function(self, player, target_pos, size_3d) diff --git a/textures/terraform_shape_cylinder.png b/textures/terraform_shape_cylinder.png new file mode 100644 index 0000000000000000000000000000000000000000..3b1b93817ad53e707d39ade0aab62940a8af267b GIT binary patch literal 870 zcmV-s1DX7ZP)EX>4Tx04R}tkv&MmP!xqvQ>7x64t5X`$xvOiAXdatt5Adrp;lE=H#a9m7b)?+q|hSP3y=44-aUu+?gNB+nQ2zn1fc1* znM%aPOmFVHWr1gg&2(y>I7}=S+E{60Rx~x@DdLE#>69;I zJXSexan{OJ*1RWwVKAq!EOVXK5E59#5+sOFP(=x4*oe}ulVTx7=kX5yLDw&lOCeVY zj2sK7K!fc1!T;d*Y^{83(n|`)f$kT_`4|BLyFjDnIN!&P(>MYA&%l-5@>lA>%qQu! zmKHezLfgQ_bxTwBfXf|V;K`6p*_HgXgnS-&KcjET0{yo@@0vHa<~dFufHci2c>^3A z0;2`WUhnYkp7y!@+tZxi56Vz-%62NOV*mgE24YJ`L;yGdH~=_mXheJpI9?}Q^000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0003!NklV+45QV?zc*#|`64#-pqN`Tr0)aIW z66=NxVgauU=f}`ZMMsJ}iO1vjK09jLmWbeby^?cgu~^VFjU{0l07(EGk4K$OC)&2< z^iPdUFwoTV{^bwr9j)-8n zTv9{4-EQQZd0VgPFG2J{L;#S-ZZ(DN_KQA(OCR(RMD%=j=U)mWNaI4+kA;T3d{7xH z*uw#nTq$T$LN>^=CYALF%*;zemq`KR8kOoAt*T596P^{gyfdGQr@=teq%x1FZKoPY z5h1YWT~!*(DpsCsq}hQ%rASW}pm34Pe^Iwc&rpOhu4Eby@+|Xs@l2i=xonYAGh8AK woaQ6dRICAEb&)3YMT#e{n$wgTJ#eu20kp%c<}Akz(EtDd07*qoM6N<$f