0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その20

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題やってみた。

練習問題

rokローダーを書け。

写真

image.png

サンプルコード

require 'sketchup.rb'

def rok_ld
	entities = Sketchup.active_model.entities
	vnam = 0
	lnam = 0
	state = 0
	fmod = 0
	verts = 0
	x, y, z, s, e = 0
	c = 0
	v = []
	l = []
	f = UI.openpanel "Select .rok file", "", "*.rok"
	return unless f
	lines = IO.readlines(f, "\r")
	lines.each do |line|
		line.strip!
		case line
		when "POINT"
			state = 1
		when "LINE0"
			state = 2
			lnam = 0
		when "FACE0"
			state = 3
		when "END00"
			UI.messagebox "ok"
		else
			if state > 0
				 c += 1
			end
			if state == 1
				if c == 1
					vnam = Integer(line)
				end
				if c == 6
					x = Float(line)
				end
				if c == 7
					y = Float(line)
				end
				if c == 8
					z = Float(line)
				end
				if c == 8
					v[vnam] = [x * 10, z * 10, -y * 10]
					c = 0
				end
			end
			if state == 2
				if c == 1
					s = Integer(line)
				end
				if c == 2
					e = Integer(line)
				end
				if c == 3
					lnam += 1
				end
				if c == 4
					l[lnam] = [s, e]
					c = 0
				end
			end
			if state == 3
				if c == 1
					fmod = Integer(line)
				end
				if c == 2
					f = []
				end
				if c == 4
					f[0] = Integer(line)
				end
				if c == 5
					f[1] = Integer(line)
				end
				if c == 6
					f[2] = Integer(line)
					if fmod == 3
						verts = [v[l[f[0]][0]], v[l[f[0]][1]], v[l[f[1]][0]], v[l[f[1]][1]], v[l[f[2]][0]], v[l[f[2]][1]]]
						verts.uniq!
						begin
							entities.add_face verts
						rescue
							UI.messagebox fmod
						end
						c = 0
					end
				end
				if c == 7
					f[3] = Integer(line)
					if fmod == 4
						verts = [v[l[f[0]][0]], v[l[f[0]][1]], v[l[f[1]][0]], v[l[f[1]][1]], v[l[f[2]][0]], v[l[f[2]][1]] , v[l[f[3]][0]], v[l[f[3]][1]]]
						verts.uniq!
						begin
							entities.add_face verts
						rescue
							entities.add_face [verts[0], verts[1], verts[2]]
							entities.add_face [verts[2], verts[3], verts[0]]
						end
						c = 0
					end
				end
			end
		end
	end
end

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?