Skip to content

Instantly share code, notes, and snippets.

@thomthom
Created March 13, 2015 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomthom/7cfae35196e00297fcef to your computer and use it in GitHub Desktop.
Save thomthom/7cfae35196e00297fcef to your computer and use it in GitHub Desktop.
require 'stringio'
output = StringIO.new
model = Sketchup.active_model
tw = Sketchup.create_texture_writer
model.selection.grep(Sketchup::Face) { |face|
tw.load(face, true)
uvh = face.get_UVHelper(true, true)
uvh_tw = face.get_UVHelper(true, true, tw)
output.puts ""
output.puts face
face.vertices.each { |vertex|
uvq = uvh.get_front_UVQ(vertex.position)
uvq_tw = uvh_tw.get_front_UVQ(vertex.position)
uv = Geom::Point3d.new(uvq.x / uvq.z, uvq.y / uvq.z, 1.0)
output.puts "> #{vertex} (#{vertex.position.inspect})"
output.puts " > UV: #{uv.inspect}"
output.puts " > UVQ: #{uvq.inspect}"
output.puts " > UVQ (TW): #{uvq_tw.inspect}"
}
}
puts output.string
nil
#<Sketchup::Face:0x0000000ad31008>
> #<Sketchup::Vertex:0x0000000c423a40> (Point3d(21.1805, 25.7197, 15.0663))
> UV: Point3d(0.761389, 0.618252, 1)
> UVQ: Point3d(-7.19346, -5.84112, -9.44781)
> UVQ (TW): Point3d(1, 0, 1)
> #<Sketchup::Vertex:0x0000000c423ab8> (Point3d(27.2152, 19.685, 27.8389))
> UV: Point3d(0.76863, 0.530675, 1)
> UVQ: Point3d(-7.26189, -5.01373, -9.44783)
> UVQ (TW): Point3d(0.882683, 1, 1)
> #<Sketchup::Vertex:0x0000000c43ad08> (Point3d(36.2468, 25.7197, 27.8389))
> UV: Point3d(0.832569, 0.527163, 1)
> UVQ: Point3d(-7.86597, -4.98055, -9.44783)
> UVQ (TW): Point3d(0.117317, 1, 1)
> #<Sketchup::Vertex:0x0000000c459910> (Point3d(32.9808, 33.6045, 15.0663))
> UV: Point3d(0.844929, 0.613663, 1)
> UVQ: Point3d(-7.98273, -5.79778, -9.44781)
> UVQ (TW): Point3d(0, 2.1476e-008, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment