[Closed] Undo and polyop.CreatePolygon
Ok I have problems with perfomance when I create a lot of polygons.
If you for example have an array of 4 verts ids, where each 4 verts representing one quad and trying to create them one by one and record this to undo stack like that:
undo on
(
for Polygon in PolyArray do
(
polyop.CreatePolygon oPoly Polygon
)
)
It will quickly become really slow. The more polygons you have – the slower this operation will be.
And this problem will go away (like works 10 times faster) if you disable undo. But I need undo I cant just disable it.
I guess this is because it records every single polygon creation as a separate action and group them as a single undo record. This kind of action recording is really slow in this case.
Is there any way to walkaround this? like create virtual polygons in memory with disabled undo and then add them to my poly object as a single action? Is this even possible to create virtual objects?
Help me step bro i’m stuck.
you could use undo for the first polygon only
with undo "create poly" on
(
polyop.createPolygon $ polys[1]
)
with undo off
(
for i=2 to polys.count do polyop.createPolygon $ polys[i]
)
update $
Almoust. In this case if you try to redo after undo – only one polygon will return and its kinda meh.
Hey I saw somewhere that meshop works differently with undo. Like it stores the result mesh based on the last operation performed.
I tried to do this this way… Like:
undo on
(
ConvertToMesh oPoly
undo off
(
for i = 1 to PolyArray.count-1 do
(
meshop.CreatePolygon oPoly PolyArray[i]
)
)
meshop.CreatePolygon oPoly PolyArray[PolyArray.count]
ConvertToPoly oPoly
)
And it seems to work and even faster. But! ConvertTo is also a slow operation and it will kill modifier stack and do all other nasty things…
Maybe there’s a way to perform meshop operation on poly object or something else?
I tried to work with trimesh using oPoly.mesh but for poly objects it’s just a read-only variable ffs. I mean you can’t put it back.
Ok. I did like that:
undo on
(
with undo off
(
for i = 1 to PolyArray.count-1 do
(
polyop.CreatePolygon oPoly PolyArray[i]
)
)
polyop.CreatePolygon oPoly PolyArray[PolyArray.count]
)
Its kinda works but breaks the undo history…
So yeah no luck so far…
theHold.Begin()
-- all your code to create polygons. NO Undo On/Off.
for i = 1 to PolyArray.count-1 do
(
polyop.CreatePolygon oPoly PolyArray[i]
)
polyop.CreatePolygon oPoly PolyArray[PolyArray.count]
theHold.Accept "Create some faces"
has to create only one Undo record.
You understood me wrong. It’s not about making one undo record. Its a bit different.
Lets say like that: every “i” in loop it will stop and update the undo record every time it creates one polygon.
Like create poly -> create record-> create poly -> update record -> create poly -> update record etc. I want it to be like: create poly -> create poly -> create poly -> create record.
It is a very time and (i guess) memory consuming thing when you creating polys one by one and update undo record each time. I’m trying to avoid that. So it should create only one record and update it only once when everything is finished.
So my current plan is crate all the polygon inside a virtual mesh and attach it to polymesh existing in 3d space.
Like:
Disable undo.
Make a 2d array of vert coordinates grouped by 4.
Create an empy trimesh variable.
Create new verts and polygons in trimesh.
Enable undo.
Crate empty mesh. Transform it the same way as original object.
Place trimesh inside created and transformed mesh.
Attach this mesh to original mesh.
Weld verts.
It might be easier if only $.mesh variable was not read-only for poly objects.
I know sounds like a giant stupid idea. But if someone suggest something better I will be glad.
It is possible to append some poly mesh to already existing one. Here’s the example
But I don’t know if you can make it undoable
Interesting.
But the only question is will the undo system make a record if I do like that?
Oh man that’s not cool…
Its seems that meshop doesnt work for trimesh… dammit!
Ok then. Lets forgot about trimesh and work directly with mesh object.
So the new plan is:
generate vers array and faces array
enable undo
create mesh object using generated arrays
transform mesh the same way as poly
attach mesh to poly
weld verts
I think it will work. I made some tests and they are pretty promising.
converttopoly with undo and do all polygons after without undo:
undo on
(
converttopoly node
with undo off (for ... do polyop.createpolygon node ...)
)
it will collapse stack but using polyop doesn’t expect the working with stack anyway
you can try to find some “dummy” polyop method instead of converttopoly… hmm… maybe polyop.movevert?