"Transforming Colors into Materials: A Plugin Inspired by Adobe Kuler"
-
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]
-
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.
Rinse and repeat for the rest of the colors.
-
@Dave-R Thank you very much
-
@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.
-
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
-
@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
-
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.
https://www.dropbox.com/scl/fi/r02n9htl725rajx9ywtco/adobe.zip?rlkey=34xiw9xw8dykpest4g7lcq3va&dl=0
Advertisement