Home Coding, Scripting, Shaders

[MaxScript] Transfer stack selection to Unrawp UVW

polycounter lvl 11
Offline / Send Message
FishMan polycounter lvl 11
Ok. You proabably aware about this problem in Max its very popular request, but for some reason almoust no one still haven't solved this issue and those who solved want you to pay them money for that solution. 

I think its not fair that you should pay something for stuff that should be there by default.
Which is why I decided to make a free script...
And I actually made one. But of cource its very slow and doesn't work for editable mesh and modifiers like edit_poly yet and so on :D

Here it is:

fn BuildUVEdgeAccordance obj UMod =

(

local EdgesCount = polyOp.getNumEdges obj

local EdgesVerts = polyop.getEdgesVerts obj #{1..EdgesCount}

local ReturnArray = #()

for i = 1 to EdgesCount do 

(

UMod.setTVSubObjectMode 2

UMod.setSelectedGeomEdgesByNode #{i} obj

UMod.edgeToVertSelect() 

UMod.setTVSubObjectMode 1

local UVEdgeVerts = umod.getSelectedGeomVertsByNode obj 

local s = timeStamp()

local j = 1

while ((UVEdgeVerts - (EdgesVerts[j] as BitArray)).numberset != 0) and (j < EdgesCount) do

(

j += 1

if ((timestamp()) - s) / 1000 > 5 then (print "Error in while loop in BuildUVEdgeAccordance" return undefined)

)

ReturnArray[j] = i

)

ReturnArray

)



fn ConvertGeomToUV GeomArray UVArray = 

(

(for a in GeomArray collect UVArray[a]) as bitarray

)


fn GetIntSelectionLevel obj =

(

case getSelectionLevel obj of

(

#object:  0

#vertex:  1

#edge: 2

#face: 3

)

)


fn UVWSetSelection UMod obj VertSel EdgeSel FaceSel =

(

UMod.setTVSubObjectMode 1

UMod.setSelectedGeomVertsByNode VertSel obj

/*UMod.setTVSubObjectMode 3

UMod.selectFacesByNode FaceSel obj*/

UMod.setTVSubObjectMode 2

UMod.setSelectedGeomEdgesByNode EdgeSel obj

UMod.setTVSubObjectMode (GetIntSelectionLevel obj)

)


fn MainFunc = 

(

local NotificationArr = callbacks.notificationParam()

local obj = NotificationArr[1]

local UMod = NotificationArr[2]

if (selection.count != 1) or (classof UMod != unwrap_uvw) then return 0

modPanel.setCurrentObject UMod

local UVArray = BuildUVEdgeAccordance $ $.modifiers[1]

local VertSel = #{}

local EdgeSel = #{}

local FaceSel = #{}


case (classof obj.baseobject) of 

(

Editable_Poly: 

(

VertSel = polyop.getVertSelection obj.baseobject

EdgeSel = polyop.getEdgeSelection obj.baseobject

FaceSel = polyop.getFaceSelection obj.baseobject

)

Editable_Mesh: 

(

VertSel = getVertSelection obj.mesh

EdgeSel = getEdgeSelection obj.mesh

FaceSel = getFaceSelection obj.mesh

)

)

local ConvertedEdgeSel = ConvertGeomToUV EdgeSel UVArray

UVWSetSelection UMod obj VertSel ConvertedEdgeSel FaceSel

)


TransferUnwrapSelection = MainFunc

 

callbacks.removeScripts id:#TransferUnwrapSelection

callbacks.addScript #postModifierAdded TransferUnwrapSelection id:#TransferUnwrapSelection


So the question here does anyone know is there any correlation between geomedges indexation in Unwrap UVW and lets say Editable_Poly edges indexation? Or may be vertexes or faces can be used somehow to figure out the geom edge index in Unwrap?

I mean Unwrap modifer is one of the most stupid and poorly designed modifier in max. Just because you don't have a direct access to vertexes edges or faces - you have to physically select them like if you pressing some buttons in modifier interface which so extremely stupid and slow. I mean even simple mesh may freeze your max forever because of this.  

So may be there's another way? Like calculating this indexes from lets say vertexes or faces?

Transferring vertexes and faces is simple though because they have the same indexes.

So if someone have any ideas how you can transfer edges - please share this important information :D

Yeah and I wonder why the hell on earth autodesk decided that making a separate indexation algorithm for geom indexes in unwrap modifier is a great idea... but this is a rhetorical question)))

Replies

Sign In or Register to comment.