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

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
カメラをアニメーションするプラグイン、見つけたので、やってみた。

写真

image.png

サンプルコード



require 'sketchup.rb'


class ViewSpinner
	def initialize
		model = Sketchup.active_model
		view = model.active_view
		camera = view.camera
		@target = model.bounds.center
		@up = Geom::Vector3d.new(0, 0, 1)
		@distance = camera.eye.distance @target
		@zmin = @target.z
		@zmax = @zmin + @distance
		@dz = @distance / 300
		@z = @zmin
		@angle = 0
		@frame = 0;
		@startTime = Time.now
		Sketchup::set_status_text($exStrings.GetString("FPS"), 1)
	end
	def nextFrame(view)
		@frame = @frame + 1
		totalTime = Time.now - @startTime
		fps = 1
		if (totalTime > 0.001)
			fps = @frame / totalTime
		end
		fps = fps.to_i
		Sketchup::set_status_text(fps, 2)
		a = @angle * Math::PI / 180.0
		x = @target.x + (@distance * Math::sin(a))
		y = @target.y + (@distance * Math::cos(a))
		eye = Geom::Point3d.new(x, y, @z)
		view.camera.set(eye, @target, @up)
		@angle = (@angle + 1) % 360
		view.show_frame
		@z += @dz
		if (@z > @zmax)
			@z = @zmax
			@dz = -@dz
		elsif (@z < @zmin)
			@z = @zmin
			@dz = -@dz
		end
		return true
	end
	def stop
		Sketchup::set_status_text("", 1)
		Sketchup::set_status_text("", 2)
	end
end 

def spinview
	Sketchup.active_model.active_view.animation = ViewSpinner.new
end

if (not file_loaded?("animation.rb"))
	add_separator_to_menu("Camera")
	animation_menu = UI.menu("Camera").add_submenu("Animations")
	animation_menu.add_item("Spin View") {
		spinview
	}
	animation_menu.add_item("Stop Spinning") {
		Sketchup.active_model.active_view.animation = nil
	}
end

file_loaded("animation.rb")





以上。

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?