Help please. How to get transformation for the face

Help please. How to get transformation for the face

Postby cesaro36 » Fri Feb 24, 2017 7:48 pm

Hi everyone
I need help to get the transformation of the current face under the cursor.
I'm using the input point method but my problem emerges when the cursor is Inferenced.

It is weird because my @ip.face is correct but @ip.transformation doesnt match.

I dont use a pick helper because I need to get faces outside p.e. when editing inside a component.

The only plugin that I've seen it managing well is AngleInpector from Freddo tools.

Any ideas?

Thanks
0
Last edited by cesaro36 on Fri Feb 24, 2017 10:57 pm, edited 1 time in total.

cesaro36 
Premium Member
Premium Member
 

Re: Help please. How to get transformation for the face

Postby sdmitch » Fri Feb 24, 2017 8:08 pm

@ip.transformation would be the transformation of the parent of the face not the face itself.
0
Nothing is worthless, it can always be used as a bad example.

http://sdmitch.blogspot.com/
User avatar
sdmitch 
PluginStore Author
PluginStore Author
 

Re: Help please. How to get transformation for the face

Postby cesaro36 » Fri Feb 24, 2017 8:37 pm

thanks, but... what I mean is how to get the correct transformation for the face bellow when the cursor is inferenced. Is there something I'm missing?
0

cesaro36 
Premium Member
Premium Member
 

Re: Help please. How to get transformation for the face

Postby TIG » Fri Feb 24, 2017 8:48 pm

A face doesn't have a "transformation" per se.
The "input point" your identify can give the transformation of where it was picked - which you can then use to modify entities' transformations later...
You can "transform" a group/instance, face, edge or vertex...

You can gather various info about any picked vertex/edge/face [e.g. position/line/center/normal ] - and devise transformations to modify these [bearing in mind the parent's transformation you have also collected...]
BUT what do you want to do ?

Please explain what you want to 'find' and what you want to do with it...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Help please. How to get transformation for the face

Postby cesaro36 » Fri Feb 24, 2017 9:08 pm

Thanks TIG
My intention is to highlight the face that the cursor is passing over.
In the Animation GIF you can see that when the interfering is happening the highlighted face is been drawn where it should'n, meaning that the transformation given by @ip.transformation is not the same as it was before the iterferencing while the @ip.face is still the same. (is that make sense)
I'm doing my best trying to explain this in english.
0

cesaro36 
Premium Member
Premium Member
 

Re: Help please. How to get transformation for the face

Postby Dan Rathbun » Sat Feb 25, 2017 8:11 pm

cesaro36 wrote:Thanks TIG
My intention is to highlight the face that the cursor is passing over.

You can do this easily by pushing the face's reference into the model selection set.

old_set = model.selection.to_a
model.selection.clear
model.selection.add(@ip.face)
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: Help please. How to get transformation for the face

    Postby Anton_S » Sun Feb 26, 2017 12:11 pm

    cesaro36,

    Like TIG and others mentioned a face doesn't have a transformation, but its point positions are bound to the transformation of a group/component instance containing the face. In that case, you will need to transform all points of the face into global space before highlighting the face.

    Here is a sample face highligher tool:
    Code: Select all
    class FaceHighlighterTool

      def initialize
        @ip = Sketchup::InputPoint.new
        @triplets = []
        @edge_points = []
        @hovered_face = nil
        @face_color = Sketchup::Color.new(0,40,255,80)
        @edge_color = Sketchup::Color.new(0,0,255,255)
        @edge_width = 3
      end

      def deactivate(view)
        @hovered_face = nil
        view.invalidate
      end

      def onMouseMove(flags, x, y, view)
        @ip.pick(view, x, y)
        face = @ip.face
        if face.nil?
          if @hovered_face
            @hovered_face = nil
            view.invalidate
          end
          return
        end
        if face != @hovered_face
          @hovered_face = face
          # In order to draw a face with holes, we must draw its mesh
          mesh = face.mesh
          polygons_size = mesh.count_polygons
          @triplets = Array.new(polygons_size)
          face_tra = @ip.transformation
          for i in 0...polygons_size
            # Obtain one of the triangles making up the face
            triplet = mesh.polygon_points_at(i+1)
            # Transform to global space
            triplet.each { |pt| pt.transform!(face_tra) }
            # Store for drawing
            @triplets[i] = triplet
          end
          # Get all edges for drawing a border
          @edge_points.clear
          face.edges.each { |edge|
            @edge_points << edge.start.position
            @edge_points << edge.end.position
          }
          # Transform all edge points to global space
          @edge_points.each { |point| point.transform!(face_tra) }
          # Trigger the drawing
          view.invalidate
        end
      end

      def draw(view)
        return unless @hovered_face
        view.drawing_color = @face_color
        @triplets.each { |triplet|
          view.draw(GL_POLYGON, triplet)
        }
        view.drawing_color = @edge_color
        view.line_width = @edge_width
        view.line_stipple = ''
        view.draw(GL_LINES, @edge_points)
      end

    end # class FaceHighlighterTool

    Sketchup.active_model.select_tool(FaceHighlighterTool.new)

    If you paste it all into Ruby Console you will see the effect.

    Anton
    0

    Anton_S 
    PluginStore Author
    PluginStore Author
     

    Re: Help please. How to get transformation for the face

    Postby cesaro36 » Sun Feb 26, 2017 7:03 pm

    Thanks Anton
    I'll try it as soon as I get to my laptop.
    0

    cesaro36 
    Premium Member
    Premium Member
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: dAlex65, tungduongarch and 2 guests

    Visit our sponsors: