I decided it might be cool to animate the opening and closing of (sliding) doors. Here is a snippet of code that opens a door, its actually very simple, I’m just moving the door in incremental steps :
I’ve tried setting the various parameters of the start_operation method but no combination seems to work. I consistently get an undo stack full of move commands (ie. my step sizes). Maybe this isn’t possible or maybe I am just missing something.
Should I just use a simple for or while loop instead of going to all the trouble with the timer business. The problem I see with that is that the animation will no longer be visible, it will happen too fast.
I’m kind of new to this kind of thing, having never really tried this before so I’m a little unsure on what is the best path forward.
I tried the move method and it gave me some strange results. For some reason it also translated in the Z as well as the X.
Also I actually do want the transformations to be added to the stack just not individually, so in for that reason alone the move method will probably not work.
So far the only thing that seems to work reliably is the last iteration of my code above.
Then you need to start the operation (a normal one with the flag3 set to false) on only the first transform. Thereafter each successive transform would need to have the flag3 set true so all the operations are appended together.
Also, it is not necessary to recreate a transformation object in every iteration.
A single transformation based upon a vector, created before a loop, can be used for each iteration.
I just realized that with my transformation, your right it can be created once prior to the loop since it itself is not changing over the entire course.
That is because the transform method uses the transformation incrementally, while the move method replaces the existing transformation with the argument.
I use move for all the incremental moves, then prior to the final move, put the component back at the original location, and the do a single transformation to the final position. It happens fast enough that you can’t see it, and leaves one item on the undo stack.
tr = @inst.transformation
@inst.move!(@original_transformation)
@model.start_operation('Move', true)
@inst.transformation = tr
... a bunch of other code
@model.commit_operation