Using the Animation Interface, need some help, stuck
-
I've been playing around with the Animation interface, but am not getting anywhere. I very simply am reading a log file line by line, and would like to move an object by 3d coordinates.
The picture was as follows: Read one line, call a function that generates the visual and updates the object's position. This however does not work as the object does not move coordinate by coordinate, rather Sketchup moves it to the last coordianate read and so it does not appear to be moving.
I've been pointed in the direction of the Animaton Interface to fix this up. I've looked at the ruby file as an example and have played around with it, but I get the feeling that this is more something to do with the camera and point of view of the Sketchup model, and not a 3d object (although I may be wrong). I have not been able to do this for my situation here. I need someone to tell me what I am doing wrong and what I should be doing, if possible.
As it stands, I have a readLogFile method which does as it's called, and after each line calls "generateVisual" which should(but doesn't work) move the object. I then implemented the nextFrame method as required by the Animation interface, and set up the camera view (I don't really care about this, but I think it is necessary). Now, i also tried to update the object's coordinates through nextFrame rather than in generateVisual, however this did not work. I thought it would make sense to update the object's position through the nextFrame so that it would show it frame by frame...but not successful. Is nextFrame invoked by Sketchup automatically? How would I/can I solve this problem using the Animation interface, and if not what should I do/use instead?
I'm a little stuck. Thanks in advance
-
I would like to help but I do not quite understand what you are trying to achieve, could you explain what you intend to animate?
Is it an object that needs to move and the camera to be stationary?
-
This code is un-tried, but should give you some ideas...
class MyAnimation def initialize @count = 0 # Open your file into an array @lines = IO.readlines "filename" # get your entity to animate @target = Sketchup.active_model.selection[0] end def nextFrame(view) # Do your work here # COnvert the line to a Point3d pt = @lines[@count].split(",") pt.map! { |e| e.to_f } @target.transformation = Geom;;Transformation.new(pt) @count += 1 view.show_frame(1) # optional delay end def self.start Sketchup.active_model.active_view.animation = self.new end def self.stop Sketchup.active_model.active_view.animation = nil end end menu = UI.menu("Plugins") menu.add_item("Start MyAnimation") { MyAnimation.start } menu.add_item("Stop MyAnimation") { MyAnimation.stop }
-
Solo: That is right. I'd like to move an object, while keeping the camera unmoved. (At least for now)
Jim: Thank you for that code. I've played around with it and was actually able to get it to work! For testing, I've been outputing the lines that I'm reading from the log file (there are about 6500 of them...). The only problem, however is that this task is VERY slow, and takes a very very long time to read and "animate" the log file, so it isn't much of an animation yet.
The example that I've looked at before moves the camera view around, and it actually is quite fast, but looking at the code, there doesn't seem to be anything to "set" the speed. Is there a way to increase the speed of this?
-
view.show_frame(1) # optional delay
This line uses an optional 1 second delay. What happens if you set it to zero?
Advertisement