# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # 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' #----------------------------------------------------------------------------- def axesTransformationTest origin = Geom::Point3d.new 0,0,0 x = Geom::Vector3d.new 0,1,0 y = Geom::Vector3d.new 1,0,0 z = Geom::Vector3d.new 0,0,1 trans = Geom::Transformation.axes origin, x, y, z UI.messagebox trans end def interpolateTransformationTest origin = Geom::Point3d.new 0,0,0 x = Geom::Vector3d.new 0,1,0 y = Geom::Vector3d.new 1,0,0 z = Geom::Vector3d.new 0,0,1 point = Geom::Point3d.new 10,20,30 t1 = Geom::Transformation.new point t2 = Geom::Transformation.axes origin, x, y, z t3 = Geom::Transformation.interpolate t1, t2, 25 UI.messagebox t3 end def newTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point if (t) UI.messagebox t else UI.messagebox "Failure" end end def rotationTransformationTest point = Geom::Point3d.new 0,0,0 vector = Geom::Vector3d.new 0,1,0 angle = 25 t = Geom::Transformation.rotation point, vector, angle UI.messagebox t end def scalingTransformationTest t = Geom::Transformation.scaling 10 UI.messagebox t end def translationTransformationTest # bug? vector = Geom::Vector3d.new 0,1,0 t = Geom::Transformation.translation vector UI.messagebox t end def multiplyTransformationTest point = Geom::Point3d.new 10,20,30 point2 = Geom::Point3d.new 2,2,2 t = Geom::Transformation.new point point3 = t * point2 UI.messagebox point3 end def cloneTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point t2 = t.clone UI.messagebox t2 end def identityTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point status = t.identity? UI.messagebox status end def inverseTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point t2 = t.inverse UI.messagebox t2 end def invertTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point t2 = t.invert! UI.messagebox t2 end def originTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point point2 = t.origin UI.messagebox point2 end def setTransformationTest origin = Geom::Point3d.new 0,0,0 x = Geom::Vector3d.new 0,1,0 y = Geom::Vector3d.new 1,0,0 z = Geom::Vector3d.new 0,0,1 point = Geom::Point3d.new 10,20,30 t1 = Geom::Transformation.new point t2 = Geom::Transformation.axes origin, x, y, z t3 = t1.set! t2 UI.messagebox t3 end def toATransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point a = t.to_a UI.messagebox a end def xaxisTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point x = t.xaxis UI.messagebox x end def yaxisTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point y = t.yaxis UI.messagebox y end def zaxisTransformationTest point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point z = t.zaxis UI.messagebox z end if( not file_loaded?("transformationtests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") Transformation_menu = plugins_menu.add_submenu("Transformation Tests") Transformation_menu.add_item("Transformation.axes") { axesTransformationTest } Transformation_menu.add_item("Transformation.interpolate") { interpolateTransformationTest } Transformation_menu.add_item("Transformation.new") { newTransformationTest } Transformation_menu.add_item("Transformation.rotation") { rotationTransformationTest } Transformation_menu.add_item("Transformation.scaling") { scalingTransformationTest } Transformation_menu.add_item("Transformation.translation") { translationTransformationTest } Transformation_menu.add_item("Transformation *") { multiplyTransformationTest } Transformation_menu.add_item("Transformation.clone") { cloneTransformationTest } Transformation_menu.add_item("Transformation.identity?") { identityTransformationTest } Transformation_menu.add_item("Transformation.inverse") { inverseTransformationTest } Transformation_menu.add_item("Transformation.invert!") { invertTransformationTest } Transformation_menu.add_item("Transformation.origin") { originTransformationTest } Transformation_menu.add_item("Transformation.set!") { setTransformationTest } Transformation_menu.add_item("Transformation.toA") { toATransformationTest } Transformation_menu.add_item("Transformation.xaxis") { xaxisTransformationTest } Transformation_menu.add_item("Transformation.yaxis") { yaxisTransformationTest } Transformation_menu.add_item("Transformation.zaxis") { zaxisTransformationTest } end #----------------------------------------------------------------------------- file_loaded("transformationtests.rb")