首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maxscript splineOps.startTrim

Maxscript splineOps.startTrim
EN

Stack Overflow用户
提问于 2018-05-17 02:18:28
回答 2查看 626关注 0票数 0

我正在尝试为3ds max构建一个脚本,允许我自动修剪样条线。

在用谷歌搜索了4个小时后,我偶然发现了splineOps的全局结构。

这就是我到目前为止所知道的:

代码语言:javascript
复制
---- Kustom Trim Lines
try (closerolloutfloater MainFloater) catch()

Rollout Menu01 "Geometry Ops"
(
    button select_trims "Trim all similar"

    on select_trims pressed do
    (
        splineOps.startTrim Shape439
    )
)

MainFloater = NewRolloutFloater "Kustom TrimLines" 300 200
addRollout Menu01 MainFloater

当我单击新卷展栏中的按钮时,我得到一个"--未知系统异常“

最后,我想构建这个脚本来自动修剪特定样条线中的所有相似线段

任何建议/想法都是非常感谢的。

干杯!

-- 2018年5月16日2:34 16 --

在玩了更多之后,我能够让脚本选择形状,进入sub,然后选择trim选项。这看起来是这样的:

代码语言:javascript
复制
---- Kustom Trim Lines
try (closerolloutfloater MainFloater) catch()

Rollout Menu01 "Geometry Ops"
(
    button select_trims "Trim all similar"

    on select_trims pressed do
    (
        select $Shape439
        subobjectlevel = 3
        splineOps.startTrim($)
    )
)

MainFloater = NewRolloutFloater "Kustom TrimLines" 300 200
addRollout Menu01 MainFloater

现在..。我该如何将其自动化呢?比方说,我想让它修剪每两条相交的平行线之间的所有小线,或者所有小于特定长度(例如< 1“)的线段。可以这样做吗?我假设我需要首先检测所有交叉点,打断线段并删除所有<1”的线段。有没有人?有什么想法吗?

EN

回答 2

Stack Overflow用户

发布于 2018-05-18 05:24:07

这提供了长度,您可以将其用作修剪或不修剪的标准。

代码语言:javascript
复制
curveLength $Circle001 1
票数 0
EN

Stack Overflow用户

发布于 2018-05-21 03:47:19

样条线修剪工具在MaxScript中并不完全可用,因此只能启动工具UI模式,但实际的修剪操作需要单击鼠标。

您可以考虑的一个技巧是在视口中模拟鼠标单击。例如,在要修剪的结点上模拟单击,我假设这些结点是形状中所有样条线(或某些样条线)的端点。下面的代码查看形状中的每个样条线,并查看样条线中的每个线段,以检查长度是否小于某个阈值。如果是这样,它会在修剪模式下模拟鼠标单击末端结。请注意,视口透视角度很重要。该脚本需要要单击的结的清晰视图,而不是相互重叠的结。它会尝试执行Zoom Extents Selected,但这不能保证,可能需要艺术家的指导。

这当然是一种黑客行为,并不是一个完美的解决方案。但这种类型的方法可能在各种情况下都很有用。

代码语言:javascript
复制
-- Define the object to operate on
s = $Circle001

-- Spline segment length threshold maximum.  Segments longer than this will NOT be trimmed
cLenMax = 100.0

-- Zoom extents.  Attempts to get all vertices in clear view (not guaranteed)
bnd = nodeGetBoundingBox s (matrix3 1)
viewport.ZoomToBounds false bnd[1] bnd[2]

-- Make sure Modify Panel is open, with object selected
cui.commandPanelOpen = true
SetCommandPanelTaskMode #modify
select s

-- Enter Spline subobject with Trim tool
subobjectlevel = 3
splineOps.startTrim(s)

-- Spline manipulation
for sn = 1 to numSplines s do
(
    cn = numKnots s sn
    if( cn>1 ) do
    (
        -- Lengths of the segments.  There are (cn-1) segments for the spline
        -- List indicates relative lengths, then the absolute lengths, then the total spline length
        -- So the total number of entries is ((cn-1) + (cn-1) + 1)
        -- We're interested in the middle values for absolute lengths
        -- First one has index [cn] and last one has index [cn+cn-2]
        cLenData = getSegLengths s sn
        cLenFirst = cLenData[cn]
        cLenLast = cLenData[cn+cn-2]

        -- If segments are shorter than our threshold lengths, trim them
        -- Trim from highest index to lowest, since indices will change after each trim step
        cRemove = #()
        if cLenLast<cLenMax then append cRemove cn
        if cLenFirst<cLenMax then append cRemove 1

        -- Click the mouse on the first and last knot of each spline
        for kn in cRemove do
        (
            -- Get the location of the knot in world space
            kp = getknotpoint s sn kn
            gw.setTransform(Matrix3 1)

            -- Transform that to window space relative to the current viewport
            wp = gw.wTransPoint kp

            -- Click the mouse on that position in the window
            -- Super sketchy ... Workaround because Trim is not really available in MaxScript
            hvp = viewport.getHWnd()
            btnCode = 1 -- left button
            posCode = (wp.x) + (65536*wp.y) -- packed x and y position
            windows.sendMessage hvp 0x0201 btnCode posCode      -- Send WM_LBUTTONDOWN
            windows.sendMessage hvp 0x0202 btnCode posCode      -- Send WM_LBUTTONUP
        )
    )
)

deselect s
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50377612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档