sketchucation logo sketchucation
    • Login
    ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

    Face Me

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 366 Views
    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.
    • T Offline
      toxicvoxel
      last edited by

      A face created with points running in a counter-clockwise direction in a plane should create a face with the normal pointing in the Z direction of the plane.
      This seems to work in most cases but sometimes the entities_addface function appears to rearrange the vertexes as the code samples below illustrate. Can anybody explain why this is happening?

      '==================================== A
      def makeface_counterclockwise __model = Sketchup.active_model __entities = __model.entities pts=[] pts[0]=[0,0,0] pts[1]=[50,0,0] pts[2]=[50,50,0] face = __entities.add_face pts puts "--------------face.vertices" face.vertices.each {|vx| puts vx.position} end

      This code returns vertexes that have been re-arranged resulting in incorrect orientation :
      --------------face.vertices
      (50", 0", 0")
      (0", 0", 0")
      (50", 50", 0")

      '==================================== B
      def makeface_clockwise __model = Sketchup.active_model __entities = __model.entities pts=[] pts[0]=[0,0,0] pts[1]=[-50,0,0] pts[2]=[-50,50,0] face = __entities.add_face pts puts "--------------face.vertices" face.vertices.each {|vx| puts vx.position} end
      This code return expected results:
      --------------face.vertices
      (0", 0", 0")
      (-50", 0", 0")
      (-50", 50", 0")

      '==================================== C
      def makeface_counterclockwise_vert __model = Sketchup.active_model __entities = __model.entities pts=[] pts[0]=[0,0,0] pts[1]=[0,0,50] pts[2]=[0,50,50] face = __entities.add_face pts puts "--------------face.vertices" face.vertices.each {|vx| puts vx.position} end

      This also returns expected results but contradicts the behaviour in A:
      --------------face.vertices
      (0", 0", 0")
      (0", 0", 50")
      (0", 50", 50")

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        SketchUp is hard wired to always make faces drawn on the groundplane face downwards. So the first example is correct, it should face upwards, but SU over-rides that and orients it to face downwards.

        The second example works because you have drawn the face in such a way that it will already point downwards, so SU does nothing to it.

        The third example works as expected, because the face is not on the groundplane, so SU does nothing to it.

        You will need to always test for that and check the orientation of faces drawn on the groundplane.

        Chris

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • T Offline
          toxicvoxel
          last edited by

          Thanks for your response Chris.
          The choice of system logic seems peculiar given the overhead that it creates if every face needs to be checked on iterating through a large collection of faces, for example when importing geometry from other file formats.

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            I wonder if Polygon Mesh works around this:

            http://code.google.com/apis/sketchup/docs/ourdoc/polygonmesh.html

            Perhaps importing as a mesh will make SU not re-orient any faces? I've not tested it.

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              hm... good question... I'm hoping it does not have this special ZeroZ rule.

              But in any case, I highly recommend using a PolygonMesh for any importer, it's by far the quickest way to add mesh to a model. Though, you don't have the control to add material per face, only per mesh.

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • T Offline
                toxicvoxel
                last edited by

                I looked at .add_faces_from_mesh before (which does not follow the 'ZeroZ' rule by the way), but because it has poor support for controlling individual outer (naked) edges of the mesh it's use is limited. If you have to iterate through the entities collection anyway to find and set individual edges it completely negates the efficiency of the method.

                Is it just me or is the documentation fraught with errors? The method does not return a collection of faces as stated:

                Syntax
                faces = entities.add_faces_from_mesh polygonmesh
                Arguments
                polygonmesh - a Polygon mesh object
                Return Value
                faces - an array of Face objects if successful 
                
                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @toxicvoxel said:

                  Is it just me or is the documentation fraught with errors?

                  It's not you. Basically - look at the API documentation as a guideline - all too often it's wrong. And look for comments at the bottom of the pages.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    toxicvoxel
                    last edited by

                    Looking into it further it turns out that add_face on the ground plane appears to re-organise vertexes using rules which would be complex and time consuming to test if vertex indexes are required to set edge visibility. A possible workaround would be to create a temporary group , add 10 to the z values of the face vertexes and then transform the group to the correct position where it can be exploded.

                    The problem with the Ruby API is that it requires so many hacks & workarounds. It would be in Google's interest to open the API development source so that it can be corrected where necessary and extended to address shortfalls. It is difficult to accept that errors in 7.x documentation remains uncorrected in 8.0.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      What makes it more troublesome is that the documentation doesn't mention bugs that appeared in the various methods in the various SU versions.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      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