Hi all,
I try to display an jpg image in Sketchup windows
When I copy and past the following code from the documentation I got an error:
module Example
class MyTool
def activate
view = Sketchup.active_model.active_view
image_rep = view.model.materials.current.texture.image_rep
@texture_id = view.load_texture(image_rep)
end
def deactivate(view)
view.release_texture(@texture_id)
end
def draw(view)
points = [ [0, 0, 0], [9, 0, 0], [9, 9, 0], [0, 9, 0] ]
uvs = [ [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] ]
view.draw(points, texture_id: @texture_id, uvs: uvs)
end
end
end
Sketchup.active_model.select_tool(Example::MyTool.new)
=>
Error: #<TypeError: no implicit conversion of Array into Integer>
<main>:16:in `draw'
<main>:16:in `draw'
So I had the the openglenum and its start working, but I don’t know how to map texture. Wich openglnum should I use ? what shoud be the UV
module Example
class MyTool
def activate
view = Sketchup.active_model.active_view
image_rep = view.model.materials.current.texture.image_rep
puts "image_rep#{image_rep}<-"
@texture_id = view.load_texture(image_rep)
end
def deactivate(view)
view.release_texture(@texture_id)
end
def draw(view)
a = 100
points = [ [a, a, 0], [a*2, a, 0], [a*2, a*2, 0], [a, a*2, 0] ]
uvs = [ [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0] ]
#view.draw(GL_POLYGON,points, texture_id: @texture_id, uvs: uvs)
view.draw2d(GL_QUADS,points, texture_id: @texture_id, uvs: uvs)
#GL_POLYGON
#GL_QUADS
#GL_QUAD_STRIP
end
end
end
Sketchup.active_model.select_tool(Example::MyTool.new)
Thanks for your help