[Closed] IsoSplines script
UPDATE:
-- IsoSplines v0.4
[color=SeaGreen] -- By Rens Heeren.
-- v0.1: basic setup.
--
-- v0.2: streamlined by Roger Hyde, with basic double spline detection.
--
-- v0.3: streamlined code extended.
-- added double edge detection.
-- added spline welding function.
--
-- v0.4: total code redesign.
-- new edge sorting functions.
-- new spline creation method.
-- Written for Max 6. Does not work on versions before 6: edge
-- selections won't be propagated.
-- Works on EPoly with NURMS or MeshSmooth modifier applied,
-- and also on EMesh with MeshSmooth modifier applied. <- NOT YET
-- USE:
-- - Make low-poly base object (EPoly).
-- - Apply meshsmooth with iterations > 0.
-- - Run script.
[/color]
max create mode
setWaitCursor()
--disableScreenRedraw()
undo off
fn polyFn obj =
(
-- *EDGE SELECTION* --
-- Goto base, select all edges, apply mesh select.
modPanel.setCurrentObject obj.baseObject
polyOp.setEdgeSelection obj #all
addModifier obj (mesh_select())
-- As the mesh select modifier is now active the edge selection
-- will now be the smoothed original edges: the isolines.
isoEdges = getEdgeSelection obj as array
-- But where there's smoke there's eMesh.
-- In this case we have to ditch the double edges.
-- This is a simple check. The vertex indices are added paired, so
-- VertContainer[1] may look like this: #(1,15). This way the edges
-- can be easily checked for duplicates.
single_edges = #()
vert_container = #()
for a in isoEdges do
(
hold = (meshop.getVertsUsingEdge obj a) as string
if findItem vert_container hold == 0 do append single_edges a
append vert_container hold
)
VertContainer = #()
isoEdges = #()
-- *EDGE SORTING* --
-- Data miner. This will provive an array with edge info for
-- the sorting functions to call
global edge_info = #()
for edge in single_edges do
(
verts = meshOp.getVertsUsingEdge obj edge as array
conn_edges_one_single = #()
conn_edges_one = meshOp.getEdgesUsingVert obj verts[1]
for edges in conn_edges_one do
(
if findItem single_edges edges != 0 do
append conn_edges_one_single edges
)
conn_edges_two_single = #()
conn_edges_two = meshOp.getEdgesUsingVert obj verts[2]
for edges in conn_edges_two do
(
if findItem single_edges edges != 0 do
append conn_edges_two_single edges
)
pos_one = getVert obj verts[1] -- can be deleted
pos_two = getVert obj verts[2] -- same
pre_edge_one = #(verts[1],conn_edges_one_single,pos_one)
pre_edge_two = #(verts[2],conn_edges_two_single,pos_two)
append edge_info #(edge,pre_edge_one,pre_edge_two)
)
-- edge_info structure
-- edge_info[i]:
[/i] -- - edge, vert1, vert2
-- - ID, conn, pos
-- edge_info[i] = edge, vert1, vert2
-- [i][1] edge ID
-- [i][2] ID1, Conn, Pos
-- [i][3] ID2, Conn, Pos
-- [i][2][1] vert 1 ID
-- [i][2][2] edges connected to vert 1
-- [i][2][3] (RED.) position of vert 1
-- [i][3][1] vert 2 ID
-- [i][3][2] edges connected to vert 2
-- [i][3][3] (RED.) position of vert 2
-- Sorting functions
global used_edges = #()
global sorted_edges = #()
global edge_line = #()
fn vert_check_func k i =
(
if edge_info[i][k][2][1] != edge_info[i][1] do
(
get_edges_func i edge_info[i][k][2][1]
)
)
fn get_edges_func j edge =
(
if findItem used_edges edge == 0 do
(
append used_edges edge
append edge_line edge
if edge_info[j][2][2].count == 2 do
(
vert_check_func 2 j
)
if edge_info[j][3][2].count == 2 do
(
vert_check_func 3 j
)
)
)
while used_edges.count != single_edges.count do
(
for i = 1 to single_edges.count do
(
get_edges_func i edge_info[i][1]
if edge_line[1] != undefined do append sorted_edges edge_line
edge_line = #()
)
)
edge_info = #()
-- *SPLINE CREATION* --
isoSpl = splineShape transform:obj.transform name:(uniqueName "IsoSpline")
for group in sorted_edges do
(
vert_pos = #()
vert_sorted = #()
for edge in group do
(
verts = meshOp.getVertsUsingEdge obj edge
for vert in verts do
(
if findItem vert_sorted vert == 0 do
append vert_sorted vert
)
)
for vert in vert_sorted do
(
append vert_pos (meshOp.getVert obj vert)
)
idx = addNewSpline isoSpl
for pos in vert_pos do
(
addKnot isoSpl idx #smooth #curve pos
)
updateShape isoSpl
)
deleteModifier obj 1
-- return the SplineShape so it can be accessed by the
-- calling context
return isoSpl
)
if selection.count == 0 then
(
messageBox "No objects are selected!" title:"IsoSplines"
)
isoSplineSel = #()
for obj in (getCurrentSelection()) do
(
append isoSplineSel (polyFn obj)
)
select isoSplineSel
--enableScreenRedraw()
--redrawViews
I looked at it again a day or so ago and I had an idea on how to solve the problems I had before. It’s pretty much a complete rewrite of the core functions.
What this script does (basically):
- Select all adges at base level.
- Add a mesh select modifier and get the same edges, now smoothed.
- Get rid of the double Emesh edges.
- Create an array with edge information.
- Sort the edges using the array so that all edges which will have two other edges connected will be selected. The idea is that all ‘lines’ will be whole splines and that the ‘junctions’ won’t be welded. I think this gives the best end result for now.
- Create the shape itself using the sorted edges.
Now, I got it to run, which was a rather pleasant surprise, but I’m not getting any spline ‘lines’. See the attachment, that would be a perfect end result from a meshsmoothed box. The ribs are connected internally but not with eachother. My problem is that the ribs are not connected internally.
Does anypne have an idea as to why this could be. I looked at it so many times now that my brain hurts.
Thanks in advance,
- Rens
I get the following error:
– Compile error: No outer local variable references permitted here: vert_check_func
– In line: vert_checvert_check_func 2 j