windows11で、sketchup6 その24

# 概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
Geodesic、見つけたので、やってみた。


# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/2fb3de9a-b007-4b92-ae76-1927eb7d2579.png)

# サンプルコード

```

require "sketchup.rb"

#Geodesic.create

class Geodesic
	SQRT2 = Math.sqrt(2)
	SQRT3 = Math.sqrt(3)
	TETRA_Q = SQRT2 / 3
	TETRA_R = 1.0 / 3
	TETRA_S = SQRT2 / SQRT3
	TETRA_T = 2 * SQRT2 / 3
	GOLDEN_MEAN = (Math.sqrt(5) + 1) / 2
	PRIMITIVES = {
		:tetrahedron => {
			:points => {
				:a => Geom::Vector3d.new( -TETRA_S, -TETRA_Q, -TETRA_R ),
				:b => Geom::Vector3d.new(	TETRA_S, -TETRA_Q, -TETRA_R ),
				:c => Geom::Vector3d.new(		0,	TETRA_T, -TETRA_R ),
				:d => Geom::Vector3d.new(		0,		0,		1 )
			},
			:faces => %w| acb abd adc dbc |
		},
		:octahedron => {
			:points => {
				:a => Geom::Vector3d.new(	0,	0,	1 ),
				:b => Geom::Vector3d.new(	1,	0,	0 ),
				:c => Geom::Vector3d.new(	0, -1,	0 ),
				:d => Geom::Vector3d.new( -1,	0,	0 ),
				:e => Geom::Vector3d.new(	0,	1,	0 ),
				:f => Geom::Vector3d.new(	0,	0, -1 )
			},
			:faces => %w| cba dca eda bea def ebf bcf cdf |
		},
		:icosahedron => {
			:points => {
				:a => Geom::Vector3d.new(	1,	GOLDEN_MEAN, 0 ),
				:b => Geom::Vector3d.new(	1, -GOLDEN_MEAN, 0 ),
				:c => Geom::Vector3d.new( -1, -GOLDEN_MEAN, 0 ),
				:d => Geom::Vector3d.new( -1,	GOLDEN_MEAN, 0 ),
				:e => Geom::Vector3d.new(	GOLDEN_MEAN, 0,	1 ),
				:f => Geom::Vector3d.new( -GOLDEN_MEAN, 0,	1 ),
				:g => Geom::Vector3d.new( -GOLDEN_MEAN, 0, -1 ),
				:h => Geom::Vector3d.new(	GOLDEN_MEAN, 0, -1 ),
				:i => Geom::Vector3d.new( 0,	1,	GOLDEN_MEAN ),
				:j => Geom::Vector3d.new( 0,	1, -GOLDEN_MEAN ),
				:k => Geom::Vector3d.new( 0, -1, -GOLDEN_MEAN ),
				:l => Geom::Vector3d.new( 0, -1,	GOLDEN_MEAN ),
			},
			:faces => %w| iea iad idf ifl ile eha ajd dgf fcl lbe ebh ahj djg fgc lcb khb kjh kgj kcg kbc |
		}
	}
	PRIMITIVES.each_pair{ |primitive, pf|
		PRIMITIVES[primitive] = pf[:faces].collect{ |pts|
			pts.split('').collect{ |pt_name|
				pf[:points][pt_name.to_sym]
			}
		}
	}
	def self.create( frequency = nil, primitive = :octahedron, radius = 36 )
		if !frequency
			prompts = [ 'Primitive:', 'Radius (in "):', 'Subdivisions:' ]
			values = [ primitive.to_s, radius, 2 ]
			primitive_types = ['tetrahedron|octahedron|icosahedron']
			results = inputbox prompts, values, primitive_types, 'Create Geodesic'
			return unless results
			primitive, radius, frequency = results
			primitive = primitive.to_sym
		end
		raise "The Geodesic class does not support the primitive type '#{primitive}'" unless PRIMITIVES[primitive]
		model = Sketchup.active_model
		model.start_operation "Create Geodesic"
		group = model.active_entities.add_group
		PRIMITIVES[primitive].each{ |face|
			self.expand_face( face, frequency.to_i, radius.to_f, group.entities )
		}
		model.commit_operation
		group
	end
	def self.expand_face( face, frequency, radius, entities )
		if frequency < 1
			entities.add_face(face.collect{ |v|
				v.normalize.scale_by( radius ).to_point3d
			})
		else
			a,b,c = face
			ab = a + (b - a).scale_by( 0.5 ) 
			ac = a + (c - a).scale_by( 0.5 )
			bc = b + (c - b).scale_by( 0.5 )
			[[ a,	ab, ac ], [ b,	bc, ab ], [ c,	ac, bc ], [ ab, bc, ac ]].each{ |f|
				self.expand_face( f, frequency-1, radius, entities )
			}
		end
	end
end

module Smoothable
	def smooth_all( new_smooth = true )
		model = Sketchup.active_model
		model.start_operation "#{new_smooth ? 'Smooth' : 'Unsmooth'} All"
		self.entities.each{ |e|
			next unless e.is_a?( Sketchup::Edge )
			e.smooth = new_smooth;
		}
		model.commit_operation
	end
	def unsmooth_all
		self.smooth_all( false )
	end
end

class Sketchup::Group
	include Smoothable
	def move_to( x, y, z )
		self.move!( Geom::Transformation.translation(Geom::Vector3d.new( x, y, z ) ) )
	end
end

class Geom::Vector3d
	def scale_by( n )
		self.x *= n
		self.y *= n
		self.z *= n
		self
	end
	def to_point3d
		Geom::Point3d.new( *self.to_a )
	end
end




```

以上。