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

    Custom selection tool

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 231 Views 3 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
      ArunYoganandan
      last edited by

      Hi All,

      As some of you might be familiar, I'm building an immersive version of Sketchup. One of the custom tools I'm building is a 3D selection tool. i.e, you select objects that lie within a cuboid in 3D rather than a rectangle drawn in screen space.

      The selection algorithm basically walks through all the entities in the active_model.entities and checks to see if the bounds of the entity are intersecting/contained with that of the selection cube or not.

      One of the difficulties I'm facing is with curved surfaces like a cylinder. My algorithm seems to be selecting every edge on curved surfaces, rather than the just the surface.

      https://lh3.googleusercontent.com/-uce63AbM914/UIBN8hiEX-I/AAAAAAAAkUU/NcLMsdKbmzY/s1440/Screen%2520Captures1.jpg

      Here is a screenshot. To the left is the effect of using Sketchup's native selection tool and to the right is the one I wrote. SU's native tool selects 72 entities, while mine selects 96. On comparing the entities, the extra ones I have are edges on the curved surface.

      I have two questions.

      a) Is there a way to differentiate these edges on curved surfaces from others, so I don't include them in selection.

      b) My performance is really slow with curved surfaces. Does SU have a region selection mechanism? or is there a better algorithm I can use than what I described above. I can post code snippets if needed.

      Thanks in advance for your help
      Arun

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        As for question 1,the "dashed" lines defining the edges of the faces that make up the surface should be excludable by testing edge.soft? and edge.smooth? and ignoring it if either is true.

        As for question 2, the only thing in the SU API related to this is the Geom.point_in_polygon_2D which is useless in this case. If you would care to post the code you are currently using, maybe I or someone could offer an openion on what might be done to speed things up.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          One thing is you should be iterating the active_model.active_entities collection, to be sure and only select items in the current editing context. (Which could be the entire model.)

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • A Offline
            ArunYoganandan
            last edited by

            @sdmitch said:

            As for question 1,the "dashed" lines defining the edges of the faces that make up the surface should be excludable by testing edge.soft? and edge.smooth? and ignoring it if either is true.

            As for question 2, the only thing in the SU API related to this is the Geom.point_in_polygon_2D which is useless in this case. If you would care to post the code you are currently using, maybe I or someone could offer an openion on what might be done to speed things up.

            edge.soft? and edge.smooth? did get rid of the dashed lines. Thanks so much!

            Here is the function I'm using

            		def selectInVolume( view)
            	
            		#Add the corners from the 3D selection box into a selection volume
            		selectionVolumeBBox = Geom;;BoundingBox.new
            		selectionVolumeBBox.add @corner1
            		selectionVolumeBBox.add @corner2
            		selectionVolumeBBox.add @corner3
            		selectionVolumeBBox.add @corner4
            		selectionVolumeBBox.add @corner5
            		selectionVolumeBBox.add @corner6
            		selectionVolumeBBox.add @corner7
            		selectionVolumeBBox.add @corner8
            		
            		
            		sel = Sketchup.active_model.selection
            		
            		universalList = Sketchup.active_model.entities
            		
            		universalList = universalList.to_a - $unSelectableList
            		
            		universalList.each{ |b|
            
            			if(b.class != NilClass )
            
            				if(b.visible? == true)
            				
            					allCornersLieWithin = true
            					boundBoxObject2D = b.bounds
            					
            					resultantboundBox =  boundBoxObject2D.intersect selectionVolumeBBox
            					status = resultantboundBox.empty?
            					
            					if(status)
            					
            					else
            						if(selectionVolumeBBox.contains?(b.bounds.center))
            						
            							for i in 0..(7)
            								pt = (b.bounds.corner(i))
            
            								if(!selectionVolumeBBox.contains?(pt))
            									allCornersLieWithin = false
            									break
            								end	
            							end
            	
            							if(allCornersLieWithin == true)
            									sel.add b
            							end
            						
            						else
            							#if center doesnt lie within, then no point in checking for corners. the object clearly is not completely within
            						end
            					end
            
            				
            				end
            
            			end				
            		}
            	
            	end
            
            1 Reply Last reply Reply Quote 0
            • A Offline
              ArunYoganandan
              last edited by

              @dan rathbun said:

              One thing is you should be iterating the active_model.active_entities collection, to be sure and only select items in the current editing context. (Which could be the entire model.)

              Thanks for the suggestion. I revised my code to active_entities. Doesn't seem to make much of a difference in performance right now, but I see your point as to how it could in other situations.

              1 Reply Last reply Reply Quote 0
              • sdmitchS Offline
                sdmitch
                last edited by

                Using the BoundingBox certainly works as long as the selection box is not rotated which will cause BoundingBox to be much larger than the selection box.

                I see no reason why the selection process should be any slower on a curved surface. It should only matter how many total entities there are in the model.

                Nothing is worthless, it can always be used as a bad example.

                http://sdmitch.blogspot.com/

                1 Reply Last reply Reply Quote 0
                • A Offline
                  ArunYoganandan
                  last edited by

                  @sdmitch said:

                  Using the BoundingBox certainly works as long as the selection box is not rotated which will cause BoundingBox to be much larger than the selection box.

                  I see no reason why the selection process should be any slower on a curved surface. It should only matter how many total entities there are in the model.

                  Yea. That is the same thing I'm confused about as well. Unless SU has a way of selecting the cylindrical surface as one unit or a collection rather than add each face of the curved surface one after the other(which is what my code does). Also, all my conditionals could be slowing things down as well.

                  The selection box is axis aligned, so the they bounding box and the selection box should pretty much be the same size.

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

                  Advertisement