• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Back face/material reverse

Scheduled Pinned Locked Moved Developers' Forum
24 Posts 5 Posters 888 Views 5 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.
  • A Offline
    Alienizer
    last edited by 5 Aug 2011, 04:55

    Either I'm insane or Sketchup is s.up 👊
    I've been trying everything and still it isn't working right. Here is the code...

    def reverseBackFaces
      view = Sketchup.active_model.active_view
      @ip = Sketchup;;InputPoint.new
      eyevec = view.camera.eye.vector_to(view.camera.target)
      i = 0
      y = view.vpheight-1
      unless y < 0
        Sketchup.set_status_text(y.to_s)
        x = view.vpwidth-1
        unless x < 0
          @ip.pick view, x, y
          if @ip.valid? and @ip.face
            if eyevec.dot(@ip.face.normal) >= 0
              @ip.face.material = @ip.face.back_material
              @ip.face.back_material = nil
              @ip.face.reverse!
              i += 1
            end
          end
          x -= 1
        end
        y -= 1
      end
      Sketchup.set_status_text(i.to_s+" faces reversed")
    end
    
    

    It work, then it doesn't, then it does, then it doesn't. What's wrong with my code? I can't find anything wrong 😡

    I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 5 Aug 2011, 06:41

      Uh... the UI::Inputpoint class, needs to be used within a Tool class instance.
      The pick method is normally called from within one of the mouse button callbacks of your tool.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • A Offline
        Alienizer
        last edited by 5 Aug 2011, 14:45

        @dan rathbun said:

        Uh... the UI::Inputpoint class, needs to be used within a Tool class instance.
        The pick method is normally called from within one of the mouse button callbacks of your tool.

        I don't think it makes any difference how it is used. It accept a view and a screen point and has no idea that the point comes from a mouse or any other screen poiting device. The Mouse and InputPoint are not related at all. Otherwise, it would be mouse.get_item_it_points_to or something like that, where you can't change the x and y. It has no idea it's from a mouse event, nor for a tool.

        I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 5 Aug 2011, 14:56

          What would you like to happen ? In words, not code...

          TIG

          1 Reply Last reply Reply Quote 0
          • A Offline
            Alienizer
            last edited by 5 Aug 2011, 15:07

            @tig said:

            What would you like to happen ? In words, not code...

            Back face/material reverse, I know you have a script for that, but I want to make my own where it scans the screen and reverse any faces that are facing back at the camera. Then I want to make it so that if you hover the mouse over your model, it'll do the same, but only on the face your mouse is pointing at.

            The code works, but if I rotate my model 90deg CW, it works half way! Some faces are not reversed, and some that should not, are!

            I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 5 Aug 2011, 15:33

              You need to make it [and launch it] as a Sketchup Tool.
              Then you can get the mouse position on screen and find the face below the mouse if any, and then flip it [and front/back materials] if you are looking at the back of it and it has a material etc...

              TIG

              1 Reply Last reply Reply Quote 0
              • A Offline
                Alienizer
                last edited by 5 Aug 2011, 15:41

                @tig said:

                You need to make it [and launch it] as a Sketchup Tool.

                ?? My code works fine 100% of the time on any models in SU7, it's screwy in SU8. Perhaps it's a bug in SU8, and nothing wrong with my code?

                I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 5 Aug 2011, 15:58

                  How is your code finding the mouse position without a tool to monitor the cursor ?
                  How is the input_point finding anything other than the near top left screen pixel point ?
                  Perhaps you haven't posted all of the code but as it stands it will not do what you want 'on its own'...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Dan Rathbun
                    last edited by 5 Aug 2011, 18:43

                    Alan.. it would likely be easier for you to start with letting the user use the built-in SelectionTool to choose single or multiple faces, then react to changes in the Selection set, ie: Sketchup.active_model.selection

                    You could add a call to your reverse face method in the mouse context menu... or get a bit fancier with a SelectionObserver

                    P.S. : The InputPoint class is defined within the UI module for a reason. It's meant to interact with the user.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Alienizer
                      last edited by 5 Aug 2011, 19:30

                      @tig said:

                      How is your code finding the mouse position without a tool to monitor the cursor ?

                      It's not using the mouse! If you read my code, I have 2 for loops to scan the screen viewport.

                      Later I will add mouse support, but my code now is only viewport scanning.

                      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Alienizer
                        last edited by 5 Aug 2011, 19:39

                        @dan rathbun said:

                        Alan..

                        I know what you mean, but I found out in another thread that raytest is FUBAR in SU8, pick is more likely using the same code as raytest.

                        That explain why my code works 100% in SU7 but not in SU8

                        from thread...
                        http://forums.sketchucation.com/viewtopic.php?f=180&t=31326&p=275718&hilit=FUBAR#p275718

                        @thomthom said:

                        Why do you not want to use an InputPoint? You can use the ip.face to test if you got the point from a face and ignore the rest.

                        But, yes, you can shoot a ray:

                        ` ray = view.pickray(x, y)
                        result = model.ray_test( ray )

                        TODO: Recast on hidden entities`

                        Then remember that in SU8 the ray_test is FUBAR.

                        I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          TIG Moderator
                          last edited by 5 Aug 2011, 22:15

                          Your code does indeed decrement x & y by 1 [having set them to the bottom-right screen-pixel] so it should scan the whole screen ?
                          The model.raytest() does work OK now in the latest SUpv8M1 but your method should work OK too...
                          Read Dan's comments...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • A Offline
                            Alienizer
                            last edited by 5 Aug 2011, 22:46

                            def onMouseMove(flags, x, y, view)
                              Sketchup.set_status_text(x.to_s+" ; "+y.to_s)
                            end
                            

                            Dan, the above code show the mouse coord to be 0,0 at the top-left corner of the viewport, regardless where the window is on the desktop. Any reference to screen coords are within the viewport, not the physical screen. I know about the status text, SK needs to refresh for it to show, and it gets replaces when you move the mouse.

                            TIG, my version is 8.0.4011 in the 'About' box.

                            I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              Dan Rathbun
                              last edited by 5 Aug 2011, 22:50


                              1) **Sketchup.set_status_text()**

                              does not work well outside a custom Tool instance, because there must be another tool active (either someone else's custom Tool, or one of the OEM tools.)
                              As soon as you move the mouse 1 pixel, or Sketchup decides (per some other criteria,) to redraw the UI, ... your message will be overwritten. (It can happen so fast, that the user never has time to read your message.)

                              2) You are not scanning the view. (Yes you are, I see now the unless loop.)

                              ..removed...

                              3) And perhaps (because UI::InputPoint uses inferencing,)

                              you might wish to use Sketchup::PickHelper instead.


                              EDITED AGAIN: removed confusing subject matter.

                              I'm not here much anymore.

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                Dan Rathbun
                                last edited by 5 Aug 2011, 22:52

                                Yup.. sorry I got confused. Removed bogus suggestions.
                                and you do have MR1 of ver 8

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  Dan Rathbun
                                  last edited by 5 Aug 2011, 22:58

                                  @alienizer said:

                                  def onMouseMove(flags, x, y, view)
                                  >   Sketchup.set_status_text(x.to_s+" ; "+y.to_s)
                                  > end
                                  

                                  or ...

                                  def onMouseMove(flags, x, y, view)
                                    Sketchup.set_status_text("x; #{x} , y; #{y}")
                                  end
                                  

                                  BTW.. on Window... you can use a Coordinate Tool that displays in model units:
                                  Sketchup.send_action( 21324 )
                                  the tool_name is "CoordinateTool" but there doesn't seem to be a send_action string for it.

                                  I'm not here much anymore.

                                  1 Reply Last reply Reply Quote 0
                                  • A Offline
                                    Alienizer
                                    last edited by 5 Aug 2011, 23:28

                                    @dan rathbun said:

                                    or ...

                                    def onMouseMove(flags, x, y, view)
                                    >   Sketchup.set_status_text("x; #{x} , y; #{y}")
                                    > end
                                    

                                    or...

                                    def onMouseMove(flags, x, y, view)
                                      Sketchup.set_status_text("x=%d, y=%d"%[x,y])
                                    end
                                    

                                    @unknownuser said:

                                    BTW.. on Window... you can use a Coordinate Tool that displays in model units:
                                    Sketchup.send_action( 21324 )
                                    the tool_name is "CoordinateTool" but there doesn't seem to be a send_action string for it.

                                    How did you come up with 21324?

                                    I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                                    1 Reply Last reply Reply Quote 0
                                    • D Offline
                                      Dan Rathbun
                                      last edited by 5 Aug 2011, 23:41

                                      @alienizer said:

                                      @unknownuser said:

                                      BTW.. on Window... you can use a Coordinate Tool that displays in model units:
                                      Sketchup.send_action( 21324 )
                                      the tool_name is "CoordinateTool" but there doesn't seem to be a send_action string for it.

                                      How did you come up with 21324?

                                      I cheat! 🤣

                                      Really I make a copy of all the SU binary executables, and put them in a %(#804000)[Dev/_EXE] folder, renaming them thus:
                                      SketchUp.exe to SketchUp.8.0.4811.exe so they have ver and build in the name.
                                      Then I open these copies in MS Visual Studio, to check resources (like String Tables, Menu Definitions, etc.)

                                      Many of the ids are already listed in the API doc: Sketchup.send_action()

                                      I'm not here much anymore.

                                      1 Reply Last reply Reply Quote 0
                                      • A Offline
                                        Alienizer
                                        last edited by 5 Aug 2011, 23:48

                                        @dan rathbun said:

                                        Many of the ids are already listed in the API doc: Sketchup.send_action()

                                        Ah!

                                        I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                                        1 Reply Last reply Reply Quote 0
                                        • A Offline
                                          Alienizer
                                          last edited by 6 Aug 2011, 01:01

                                          Problem solved.

                                          After doing more testing, displaying the dot(face.normal, ray) returned <0 and when viewed cam rotated 45deg it was >0

                                          So after applying a transformation_at the dot() returned the correct cosine. So now my code works perfectly

                                          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

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

                                          Advertisement