Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,25 @@ local CUBIC_SIDE_FACES = {
{vec( 0.5, -0.5, 0.5), vec(-0.5, -0.5, 0.5), vec(-0.5, 0.5, 0.5), vec( 0.5, 0.5, 0.5)}, -- Z+
{vec(-0.5, -0.5, -0.5), vec( 0.5, -0.5, -0.5), vec( 0.5, 0.5, -0.5), vec(-0.5, 0.5, -0.5)}, -- Z-
}


local function face_is_facing_out(startPoint, endPoint, blockPosition, direction)
if meshport.NEIGHBOR_DIRS[direction] == vector.new( 0, 1, 0) and math.max(startPoint[2], endPoint[2]) == blockPosition[2] then -- UP
return true
elseif meshport.NEIGHBOR_DIRS[direction] == vector.new( 1, 0, 0) and math.max(startPoint[1], endPoint[1]) == blockPosition[1] then -- RIGHT
return true
elseif meshport.NEIGHBOR_DIRS[direction] == vector.new( 0, 0, 1) and math.max(startPoint[3], endPoint[3]) == blockPosition[3] then -- FORWARD
return true
elseif meshport.NEIGHBOR_DIRS[direction] == vector.new( 0,-1, 0) and math.min(startPoint[2], endPoint[2]) == blockPosition[2] then -- DOWN
return true
elseif meshport.NEIGHBOR_DIRS[direction] == vector.new(-1, 0, 0) and math.min(startPoint[1], endPoint[1]) == blockPosition[1] then -- LEFT
return true
elseif meshport.NEIGHBOR_DIRS[direction] == vector.new( 0, 0,-1) and math.min(startPoint[3], endPoint[3]) == blockPosition[3] then -- BACKWARD
return true
else
return false
end
end
-- For normal, plantlike_rooted, and liquid drawtypes
local function create_cubic_node(pos, content, param2, nodeDef, drawtype, neighbors)
local function create_cubic_node(pos, content, param2, nodeDef, drawtype, neighbors, startPoint, endPoint)
local facedir = meshport.get_facedir(nodeDef.paramtype2, param2)
local selfPriority = CUBIC_FACE_PRIORITY[drawtype]
-- If the current node is a liquid, get the flowing version of it.
Expand All @@ -84,7 +99,7 @@ local function create_cubic_node(pos, content, param2, nodeDef, drawtype, neighb
for i = 1, 6 do
local drawFace

if neighbors[i] == core.CONTENT_AIR then
if neighbors[i] == core.CONTENT_AIR or face_is_facing_out(startPoint, endPoint, pos, i) then
drawFace = true
elseif neighbors[i] == core.CONTENT_IGNORE
-- Don't draw faces between identical nodes
Expand Down Expand Up @@ -713,7 +728,7 @@ local function create_plantlike_node(pos, param2, nodeDef)
end


local function create_node(idx, area, vContent, vParam2, playerName)
local function create_node(idx, area, vContent, vParam2, startPoint, endPoint, playerName)
if vContent[idx] == core.CONTENT_AIR
or vContent[idx] == core.CONTENT_IGNORE
or vContent[idx] == core.CONTENT_UNKNOWN then -- TODO: Export unknown nodes?
Expand All @@ -734,8 +749,7 @@ local function create_node(idx, area, vContent, vParam2, playerName)
end

if (CUBIC_FACE_PRIORITY[nodeDrawtype] or 0) >= 3 then -- liquid, normal, plantlike_rooted
faces = create_cubic_node(pos, vContent[idx], vParam2[idx], nodeDef, nodeDrawtype, neighbors)

faces = create_cubic_node(pos, vContent[idx], vParam2[idx], nodeDef, nodeDrawtype, neighbors, startPoint, endPoint)
if nodeDrawtype == "plantlike_rooted" then
local plantPos = vector.add(pos, vector.new(0, 1, 0))
local plantFaces = create_plantlike_node(plantPos, vParam2[idx], nodeDef)
Expand Down Expand Up @@ -802,7 +816,7 @@ function meshport.create_mesh(playerName, p1, p2, path)
-- Loop through all positions in the desired area.
for idx in vArea:iterp(p1, p2) do
-- Generate a mesh for the node.
local faces = create_node(idx, vArea, vContent, vParam2, playerName)
local faces = create_node(idx, vArea, vContent, vParam2, p1, p2, playerName)

if faces then
-- Move the node to its proper position.
Expand Down