Notifications
Clear all

[Closed] How to optimize this code

dividing edges using max length of all edges doesn’t make sense for. i think that the function has to get as parameter a min length of edge that has to stay not divided. using this condition the function can calculate how many times the edge has to be divided. using this method you will not be limited by number of edge divisions.

Very nice, Denis
By the way, thanks for reply and help.
This is the test on my PC
–Your code
time:235 memory:91664L
–My code
time:286 memory:-111040L
Now the code is cleaner and sufficiently optimized.
Is it possible to increase the divide value more then 3?
(same as

PolyToolsModeling.InsertVertex number

)
This works great but you mast stay in modify panel and have SOLevel selected

any operation with geometry with modifier panel open is slow. look how i do dividing an edge. i do it in reverse order. it gives me the way to divide the same edge as many times as i want.

originally posted by DenisT
dividing edges using max length of all edges doesn’t make sense for.

I calculate the max length only of selected edges not all edges.
Does not make sense to work with all edges in geometry object.
Script will also be executed only if “selected edges” count is greater then zero.

originally posted by DenisT
using this method you will not be limited by number of edge divisions.

How can i do that?

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i know. but i mean all edges used in operation.

how to calculate the number of divisions? easy: n = ceil (edgeLength/minLength)

originally posted by DenisT
look how i do dividing an edge. i do it in reverse order. it gives me the way to divide the same edge as many times as i want.

I figured that now.
Same as when divides the sline shape (reverse order).

here is a function how to divide an edge with number of divisions:


	fn divideEdge obj edge divisions:1 = 
	(
		for k=divisions to 1 by -1.0 do polyOp.divideEdge obj edge (1 - 1/(k+1))
	)


originally posted by DenisT
i think that the function has to get as parameter a min length of edge that has to stay not divided. using this condition the function can calculate how many times the edge has to be divided.

i know. but i mean all edges used in operation.

What you said is the main problem that I could not solve from the start
Could you help me to solve this?

originally posted by DenisT
here is a function how to divide an edge with number of divisions:

fn divideEdge obj edge divisions:1 = ( for k=divisions to 1 by -1.0 do polyOp.divideEdge obj edge (1 - 1/(k+1)) )

You gave me the answer before I asked you a question .
Thanks for that.:applause:

While I tested this code, I noticed that the “UNDO” is the bad choice for this tool.
May be wrong but here’s what I got in the test:
if i use [color=DeepSkyBlue]undo “WrinkledEdge” on (…)[/color] –> [color=Magenta]time:252 memory:91880L
[/color]but using [color=RoyalBlue][color=DeepSkyBlue]with [/color][/color]undo off (…) –> time:51 memory:91784L [5 time faster!]
With this time is definitely possible to achieve an interactive “retopology” mode.

     The question is, which of these two methods may be better to replace "[b]UNDO[/b]" using
     "on  button press" event.
     [b]METHOD #1 >>>
     [/b] 

    backupObj = $.mesh -- to place node to variable
         $.baseoject = backupObj --to restore node (before "chewing")
    
     [b]METHOD #2 >>>
[/b]

    fn backupNode obj = --to save node to a file
          (
         	 if obj != undefined do saveNodes obj (getdir #autoback + "backUPnode.max")
          )
         fn restoreNode = --to restore node from a file
         (
         	local backupFile = (getdir #autoback + "backUPnode.max")
         	if not (doesFileExist backupFile) then #abort else mergemaxfile backupFile #select
         )
    

the best way to make the operation undoable in your case is:


    undo "WrinkledEdges" on
	(
		if (mode = getCommandPanelTaskMode()) != #create do setCommandPanelTaskMode mode:#create
		obj = converttopoly selection[1]
		t1 = timestamp()
		m1 = heapfree
		undo off wrinkleEdges obj 
		format "time:% memory:%
" (timestamp() - t1) (m1 - heapfree)
		if (getCommandPanelTaskMode()) != mode do setCommandPanelTaskMode mode:mode
	)

Page 3 / 8