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

Posted at

概要

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

練習問題

objエクスポーターを書け。

写真

image.png

image.png

サンプルコード


require "sketchup.rb"

module Oe
	def self.export_entities(of, entities, o = nil)
		faces = entities.find_all { |e|
			e.typename == "Face"
		}
		verts = faces.map { |f|
			f.vertices
		}
		verts.flatten!
		verts.uniq!
		if verts.length < 1
			UI.messagebox("Nothing to export")
			return
		end
		verts.each do |v|
			pt = v.position
			pt.transform!(o) if o
			of.print "v #{pt.x.to_f} #{pt.z.to_f} #{pt.y.to_f}\n"
		end
		gc = 0
		puts "face count: #{faces.length}"
		faces.each do |f|
			gc += 1
			of.print "f "
			f.outer_loop.vertices.each do |v|
				i = verts.index(v) + @verts.length
				of.print "#{i + 1} "
			end
			of.puts
		end
		of.puts
		@verts << verts
		@verts.flatten!
	end
	def self.export_group(of, g)
		o = g.transformation
		of.print "g "
		id = g.entityID
		name = g.name.empty? ? "Group#{id}" : g.name
		of.puts "#{name}"
		export_entities(of, g.entities, o)
	end
	def self.obj_export
		of = File.new("C:/Users/User/Desktop/oe.obj", "w")
		of.puts "# Wavefront OBJ for SketchUp"
		grps = Sketchup.active_model.entities.find_all { |e|
			e.typename == "Group"
		}
		@verts = []
		@vcnt = 0
		entities = Sketchup.active_model.entities
		export_entities(of, entities)
		grps.each { |g|
			export_group(of, g)
		}
		of.flush
		of.close
		UI.messagebox("ok")
	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?