• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Help Needed - Using Ruby to Project a Vertical Face.

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 2 Posters 356 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    EnglishTiger
    last edited by 7 Jun 2012, 07:06

    I need some help with Projecting a Vertical Face onto the Horizontal when the only Geometry that has been Selected is a Face.
    I am in the process of trying to write a Ruby Plugin that allows the User to "Paint" Geometric Representations of Cal3D Node onto a Selected Face. I'm trying to set the plugin up so that all the user has to do is Select a Face and then, via a user input form, specify where on the face the Cal3d Node(s) should be placed. By borrowing and adapting some Code Snippets from one of ThomThom's Plugins I can create a Projected Horizontal Face from a Face that is sloping but no matter what I try I don't seem to be able to do it for Vertical Faces.
    The Temporary Horizontal Face is needed to check that any Location the User Specifies is on the Face without them having to know the Faces Orientation and Size and to ensure that when the Cal3D Node is Painted onto the Selected Face it has the Required Z Axis Orientation.

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdmitch
      last edited by 7 Jun 2012, 21:10

      are you wanting to lay the selected face itself down on the xy plane or make a copy "projected" on the the xy plane.

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • E Offline
        EnglishTiger
        last edited by 7 Jun 2012, 21:49

        It is the Copy that has to be Projected onto the XY Plane, the Selected Face has to remain where it was.

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdmitch
          last edited by 7 Jun 2012, 23:27

          This code snippit seems to work with vertical faces or any other angle.

          mod = Sketchup.active_model
          ent = mod.entities
          sel = mod.selection
          
          face=sel.first
          norm=face.normal
          axis=norm.axes[0];rp=nil
          ang=norm.angle_between Z_AXIS
          pts=face.outer_loop.vertices.collect{|v| v.position}
          mp=face.bounds.min;md=1e6;
          last=pts.length-1
          0.upto(last) do |i|
           dis=mp.distance(pts[i])
           (md=dis;rp=pts[i]) if dis<md
          end
          tr=Geom;;Transformation.rotation(rp,axis,-ang)
          pts.each{|p| p.transform! tr}#rotate points to horizontal
          tr=Geom;;Transformation.translation([0,0,-rp.z])
          pts.each{|p| p.transform! tr}#move points to xy plane at 0 z
          face=ent.add_face(pts)#create the projected copy
          face.reverse! if face.normal.z < 0.0 # turn it face up
          
          

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • E Offline
            EnglishTiger
            last edited by 27 Jun 2012, 10:37

            Thanks sdmitch - that helped enormously however I now have another problem - Once I've got the Horizontal "Cloned" Face how do I rotate it to get it's "base" parallel to the X-Axis so that I can obtain the Dimensions of the Face and not those of the Bounding Box that surrounds a face that is not parallel to the X Axis?

            1 Reply Last reply Reply Quote 0
            • S Offline
              sdmitch
              last edited by 27 Jun 2012, 14:28

              If I may assume that we are dealing strictly with rectangles, then the dimensions can be obtain by getting the distances between adjacent corners. Just add this to the previous code.

              d1=pts[0].distance(pts[1]);d2=pts[1].distance(pts[2])
              d1>=d2 ? (w=d1;h=d2) ; (w=d2;h=d1)
              UI.messagebox "Face dimensions are #{w} X #{h}"
              
              

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • E Offline
                EnglishTiger
                last edited by 28 Jun 2012, 13:13

                The need/desire to rotate the "Cloned Face" so that it's base is parallel to the X-Axis is to Ensure that the User Can Specify the Location of any Objects being Added/Painted onto the Actual Face by entering only the X and Z distances (offsets) from the Bottom Left Corner of the Face (or the bounding box surrounding a non-rectangular face).
                If I place a 24" High Octagon, which has none of it's vertical faces parallel to the X-Axis, into the workspace and select any Face that forms the "Front Half" of the Octagon I can rotate their Cloned Faces so that its base is parallel to the X-Axis. Unfortunately if I choose any of the Faces that form the Back-Half of the Octagon the Cloned Face ends up being rotated away from the X-Axis and not towards it.
                Presumably the question is - How do I detect a Face that is Currently Facing the Camera but would have it's Back to a Camera set to "viewFront" so that I can Adjust the Direction of Rotation to get the Cloned Faces Base parallel to the X-Axis?

                1 Reply Last reply Reply Quote 0
                • S Offline
                  sdmitch
                  last edited by 28 Jun 2012, 16:30

                  To prevent the face copy from sticking to existing geometry, I have made it a group and added code to rotate the copy to align with x and y axes.

                  mod = Sketchup.active_model
                  ent = mod.entities
                  sel = mod.selection
                  grp = ent.add_group
                  face=sel.first
                  norm=face.normal
                  axis=norm.axes[0];rp=nil
                  ang=norm.angle_between Z_AXIS
                  pts=face.vertices.collect{|v| v.position}
                  mp=face.bounds.min;md=1e6;
                  last=pts.length-1
                  0.upto(last) do |i|
                   dis=mp.distance(pts[i])
                   (md=dis;rp=pts[i]) if dis<md
                  end
                  tr=Geom;;Transformation.rotation(rp,axis,-ang)
                  pts.each{|p| p.transform! tr}
                  tr=Geom;;Transformation.translation([0,0,-rp.z])
                  pts.each{|p| p.transform! tr}
                  face=grp.entities.add_face(pts)
                  face.reverse! if face.normal.z < 0.0
                  #d1=pts[0].distance(pts[1]);d2=pts[1].distance(pts[2])
                  #d1>=d2 ? (w=d1;h=d2) ; (w=d2;h=d1)
                  #UI.messagebox "Face dimensions are #{w} X #{h}"
                  ang=norm.angle_between Y_AXIS
                  ang = -ang if norm.x < 0.0
                  ang = ang + 180.degrees if norm.y > 0.0
                  tr=Geom;;Transformation.rotation(rp,Z_AXIS,ang)
                  grp.transform! tr
                  
                  

                  Nothing is worthless, it can always be used as a bad example.

                  http://sdmitch.blogspot.com/

                  1 Reply Last reply Reply Quote 0
                  • E Offline
                    EnglishTiger
                    last edited by 2 Jul 2012, 12:53

                    Thanks sdmitch - The Updated Code Snippet does everything I wanted to achieve and it is now being used by members of the IMVU-SketchUp Community to "Antagonize/Annoy" some of those unfortunate people who mistakenly think only AutoDesk can produce 3D Model Making Software.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement