param2 cleanup
This commit is contained in:
parent
c1df35e4b9
commit
c40ab32f68
@ -15,8 +15,7 @@ function mtscad.create_context(opts)
|
||||
pos = opts.pos and vector.copy(opts.pos) or vector.zero(),
|
||||
mirror_pos = opts.mirror_pos and vector.copy(opts.mirror_pos) or vector.new(1,1,1),
|
||||
rotation = opts.rotation or mtscad.rotation_matrix_x(0),
|
||||
nodefactory = opts.nodefactory,
|
||||
node_param2 = opts.node_param2 or 0,
|
||||
node_spec = opts.node_spec or { name = "air" },
|
||||
job_context = job_context,
|
||||
-- global session info
|
||||
session = opts.session or {
|
||||
|
@ -1,7 +0,0 @@
|
||||
|
||||
function mtscad.Context:param2(param2)
|
||||
local ctx = self:clone()
|
||||
ctx.node_param2 = param2
|
||||
return ctx
|
||||
end
|
||||
|
@ -1,10 +1,17 @@
|
||||
function mtscad.Context:set_node()
|
||||
-- get node name and param2
|
||||
local node = self.nodefactory and self.nodefactory(self.param2) or { name="air" }
|
||||
if not node.node_param2 and self.node_param2 then
|
||||
node.param2 = self.node_param2
|
||||
local node = { name="air" }
|
||||
|
||||
if type(self.node_spec) == "string" then
|
||||
node = { name=self.node_spec }
|
||||
elseif type(self.node_spec) == "table" then
|
||||
node = self.node_spec
|
||||
elseif type(self.node_spec) == "function" then
|
||||
node = self.node_spec()
|
||||
end
|
||||
|
||||
-- default param2
|
||||
node.param2 = node.param2 or 0
|
||||
|
||||
-- rotate param2
|
||||
local tnode = mtscad.transform_node(node, self.rotation)
|
||||
if self.mirror_pos.x == -1 or self.mirror_pos.z == -1 then
|
||||
|
@ -1,38 +1,7 @@
|
||||
|
||||
|
||||
local function create_nodefactory(def)
|
||||
if type(def) == "string" then
|
||||
-- string
|
||||
return function(param2)
|
||||
return { name=def, param2=param2 }
|
||||
end
|
||||
elseif type(def) == "table" and def.nodefactory then
|
||||
-- other context with nodefactory
|
||||
return def.nodefactory
|
||||
|
||||
elseif type(def) == "table" and def.name then
|
||||
-- node table
|
||||
return function()
|
||||
return def
|
||||
end
|
||||
|
||||
elseif type(def) == "table" then
|
||||
-- multiple nodes with chance value
|
||||
local nodes = {}
|
||||
for nn, ch in pairs(def) do
|
||||
for _=1,ch do
|
||||
table.insert(nodes, nn)
|
||||
end
|
||||
end
|
||||
return function(param2)
|
||||
return { name=nodes[math.random(#nodes)], param2=param2 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mtscad.Context:with(def)
|
||||
function mtscad.Context:with(node_spec)
|
||||
local ctx = self:clone()
|
||||
ctx.nodefactory = create_nodefactory(def, self.node_param2)
|
||||
ctx.node_spec = node_spec
|
||||
return ctx
|
||||
end
|
||||
|
||||
|
1
init.lua
1
init.lua
@ -13,7 +13,6 @@ dofile(MP .. "/context/polygon.lua")
|
||||
dofile(MP .. "/context/cube.lua")
|
||||
dofile(MP .. "/context/sphere.lua")
|
||||
dofile(MP .. "/context/dome.lua")
|
||||
dofile(MP .. "/context/param2.lua")
|
||||
dofile(MP .. "/context/cylinder.lua")
|
||||
dofile(MP .. "/context/pattern.lua")
|
||||
dofile(MP .. "/context/char.lua")
|
||||
|
@ -1,6 +1,5 @@
|
||||
return function(ctx)
|
||||
ctx
|
||||
:with("default:mese")
|
||||
:param2(3)
|
||||
:with({ name="default:mese", param2=3 })
|
||||
:line(10,10,10)
|
||||
end
|
@ -1,8 +1,7 @@
|
||||
local function fn(ctx)
|
||||
ctx
|
||||
:translate(2, 0, 1)
|
||||
:with("default:mese")
|
||||
:param2(3)
|
||||
:with({ name="default:mese", param2=3 })
|
||||
:set_node()
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user