Is it possible to rotate textures using Ruby API?


#1

Rather than creating duplicate textures in various rotations, we would like to be able to rotate a texture programmatically. Is this possible?


Rotate texture, not on a face
Distance between 2 uvHelp points returning wrongly 0
#2

Yes this is possible:

   def rotated_material(face)
      material = face.material
      pt_array = []

      edge = longest_edge(face)
      return unless edge.is_a?(Sketchup::Edge)

      length = edge.start.position.distance(edge.end.position)
      vector = Geom::Vector3d.new length,0,0
      t = Geom::Transformation.translation vector

      tw = Sketchup.create_texture_writer
      uvHelp = face.get_UVHelper(true, true, tw)

      p1 = uvHelp.get_front_UVQ(edge.start.position)
      p2 = uvHelp.get_front_UVQ(edge.start.position.transform(t))
      d = p1.distance(p2)

      pt_array[0] = edge.start.position
      pt_array[1] = Geom::Point3d.new(0,0,0)
      pt_array[2] = edge.end.position
      pt_array[3] = Geom::Point3d.new(d,0,0)

      face.position_material(material, pt_array, true)
    end

#3

Thank you Guy, we are going to give this approach a whirl. Looks like it should the trick. :slight_smile: