Home Coding, Scripting, Shaders

Maxscript question : Converting one Uv vertex to edges.

polycounter lvl 14
Offline / Send Message
Cathodeus polycounter lvl 14
Hello,

I would like to convert one vertex to edges in unwrap uvw but it doesn't work with one uv vertex selected ... it do work with 2 vertices or more.

Do anyone know how can i achieve that ? So basiclally we select one Uv vertex we execute the script and boum, we do obtain all the adjacent edges.

Thanks.
Massimo

Replies

  • Bek
    Options
    Offline / Send Message
    Bek interpolator
    Not a maxscript person but wouldn't you just have to grow the selection then convert from verts to edges? So you select a vertex, then the script adds the first set of connected verts to the selection and converts that to edges.
  • Cathodeus
    Options
    Offline / Send Message
    Cathodeus polycounter lvl 14
    No this will not work because if you have a plane  2x2 [so 4 faces]. And you select the vertex in the middle. With what i'm searching for i should have 4 edges selected [basically the cross] but with what you suggest you will get all edges selected [12 edges.]
  • PolyHertz
    Options
    Offline / Send Message
    PolyHertz polycount lvl 666
    Pass the selection down to the editable poly and get the connected edges from there before passing it back to the UV modifier. Something like this:

    vrt = $.modifiers[#unwrap_uvw].getSelectedGeomVertsByNode $
    modPanel.setCurrentObject $.baseObject
    tmp = polyop.getEdgesUsingVert $ vrt
    modPanel.setCurrentObject $.modifiers[#Unwrap_UVW]
    subobjectLevel = 2
    $.modifiers[#unwrap_uvw].selectEdgesByNode tmp $

    Edit: Just checked and it seems like Max reorders the Edge numbers in the UVW modifier (ugh...), so you'll want to select them by position instead of number.
  • Cathodeus
    Options
    Offline / Send Message
    Cathodeus polycounter lvl 14
    Hello polyhertz and thanks for your reply. Did you corrected the provided code ? I just tried it but it doesn't work. I'm a maxscript beginner so i don't know how to achieve what you're talking about. The would be kind of you if you could maybe provide the code [by position method] as i really don't know about it.
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Cathodeus said:
    No this will not work because if you have a plane  2x2 [so 4 faces]. And you select the vertex in the middle. With what i'm searching for i should have 4 edges selected [basically the cross] but with what you suggest you will get all edges selected [12 edges.]
    This works for me if an Editable Poly or Edit Poly is below the Unwrap modifier. If it's a primitive or a mesh, the problem happens as you describe.

    (
    	--GET UVMOD
    	uvMod = modPanel.getCurrentObject()
    	
    	--CHECK IF UVMOD IS SELECTED
    	if classof uvMod == Unwrap_UVW do
    	(
    		--EXPAND AND CONVERT SELECTION
    		uvMod.expandGeomVertexSelection()
    		subobjectLevel = 2
    		uvMod.vertToEdgeSelect()
    	)
    )
  • Cathodeus
    Options
    Offline / Send Message
    Cathodeus polycounter lvl 14
    Hello Monster thanks for your help however as i told before it partialy work as this method select more edge than what it should. If it's all quad than ok. if there's only one triangle it fail please have a look at the video https://db.tt/O3NCSykU this video start with your solution and show the result with one edge that shouldn't be selected. TYhis video finish with the behaviour of converting one vertex to edge in editable poly. The result is not the same and this is what i would like to replicate inside unwrap uvw.

  • FishMan
    Options
    Offline / Send Message
    FishMan polycounter lvl 11
    Cathodeus said:
    Hello,

    I would like to convert one vertex to edges in unwrap uvw but it doesn't work with one uv vertex selected ... it do work with 2 vertices or more.

    Do anyone know how can i achieve that ? So basiclally we select one Uv vertex we execute the script and boum, we do obtain all the adjacent edges.

    Thanks.
    Massimo
    Here I did it... after 4 years, lol :D I've found this thread in google. I hope you still need this... lol
    It's unoptimized and slow though. If someone can help to speed it up - I will appreciate.
    Here is the code (slow, but should work for instanced modifier):
    macroScript UVConvertToEdges
    category:"Custom"
    internalCategory:"Custom" 
    tooltip:"UV Convert To Edges"
    ButtonText:"UVConvertToEdges" 
    autoUndoEnabled:false
    (
    local uvw_mod = modpanel.getcurrentobject()
    if uvw_mod != undefined and classof (uvw_mod) == Unwrap_UVW then
    (
    if uvw_mod.getTVSubObjectMode() == 2 do return undefined
    local original_verts = #()
    local selected_edges = #()
    for i = 1 to selection.count where isKindof selection[i] GeometryClass do
    (
    original_verts[i] = uvw_mod.getSelectedVerticesByNode selection[i]
    )
    uvw_mod.expandSelection() 
    uvw_mod.vertToEdgeSelect()
    for i = 1 to selection.count where isKindof selection[i] GeometryClass do
    (
    if original_verts[i].numberSet == 0 do continue 
    --uvw_mod.selectVerticesByNode original_verts[i] selection[i]
    If uvw_mod.getTVSubObjectMode() == 1 then --convert verts to edges
    (
    edges = uvw_mod.getSelectedEdgesByNode selection[i]
    for edge in edges do 
    (
    uvw_mod.selectEdgesByNode #{edge} selection[i]
    uvw_mod.edgeToVertSelect() 1
    if ((uvw_mod.getSelectedVerticesByNode selection[i]) * original_verts[i]).numberSet == 0 do 
    edges[edge] = false
    )
    --uvw_mod.selectVerticesByNode original_verts[i] selection[i]
    uvw_mod.selectEdgesByNode edges selection[i]
    )
    else uvw_mod.faceToEdgeSelect() --convert faces to edges
    )
    for i = 1 to selection.count where isKindof selection[i] GeometryClass do uvw_mod.selectVerticesByNode original_verts[i] selection[i]
    uvw_mod.setTVSubObjectMode 2
    )
    )


    And another one (faster, but will work only for single  object with Unwrap applied)
    macroScript UVConvertToEdges
    category:"Custom"
    internalCategory:"Custom" 
    tooltip:"UV Convert To Edges"
    ButtonText:"UVConvertToEdges" 
    autoUndoEnabled:false
    (
    local uvw_mod = modpanel.getcurrentobject()
    if uvw_mod != undefined and classof (uvw_mod) == Unwrap_UVW then
    (
    if uvw_mod.getTVSubObjectMode() == 2 do return undefined
    local original_verts = uvw_mod.getSelectedVertices()
    If uvw_mod.getTVSubObjectMode() == 1 then --convert verts to edges
    (
    if original_verts.numberSet > 0 then
    (
    uvw_mod.expandSelection() 
    uvw_mod.vertToEdgeSelect()
    local edges = uvw_mod.getSelectedEdges() 
    for edge in edges do 
    (
    uvw_mod.selectEdges #{edge}
    uvw_mod.edgeToVertSelect() 
    if (uvw_mod.getSelectedVertices() * original_verts).numberSet == 0 do 
    edges[edge] = false
    )
    uvw_mod.selectVertices original_verts
    uvw_mod.selectEdges edges
    )
    )
    else uvw_mod.faceToEdgeSelect() --convert faces to edges
    uvw_mod.setTVSubObjectMode 2
    )
    )

    P.S. Damn autodesk... why logic inside max is not consistent? The problem is not only that there is different approach for instanced and usual Unwrap UVW (you should cycle through all selected objects and use .getSelectedEdgesByNode instead), but also there is no way to do things just in memory without messing with selections in TV (UVW Editor). I mean I need 3 cycles for this: 1st to remember verts selections, 2nd to convert them to edges, 3rd to revert back verts selection...

    For example in Editable Poly you can grow or convert selections without ruining your selections, while in Unwrap UVW its more like pressing buttons using maxscript code (so stupid). Autodesk was so fucking lazy then was making maxscript commands and functions for Unwrap modifier...
  • Tekoppar
    Options
    Offline / Send Message
    Tekoppar polycounter lvl 10
    I made a slightly faster version (it's missing the checks FishMans script has and unwrap needs to be the first modifier, but those should be easy enough to fix), the most expensive calls seems to be the conversions, setters and getters. I'm guessing that the relation between vert/edge/faces neighbours aren't stored and they just loop over all the vert/edge/faces until they find all the correct ones instead of having them stored.

    </code><code>(<br>	mod = $.modifiers[1]<br>	gVerts = mod.getSelectedGeomVerts() --gets the selected vertices in the unwrap modifier<br>	edges = polyop.getEdgesUsingVert $ gVerts --gets the edges where the vertices exists<br>	corEdge = #() <br>	for edge in edges do (<br>		polyop.setEdgeSelection $ edge --set current selection to single edge<br>		seVerts = polyop.getVertsUsingEdge $ #{edge} --gets the vertices from the single edge<br>		mod.selectVertices seVerts --selects the vertices we got from the single edge<br>		mod.vertToEdgeSelect() --selects the edge that those vertices makes up<br>		newEdges = mod.getSelectedEdges() as array --gets the edge index from the unwrap<br>		append corEdge newEdges[1]<br>	)<br>	mod.selectEdges (corEdge as bitarray) --selects the correct edges<br>	mod.selectVertices gVerts --selects the verts the user selected<br>	mod.setTVSubObjectMode 2<br>)


Sign In or Register to comment.