Improve shading for rotated cubes, slabs and stairs

This commit is contained in:
stujones11 2017-02-24 19:58:48 +00:00
parent 84fe9864a3
commit 80adbb7f3b
6 changed files with 248 additions and 7 deletions

View File

@ -116,6 +116,7 @@ meshnode_yaw_amount = 0.017
meshnode_max_radius = 8
meshnode_show_in_creative = false
meshnode_enable_crafting = false
meshnode_fake_shading = false
meshnode_autoconf = false
```
Note that speed, lift, yaw and radius may still be altered by other mods after

72
api.lua
View File

@ -7,6 +7,7 @@ meshnode.config = {
max_radius = 8,
show_in_creative = false,
enable_crafting = false,
fake_shading = false,
autoconf = false,
}
@ -34,7 +35,42 @@ local function connects_to_group(pos, groups)
end
end
local function get_face_textures(facecons, texture)
local function get_tile_textures(t, facedir)
local textures = {t[1], t[1], t[1], t[1], t[1], t[1]}
if #t == 3 then
textures = {t[1], t[2], t[3], t[3], t[3], t[3]}
elseif #t == 6 then
textures = table.copy(t)
end
if facedir and meshnode.config.fake_shading == true then
local tile_opposite = {2, 1, 4, 3, 6, 5}
local tile_rotation = {
{1, 6}, {1, 3}, {1, 5}, {1, 4},
{6, 2}, {3, 2}, {5, 2}, {4, 2},
{5, 1}, {4, 1}, {6, 1}, {3, 1},
{4, 6}, {6, 3}, {3, 5}, {5, 4},
{3, 6}, {5, 3}, {4, 5}, {6, 4},
{2, 6}, {2, 3}, {2, 5}, {2, 4},
}
local modifiers = {}
local rot = tile_rotation[facedir + 1]
local top = rot[1]
local front = rot[2]
local bottom = tile_opposite[top]
local back = tile_opposite[front]
modifiers[top] = "^[colorize:#000000:16"
modifiers[bottom] = "^[colorize:#000000:128"
modifiers[front] = "^[colorize:#000000:64"
modifiers[back] = "^[colorize:#000000:64"
for i = 1, 6 do
local modifier = modifiers[i] or "^[colorize:#000000:32"
textures[i] = textures[i]..modifier
end
end
return textures
end
local function get_facecon_textures(facecons, texture)
local textures = {
"meshnode_trans.png",
"meshnode_trans.png",
@ -151,27 +187,40 @@ meshnode.add_entity = function(ref, parent)
if object then
local properties = {textures={ref.node.name}}
local def = minetest.registered_items[ref.node.name] or {}
if ref.meshtype == "plant" then
if ref.meshtype == "stair" or
ref.meshtype == "cube" or
ref.meshtype == "slab" then
local param2 = ref.node.param2 or 0
properties.visual = "mesh"
properties.visual_size = {x=1, y=1}
properties.mesh = "meshnode_"..ref.meshtype..".obj"
properties.textures = get_tile_textures(def.tiles, param2)
elseif ref.meshtype == "mesh" then
properties.visual = "mesh"
properties.visual_size = {x=10, y=10}
properties.mesh = def.mesh
properties.textures = get_tile_textures(def.tiles)
elseif ref.meshtype == "plant" then
properties.visual = "mesh"
properties.visual_size = {x=1, y=1}
properties.mesh = "meshnode_plant.obj"
properties.textures = {def.tiles[1]}
elseif ref.meshtype == "fence" then
local textures = get_face_textures(ref.facecons, def.tiles[1])
local textures = get_facecon_textures(ref.facecons, def.tiles[1])
table.insert(textures, 1, def.tiles[1])
properties.visual = "mesh"
properties.visual_size = {x=1, y=1}
properties.mesh = "meshnode_fence.obj"
properties.textures = textures
elseif ref.meshtype == "wall" then
local textures = get_face_textures(ref.facecons, def.tiles[1])
local textures = get_facecon_textures(ref.facecons, def.tiles[1])
table.insert(textures, 1, def.tiles[1])
properties.visual = "mesh"
properties.visual_size = {x=1, y=1}
properties.mesh = "meshnode_wall.obj"
properties.textures = textures
elseif ref.meshtype == "pane" then
local textures = get_face_textures(ref.facecons, def.tiles[3])
local textures = get_facecon_textures(ref.facecons, def.tiles[3])
properties.visual = "mesh"
properties.visual_size = {x=1, y=1}
properties.mesh = "meshnode_pane.obj"
@ -189,8 +238,7 @@ meshnode.add_entity = function(ref, parent)
end
local yaw = parent.object:getyaw()
local offset = vector.multiply(ref.offset, 10)
local rotation = vector.new(ref.rotation)
object:set_attach(parent.object, "", offset, rotation)
object:set_attach(parent.object, "", offset, ref.rotation)
end
end
return object
@ -217,6 +265,16 @@ meshnode.create = function(pos, parent)
def.paramtype2 == "wallmounted" or
def.paramtype2 == "flowingliquid" then
return
elseif def.drawtype == nil or def.drawtype == "normal" then
meshtype = "cube"
elseif def.drawtype == "mesh" then
if string.find(node.name, ":stair") then
meshtype = "stair"
else
meshtype = "mesh"
end
elseif string.find(node.name, ":slab") then
meshtype = "slab"
elseif def.drawtype == "plantlike" then
meshtype = "plant"
elseif minetest.get_item_group(node.name, "fence") > 0 then

View File

@ -21,6 +21,7 @@ if is_singleplayer then
meshnode.config.max_radius = 16
meshnode.config.show_in_creative = true
meshnode.config.enable_crafting = true
meshnode.config.fake_shading = true
meshnode.config.autoconf = true
else
meshnode.blacklist["default:chest_locked"] = true

38
models/meshnode_cube.obj Normal file
View File

@ -0,0 +1,38 @@
# Blender v2.72 (sub 0) OBJ File: 'invtest_cube.blend'
# www.blender.org
mtllib meshnode_cube_0.mtl
v -5.000000 -5.000000 5.000000
v -5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 5.000000
v -5.000000 5.000000 5.000000
v -5.000000 5.000000 -5.000000
v 5.000000 5.000000 -5.000000
v 5.000000 5.000000 5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 5.000000
v 5.000000 5.000000 -5.000000
v 5.000000 5.000000 5.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
g Cube_Cube_Top
usemtl Top
s off
f 8/1 7/2 6/3 5/4
g Cube_Cube_Bottom
usemtl Bottom
f 1/3 2/4 3/1 4/2
g Cube_Cube_Right
usemtl Right
f 5/4 6/1 2/2 1/3
g Cube_Cube_Left
usemtl Left
f 11/4 12/1 10/2 9/3
g Cube_Cube_Back
usemtl Back
f 8/4 5/1 1/2 4/3
g Cube_Cube_Front
usemtl Front
f 6/4 7/1 3/2 2/3

40
models/meshnode_slab.obj Normal file
View File

@ -0,0 +1,40 @@
# Blender v2.72 (sub 0) OBJ File: 'invtest_cube.blend'
# www.blender.org
mtllib meshnode_slab_0.mtl
v -5.000000 -5.000000 5.000000
v -5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 5.000000
v -5.000000 0.000000 5.000000
v -5.000000 0.000000 -5.000000
v 5.000000 0.000000 -5.000000
v 5.000000 0.000000 5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 5.000000
v 5.000000 0.000000 -5.000000
v 5.000000 0.000000 5.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 0.500000
vt 0.000000 0.500000
g Cube_Cube_Top
usemtl Top
s off
f 8/1 7/2 6/3 5/4
g Cube_Cube_Bottom
usemtl Bottom
f 1/3 2/4 3/1 4/2
g Cube_Cube_Right
usemtl Right
f 5/5 6/6 2/2 1/3
g Cube_Cube_Left
usemtl Left
f 11/5 12/6 10/2 9/3
g Cube_Cube_Back
usemtl Back
f 8/5 5/6 1/2 4/3
g Cube_Cube_Front
usemtl Front
f 6/5 7/6 3/2 2/3

103
models/meshnode_stair.obj Normal file
View File

@ -0,0 +1,103 @@
# Blender v2.72 (sub 0) OBJ File: 'invtest.blend'
# www.blender.org
mtllib meshnode_stair_0.mtl
g stairs_top
v 5.000000 0.000000 -5.000000
v -5.000000 0.000000 -5.000000
v -5.000000 0.000000 0.000000
v 5.000000 0.000000 0.000000
v -5.000000 5.000000 5.000000
v 5.000000 5.000000 5.000000
v 5.000000 5.000000 0.000000
v -5.000000 5.000000 0.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 0.500000
vt 0.000000 0.500000
vt 1.000000 1.000000
vt 0.000000 1.000000
usemtl None
s off
f 1/1 2/2 3/3 4/4
f 5/5 6/6 7/4 8/3
g stairs_bottom
v -5.000000 -5.000000 5.000000
v -5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 -5.000000 5.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
usemtl None.001
s off
f 9/7 10/8 11/9 12/10
g stairs_right
v -5.000000 0.000000 -5.000000
v -5.000000 -5.000000 -5.000000
v -5.000000 0.000000 0.000000
v -5.000000 5.000000 5.000000
v -5.000000 5.000000 0.000000
v -5.000000 -5.000000 5.000000
vt 0.000000 0.500000
vt 0.000000 0.000000
vt 0.500000 0.500000
vt 1.000000 1.000000
vt 0.500000 1.000000
vt 1.000000 0.000000
usemtl None.002
s off
f 13/11 14/12 15/13
f 15/13 16/14 17/15
f 14/12 18/16 15/13
f 18/16 16/14 15/13
g stairs_left
v 5.000000 0.000000 0.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 0.000000 -5.000000
v 5.000000 5.000000 0.000000
v 5.000000 5.000000 5.000000
v 5.000000 -5.000000 5.000000
vt 0.500000 0.500000
vt 1.000000 0.000000
vt 1.000000 0.500000
vt 0.500000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
usemtl None.003
s off
f 19/17 20/18 21/19
f 19/17 22/20 23/21
f 20/18 19/17 24/22
f 19/17 23/21 24/22
g stairs_back
v 5.000000 -5.000000 5.000000
v 5.000000 5.000000 5.000000
v -5.000000 5.000000 5.000000
v -5.000000 -5.000000 5.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
usemtl None.004
s off
f 25/23 26/24 27/25 28/26
g stairs_front
v -5.000000 -5.000000 -5.000000
v -5.000000 0.000000 -5.000000
v 5.000000 0.000000 -5.000000
v 5.000000 -5.000000 -5.000000
v -5.000000 0.000000 0.000000
v -5.000000 5.000000 0.000000
v 5.000000 5.000000 0.000000
v 5.000000 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 0.500000
vt 0.000000 0.500000
vt 0.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
usemtl None.005
s off
f 29/27 30/28 31/29 32/30
f 33/28 34/31 35/32 36/29