Simple vertex positions caching When your vertices get misplaced too often

A forum member at maxarea asked about the possibility to retrieve the original positions of certain mesh vertex, something like an undo for single vertex movement without having to undo moving all the other vertices that changed their position in the process of tweaking the mesh (original discussion: Maxarea :: Modelování s relativními posuny vertexů). While it definitely isn't the best way to do it, it looked like a nice maxscript exercise. Anyway, here is the rough code:
try destroyDialog vertPositions catch()
rollout vertPositions "Vertex Positions"
    button btnPopulate "Populate" across:2
    button btnUpdate "Update"
    dotNetControl vertList "System.Windows.Forms.ListView" pos:[12,27] width:225 height:500
    button btnRevert "Revert Selected"

    local given_mesh
    local my_cool_vertices = #()
    local get_vert_alias = polyOp.getVert
    local set_vert_alias = polyOp.setVert
    local list_item_class = dotNetClass "System.Windows.Forms.ListViewItem"

    fn asPoint3 str = readValue (str as stringStream)

    fn fillVertList given_mesh given_list:vertPositions.vertList =
        if classOf given_mesh == Editable_Poly do
            local vert_count = polyOp.getNumVerts given_mesh

            lv_item_arr = for v = 1 to vert_count collect
                list_item = dotNetObject vertPositions.list_item_class (v as string)
                list_item.SubItems.AddRange #(((get_vert_alias given_mesh v) as string), "[0,0,0]", "true")
            given_list.Items.AddRange lv_item_arr

    on vertPositions open do
        vertList.View = vertList.View.Details
        vertList.FullRowSelect = true
        vertList.GridLines = true
        vertList.BorderStyle = vertList.BorderStyle.FixedSingle
        vertList.Columns.Add "Nr." 35
        vertList.Columns.Add "Orig.pos." 65
        vertList.Columns.Add "Difference" 65
        vertList.Columns.Add "No Change" 60

    on btnPopulate pressed do
        setCommandPanelTaskMode mode:#create
        with redraw off fillVertList (given_mesh = $)

    on btnUpdate pressed do
        setCommandPanelTaskMode mode:#create

        with redraw off
            local list_items_count = vertList.Items.Count - 1

            for i = 0 to list_items_count where 
                (local orig_pos = asPoint3 vertList.Items.Item[i].SubItems.Item[1].Text) as string != (local new_pos = get_vert_alias given_mesh (i+1)) as string do
                    vertList.Items.Item[i].SubItems.Item[2].Text = (new_pos - orig_pos) as string
                    vertList.Items.Item[i].SubItems.Item[3].Text = "false"

    on btnRevert pressed do
        if (local selected_items_count = vertList.SelectedItems.Count - 1) >= 0 do
            for i = 0 to selected_items_count where 
                NOT (local current_items_subitems = vertList.SelectedItems.Item[i].SubItems).Item[3].Text as booleanClass do
                    set_vert_alias given_mesh (current_items_subitems.Item[0].Text as integer) (asPoint3 current_items_subitems.Item[1].Text)
                    current_items_subitems.Item[2].Text = "[0,0,0]"
                    current_items_subitems.Item[3].Text = "true"

createDialog vertPositions width:250 height:570
USAGE: Run the script, pick an Editable Poly object of your choice and click Populate. Do some serious tweaking of the mesh (avoid deleting vertices though). Now let's say that in the process of tweaking you've accidentally moved two vertices instead of one without noticing it and when you finally notice it, it's too late... or not? Press the Update button and find the vertex you want to move back. Select it in the list (it should have false as its No change state) and press Revert Selected. You can also select more items (vertices in the list) at the same time.

Vertex positons interface

DISCLAIMER: All scripts and snippets are provided as is under Creative Commons Zero (public domain, no restrictions) license. The author and this blog cannot be held liable for any loss caused as a result of inaccuracy or error within these web pages. Use at your own risk.

This Post needs Your Comment!

Return to top