Heat map for 3d model

Hello,

I am new to sketchup. I want to do a heat map for 3d model. I did this in autocad by meshing the solids/ faces and colouring the mesh. I wonder how can i generate a mesh on the face and then colour them in sketchup ? Is it possible to create mesh in sketchup using ruby api ? Is there any sample ruby code for this.

Thanks.

Yes.You basically create a Ruby script and put it in the plugins folder. In order to properly encapsulate your code from others, you need to follow a basic outline. I use this one (jimhami42_test_file.rb) for my quick and dirty stuff:

#----------------------------------------------------------------------------------------
require 'sketchup.rb'
#----------------------------------------------------------------------------------------
module JimHami42
  module TestFile
# MAIN BODY -----------------------------------------------------------------------------
    class  << self
      def start_test()
#      
# Insert code here      
#
        UI.messagebox('Hello, World!', MB_OK)
      end
    end
# MAIN BODY -----------------------------------------------------------------------------
  file = __FILE__
  unless file_loaded?( file )
    menu = UI.menu("PlugIns").add_item("Test file") { start_test() }
    file_loaded( file )
  end
# MAIN BODY -----------------------------------------------------------------------------
  end
end

[Thanks to @john_drivenupthewall for correcting the file load part of my code]

As you may already know, both module names need to start with a capital letter.

If you are looking for a 2D display, you can create a unit square face and make it a component. Duplicating this across rows and columns with unique component names will give you a grid. You will need to keep track of the component names and use them to apply the texture (or color).

More simply, you can create the unit faces as you go along and color them as you go. This is probably a lot easier than the above approach.

You can also create something called a “polygon mesh” that is an ordered collection of points, but I don’t believe it would be useful for what you’re trying to accomplish.

Hi,
Is it possible to share with us in what context are you looking at for the heat map for the 3D model?
Is it heat map for a product/object?

I am doing up a heat map plugin for a warehouse layout now. Not sure whether this is relevant to you though.

I created a simple piece of sample code that produces this:

In order to apply the colors to the faces, a different material is required for each. In this example, 400 new textures were added to the model to only give a 20 x 20 array. I initially created the squares as raw geometry, but it seems more efficient to isolate them in separate groups.

#----------------------------------------------------------------------------------------
require 'sketchup.rb'
#----------------------------------------------------------------------------------------
module JimHami42
  module TestFile
# MAIN BODY -----------------------------------------------------------------------------
    @@model = Sketchup.active_model
    class  << self
      def create_square(x,y,w,r,g,b)
        group = @@model.entities.add_group
        face = group.entities.add_face([x,y,0],[x+w,y,0],[x+w,y+w,0],[x,y+w,0],[x,y,0])
        face.reverse!
        face.material = b * 65536 + g * 256 + r
      end
      def start_test()
        UI.messagebox('Hello, World!', MB_OK)
        for y in 0...20
          for x in 0...20
            create_square(x,y,1,x * 10 + 20,y * 10 + 20,0)
          end
        end
      end
    end
# MAIN BODY -----------------------------------------------------------------------------
    file = __FILE__
    unless file_loaded?( file )
      menu = UI.menu("PlugIns").add_item("Test file") { start_test() }
      file_loaded( file )
    end
# MAIN BODY -----------------------------------------------------------------------------
  end
end

You might find this post useful

In a nutshell. As long as the number of colors is limited, you can do it quite easily. For more complex cases you probably need to generate the heat map outside SketchUp and apply it as a texture.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.