fn getMapElements node channel:1 = if iskindof node Editable_Poly or iskindof node.baseobject Editable_Poly do
(
if polyop.getmapsupport node channel do
(
mesh = snapshotasmesh node
if not iskindof node Editable_Poly do node = node.baseobject
elements = #()
done = #{}
num = mesh.numfaces
for f=1 to num while not keyboard.escpressed where not done[f] do
(
last = -1
faces = #{f}
verts = #{}
while faces.numberset != last and not keyboard.escpressed do
(
last = faces.numberset
verts = meshop.getmapvertsusingmapface mesh channel faces
faces = meshop.getmapfacesusingmapvert mesh channel verts
)
append elements verts
join done faces
)
free mesh
elements
)
)
fn getMapElementBBox3 node tverts channel:1 = if iskindof node Editable_Poly or iskindof node.baseobject Editable_Poly do
(
if polyop.getmapsupport node channel do
(
mesh = snapshotasmesh node
bmin = [1e9,1e9,1e9]
bmax = -[1e9,1e9,1e9]
pp = for tv in tverts collect
(
p = meshop.getMapVert mesh channel tv
if p.x < bmin.x do bmin.x = p.x
if p.y < bmin.y do bmin.y = p.y
if p.z < bmin.z do bmin.z = p.z
if p.x > bmax.x do bmax.x = p.x
if p.y > bmax.y do bmax.y = p.y
if p.z > bmax.z do bmax.z = p.z
p
)
free mesh
#(box3 bmin bmax, tverts, pp)
)
)
fn alignMapElement node data channel:1 = if iskindof node Editable_Poly or iskindof node.baseobject Editable_Poly do
(
if polyop.getmapsupport node channel do
(
-- data == #(box3 bmin bmax, tverts, pp)
shift = data[1].min
k = 1
for tv in data[2] do
(
p = data[3][k] - shift
polyop.setmapvert node channel tv p
k += 1
)
)
)
/****************************************************************************************/
sp =
(
max create mode
delete objects
sp = teapot name:"test_mesh" mapcoords:on
addmodifier sp (Uvwmap maptype:0)
sp = converttopoly sp
for k=1 to 3 do polyop.attach sp (copy sp)
update sp
sp
)
clusters = getMapElements sp
data = for cluster in clusters collect (getMapElementBBox3 sp cluster)
for d in data do alignMapElement sp d
(
modi = Unwrap_UVW()
addmodifier sp modi
max modify mode
modpanel.setcurrentobject modi
)
I hope I didn’t forget anything… of course, this can be algorithmically optimized, but already much faster than the built-in unwrap…
it definitely beats the Blender

