@@ -72,7 +72,6 @@ function TerrainConverter:CanConvert(items)
7272 return false
7373end
7474
75-
7675function TerrainConverter :_canConvertPart (item )
7776 if not (item :IsA (" Part" ) or item :IsA (" WedgePart" )) then
7877 return false
@@ -138,12 +137,12 @@ function TerrainConverter:_convertPart(part, material)
138137 elseif part .Shape == Enum .PartType .Block then
139138 self :_fillBlock (part .CFrame , part .Size , material )
140139 elseif part .Shape == Enum .PartType .Ball then
141- self :_fillBall (part .Position , part .Size .x / 2 , material )
140+ self :_fillBall (part .Position , part .Size .x / 2 , material )
142141 elseif part .Shape == Enum .PartType .Cylinder then
143142 local size = part .Size
144143 local height = size .x
145- local radius = math.min (size .y , size .z )
146- self :_fillCylinder (part .CFrame * CFrame .Angles (0 , 0 , math.pi / 2 ), height , radius , material )
144+ local radius = math.min (size .y , size .z ) / 2
145+ self :_fillCylinder (part .CFrame * CFrame .Angles (0 , 0 , math.pi / 2 ), height , radius , material )
147146 else
148147 warn ((" [PartToTerrain] - Bad part.Shape, '%s' is not supported" ):format (tostring (part .Shape .Name )))
149148 return false
@@ -157,7 +156,7 @@ function TerrainConverter:_convertPart(part, material)
157156end
158157
159158function TerrainConverter :_fillWedge (wedgeCFrame , wedgeSize , desiredMaterial )
160- if ( self .OverwriteTerrain .Value and self .OverwriteWater .Value ) then
159+ if self .OverwriteTerrain .Value and self .OverwriteWater .Value then
161160 Workspace .Terrain :FillWedge (wedgeCFrame , wedgeSize , desiredMaterial )
162161 return
163162 end
@@ -166,7 +165,7 @@ function TerrainConverter:_fillWedge(wedgeCFrame, wedgeSize, desiredMaterial)
166165end
167166
168167function TerrainConverter :_fillCylinder (cylinderCFrame , height , radius , desiredMaterial )
169- if ( self .OverwriteTerrain .Value and self .OverwriteWater .Value ) then
168+ if self .OverwriteTerrain .Value and self .OverwriteWater .Value then
170169 Workspace .Terrain :FillCylinder (cylinderCFrame , height , radius , desiredMaterial )
171170 return
172171 end
@@ -175,7 +174,7 @@ function TerrainConverter:_fillCylinder(cylinderCFrame, height, radius, desiredM
175174end
176175
177176function TerrainConverter :_fillBlock (blockCFrame , blockSize , desiredMaterial )
178- if ( self .OverwriteTerrain .Value and self .OverwriteWater .Value ) then
177+ if self .OverwriteTerrain .Value and self .OverwriteWater .Value then
179178 Workspace .Terrain :FillBlock (blockCFrame , blockSize , desiredMaterial )
180179 return
181180 end
@@ -185,22 +184,22 @@ function TerrainConverter:_fillBlock(blockCFrame, blockSize, desiredMaterial)
185184
186185 -- https://pastebin.com/S03Q8ftH
187186
188- local aa_size , aa_position = BoundingBoxUtils .getBoundingBox ({{
189- Size = blockSize ;
190- CFrame = blockCFrame ;
191- }})
187+ local aa_size , aa_position = BoundingBoxUtils .getBoundingBox ({ {
188+ Size = blockSize ,
189+ CFrame = blockCFrame ,
190+ } })
192191
193192 local smallestSize = math.min (blockSize .x , blockSize .y , blockSize .z )
194193 local resolution = self .RESOLUTION
195194
196195 -- make sure to get all grids
197- local min = aa_position - aa_size / 2
198- local max = aa_position + aa_size / 2
196+ local min = aa_position - aa_size / 2
197+ local max = aa_position + aa_size / 2
199198 local region = Region3 .new (min , max ):ExpandToGrid (resolution )
200- min = region .CFrame .p - region .Size / 2
199+ min = region .CFrame .p - region .Size / 2
201200
202201 -- luacheck: push ignore
203- max = region .CFrame .p + region .Size / 2
202+ max = region .CFrame .p + region .Size / 2
204203 -- luacheck: pop ignore
205204
206205 local materialVoxels , occupancyVoxels = Workspace .Terrain :ReadVoxels (region , resolution )
@@ -212,22 +211,20 @@ function TerrainConverter:_fillBlock(blockCFrame, blockSize, desiredMaterial)
212211
213212 -- Since we only care about the size if it's less than one cell, we clamp this to make the calculations below faster.
214213 local sizeCellClamped = (blockSize / resolution )
215- sizeCellClamped = Vector3 .new (
216- math.min (1 , sizeCellClamped .x ),
217- math.min (1 , sizeCellClamped .y ),
218- math.min (1 , sizeCellClamped .z ))
214+ sizeCellClamped =
215+ Vector3 .new (math.min (1 , sizeCellClamped .x ), math.min (1 , sizeCellClamped .y ), math.min (1 , sizeCellClamped .z ))
219216 local sizeCellsHalfOffset = blockSize * (0.5 / resolution ) + Vector3 .new (0.5 , 0.5 , 0.5 )
220217
221- for x = 1 , size .X do
218+ for x = 1 , size .X do
222219 local cellPosX = min .x + (x - 0.5 ) * resolution
223- for y = 1 , size .Y do
220+ for y = 1 , size .Y do
224221 local cellPosY = min .y + (y - 0.5 ) * resolution
225- for z = 1 , size .Z do
222+ for z = 1 , size .Z do
226223 local cellPosZ = min .z + (z - 0.5 ) * resolution
227224 local position = Vector3 .new (cellPosX , cellPosY , cellPosZ )
228225
229226 -- -0.5 to 0.5
230- local offset = blockCFrame :pointToObjectSpace (position )/ resolution
227+ local offset = blockCFrame :pointToObjectSpace (position ) / resolution
231228
232229 -- Draw.Point(position)
233230
@@ -269,7 +266,7 @@ function TerrainConverter:_fillBlock(blockCFrame, blockSize, desiredMaterial)
269266end
270267
271268function TerrainConverter :_fillBall (center , radius , desiredMaterial )
272- if ( self .OverwriteTerrain .Value and self .OverwriteWater .Value ) then
269+ if self .OverwriteTerrain .Value and self .OverwriteWater .Value then
273270 Workspace .Terrain :FillBall (center , radius , desiredMaterial )
274271 return
275272 end
@@ -283,23 +280,23 @@ function TerrainConverter:_fillBall(center, radius, desiredMaterial)
283280 local max = center + radius3
284281 local region = Region3 .new (min , max ):ExpandToGrid (resolution )
285282
286- min = region .CFrame .p - region .Size / 2
283+ min = region .CFrame .p - region .Size / 2
287284 -- luacheck: push ignore
288- max = region .CFrame .p + region .Size / 2
285+ max = region .CFrame .p + region .Size / 2
289286 -- luacheck: pop ignore
290287
291288 local materialVoxels , occupancyVoxels = Workspace .Terrain :ReadVoxels (region , resolution )
292289 local size = materialVoxels .Size
293- for x = 1 , size .X do
290+ for x = 1 , size .X do
294291 local cellX = min .x + (x - 0.5 ) * resolution - center .x
295- for y = 1 , size .Y do
292+ for y = 1 , size .Y do
296293 local cellY = min .y + (y - 0.5 ) * resolution - center .y
297- for z = 1 , size .Z do
294+ for z = 1 , size .Z do
298295 local cellZ = min .z + (z - 0.5 ) * resolution - center .z
299296
300297 local cellMaterial = materialVoxels [x ][y ][z ]
301298 local cellOccupancy = occupancyVoxels [x ][y ][z ]
302- local distance = math.sqrt (cellX * cellX + cellY * cellY + cellZ * cellZ )
299+ local distance = math.sqrt (cellX * cellX + cellY * cellY + cellZ * cellZ )
303300 local brushOccupancy = math.max (0 , math.min (1 , (radius + 0.5 * resolution - distance ) / resolution ))
304301
305302 -- Use terrain tools filling behavior here
@@ -326,4 +323,4 @@ function TerrainConverter:_fillBall(center, radius, desiredMaterial)
326323 Workspace .Terrain :WriteVoxels (region , resolution , materialVoxels , occupancyVoxels )
327324end
328325
329- return TerrainConverter
326+ return TerrainConverter
0 commit comments