Jump to content

touslecoq
 Share

Recommended Posts

Has anyone created simple undo/redo function in Babylon?  I've had a quick search and cannot see any examples.  Is it as simple as taking copies of the scene variable and storing in an array and recalling when user selects undo from a UI button or keyboard shortcut?  That would be too easy right?

Cheers, Rich

Link to comment
Share on other sites

@touslecoq -

I have built many undo.history functions in various applications - and you can use any memory element (container) such as an array, a text file, a DB, make use of pointers etc. The trick is to establish what events make up the data set such as if you have built a drawing app,and want to add an undo feature - you might consider a single undo operation to consist of all pointer X,Y data between a pointerdown and a pointerup canvas or Window event.

It all depends on the application, what the dataset represents, and optimize as much as possible to avoid undoing long events - unless your application requires this - especially if you're running off a server to avoid delays due to the amount of data streaming in the undo function; whatever that might be.

This is a very broad question, so it's difficult to provide a specific answer without additional info on the  app the operations involved, user connectivity, badwidth, user hardware, etc. However, you'll find that buffering such data and recalling the data to "undo" an operation or set of operations is generally quite simple - and if required, I highly advise implimenting sooner than later.

DB

Link to comment
Share on other sites

Thanks both for your responses.

@Adam - the pattern I was looking at implementing I think was a cross between 2 and 3 in that link.

I had intended using the push/pop of "events" to/from undo/redo queue.  However rather than creating individual reversible actions (e.g. mesh moved from position a to b, undo moves back to a) my plan was to take a snapshot of everything at key points and be able to revert to that point.

The main reason for this is that reversing the actions undertaken by a user would also require reversal of any consequential actions and because of the free-roaming capability in 3D this could become quite tedious and difficult to code (yes I am looking for a shortcut!).

For context, imagine a scene with up to 100 components (think simple lego bricks) that can be plugged together.  Imagine the user drags a brick close to another and the 2 snap together.  However because the gap was exactly one brick wide, it also triggers a snap to a third brick (ie our moved brick is now sandwiched between 2 others and has snapped/locked to both).  To undo a move would also require the undoing of any deliberate connections and any consequential connections.  

As we are not talking about a huge number of components/bricks (ie meshes) or a huge undo history (maybe 3 steps?) I hoped it would be more simple to reload the scene and would not be too resource intensive.

I have been looking at the scene serializer function to effectively save the scene at key points and allow the user to hit the "u" key to undo and return to saved point.  Haven't managed to get that to work yet though.  Once I have this working for a single step then I'll implement the push/pop method which will allow me to configure MAX_UNDO_STEPS and v check performance.

Thoughts - am I barking?

Thanks

Rich 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...