sketchucation logo sketchucation
    • Login
    1. Home
    2. shotgunefx
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 11
    • Groups 1

    shotgunefx

    @shotgunefx

    10
    Reputation
    1
    Profile views
    11
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    shotgunefx Unfollow Follow
    registered-users

    Latest posts made by shotgunefx

    • RE: Determine the origin of a component in world space

      @tig said:

      Every group or component-instance has a complex transformation giving 3d location, rotation, scaling and so on...
      You can use that
      insertion_point = instance.transformation.origin

      I had a feeling you'd be the one to answer TIG, and Thank you, thank you, thank you. Works perfectly. I spent hours pulling hair on this. Don't know why I didn't think of that.

      posted in Developers' Forum
      S
      shotgunefx
    • Determine the origin of a component in world space

      This is probably a dumb question, but hopefully someone can shed some light on this for me.

      I'm basically exporting geometry out of Sketchup for use as game models. The exporter I use (an rbs) exports the origin of the component as the origin of the model. So far so good.

      Well some of my models are quite large and need to be split into quads for performance (and visibility). Once they are exported, I need to translate them back to where they were in the sketchup file in the game editor (Hammer). So I start the model entity at 0,0,0 and translate by the Sketchup component's coordinates (or what I think they are).

      This almost all works. The problem I'm having is that while they all align perfectly in the X,Y dimension, the Z is always off between models (ie components). Sometimes very little, sometimes more than 1 unit, which I think rules out a rounding error.

      I've tried various things, adding a common "bottom" element to each quad model, and moving the axis to the bottom center via axiscomp.rb plugin, but still off.

      So I'm flummoxed at this point, I'm probably not understanding something about insertion points (or maybe it's something in the game tools) but if anyone can tell me the proper way to retrieve this information, I'd appreciate it.

      posted in Developers' Forum
      S
      shotgunefx
    • RE: Calculating the final vertices of a nested face

      @tig said:

      Have you tried tr=container.transformation.inverse and applying it to the initial object and then iterating and getting/setting the transformation for the container's container etc until you get to the model level...

      That didn't seem to work (inverse), though I may very well have misunderstood what you meant, but what you said gave me an answer anyway. By applying the transform to the points at each container successively, it works perfectly! (or at least in every test so far)

      Which is how I should have tried it initially but I was thinking from a performance standpoint, and forgot the old adage "premature optimization is the root of all evil"

      
      def WALK.GetParent(ent)
         Sketchup.active_model.start_operation("Walk")
         model = Sketchup.active_model
         @newg = model.entities.add_group
         m = model.materials.add "test"
         m.color="red"
         orig = ent
         tpos = Geom;;Point3d.new 0,0,0  # keep track of origin
         trans = Geom;;Transformation.new(Geom;;Point3d.new(0,0,0))    # add transforms to this
      
         vertices = orig.outer_loop.vertices.map {|v| v.position.clone}
         
         while (ent.respond_to?('parent') )   # walk up hierarchy
              if ((ent.is_a? Sketchup;;ComponentDefinition))
                  if ent.group?
                      t = ent.instances[0].transformation # Get the group's transform
                      vertices.each_with_index do |v,i|
                          vertices[i].transform! t 
                      end
                  end     
                  ent =  ent.instances[0]     # become the instance
              end
              ent = ent.parent
         end
         f = @newg.entities.add_face vertices    # create the face
         f.material=m
         Sketchup.active_model.commit_operation
      end   
      
      
      

      Thanks again for the help!

      posted in Developers' Forum
      S
      shotgunefx
    • Calculating the final vertices of a nested face

      I've tried to boil this down to a small as example as possible, what I need to do is given a face, calculate it's absolute final position in XYZ (taking into account transforms, etc). It's for a paint tool I'm working on that works (and aligns regardless of grouping. I happen to use Sketchup for game mapping and the particulars of the exporter force pretty much everything to be a group.

      A less than compelling example video of the paint tool http://www.youtube.com/watch?v=hb63D7Cmt50

      I've mostly got it working, except for the origin is off when dealing with groups within groups, there is just something I'm not grokking here. So after many hours of head scratching, I figured I'd see if anyone can enlighten me.

      So I take the face, I walk up the hierarchy, adding transforms, (and in theory, transformation origins) and compute the new points. The code below just adds the transformation.origin, I know this is wrong, and it's what trying to solve. I've tried a dozen things (transforming them by the container, etc,) but there is just something I'm not understanding.

      Here's the code

      module WALK
      
      def WALK.setface
          model = Sketchup.active_model
          @newg = model.entities.add_group
          @s = nil
          if model.selection.empty?
              UI.messagebox "Selection empty"
              return nil
          else
              if model.selection[0].is_a? Sketchup;;Face
                  @s = model.selection[0]
              else 
                  UI.messagebox "Face not selected"
              end 
          end
      end
      
      # make sure groups are unique
      Sketchup.active_model.definitions.each{|d|d.instances[1..-1].each{|i|i.make_unique}if d.group? and d.instances[1]}
       
      def WALK.main
           WALK.GetParent(@s)
      end
      
      def WALK.GetParent(ent)
         Sketchup.active_model.start_operation("Walk")
         model = Sketchup.active_model
         @newg = model.entities.add_group
         m = model.materials.add "test"
         m.color="red"
         orig = ent
         tpos = Geom;;Point3d.new 0,0,0  # keep track of origin
         trans = Geom;;Transformation.new(Geom;;Point3d.new(0,0,0))    # add transforms to this
         
         while (ent.respond_to?('parent') )   # walk up hierarchy
              if ((ent.is_a? Sketchup;;ComponentDefinition))
                  if ent.group?
                      t = ent.instances[0].transformation # Get the group's transform
                      tpos += t.origin.transform(trans).to_a  # !!!WRONG
                      trans *= t  # combine transforms
                  end     
                  ent =  ent.instances[0]     # become the instance
              end
              ent = ent.parent
         end
         vertices = orig.outer_loop.vertices
         newverts = []
         vertices.each do |v|
              np = v.position.clone
              np+= tpos.to_a      # !!! Wrong
              np.transform! trans
              newverts.push  np
          end   
         f = @newg.entities.add_face newverts    # create the face
         f.material=m
         Sketchup.active_model.commit_operation
      end   
      end # end mod
      if !file_loaded?(__FILE__)
        UI.menu("Plugins").add_item("Select Walk Face") { WALK.setface }
        UI.menu("Plugins").add_item("Make Walk Face") { WALK.main }
      end
      
      file_loaded(__FILE__)
      
      

      It adds two items to the plugin menu
      Select Walk Face and Make Walk Face

      Take the example here

      http://farm6.static.flickr.com/5293/5494975921_63bd7d0e3a_z.jpg

      The geom looks like this...
      Group
      --Group
      ----Wide Cylinder faces
      --Group
      ----Group
      ------Cube faces
      ----Group
      ------ Tall Cylinder Faces

      Seeing backing out of a group clears the selection, here's where Select Walk Face comes in. Click down into the inner group of the cube and select a face and then select Select Walk Face, this simply stashes the face for Make Walk Face

      Now if you actually ran Make Walk Face here, it works fine, making a new face, respecting transforms and in the right place.

      But back all the way out of the group and run Make Walk Face

      and you get this....

      http://farm6.static.flickr.com/5259/5494975933_05f17d3207_z.jpg

      If you've read this far, I commend you 😄

      Any insight on what I'm not understanding would truly be appreciated.

      Thanks!
      -Lee

      posted in Developers' Forum
      S
      shotgunefx
    • RE: [Plugin] VTF Normal Map Creator

      @numbthumb said:

      Thanks, looking forward to its further development!. Now it´s time to dust-off my DoD:Source 😄

      Actually most of my Sketchup work is for exporting to Hammer. I've been working on a campaign for Left4Dead2 for quite some time set in my neighborhood. Little did I know how hard it would be to try and model such a large real world (and hilly) area somewhat accurately within the limitations of a game engine. While Sketchup isn't the most intuitive tool for Hammer mapping (brushes vs planes), for geo-locating, it can't be beat.

      I have a few plugins that are not released yet. They all will be eventually, some of them need some work to make them more general as opposed to my specific uses.

      "texture tool" - Don't know what I'll eventually call it, but mostly done. It allows you to paint faces (and align textures) regardless of groups. Like alt-click in Hammer. Seeing anything being exported to Hammer has to be a grouped solid, huge time saver. Should be done within a week.
      http://www.youtube.com/watch?v=hb63D7Cmt50

      terrain displacement generator - it exports your selection of geometry and creates a series of VMF sewn displacement from it for Hammer. Great for making maps from GE snapshots or TINs, the first version simply chopped it into blocks, the 2nd version uses faces drawn on a layer, (it also suppresses occluded sides). Using the faces, you can make the boundaries where they make sense, so you can easily use different materials and blends.

      http://farm5.static.flickr.com/4151/5037666085_cf2db3596a_o.jpg

      Here's a very old shot of it.

      http://ep.yimg.com/ca/I/leeland_2147_107668229

      It's also great for making curbs (city blocks) and pathways on top of those displacements.

      http://farm5.static.flickr.com/4124/4997162582_db3fd98b06_z.jpg

      http://farm5.static.flickr.com/4111/5029715009_be672da736.jpg

      Manually floating those displacements at fixed intervals above other displacements would be insanely time consuming.

      I've also got a VMF importer in the works, though that one isn't for sure yet, and also a proper VMF exporter as Valve's doesn't support func_details and all kinds of other important stuff. If these get done, won't be for awhile

      posted in Plugins
      S
      shotgunefx
    • RE: Closing open groups via Ruby?

      @tig said:

      @tig said:

      Not sure about your code - I don't have time to test it tonight...
      Here's a one-liner method to ensure that ALL groups in the model are unique [as they ought to be!] BEFORE you start doing anything
      Sketchup.active_model.definitions.each{|d| d.instances[1..-1].each{|i| i.make_unique} if d.group? and d.instances[1]}

      Thank you sir! That did the trick.

      posted in Developers' Forum
      S
      shotgunefx
    • RE: Closing open groups via Ruby?

      @tig said:

      If you use group.make_unique on every copy you make they should each become 'individual' - there is still the misleading 'deprecated' error message that is plain 'wrong'!
      Are you using 'copy' and transforming the 'copy' or 'add_instance()' ??

      What I tried to do was something like this..

      I call it on the face returned by picked_face

      def GroupUniqueAsNeeded(ent)
         while (ent.respond_to?('parent') )
              if ((ent.is_a? Sketchup;;ComponentDefinition))
                  if ent.group?
                      if ent.instances.length > 0
                          ent.instances.each do |e|    
                              e.make_unique
                          end
                          return 1
                      end
                  # else component    
                  end
              end
              ent = ent.parent
         end
      end
      

      If it returns one, I redo the pick, getting (theoretically) the correct face. But in practice, sometimes when I assign a material to the face, it's still painting that face in all copies.

      Perhaps I'm getting caught in this parent bug
      http://forums.sketchucation.com/viewtopic.php?f=180&t=31318&p=275894#p275894

      posted in Developers' Forum
      S
      shotgunefx
    • [Plugin] VTF Normal Map Creator

      This is a fairly limited use plugin I wrote some time ago for creating normal maps, primarily for games based on Valve's Source engine. It's audience is really people who don't have the time or inclination to learn something more complicated like Blender.

      http://ep.yimg.com/ca/I/leeland_2147_109725229

      It's fairly slow as it uses model.raytest per output pixel. On complicated models this can be very slow. And it actually exports a BMP file, not a VTF, but there are many tools for converting common image files into VTF (such as VTFedit)

      I was hoping to make it a little more general purpose by adding the ability to paint your geometry with other normal maps (like wood) and combining them on creation, but Sketchup lacks the method to read texels. If I can figure out how to include a binding to ImageMagick or a similar library, I may implement that in the future.

      Instructions and source available here. http://www.leeland.net/sketchup-makenormalmap.html

      posted in Plugins
      S
      shotgunefx
    • RE: Closing open groups via Ruby?

      Well, Group.make_unique doesn't cut it. I get a warning that it's depreciated, but still the same behavior. I suppose I could make new groups and copy the entities over, delete the originals and insert them, but it seems like there should be an easier way. Obviously, at least internally, Sketchup has a way to do this.

      posted in Developers' Forum
      S
      shotgunefx
    • RE: Closing open groups via Ruby?

      Thank you for the replies. Given the issues involved, I think I'll either let them back out on their own, or at most go with a UI message.

      On a related subject, I've found something I never noticed before regarding groups. It seems that if you copy a group, it acts like a component until you modify it through one of the default tools.

      Example, I have a group containing an arch, I copy that group to another location. My tool (which adds the face under the cursor to a selection for visual feedback), will highlight that face in all instances as if it were a component. Though if I go to one of the instances and say... position the texture, it only affects the open group as expected.

      So I'm guessing that Sketchup does something similar to copy on write as far as groups. So what's the best way for me to do the same?

      I'm guessing depreciated or not, Group.make_unique is probably the way to go. So I'm guessing I'll have to walk up the entities to find the groups's Sketchup::ComponentDefinition, and if the instance's are greater than 1, make each unique, and the call pickhelper again to get the possible "new" face.

      Is there a better way to do this?

      Am I better off using an observer for this? (I've not used them before) and just make each group unique as they are created?

      Thanks!

      posted in Developers' Forum
      S
      shotgunefx