setzer22 / blackjack

A procedural, node-based modelling tool, made in rust 🦀
Mozilla Public License 2.0
1.41k stars 59 forks source link

Extrude Along Curve issues #95

Closed gmlewis closed 11 months ago

gmlewis commented 12 months ago

First off, thank you for this project!

I wrote a custom "Helix" node in Lua, that looks like this: helix-2023-10-08_22-12-27

When I attempt to extrude a quad along the helix curve using "Extrude Along Curve", I get this: extrude-along-curve-2023-10-08_22-12-47

I'm a Rust newbie so I haven't dug into the code yet, but just wanted to report it here to keep track of the issue.

Here is the custom helix.lua code (placed in the blackjack_lua/run directory) I wrote in case you want to try it out:

local P = require("params")
local NodeLibrary = require("node_library")

NodeLibrary:addNodes({
    Helix = {
        label = "Helix",
        op = function(inputs)
        local points = {}
        -- Generate the points
        local max_angle = inputs.turns * 2.0 * math.pi
        local num_steps = math.ceil(inputs.turns * inputs.segments)

        if num_steps < 1 then
                return { out_mesh = Primitives.line_from_points(points) }
        end

        local angle_delta = max_angle / num_steps
        local delta_y = inputs.size.y * inputs.turns / num_steps
        local direction = inputs.direction == "Clockwise" and -1 or 1
        local start_angle = math.pi * inputs.start_angle / 180
        for i = 0, num_steps do
            local angle = direction * (start_angle + i * angle_delta)
            local x = inputs.pos.x + inputs.size.x * math.cos(angle)
            local z = inputs.pos.z + inputs.size.z * math.sin(angle)
            local y = inputs.pos.y + i * delta_y
        table.insert(points, vector(x, y, z))
        end
            return { out_mesh = Primitives.line_from_points(points) }
        end,
        inputs = {
            P.v3("pos", vector(0, 0, 0)),
            P.v3("size", vector(1, 1, 1)),
            P.scalar("start_angle", { default = 0, min = 0, soft_max = 360 }),
            P.scalar("turns", { default = 1, min = 0, soft_max = 10 }),
            P.scalar_int("segments", { default = 36, min = 1, soft_max = 360 }),
        P.enum("direction", { "Clockwise", "Counter-Clockwise"}, 0),
        },
        outputs = {
            P.mesh("out_mesh"),
        },
        returns = "out_mesh",
    },
})
gmlewis commented 12 months ago

While I'm here, would you consider the possibility of being able to rename nodes? Additionally, it would be nice to be able to search for a node with a keyboard shortcut (maybe "/"?) that would zoom into (zoom-fit) any nodes that match that name.

As the network grows more complex, I think it would be nice to label nodes especially for really important inputs from the user. As an example in the above screenshots, the far left "Point" node really represents an "Inner Radius" of a coil I would like to make, and I would like to name it that instead of just leaving it as a generic "Point".

gmlewis commented 11 months ago

Please note that the helix.lua code above is out-of-date and has been replaced by code in #96.

gmlewis commented 11 months ago

It turns out that all of the above was just user error, but I learned a lot. I think #96 might still be a nice addition, so I'll leave that PR open but will close this issue as "working as intended". Sorry for the noise.