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

Posted at

概要

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

練習問題

stlローダーを書け。

写真

image.png

サンプルコード


require "sketchup.rb"

def stl_ld
	entities = Sketchup.active_model.entities
	groups = {}
	vertices = []
	state = 0
	f = UI.openpanel "Select .stl file", "", "*.stl"
	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 "facet"
			state = 0
			vertices = []
		when "vertex"
			state = state + 1
			v = []
			v << Float(values[0])
			v << Float(values[2])
			v << Float(values[1])
			vertices << v
			if (state == 3)
				begin
					entities.add_face vertices
				rescue
					UI.messagebox "err"
					p vertices
				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?