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 その19

Posted at

概要

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

練習問題

objローダーを書け。

写真

image.png

サンプルコード


require "sketchup.rb"

def obj_ld
	entities = Sketchup.active_model.entities
	groups = {}
	vertices = []
	f = UI.openpanel "Select .obj file", "", "*.obj"
	return unless f
	lines = IO.readlines(f)
	lines.each do | line |
		next if line[0] == ?#
		line.strip!
		values = line.split
		next if values.length == 0
		cmd = values.shift
		case cmd
		when "v"
			v = values.map {| e | Float(e)}
			vertices << v
		when "g"
			gname = values.join "_"
			if (groups[gname].nil?)
				groups[gname] =	Sketchup.active_model.entities.add_group
				groups[gname].name = gname
			end
			entities = groups[gname].entities
		when "f"
			face = []
			values.each do | v |
				w = v.split("/")
				face << Integer(w[0])
		end
		verts = face.map {| v | vertices[v - 1]}
		begin
			entities.add_face verts
		rescue
			#UI.messagebox line
		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?