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

    Posts

    Recent Best Controversial
    • RE: Raytest Alternative?

      Well I hadn't thought of the sun vector that way, but that is great advice-- should certainly speed things up, a little at least.

      As for the number of faces...I'd like to take a surface and run it with arbitrary granularity; so, thousands. Running my code as it stands for 1000 faces takes on the order of 15 minutes to run.

      Making the change you suggested now...

      posted in Developers' Forum
      A
      ArjunaMeridian
    • RE: Raytest Alternative?

      You're right about what the code is attempting to do, and no doubt it needs to be cleaned up and modularized a bit. To answer your question: I call si["SunDirection"] when generating the @sun array because the Point3ds (generated from vectors about ORIGIN) will depend on the geolocation and date of the model. Hence, Colorado's suns will differ from London's.

      Regardless, the ShadowInfo calls within the sun array routine aren't the time constraint within the code-- RayTest seems to be the culprit. Given the profusion of rendering programs which are undoubtedly doing MANY more collision calculations, I'm wondering if there's an obvious, less computationally expensive substitute to calling RayTest.

      posted in Developers' Forum
      A
      ArjunaMeridian
    • RE: Raytest Alternative?

      You're absolutely correct...I pulled the code out of context of a longer section of code, re-(mis-)labeled a few things, all in an effort to minimize the reading required by anyone attempting to help me out, since RAYTEST seems to be the crux of the problem (I think).

      In case you care to read my entire code, it is below, though I've added a big comment block with #RAYTEST SECTION# if you want to skip to that.

      The test point array is '@suns'

      Thank you for trying to help me

      module MC_sun_tools
         @model = Sketchup.active_model
         @ents = @model.entities
         @sel = @model.selection
      
      
      
         def MC_sun_tools.generate_suns
      
           
           # Initialize some variables
      
           tz = -5.0  
           altitude = 1000.m #We'll generate points 1km away
      
            @suns = [] # An array to hold our "suns"
      
            si = @model.shadow_info
      
            ct = si["ShadowTime"]   #the class of ct is Time
      
            yr = ct.year
            mon = 9 #ct.month
            day = ct.day
      
            # The points we add will be part of a new group
      
            #my_verts = @sel[0].vertices
      
            new_ent = @ents.add_group
            new_ent.name = "{mon}-{day}"
      
            0.upto(24*4-1) {|hour|
               t = Time.local(yr, mon, day, hour/4, (hour.to_f/4 % 1)*60)
               si['ShadowTime'] = t
               v = si["SunDirection"]
               v.length = altitude
               pt = ORIGIN + v
               new_ent.entities.add_cpoint(pt)
               new_ent.entities.add_text(((hour/4-tz) % 24).to_i.to_s, pt)
               @suns << pt #if pt.is_a? Sketchup;;Point3d
            }
        end
      
         def MC_sun_tools.get_faces
             my_faces = []
                @sel.each {|e|
                   if e.is_a? Sketchup;;Face
                   my_faces << e
                end
             }
             my_faces.each {|e|
                 MC_sun_tools.test_suns(e)
             }
             puts my_faces.length
         end
      ######################################################
      #########RAYTEST SECTION##############################
         
         def MC_sun_tools.test_suns(face)
            center = face.bounds.center
            normal = face.normal
            face.material= @color_hash[1]
            counter = 1
            0.upto(@suns.length-1) {|s|
               ray = [center,@suns[s]]
               item = @model.raytest(ray,false)
               #puts item         
               if item == nil
                  sun_vector = center.vector_to @suns[s]
                  an = normal.angle_between sun_vector
                  counter = counter + Math.cos(an)*0.8
                  #puts cos(an)     
                  #@ents.add_cline(center, @suns[s])
                  
               end
               
            }
            face.material = @color_hash[[counter.to_i, 25].min]
         end
      ########################################################
      
      @color_hash = [[0, 0, 180], 
      [0, 30, 180], 
      [0, 60, 180], 
      [0, 90, 180], 
      [0, 120, 180], 
      [0, 150, 180], 
      [0, 180, 180], 
      [0, 180, 150], 
      [0, 180, 120], 
      [0, 180, 90], 
      [0, 180, 60], 
      [0, 180, 30], 
      [0, 180, 0], 
      [30, 180, 0], 
      [60, 180, 0], 
      [90, 180, 0], 
      [120, 180, 0], 
      [150, 180, 0], 
      [180, 180, 0], 
      [180, 150, 0], 
      [180, 120, 0], 
      [180, 90, 0], 
      [180, 60, 0], 
      [180, 30, 0], 
      [180, 0, 0]] 
      
      end
      
      plug_menu = UI.menu("Plugins")
      plug_menu.add_item("Generate Suns") {MC_sun_tools.generate_suns}
      plug_menu.add_item("Test Suns") {MC_sun_tools.test_suns}
      plug_menu.add_item("Get Faces") {MC_sun_tools.get_faces}
      
      posted in Developers' Forum
      A
      ArjunaMeridian
    • Raytest Alternative?

      I'm using code to iterate through a series of faces, taking each center point, and testing each individually using raytest to see if the face is "visible" to another far away test point, given the other geometry present in the model (ie, if the ray "hits" something else, it isn't visible).

      It works great EXCEPT that it is excruciatingly slow, especially when there are many faces and/or test points.

      Is there a better way?

      Here's a snippet:

      def self.test_points(face)
               center = face.bounds.center
               normal = face.normal
               counter = 1
               0.upto(test_points.length-1) {|s|
               ray = [center,test_points[s]]
               item = @model.raytest(ray,false)
               #puts item         
               if item == nil
                  sv = center.vector_to test_points[s]
                  an = normal.angle_between sv
                  counter += Math.cos(an)
               end
      
      posted in Developers' Forum
      A
      ArjunaMeridian
    • Method 'receives_shadows?' mis-nomer...

      Was thrilled to find the

      receives_shadows?
      

      method (drawingelements class) in the SketchUp documentation, having planned to use it to test whether a given face/polygon was receiving shadows under my assumed shadowinfo conditions...

      unfortunately, I was wrong-- the method test whether an element is ENABLED to receive shadows-- an attribute

      My question: Is there a way to test within a model whether a face/ drawing element is presently shadowed?

      ps I am very grateful for this site and its knowledgeable, generous moderators

      posted in Developers' Forum
      A
      ArjunaMeridian
    • RE: Using Polygon Mesh

      @adamb said:

      If you just wish to color your model, you can just apply a new material to the Faces.

      Yes, but if for example i had a landscape with changing lighting conditions and wanted to break up a selected face within the model into an arbitrary number (perhaps user defined) of polygons that I then could store in an array...how could I do this?

      posted in Developers' Forum
      A
      ArjunaMeridian
    • Using Polygon Mesh

      I'm a newbie to the terrific Sketchucation site and to ruby programming generally.

      My question:

      I'm writing ruby code where I would like to convert a selected face into a subset of either 1) points or 2) polygons and store them in an array. Then, I would like to iterate through the array and potentially color-code the points or polygons based on some arbitrary criteria.

      I've looked at the documentation for both the face.mesh method and the Polygonmesh class, but it isn't obvious.

      Thanks to anyone in advance for help

      posted in Developers' Forum
      A
      ArjunaMeridian
    • 1 / 1