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

    [Code] Texture Faces that are on Shadow

    Scheduled Pinned Locked Moved Developers' Forum
    1 Posts 1 Posters 194 Views 1 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.
    • renderizaR Offline
      renderiza
      last edited by

      Hi,

      I want to share some insight on what I am interested in doing in hope someone finds it useful and apply some techniques here to their own projects. Keep in mind the following code is a starting point meaning it still needs to be develop.

      Here is the concept behind it...I want to automate the painting with color or textures the faces that are in shadow. Technique I am using is the following;

      1. Go through all faces

      2. Find center

      3. Cast a raytrace from face center point to sun position

      4. if raytrace hits another surface it means is being blocked from the sun.

      5. Paint that face with specified color or texture.

      This was a modification of a similar technique I used in Canvas plugin to place components only in shadow. Here is a thread me asking for help in that regard... http://sketchucation.com/forums/viewtopic.php?f=180&t=51715

      Anyways, the image below is an example of what can be achieved with few extra steps I will mention later.

      tt-1.png

      The extra step I took was create faces on shadows that were projected by other faces but most of the work is done by code. I believe TIG developed a plugin named "TIG-shadowProjector" so you can use that but in some instances it doesn't work so you have to do it by hand.

      Here is the code:

      model = Sketchup.active_model
      ents = model.entities 
      sel = model.selection 
      
      materials = model.materials
      m = materials.add "shadow" 
      texture = m.texture = "c;\\Users\\Renderiza\\Desktop\\folder\\b.jpg"	 
      m.texture.size = 10
      
      faces = []
      v_sun = model.shadow_info["SunDirection"] 
      
      ents.each do |e|
      
      	if e.is_a? Sketchup;;Face
      		faces << e 
      	end
      	
      end
      
      
      faces.each do |e|
      
      	boundbox = e.bounds
      	center = boundbox.center
      	hit_path = Sketchup.active_model.raytest [center,v_sun]
      
      	if hit_path != nil
      		e.material = m
      	else
      		e.material = [190,190,190]
      				
      			znormal = e.normal.z #Face that are facing up
      			if znormal == 1 
      			e.material = [250,250,250]	
      			end
      	end
      
       end  
      

      This is it for now hope someone finds it helpfull or interesting. 😛

      [url=https://www.sketchupcode.com/:z3kqsidd]My Extensions ...[/url:z3kqsidd]

      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