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

    [Plugin] Hatchfaces (v1.8 beta) UPDATED 15-Dec-2012

    Scheduled Pinned Locked Moved Plugins
    360 Posts 41 Posters 228.5k Views 41 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

      Deliberately testing off origin and it works for me πŸ˜•

      TIG

      1 Reply Last reply Reply Quote 0
      • jolranJ Offline
        jolran
        last edited by

        @unknownuser said:

        Deliberately testing off origin and it works for me

        Yeah, that was a desperate long shot, assuming you did not think off that 😳 .

        Ok, so now I guess I'll have to pinpoint what goes on with the geometry at each step, that would different than in your model.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Select a face in the model, in the Ruby Console type or copy&paste face=Sketchup.active_model.selection[0] to get a reference to it - we'll use it later.
          Make a standard piece of hatching on that face [it needs to be smiley face type in a group] with no attempt at make it a component, or glued or cutting in code.
          Select that group, in the Ruby Console type or copy&paste group=Sketchup.active_model.selection[0] to get a reference to it.
          Now run the individual lines of code one at a time on that 'group' - see it's changes.
          It should eventually become a component that glues and cuts and is attached to 'face'...

          Repeat with a face inside another group.
          See if it fails - if it does then try changing the code for the transformation used in the initial group.entities.transform_entities() to the 'parent' version I gave. If that part succeeds but the later instance transformation fails try using something like (group.transformation*parent.transformation).origin etc instead...

          TIG

          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            Thanks TIG. I've acctually just done something similar.
            Although with the smiley exploded.

            I will try your method as well.

            What I have discoverd so far is that when turning group to component.
            ins=gp2.to_component
            The center of component.entities get to world origin(you follow my explanation?)
            (I see this if double clicking the component and the axis are shown. PIC)

            **This happends with or without your rotations.**Your rotations flips the "blue" axis in the face normal direction, wich is what we want, right? So thats good.

            But in order to make the cutting work in think one must move the component.entities center to the face, can't explain it better..
            That's probably why it works when I'm doing test at ORIGIN.

            In short! It doesent look like something fishy is going on with the geometry UNTIL turning group to component.

            Elaborating with group.transformation*parent.transformation might be a good idea. Cause this problem has to do with transformations. The glue to face is working.


            testing2.jpg

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              Hmm a second thought. I might have looked at it the wrong way.
              The problem is not turning group into component. But Transformations made to entities before that.

              And the problems comes from the intersection I think. It uses face-clone group.transformation. And I MUST use that transformation to intersect. So maybe it alters the group.orgin somehow..

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                BTW your code works. For testing with a group, not inside my script though πŸ˜•

                I had to do it a little differently selecting groups. I can understand why your asking youself
                what the heck I'm fuzzing about.. πŸ˜„

                Although! the result have the inputpoint at face(like I desired), so that is what I must solve then.

                ss=Sketchup.active_model.selection
                faces=[]; groups=[]; ss.each{|e|
                    if e.class==Sketchup;;Face
                     faces << e
                   end
                    if e.class==Sketchup;;Group
                     groups << e
                     end}
                face=faces[0] if faces; gp=groups[0] if groups
                
                
                puts face
                puts gp
                tr=Geom;;Transformation.rotation(ORIGIN, X_AXIS, -90.degrees)
                gp.entities.transform_entities(tr, gp.entities.to_a)
                ### it's made flat
                ###
                tran=gp.transformation
                tr=Geom;;Transformation.rotation(tran.origin, tran.xaxis, 90.degrees)
                gp.transform!(tr)
                ### it stands up but...
                ### we have now corrected the axes to suit a cutting-component
                ###
                ### now make it a component...
                ins=gp.to_component
                defn=ins.definition
                ###
                ### make it 'cutting'
                defn.behavior.is2d=true
                defn.behavior.cuts_opening=true
                defn.behavior.snapto=0
                ###
                ### glue to the original 'face'
                ins.glued_to=face
                ### it now 'cuts holes' in the 'face'
                
                1 Reply Last reply Reply Quote 0
                • TIGT Offline
                  TIG Moderator
                  last edited by

                  OK...
                  I now see the issue. πŸ˜•
                  Before you do any of the steps I mentioned in converting the group into a cutting component we need to ensure that the groups bounds are reset so its bbox is parallel to the face...
                  Insert these steps between making the grouped hatch and flattening it.
                  We find the group's rotation in 3d relative to the main axes.
                  We rotate the faces in side the group so they lie on the X_AXIS and the bounds are a rectangle.
                  We rotate the group back so it is back on the face.
                  tr=Geom::Transformation.new(bbc,zaxis)
                  where 'bbc' is the group.bounds.center and zaxis is the face.normal will transform the group.entities axes correctly so, then transform the group.bound.center back to bbc which itself should be transformed translated inversed back to the origin...

                  This is all getting too too complex. πŸ˜’
                  I'll try to write some simple generic code to turn a grouped face that's coplanar to a face into a group that is placed on the face with its z-axis==face.normal...watch this space...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • jolranJ Offline
                    jolran
                    last edited by

                    OK! Now I think I've actually found the problem. And it's kind of a careless and stupid one.

                    In the code I first make a group called gp2. Then I add the selected component instance to the group.
                    I do that by it's definition and transformation. Now since I did it in an iterator using e=instance (e.definition, e.transformation) the transformation is using defintion.origin!! I must use another transformation in (e.definition, e.?)

                    Be back soon πŸ˜„

                    Edited: Sorry TIG I was typing when your answer came, I think this issue is THE problem
                    Or maybe at least have a look at it before you make a fix. This is happening at the very first in the plugin.

                    1 Reply Last reply Reply Quote 0
                    • jolranJ Offline
                      jolran
                      last edited by

                      Γ„hh.. 😞 Nothing seams to work.. I'm trying to add the function to use groups in the plugin. Like the testingcode from TIG.

                      Anyway, here is the part where the sketchup selection get's turned into groups. ...
                      Probably some basic faults in here. Would appreciate a cleanup on this.. I do have to add the instance by definition to cents, no? Also the groups in cents don't get exploded.

                      Edited Well, found a thread about adding groups. So now that feature is added(code changed), but not without issues.. At least one can use groups for 2dbooleans, now. Could be useful.

                      Did not fix transformation issue, though... My guess is I cannot use the groups own instance transformation?
                      Very wierd to see groups as instances though. Illogical... lets see what TIG will comes up with..

                       if comps ##comps=Collection, array of instances and groups #######
                             
                              gp2=ents.add_group(); cents=gp2.entities; gp2.name=name; gp2.layer=hatch_layer
                      		
                      
                      		
                      		
                      	   comps.each{|e| #Add instance to group and erase original.
                      	       if e.class==Sketchup;;ComponentInstance
                                     cents.add_instance(e.definition, e.transformation) 
                      			   e.erase!
                      			   
                      		   end
                      		   if e.class==Sketchup;;Group
                      		     gp2ents = e.parent.entities
                                   gp2defn = e.entities.parent
                                   gp2tran = e.transformation
                                   cents.add_instance(gp2defn, gp2tran) ### group instances
                                   e.erase! ### remove original groups  ###################
                      		   end
                      	    }
                      	 ####### Explode everything inside gp2.entities ####
                      	   cents.to_a.each{|e| 
                      	       if e.class==Sketchup;;ComponentInstance 
                      	           e.explode
                                 end
                      	       if e.class==Sketchup;;Group
                      	           e.explode
                      	       end
                              }
                      	   
                         end
                      
                      1 Reply Last reply Reply Quote 0
                      • jolranJ Offline
                        jolran
                        last edited by

                        @unknownuser said:

                        We find the group's rotation in 3d relative to the main axes.
                        We rotate the faces in side the group so they lie on the X_AXIS and the bounds are a rectangle.
                        We rotate the group back so it is back on the face.
                        tr=Geom::Transformation.new(bbc,zaxis)

                        @unknownuser said:

                        This is all getting too too complex.
                        I'll try to write some simple generic code to turn a grouped face that's coplanar to a face into a group that is placed on the face with its z-axis==face.normal...watch this space...

                        Yes, I feel it maybe be a complex transformation, no? TIG, are you working on something or should I dig in to the rotation part?
                        I'm still not sure if I'm creating the instances from definition correct. I've split the code up for testing.
                        After exploding the instances into group B.BOX looks OK.
                        After intersection and deleting edges still OK.
                        It's when turning group.to_component the B.BOX reaches to ORIGIN.
                        I've already shown this in picture, just doublechecked it again..

                        Although! If I manually make component from group at each step described. In Sketchup, the boundingbox reaches to ORIGIN. So that's why I'm wondering if the instances has been created improperly from the definition, regarding the transformation.
                        Once again: When saying B.BOX I mean entity bounds from doubleclicking the component.

                        1 Reply Last reply Reply Quote 0
                        • jolranJ Offline
                          jolran
                          last edited by

                          BTW. Is there any possibility to explode the instances first thing? Collect the exploded entities and put them into a group, before they merge with underlying entities. I know there are some issues in this field.. Don't have time to test that right now.
                          But maybe that would be better than messing around with definitions and transformations..

                          After surfing info in this forum, I think doing above is not possible.. Not without trouble anyway..

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            This code takes any 'flat' 'group' drawn on a 'face' [that's at any orientation] and turns it into a gluing/cutting component... it needs completing for the name/layer etc and also testing for nested groups... You also don't need the start/commit operation code as it'll be inside another set - it's put there for testing separate from the main code...

                            ### turns the 'group' into a component glued/cutting 'face'
                            def g2cut(group, face)
                              model=Sketchup.active_model
                              ###
                              model.start_operation('g2cut')
                              ents=model.entities
                              pents=group.parent.entities
                              gents=group.entities
                              bb=group.bounds
                              bbc=bb.center
                              norm=face.normal
                              if pents==ents
                                xaxis=X_AXIS.clone
                                yaxis=Y_AXIS.clone
                                zaxis=Z_AXIS.clone
                              else ###??? unsure if we need to redefine for nested groups?
                                xaxis=X_AXIS.clone
                                yaxis=Y_AXIS.clone
                                zaxis=Z_AXIS.clone
                              end
                              ve=group.transformation.origin.vector_to(bbc)
                              tr=Geom;;Transformation.translation(ve)
                              group.transform!(tr)
                              tr=Geom;;Transformation.translation(ve.reverse)
                              gents.transform_entities(tr, gents.to_a)### centered
                              tr=Geom;;Transformation.new(group.transformation.origin, norm)
                              group.transform!(tr)
                              ve=group.transformation.origin.vector_to(bbc)
                              tr=Geom;;Transformation.translation(ve)
                              group.transform!(tr)
                              tr=Geom;;Transformation.rotation(group.transformation.origin, group.transformation.xaxis, -90.degrees)
                              gents.transform_entities(tr, gents.to_a)
                              ang=xaxis.angle_between(group.transformation.xaxis)
                              tr=Geom;;Transformation.rotation(group.transformation.origin, zaxis, ang)
                              gents.transform_entities(tr, gents.to_a)
                              pt=gents[0].vertices[0].position
                              ve=Geom;;Vector3d.new(0,0,-(pt.z))
                              tr=Geom;;Transformation.translation(ve)
                              gents.transform_entities(tr, gents.to_a)
                              gents.parent.invalidate_bounds
                              bc=group.bounds.center
                              ve=bc.vector_to(bbc)
                              tr=Geom;;Transformation.translation(ve)
                              group.transform!(tr)
                              ve=group.transformation.origin.vector_to(bbc)
                              tr=Geom;;Transformation.translation(ve)
                              group.transform!(tr)
                              v=ve.reverse.transform(group.transformation.inverse)
                              tr=Geom;;Transformation.translation(v)
                              gents.transform_entities(tr, gents.to_a)
                              ### make component
                              inst=group.to_component
                              defn=inst.definition
                              be=defn.behavior
                              be.is2d=true
                              be.cuts_opening=true
                              be.snapto=0
                              inst.glued_to=face
                              ###
                              ### complete these items...
                              #defn.name=
                              #inst.name=
                              #inst.layer=
                              ###
                              model.commit_operation
                            end
                            

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • jolranJ Offline
                              jolran
                              last edited by

                              Yeeehhaaa TIG!! β˜€ BIG job from you. Thanks a million+ times.

                              That's quite some extra bit of code. We will have to see some performance tests when/if I manage to add this.
                              Already the plugin is quite processor intensive, doing all the iterators face_classify, erasing stuff etc..We won't know until tested.

                              In general, do transformations put a lot of strain on the calculation/computation?

                              Anyway, thanks again. This will be interesting to test.

                              1 Reply Last reply Reply Quote 0
                              • jolranJ Offline
                                jolran
                                last edited by

                                Much better TIG!
                                There are still some issues. Pic says all. Now I was gonna put this "is as" a method at the end no, passing arguments? There won't be any problem with putting declarations inside a method I persume. I mean for ex model=Sketchup.active_model..

                                It works perfectly on Y axis. X axis it flips upside down. Off axis, a little troublesome..

                                The definition has quite a lot of transformations πŸ˜„ might take a while before I understand what's going on, and can track issues.

                                Performance is good. Havent tested on super heavy geometry.


                                cutmethod2.jpg

                                1 Reply Last reply Reply Quote 0
                                • jolranJ Offline
                                  jolran
                                  last edited by

                                  Going through your script trying to get a grasp on it. It's comparing axis to vectors a lot, no? I wonder would it be more predictable to use crossproducts where possible? I don't know, from for ex face.normal? Just a wild guess.

                                  1 Reply Last reply Reply Quote 0
                                  • jolranJ Offline
                                    jolran
                                    last edited by

                                    Talking to myself mostly... Another pic(will delete older pics later on, in case I'm overusing this function a little to much).

                                    I think we are hitting some bug here. Isent this strange behavior?


                                    comp_behavior2.jpg

                                    1 Reply Last reply Reply Quote 0
                                    • jolranJ Offline
                                      jolran
                                      last edited by

                                      TIG, yes I got true on all of those.

                                      Did a little test! Placed the face at origin and the component on top. Changed the transformation to 0 rotation=NO transformation. Transformation is not needed when placed on ORIGIN, of course. Did the test on both the created component instance, and on a new freshly inserted instance. And voila it glues, and cuts the face.

                                      Test nr2 I removed ANY transformation made on the component, (after group.to_component).Still on ORIGIN.
                                      And it worked as well??? Of course this only works when the component is lying flat at 0 position.

                                      Is this some sort of bug? Cause I get the impression you can only invoke cutting behavior IF you do it on 0,0,0 and 0 rotation= ORIGIN ❓

                                      Maybe the problem has to do with what position you create the component from group(group.to_component).
                                      And it's position relative to insertion-point.

                                      SO what's the fix? Transform the group to ORIGIN. Make the comp and remove it back to where it was?
                                      Seams a very strange solution but can't figure out the logic in this one..

                                      I guess just have to find a transformation that get the group to origin flat from ALL postions, do the behavior and transform back with an inversion of that transformation.

                                      **Edited:**As it turns out TIG's rotation transformation is all that's needed(first rotation), if it only get's translated to the ground at 0.
                                      Now, this must be done in 1 transformation OR multiplied because I am going to use THIS transformation.inverted to get back to the face. PFFIooUUH. Don't have a grasp of this transformation stuff yet. It's quite complex to understand when doing multiple transformation's.

                                      1 Reply Last reply Reply Quote 0
                                      • TIGT Offline
                                        TIG Moderator
                                        last edited by

                                        I'm absolutely sure we can streamline this code a lot - I threw it together to show it was 'do-able'...........

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • jolranJ Offline
                                          jolran
                                          last edited by

                                          I trying to understand what you are getting at. πŸ˜„ The cutting behavior is still not working.
                                          Unless face is on "ground" an I apply NO transformation or O rotation(same thing).

                                          Blue Z axis should point in the face.normal direction? To have a chance invoking inst.glued_to=face
                                          Well It does, after your rotations, and the instance is glued to the face.

                                          But must not the World axis origin be at the instance to get cutting behavior?

                                          To do that: move group to global(world?) origin. Reset any rotations= group made flat. THEN make instance from group and move back to face?? I know it sounds strange but why is the inputpoint at orgin if inserting an instance(copy) of the result?

                                          1 Reply Last reply Reply Quote 0
                                          • jolranJ Offline
                                            jolran
                                            last edited by

                                            Are you testing at ORIGIN by a chance? Or does it work for you in all positions? Another pic..

                                            EDITED After some rigorous testing, I have a strong feeling the entities inside the group is off according to the group. Must experiment more with rotation axis etc, but time is running out for this.. Must move on.
                                            Give it another day..

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 6
                                            • 17
                                            • 18
                                            • 4 / 18
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement