sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    "Tell me what's goin' on. I ain't got a clue!"

    Scheduled Pinned Locked Moved Developers' Forum
    28 Posts 6 Posters 980 Views 6 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      Haven't tried it, but your get_corners always returns ret as the the last test because the other test possibilities are never met - plane is never defined so it's always nil and can never == the strings' '' values...
      face.reverse!() unless @plane == 'rb'
      says reverse the face unless the @plane is 'rb'
      BUT since @plane is not defined anywhere it's always nil, so it can't == 'rb' - so the face isn't reversed ?
      You need to define @plane somewhere to test it, and get_corners needs to test some actual possibilities...
      πŸ€“

      TIG

      1 Reply Last reply Reply Quote 0
      • M Offline
        MartinRinehart
        last edited by

        @tig said:

        Haven't tried it, but

        Sorry TIG. This is working code in a working class. @plane is created in the constructor. It's one of 'rb', 'gb', 'gr' or 'no' (Not Orthogonal). My question is why every face I create needs to be reversed, unless it's in the 'rb' plane. Let me put it another way.

        Why do I care that the normal points to the positive end of the perpendicular axis? This is the foundation of the box class, among others. The box class commits to having a positive pushpull value pushpull in the positive direction.

        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

          You have to reverse the face when you create it on the Red-Green plane?
          That's SU'd famous exception to face-creation. When you make a face on the ground it flips the front face down regardless. Though, I think it only does that on level 0 (z==0). Do you see this behaviour on other levels?

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

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            As TT says if you make faces and the points are ordered appropriately the normal is fixed as you expect... EXCEPT if Z=0 and the face is flat in the XY plane then the face will always have normal.z=-1 no matter what you have set it to be - It's a SUp built-in foilble - draw a Rectangle anywhere and the normal in fixed sensibly - BUT if it's on the ground plane the normal will face down no matter what you do...
            So check for flat faces where Z=0 and ALWAYS flip them if you want normal.z=+1...

            TIG

            1 Reply Last reply Reply Quote 0
            • M Offline
              MartinRinehart
              last edited by

              What you guys are saying and what I'm seeing are not the same. I'm flipping faces in two of the three planes. And I'm flipping regardless of the z value.

              Here 'r' creates a rectangle instance.

              
              # /r/rects.rb
              
              rec1 = r [0,0,10], [20,20,10]
              rec2 = r [10,0,0], [10,20,10]
              rec3 = r [0,10,0], [20,10,10]
              
              

              This is the result:
              samp.gif
              I've got three faces, outsides all facing the positive direction. rb was not flipped. The other two, rg (z == 10) and bg were flipped. (SU 7.1, PC).
              @tig said:

              As TT says if you make faces and the points are ordered appropriately the normal is fixed as you expect... EXCEPT if Z=0 and the face is flat in the XY plane then the face will always have normal.z=-1 no matter what you have set it to be - It's a SUp built-in foilble - draw a Rectangle anywhere and the normal in fixed sensibly - BUT if it's on the ground plane the normal will face down no matter what you do...
              So check for flat faces where Z=0 and ALWAYS flip them if you want normal.z=+1...

              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                Because the order of the vertices matters when creating a face? (with the possible exception when drawing on the rg plane at z=0.)

                swapping verts 2 and 4 (index 1 and 3) might reverse the normal.

                Hi

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MartinRinehart
                  last edited by

                  @jim said:

                  Because the order of the vertices matters when creating a face? (with the possible exception when drawing on the rg plane at z=0.)

                  swapping verts 2 and 4 (index 1 and 3) might reverse the normal.

                  I gave that a really quick try and didn't see a difference.

                  Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    Hmm. Just throwing things out if anything sticks.

                    @martinrinehart said:

                    Sorry TIG. This is working code in a working class.

                    TIG's right about the plane variable. It is a variable local to the get_corners method, and is never defined in get_corners before use. You will get an undefined variable exception if you try to run the code. If you are not getting an exceprion, you have another problem.

                    @martinrinehart said:

                    The box class commits to having a positive pushpull value pushpull in the positive direction.

                    What does "positive" mean in this context? Ruby pushpull uses the face normal as "positive", no matter its orientation globally or in the Group context.

                    If you draw a face with a normal in the same direction as an Axis, then pushpull the face in the positive direction, the face is going to reverse automatically.

                    Edit - I'll generalize that last statement to: a face pushpulled in its positive direction (its own normal direction) will reverse.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      MartinRinehart
                      last edited by

                      @jim said:

                      TIG's right about the plane variable. It is a variable local to the get_corners method, and is never defined in get_corners before use.

                      Oh dear. Should have been "@plane". Now my question is, why does it work as written?

                      @jim said:

                      @martinrinehart said:

                      The box class commits to having a positive pushpull value pushpull in the positive direction.

                      What does "positive" mean in this context?

                      Toward the positive end of the perpendicular axis.

                      Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        MartinRinehart
                        last edited by

                        @martinrinehart said:

                        Oh dear. Should have been "@plane". Now my question is, why does it work as written?

                        No more question, except maybe, "Why could we all be so foolish?"

                        From the constructor:

                        
                        attr_reader ... ;plane, ...
                        ...
                        @plane = ...
                        
                        

                        It's not a local variable, it's a method call. This is Ruby.

                        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                        1 Reply Last reply Reply Quote 0
                        • TIGT Offline
                          TIG Moderator
                          last edited by

                          If you haven't defined 'plane' then it's taken to be nil, so the test is if nil==something if something is also nil then it's true !!! πŸ˜’

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            How were we meant to know that you had defined 'plane' as a method, let alone a variable - which it seemed it might be at first glance, there were no clues in your published code ???
                            If you publish half of the story you'll get a lot more 'answers' than you need... ❓

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              MartinRinehart
                              last edited by

                              @tig said:

                              If you haven't defined 'plane' then it's taken to be nil, so the test is if nil==something if something is also nil then it's true !!! πŸ˜’

                              TIG, plane is defined. attr_reader ... :plane ... is equivalent to

                              
                              def plane()
                                  return @plane
                              end
                              
                              

                              edit: and this being Ruby plane is also plane() - maybe not Matz's best decision as this discussion shows.

                              All of which is to say I've got good working code that produces faces facing the positive end of the perpendicular axis and it does this by reverse!() for everything not in the 'rb' plane and I've no clue why and the standard answer "SU draws upside down in the rg plane when z=0" is true but it's not an answer to my question.

                              Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                              1 Reply Last reply Reply Quote 0
                              • M Offline
                                MartinRinehart
                                last edited by

                                @tig said:

                                How were we meant to know that you had defined 'plane' as a method, let alone a variable - which it seemed it might be at first glance, there were no clues in your published code ???
                                If you publish half of the story you'll get a lot more 'answers' than you need... ❓

                                My apologies.

                                Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                1 Reply Last reply Reply Quote 0
                                • J Offline
                                  Jim
                                  last edited by

                                  So, what does the plane() method look like?

                                  Hi

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

                                    @jim said:

                                    So, what does the plane() method look like?

                                    There is none. He used attr_reader(:plane) which is the same as:

                                    def plane()
                                      return @plane
                                    end
                                    

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

                                    1 Reply Last reply Reply Quote 0
                                    • J Offline
                                      Jim
                                      last edited by

                                      Yes, well, I see that now. 😳 So it's just a string anyway.

                                      Hi

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by

                                        Seems this is making it all too complicated for its own good πŸ˜‰
                                        What's wrong with testing @plane directly ?

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • J Offline
                                          Jim
                                          last edited by

                                          @tig said:

                                          Seems this is making it all too complicated for its own good πŸ˜‰

                                          There is no doubt of that.

                                          Hi

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

                                            @jim said:

                                            Yes, well, I see that now. 😳 So it's just a string anyway.

                                            No - it's nothing. it's nil until a value is assigned. it just makes the instance variable available to the outside scope.

                                            but in the context of Martin's code - yes @plane is a string.

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

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

                                            Advertisement