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

    Face pointing towards the camera?

    Scheduled Pinned Locked Moved Developers' Forum
    25 Posts 7 Posters 1.0k Views 7 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

      If the angle between the vector [picked_point_to_eye] and the picked_face_normal is > 90.degrees then you are looking at the back ? If it is 90.degrees toss a coin ???

      TIG

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

        I'm wondering is the sign of the dot product between the camera vector and the face's global vector will work...
        will have to try tomorrow.

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

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

          @thomthom said:

          I'm wondering is the sign of the dot product between the camera vector and the face's global vector will work...
          will have to try tomorrow.

          This appear to work. But I'm not generating the global vector correctly. I thought I could take the face vector and transform! it with each of the group's transformation...

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

          1 Reply Last reply Reply Quote 0
          • AdamBA Offline
            AdamB
            last edited by

            FWIW LightUp does this:

            pickface.normal.transform(@xform).dot(view.pickray(x, y)[1]) > 0

            Developer of LightUp Click for website

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

              Won't view.pickray(x, y)[1] be a vector parallel to camera.direction?

              @xform is the total transformation?

              given the path to a face, I initially started with the out most transformation, but I should instead go the other way?

              then you have the issue of SU changing the co-ordinates if you open a group/component. If I'm inside an open component and pick a face outside the scope - then what?

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

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

                Does PickHelper.transformation_at return the total transformation for that entity, including it's parents?

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

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

                  @thomthom said:

                  Does PickHelper.transformation_at return the total transformation for that entity, including it's parents?

                  Yes.

                  Seems to be working fine now.

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

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

                    Sounds complicated. How about:

                    ` center = face.bounds.center
                    edge1 = camera.eye to center
                    edge2 = camera.eye to (center + face.normal)

                    edge1 longerThan edge2 ? outside : inside`

                    This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.

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

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

                      Heh, I like that method Martin. I think the logic is sound. Should be simple to implement also, which is always welcome!

                      Chris

                      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

                        @martinrinehart said:

                        Sounds complicated. How about:

                        ` center = face.bounds.center
                        edge1 = camera.eye to center
                        edge2 = camera.eye to (center + face.normal)

                        edge1 longerThan edge2 ? outside : inside`

                        This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.

                        That will tell if the face is pointing frontside or backside towards the camera?

                        This seems to work without any special cases.

                        
                        t = ph.transformation_at(index)
                        n = picked.normal.transform(t).normalize
                        c = Sketchup.active_model.active_view.camera.direction
                        m = (c % n > 0) ? e.back_material ; e.material
                        
                        

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

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

                          face = Sketchup.active_model.selection[0] cam = Sketchup.active_model.active_view.camera.eye e1 = cam.vector_to(face.bounds.center) e2 = e1 + (face.normal) (e1.length > e2.length) ? (puts "front") : (puts "back")

                          That is the method Martin outlined. I don't know about the transformation. I guess you would have to figure that in on your own. Is it because the InpointPoint returns the un-transformed normal for a face?

                          Chris

                          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

                            InputPoint only returns entities. So when I pick a face I only get the normal via face.normal, which is the local normal.

                            But PickHelper.transformation_at(index) returns the complete global transformation for the entity.

                            only thing is - I need to test what happends when I'm inside an open group/component, but pick from something outside the current context. (if that's at all possible)

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

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

                              Yikes, good luck. This seems to go back to the complaint that SU does not like to traverse through the heirarchy backwards like this.

                              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

                                Turns out - there isn't a problem. The PickHelper doesn't pick anything but what's in the currently open context.

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

                                1 Reply Last reply Reply Quote 0
                                • AdamBA Offline
                                  AdamB
                                  last edited by

                                  @martinrinehart said:

                                  Sounds complicated. How about:

                                  ` center = face.bounds.center
                                  edge1 = camera.eye to center
                                  edge2 = camera.eye to (center + face.normal)

                                  edge1 longerThan edge2 ? outside : inside`

                                  This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.

                                  But thats much more work than a dot product. Your turning an orientation problem into something its not.

                                  Developer of LightUp Click for website

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

                                    Interesting Thom. So how do people make tools that select entities outside the current editing level? Can you use the inputpoint class to succesfully return entities outside the current editing level? This is something I really never work with, in case you couldn't tell!

                                    Chris

                                    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

                                      I'm not sure if you can. I think that when the user digs into groups/components it narrows the available scope.
                                      Though this is not something I've explored, as I've never needed to do this.

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

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

                                        @adamb said:

                                        But thats much more work than a dot product. Your turning an orientation problem into something its not.

                                        I'm not seeing how a dot product solves the problem. Could you articulate or maybe Sketch something Up?

                                        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

                                          The result of the dot product can be used to determine if its the front or back side pointing towards the camera.

                                          t = ph.transformation_at(index) n = picked.normal.transform(t).normalize # global vector orientation c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material : e.material

                                          If the dot product is positive then the backface is facing the camera, otherwise it's the front side.

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

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

                                            @thomthom said:

                                            The result of the dot product can be used to determine if its the front or back side pointing towards the camera.

                                            t = ph.transformation_at(index) n = picked.normal.transform(t).normalize # global vector orientation c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material : e.material

                                            If the dot product is positive then the backface is facing the camera, otherwise it's the front side.

                                            Who is ph? Who is picked?

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

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

                                            Advertisement