Module: TT::Face

Defined in:
TT_Lib2/faces.rb

Overview

Collection of Face methods.

Since:

  • 2.0.0

Class Method Summary collapse

Class Method Details

.corners(face) ⇒ Array<Sketchup::Vertex>

Returns all vertices in the face's outer loop that isn't connecting colinear edges.

Parameters:

  • face (Sketchup::Face)

Returns:

  • (Array<Sketchup::Vertex>)

Since:

  • 2.5.0



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'TT_Lib2/faces.rb', line 24

def self.corners(face)
	corners = []
	# We only check the outer loop, ignoring interior lines.
	face.outer_loop.edgeuses.each { |eu|
		# Ignore vertices that's between co-linear edges.
     v1 = eu.edge.line[1]
     v2 = eu.next.edge.line[1]
		if v1.valid? && v2.valid? && !v1.parallel?( v2 )
		#unless v1.parallel?( v2 )
		#unless eu.edge.line[1].parallel?( eu.next.edge.line[1] )
			# Find which vertex is shared between the two edges.
       # (?) TT::Edges.common_vertex( eu.edge, eu.next.edge )
			if eu.edge.start.used_by?(eu.next.edge)
				corners << eu.edge.start
			else
				corners << eu.edge.end
			end
		end
	}
	return corners
end

.is_quad?(face) ⇒ Boolean

Returns true if the face has four corners.

Parameters:

  • face (Sketchup::Face)

Returns:

  • (Boolean)

    Returns true if the face has four corners.

Since:

  • 2.5.0



51
52
53
54
# File 'TT_Lib2/faces.rb', line 51

def self.is_quad?( face )
  face.is_a?( Sketchup::Face ) &&
  self.corners( face ).length == 4
end

.mirror_material(face, texture_writer, front_to_back = true) ⇒ Boolean

Returns true if the face has four corners.

Parameters:

  • face (Sketchup::Face)
  • texture_writer (Sketchup::TextureWriter)
  • front_to_back (Boolean) (defaults to: true)

Returns:

  • (Boolean)

    Returns true if the face has four corners.

Since:

  • 2.5.0



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'TT_Lib2/faces.rb', line 63

def self.mirror_material(face, texture_writer, front_to_back=true)
# Get the material to mirror
material = (front_to_back) ? face.material : face.back_material
# Plain colour and Default is simply mirrored
if material.nil? || material.materialType < 1
	if front_to_back
		face.back_material = material
	else
		face.material = material
	end
	return
end
# Get four Point3d samples from the face's plane.
# We take one point from the face and offset that in X and Y
# on the face's plane. This ensures we get enough data.
# Previously I sampled data from vertices, which lead to problems
# for triangles with distorted textures. Distorted textures require
# four UV points.
samples = []
samples << face.vertices[0].position			 # 0,0 | Origin
samples << samples[0].offset(face.normal.axes.x) # 1,0 | Offset Origin in X
samples << samples[0].offset(face.normal.axes.y) # 0,1 | Offset Origin in Y
samples << samples[1].offset(face.normal.axes.y) # 1,1 | Offset X in Y
# Arrays containing 3D and UV points.
xyz = []
uv = []
uvh = face.get_UVHelper(true, true, texture_writer)
samples.each { |position|
	# XYZ 3D coordinates
	xyz << position
	# UV 2D coordinates
	if front_to_back
		uvq = uvh.get_front_UVQ(position)
	else
		uvq = uvh.get_back_UVQ(position)
	end
	uv << TT::UVQ.normalize(uvq)
}
# Position texture.
pts = []
(0..3).each { |i|
	pts << xyz[i]
	pts << uv[i]
}
face.position_material(material, pts, !front_to_back)
  nil
end