# Copyright 2004, @Last Software, Inc., modified by Matt Gorbet, using tons of code by RickW # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' require 'linetool.rb' #----------------------------------------------------------------------------- # This tool inherits from linetool.rb and implements RickW's flightpath algorithm. # Use it by first selecting your curve, then right-click (context menu) and choose # FlightPath Tool. Then select a start point for your target, then an end point. # The flightpath will be created as a set of pages that you can view as a slideshow. ## YOU MUST HAVE linetool.rb (from the examples) in your plugins folder for this to work. #A few other changes -- I hardcoded a FOV of 60 degrees into the cameras - I find that's # generally a nice wide FOV for flying through architecture. You can change it in below # if you like. Also the new pages do not remember the rendering settings ('display' # checkbox) or the hidden settings -- this way you can watch or export your flythrough with # various styles, modes, and geometry hidden or showing. # I also removed RickW's "reverse path" option -- it wasn't useful to me -- you can # uncomment a few lines and put it back, although I think my code for the forward # path is now different from the reverse path so it might take some tweaking. # enjoy! class FlightPathTool < LineTool # Override the create_geometry method to use # the points to define the target start and end). def create_geometry(pt1, pt2, view) model = view.model model.start_operation "Set Flightpath Targets" ents=model.active_entities view=model.active_view sel=model.selection pages=model.pages layers=model.layers lyr=layers.add("FlightPath_Layer") lyr.page_behavior=LAYER_IS_HIDDEN_ON_NEW_PAGES up=[0,0,1] edge=sel[sel.length-1] path=edge.curve edges=path.edges cameras=[] transTimes=[0] newPages=[] flyThroughRate=10 if not defined? flyThroughRate prompts=["Enter distance per second (with units): \n "] values=[flyThroughRate] results=inputbox(prompts,values,"Flythrough Rate") flyThroughRate=results[0].to_l targstart = pt1 targend = pt2 sel.clear sel.add(edges[0]) edge.layer=lyr # UI.messagebox("rate is #{flyThroughRate.to_s} per second"); numpages = edges.length-1 targdx = (targend.x-targstart.x)/numpages targdy = (targend.y-targstart.y)/numpages targdz = (targend.z-targstart.z)/numpages ### I commented out Rick's original "reverse path" stuff because I found I never needed to and it was in my way... if UI.messagebox("Reverse Path?", MB_YESNO, "Flight Path")==7 sel.clear 0.upto(numpages) do |e| eye=edges[e].start.position target=[(targstart.x+(targdx*e)),(targstart.y+(targdy*e)),(targstart.z+(targdz*e))] ## I SET MY CAMERA FOV to SIXTY DEGREES w/ perspective HERE: newCamera=Sketchup::Camera.new(eye,target,up, true, 60.0) view.camera=newCamera p=pages.add ## I turn off memory of display options and hidden stuff in the pages p.use_rendering_options=false p.use_hidden=false p.transition_time=edges[e].length/flyThroughRate # UI.messagebox("transtime #{e} will be #{p.transition_time} seconds") edges[e].layer=lyr end else sel.clear edges.reverse! # UI.messagebox("ok doing the reverse...") 0.upto(numpages) do |e| eye=edges[e].start.position target=[(targstart.x+(targdx*e)),(targstart.y+(targdy*e)),(targstart.z+(targdz*e))] ## I SET MY CAMERA FOV to SIXTY DEGREES w/ perspective HERE: newCamera=Sketchup::Camera.new(eye,target,up, true, 60.0) view.camera=newCamera p=pages.add ## I turn off memory of display options and hidden stuff in the pages p.use_rendering_options=false p.use_hidden=false p.transition_time=edges[e].length/flyThroughRate # UI.messagebox("transtime #{e} will be #{p.transition_time} seconds") edges[e].layer=lyr end end model.commit_operation Sketchup.send_action("selectSelectionTool:") end end # class FlightPathTool #----------------------------------------------------------------------------- # This functions is just a shortcut for selecting the new tool def flightpathtool Sketchup.active_model.select_tool FlightPathTool.new end def preparefortakeoff return true if Sketchup::active_model.selection.first.class==Sketchup::Edge return nil end if( not file_loaded?("flightpathtool.rb") ) UI.add_context_menu_handler do |menu| menu.add_separator menu.add_item("Flight Path Tool") { flightpathtool } if preparefortakeoff end end file_loaded("flightpathtool.rb")