by 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
Last edited by cesaro36 on Fri Feb 24, 2017 10:57 pm, edited 1 time in total.
-
cesaro36
- Premium Member

-
- Posts: 22
- Joined: Sat Jul 18, 2009 7:29 pm
- Name: cesaro36
by sdmitch » Fri Feb 24, 2017 8:08 pm
@ip.transformation would be the transformation of the parent of the face not the face itself.
-

sdmitch
- PluginStore Author

-
- Posts: 1496
- Joined: Wed Mar 02, 2011 9:21 pm
- Name: sdmitch
- Operating system: Windows
- SketchUp version: 2014
- License type: Free/Make
- SketchUp use: hobby
- Level of SketchUp: Beginner
by 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?
-
cesaro36
- Premium Member

-
- Posts: 22
- Joined: Sat Jul 18, 2009 7:29 pm
- Name: cesaro36
by 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...
TIG
-

TIG
- Global Moderator
-
- Posts: 20297
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by 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.
-
cesaro36
- Premium Member

-
- Posts: 22
- Joined: Sat Jul 18, 2009 7:29 pm
- Name: cesaro36
by 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)
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5042
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by 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 @hovered_face_tra = 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 @hovered_face_tra = @ip.transformation # 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) 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!(@hovered_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!(@hovered_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
Last edited by Anton_S on Sun May 14, 2017 8:02 am, edited 1 time in total.
-
Anton_S
- PluginStore Author

-
- Posts: 1213
- Joined: Tue Nov 23, 2010 9:15 pm
- Name: Anton
- Operating system: Windows
- SketchUp version: 2018
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Advanced
by cesaro36 » Sun Feb 26, 2017 7:03 pm
Thanks Anton I'll try it as soon as I get to my laptop.
-
cesaro36
- Premium Member

-
- Posts: 22
- Joined: Sat Jul 18, 2009 7:29 pm
- Name: cesaro36
by TBoy » Tue May 09, 2017 4:03 pm
Anton_S, Do you have similar code to highlight local bounding boxes (including those inside groups and components)?
-
TBoy
-
- Posts: 84
- Joined: Mon Jan 04, 2016 10:45 am
- Name: TBOY
- Operating system: Windows
- SketchUp version: 2014
- License type: Free/Make
- SketchUp use: architecture
- Level of SketchUp: Beginner
by Anton_S » Sun May 14, 2017 9:28 am
There it is, TBoy: - Code: Select all
class BoundsHighlighterTool
def initialize @ip = Sketchup::InputPoint.new @hovered_inst = nil @global_parent_tra = nil @global_bb = nil @labb_global_faces = [] # Faces for the local axes aligned bounding box. @gabb_global_faces = [] # Faces for the global axes aligned bounding box. @labb_global_edges = [] @gabb_global_edges = [] @labb_face_color = Sketchup::Color.new(255,40,0,80) @gabb_face_color = Sketchup::Color.new(0,40,255,80) @labb_edge_color = Sketchup::Color.new(255,0,0,255) @gabb_edge_color = Sketchup::Color.new(0,0,255,255) @edge_width = 3 end
def deactivate(view) reset(view) end
def onMouseMove(flags, x, y, view) @ip.pick(view, x, y) ip_path = @ip.instance_path if ip_path.empty? reset(view) return end inst = nil gptra = nil ip_path.each { |ent| break if !ent.is_a?(Sketchup::Group) && !ent.is_a?(Sketchup::ComponentInstance) if gptra gptra = gptra * inst.transformation elsif inst gptra = inst.transformation end inst = ent } unless inst reset(view) return end return if inst == @hovered_inst @hovered_inst = inst @global_parent_tra = gptra local_bb = @hovered_inst.bounds # Obtain corners of local axes aligned bounding box in global space lagc = [] for i in 0..7 lagc << local_bb.corner(i) end if @global_parent_tra lagc.each { |point| point.transform!(@global_parent_tra) } end @labb_global_faces = [ [lagc[0], lagc[2], lagc[3], lagc[1]], [lagc[4], lagc[6], lagc[7], lagc[5]], [lagc[1], lagc[0], lagc[4], lagc[5]], [lagc[2], lagc[3], lagc[7], lagc[6]], [lagc[0], lagc[2], lagc[6], lagc[4]], [lagc[3], lagc[1], lagc[5], lagc[7]] ] @labb_global_edges = [ lagc[0], lagc[2], lagc[2], lagc[6], lagc[6], lagc[4], lagc[4], lagc[0], lagc[3], lagc[1], lagc[1], lagc[5], lagc[5], lagc[7], lagc[7], lagc[3], lagc[0], lagc[1], lagc[2], lagc[3], lagc[4], lagc[5], lagc[6], lagc[7] ] # Create global axes aligned bounding box @global_bb = Geom::BoundingBox.new() @global_bb.add(lagc) # Obtain corners of global axes aligned bounding box in global space gagc = [] for i in 0..7 gagc << @global_bb.corner(i) end @gabb_global_faces = [ [gagc[0], gagc[2], gagc[3], gagc[1]], [gagc[4], gagc[6], gagc[7], gagc[5]], [gagc[1], gagc[0], gagc[4], gagc[5]], [gagc[2], gagc[3], gagc[7], gagc[6]], [gagc[0], gagc[2], gagc[6], gagc[4]], [gagc[3], gagc[1], gagc[5], gagc[7]] ] @gabb_global_edges = [ gagc[0], gagc[2], gagc[2], gagc[6], gagc[6], gagc[4], gagc[4], gagc[0], gagc[3], gagc[1], gagc[1], gagc[5], gagc[5], gagc[7], gagc[7], gagc[3], gagc[0], gagc[1], gagc[2], gagc[3], gagc[4], gagc[5], gagc[6], gagc[7] ] view.invalidate end
def draw(view) return unless @hovered_inst # Draw local axes aligned global bounding box view.drawing_color = @labb_face_color @labb_global_faces.each { |face| view.draw(GL_POLYGON, face) } view.drawing_color = @labb_edge_color view.line_width = @edge_width view.line_stipple = '' view.draw(GL_LINES, @labb_global_edges) # Draw global axes aligned global bounding box view.drawing_color = @gabb_face_color @gabb_global_faces.each { |face| view.draw(GL_POLYGON, face) } view.drawing_color = @gabb_edge_color view.line_width = @edge_width view.line_stipple = '' view.draw(GL_LINES, @gabb_global_edges) end
def reset(view) return false unless @hovered_inst @hovered_inst = nil @global_parent_tra = nil @global_bb = nil @labb_global_faces.clear @gabb_global_faces.clear @labb_global_edges.clear @gabb_global_edges.clear view.invalidate return true end
end # class BoundsHighlighterTool
Sketchup.active_model.select_tool(BoundsHighlighterTool.new)
This time we iterate through the InputPoint's instance_path and transform the bounding box of the deepest instance across all the the parent groups/component instances in the path.
-
Anton_S
- PluginStore Author

-
- Posts: 1213
- Joined: Tue Nov 23, 2010 9:15 pm
- Name: Anton
- Operating system: Windows
- SketchUp version: 2018
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Advanced
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|