sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    "Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"

    Scheduled Pinned Locked Moved Extensions & Applications Discussions
    7 Posts 3 Posters 85 Views 3 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.
    • bagateloB Offline
      bagatelo
      last edited by

      I would like a plugin that extracts the colors from a figure and transforms them into materials, but without images, just the pure colors. See the figures on the Adobe Kuler website.![alt text]AdobeColor-Northern Coast of Spain 2024.jpeg AdobeColor-Coral Teal Gray.jpeg AdobeColor-Aileen.jpeg AdobeColor-Önundarfjörður Pier - Iceland.jpeg AdobeColor-Colors of rainbow. Pattern of multicolored butterflies morpho, texture background..jpeg

      While the cat's away, the mice will play

      1 Reply Last reply Reply Quote 0
      • Dave RD Offline
        Dave R
        last edited by

        Until such time as someone figures out and writes an extension to do that you can do it natively. I imported your first two images as images into SketchUp. Then select a random color from the native Colors collection and added it to the model. Under the Edit tab I selected the eyedropper to sample a color, named it, and then clicked on the Create New Material button.
        Screenshot - 6_8_2024 , 12_41_05 PM.png
        Rinse and repeat for the rest of the colors.
        Screenshot - 6_8_2024 , 12_39_55 PM.png

        Etaoin Shrdlu

        %

        (THERE'S NO PLACE LIKE)

        G28 X0.0 Y0.0 Z0.0

        M30

        %

        bagateloB 2 Replies Last reply Reply Quote 2
        • bagateloB Offline
          bagatelo @Dave R
          last edited by

          @Dave-R Thank you very much

          While the cat's away, the mice will play

          1 Reply Last reply Reply Quote 1
          • bagateloB Offline
            bagatelo @Dave R
            last edited by

            @Dave-R I felt like a complete idiot, I knew there was this function but I couldn't use it, I haven't used Sketchup lately.

            While the cat's away, the mice will play

            1 Reply Last reply Reply Quote 1
            • bagateloB Offline
              bagatelo
              last edited by bagatelo

              I tried to create the desired script with chatgpt, but I didn't get the desired result, the colors are simply not obtained from the desired points. As a goal this script should do this, but it cannot. Can anyone fix it?

              This script extracts colors from a selected image in SketchUp. It resizes the image to 100cm x 150cm, moves it to the origin (0, 0, 0), and defines specific points in centimeters where colors will be extracted. It then converts the image to PPM format, reads the colors at the specified points, and creates materials in the SketchUp model based on these colors. Additionally, it adds guide points for debugging purposes. Finally, it provides a menu item under "Plugins" in SketchUp to execute the color extraction process.

              require 'sketchup.rb'
              require 'tempfile'
              
              
              module ColorExtractor
                def self.extract_colors(image_path, points, width, height)
                  colors = []
              
                  Tempfile.open(['image', '.ppm']) do |tempfile|
                    # Converte a imagem para PPM usando o ImageMagick
                    system("convert \"#{image_path}\" -resize 1600x2400! -depth 8 PPM:#{tempfile.path}")
              
                    # Verifica se o arquivo foi criado corretamente
                    unless File.exist?(tempfile.path) && !File.zero?(tempfile.path)
                      UI.messagebox("Failed to convert image to PPM format.")
                      return []
                    end
              
                    # Lê o arquivo PPM
                    File.open(tempfile.path, 'rb') do |file|
                      header = file.readline # Tipo PPM (ex. P6)
                      img_width, img_height = file.readline.split.map(&:to_i) # Dimensões da imagem
                      max_value = file.readline # Valor máximo de cor
              
                      # Converte os pontos em cm para pixels, considerando a origem no canto superior esquerdo
                      pixel_points = points.map do |x, y|
                        pixel_x = (x * img_width / width).to_i
                        pixel_y = (y * img_height / height).to_i
                        [pixel_x, img_height - pixel_y - 1]
                      end
              
                      # Extrai as cores dos pontos específicos
                      pixel_points.each do |x, y|
                        file.seek(3 * (y * img_width + x), IO::SEEK_SET)
                        rgb = file.read(3)
                        if rgb.nil? || rgb.size < 3
                          UI.messagebox("Failed to read color at point (#{x}, #{y}).")
                          next
                        end
                        r, g, b = rgb.bytes
                        colors << { :color => [r, g, b], :point => [x, y] }
                      end
                    end
                  end
              
                  colors
                end
              
                def self.create_materials_from_colors(model, colors, image_filename)
                  materials = model.materials
              
                  colors.each_with_index do |color_data, index|
                    color = color_data[:color]
                    point = color_data[:point]
                    material_name = "#{image_filename}_Point#{index + 1}_#{point[0]}_#{point[1]}"
                    material = materials.add(material_name)
                    material.color = Sketchup::Color.new(color[0], color[1], color[2])
                  end
                end
              
                def self.create_guide_points(model, points)
                  points.each do |x, y|
                    point = Geom::Point3d.new(x.cm, (150 - y).cm, 0) # Ajustando para considerar o canto superior esquerdo
                    model.active_entities.add_cpoint(point)
                  end
                end
              
                def self.run
                  model = Sketchup.active_model
                  selection = model.selection
              
                  if selection.empty? || selection.length != 1 || !selection.first.is_a?(Sketchup::Image)
                    UI.messagebox("Please select a single imported image.")
                    return
                  end
              
                  image_entity = selection.first
                  image_path = image_entity.path
                  image_filename = File.basename(image_path, ".*")
              
                  unless File.exist?(image_path)
                    UI.messagebox("The image file does not exist.")
                    return
                  end
              
                  # Redimensiona a imagem para 100cm x 150cm
                  image_entity.width = 100.cm
                  image_entity.height = 150.cm
              
                  # Move a imagem para a origem (0, 0, 0)
                  tr = Geom::Transformation.new(ORIGIN)
                  image_entity.transform!(tr)
              
                  # Pontos em cm onde as cores serão extraídas, considerando a origem no canto superior esquerdo
                  points = [
                    [18, 25],
                    [50, 25],
                    [82, 25],
                    [18, 85],
                    [50, 85]
                  ]
              
                  # Adiciona pontos guia para depuração
                  create_guide_points(model, points)
              
                  colors = extract_colors(image_path, points, 100, 150)
                  if colors.empty?
                    UI.messagebox("No colors extracted from the image.")
                    return
                  end
              
                  create_materials_from_colors(model, colors, image_filename)
                  UI.messagebox("Materials created from image colors.")
                end
              
                unless file_loaded?(__FILE__)
                  UI.menu("Plugins").add_item("Extract Colors from Image") { self.run }
                  file_loaded(__FILE__)
                end
              end
              

              5454.jpg

              While the cat's away, the mice will play

              Rich O BrienR 1 Reply Last reply Reply Quote 0
              • Rich O BrienR Offline
                Rich O Brien Moderator @bagatelo
                last edited by Rich O Brien

                @bagatelo I'd do the reverse. Feed ChatGPT the image and ask it to generate the rgb values. It will even generate the necessary .txt file.

                Then use ThruPaint or MatSim to import the Color Fan

                eca45bc6-6702-4964-9584-14faa3c27844-image.png

                Download the free D'oh Book for SketchUp 📖

                bagateloB 1 Reply Last reply Reply Quote 0
                • bagateloB Offline
                  bagatelo @Rich O Brien
                  last edited by bagatelo

                  @Rich-O-Brien 5454.jpg

                  I got what I wanted, but I had to do a python script to get what I wanted. Chatgpt helped me a lot. See the zip file attached in the link. There are the scripts, the images downloaded from the Adobe Color website, and an skp file with the results of everything I wanted.

                  Dropbox

                  favicon

                  (www.dropbox.com)

                  While the cat's away, the mice will play

                  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