【応用】MaxScript – 3dsmax – 樹木をMatIDで分割

AEC拡張機能の樹木をMatIDで分割したい時ありますよね。
今回は標準で入っているヨーロッパ赤松を操作してみます。

まず、MatIDを調べます。
MatIDは

getFaceMatID $tree01 i

で取得できます。

$tree01はオブジェクト名で、iはface番号です。

標準で入っているヨーロッパ赤松はIDが1~4だったので、今回は4つにわけます。

1:幹、2:枝、3:小枝、4:葉 のようです。

もちろん他の樹木パックとかでは枝と葉のように2つだったりします。

事前に編集可能メッシュにしておきます。

んで、振り分けます。

for i = 1 to $tree01.numfaces do
(
type = getFaceMatID $tree01 i

	if(type == 1) then (
		append leader i
	)
	if(type == 2) then (
		append branch i
	)
	if(type == 3) then (
		append subbranch i
	)
	if(type == 4) then (
		append leaf i
	)
)

次に元のオブジェクトからデタッチします。

test = meshop.detachFaces $tree01 leader delete:false asMesh:true isSelected:on
mesh mesh:test
$Object001.name ="1"

test2 = meshop.detachFaces $tree01 branch delete:false asMesh:true isSelected:on
mesh mesh:test2
$Object001.name ="2"

test3 = meshop.detachFaces $tree01 subbranch delete:false asMesh:true isSelected:on
mesh mesh:test3
$Object001.name ="3"

test4 = meshop.detachFaces $tree01 leaf delete:false asMesh:true isSelected:on
mesh mesh:test4
$Object001.name ="4"

最後に元オブジェクトを削除します。

delete $tree01

まとめ

leader=#()
branch=#()
subbranch=#()
leaf=#()

for i = 1 to $tree01.numfaces do
(
type = getFaceMatID $tree01 i

	if(type == 1) then (
		append leader i
	)
	if(type == 2) then (
		append branch i
	)
	if(type == 3) then (
		append subbranch i
	)
	if(type == 4) then (
		append leaf i
	)
)

test = meshop.detachFaces $tree01 leader delete:false asMesh:true isSelected:on
mesh mesh:test
$Object001.name ="1"

test2 = meshop.detachFaces $tree01 branch delete:false asMesh:true isSelected:on
mesh mesh:test2
$Object001.name ="2"

test3 = meshop.detachFaces $tree01 subbranch delete:false asMesh:true isSelected:on
mesh mesh:test3
$Object001.name ="3"

test4 = meshop.detachFaces $tree01 leaf delete:false asMesh:true isSelected:on
mesh mesh:test4
$Object001.name ="4"

delete $tree01

実行結果

(移動させています。スクリプト実行後は全て原点にあります)

 

ネタ切れ気味です。

 

3dsmax, maxscript Leave a comment

【応用】MaxScript – 3dsmax – GUIなウィンドウでボックス作って色を変える操作

今回はGUIなウィンドウでボックスを作ったり、色を変えたりします。

今までリスナーや、エディタ上で操作していたことがGUIで行えます。それっぽくなるね!!

 

rollout test "ボックス作って色を変える"
(
	  button btn_box "Create Box"
        tooltip: "Create BOX(10*10*10)" \
	  button btn_color "Change color"
        tooltip: "Random Color" \
	      enabled:false \

	on btn_box pressed do(
		Box length:10 width:10 height:10 mapcoords:on pos:[0,0,0] isSelected:on wirecolor:[0,0,0]
		btn_color.enabled = true

	)
	on btn_color pressed do(
		$.wirecolor = [random 0 255 ,random 0 255 ,random 0 255 ]
	)
)

Dialog = newRolloutFloater "CreateBox Dialog" 200 100

addrollout test Dialog

手抜きですみません。

3dsmax, maxscript Leave a comment

【応用】MaxScript – 3dsmax – 重ならないようにランダムに球体をレイアウト

前回の応用は球体をランダムにレイアウトしました。
多くの球体をレイアウトすると、重なってしまう球体も出てきます。
半径10の球体を30個レイアウト

-- 30回ループ
for i=1 to 30 do(
	-- x : [-50~50] y : [-50~50] z : [0~50]のランダムな3pointを生成
	rp = [random -50 50, random -50 50, random 0 50]

	-- 座標rpに半径10でランダムな色の球をレイアウト
	Sphere radius:10 smooth:on chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:rp wirecolor:[random 0 255, random 0 255, random 0 255]
)

実行結果

球体の座標を配列に格納し、被りそうな座標を避けるスクリプトを組んでみます。

--配列を初期化
points=#()
--30回ループ
for i=1 to 30 do(

	-- x : [-50~50] y : [-50~50] z : [0~50]のランダムな3pointを生成
	rp = [random -50 50, random -50 50, random 0 50]
	--points配列の要素数をloへ
	lo = points.count
	t=1
	while (t --distance [ax,ay,az] [bx,by,bz]でaとbの距離を出す
		--もし、距離が10以下であれば再度ランダム座標を生成する
		if( (distance rp points[t]) < 25) then (
			rp = [random -50 50, random -50 50, random 0 50]
			t=0
		)
		t += 1
	)
	append points rp
	Sphere radius:10 smooth:on chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:rp wirecolor:[random 0 255, random 0 255, random 0 255]
)

 

しかし、これではもし、運悪く座標が見つからない場合、無限ループに入ってしまうので以下のように安全装置?を入れる。

points=#()
safety=0
--30回ループ
for i=1 to 30 do(
	-- x : [-50~50] y : [-50~50] z : [0~50]のランダムな3pointを生成
	rp = [random -50 50, random -50 50, random 0 50]
	--points配列の要素数をloへ
	lo = points.count
	t=1
	while (t --distance [ax,ay,az] [bx,by,bz]でaとbの距離を出す
		--もし、距離が10以下であれば再度ランダム座標を生成する
		if( (distance rp points[t]) < 25) then (
			rp = [random -50 50, random -50 50, random 0 50]
			t=0
			safety += 1
		)
		t += 1
		if safety > 2000 then exit
	)

	append points rp
	Sphere radius:10 smooth:on chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:rp wirecolor:[random 0 255, random 0 255, random 0 255]
)
safety

2000回以上ループした場合に強制的にレイアウトをやめる処理。

実行結果

重なってない!!

 

もし、「きっちり並べたいだけ」であれば以下のプログラムで瞬時にレイアウトが可能。
for文の「by」はステップで、もしこのbyが無いと、100*100*50個の球体がレイアウトされてしまう。
メモリ8GB程度の並の計算機ではすぐにハングアップしてしまうので注意が必要。

for x=-50 to 50 by 20 do(
	for y=-50 to 50 by 20 do(
		for z=0 to 50 by 20 do(
			Sphere radius:10 smooth:on segs:32 chop:0 slice:off sliceFrom:0 sliceTo:0 mapcoords:on recenter:off pos:[x,y,z] wirecolor:[random 0 255, random 0 255, random 0 255]
		)
	)
)

実行結果

3dsmax, maxscript Leave a comment

Autodesk製品 学生無料(3ds Max AutoCAD等…)

前に書いた記事から少し取得方法が変わっていたのでまた書いてみます。

学生が教育目的で使用する場合、無料でAutodesk製品を使用することができます。

詳細は前回の記事をご覧下さい。

3dsMaxやAutoCADを無料で使う方法

 

入手出来るのは

AutoCAD
AutoCAD Architecture
AutoCAD Civil 3D
AutoCAD Electrical
AutoCAD for Mac
AutoCAD Map 3D
AutoCAD Mechanical
AutoCAD MEP
AutoCAD P and ID
AutoCAD Raster Design
AutoCAD Revit MEP Suite
AutoCAD Structural Detailing
Autodesk 3ds Max
Autodesk 3ds Max Design
Autodesk Alias Automotive
Autodesk Alias Design
Autodesk Ecotect Analysis
Autodesk Green Building Studio
Autodesk Impression
Autodesk Inventor Professional
Autodesk Inventor Publisher
Autodesk Maya
Autodesk Moldflow Adviser Advanced
Autodesk MotionBuilder
Autodesk Mudbox
Autodesk Navisworks Manage
Autodesk Quantity Takeoff
Autodesk Revit Architecture
Autodesk Revit Structure
Autodesk Robot Structural Analysis Professional
Autodesk Showcase
Autodesk Simulation Multiphysics
Autodesk SketchBook Designer
Autodesk SketchBook Pro
Autodesk Smoke for Mac OS X
Autodesk Softimage

の日本語版がダウンロードできますが、登録やダウンロードは英語です。

(簡単な英語なので特に問題は無いと思いますが一応解説します)

 

まずはAutodeskの学生向けサイトを開きます。

上部右側にある「Register」をクリックします。

必要事項を記入して「continue to Step2」をクリック

必要事項を記入して「continue to Step3」をクリック

メールが届くので、本文のURLをクリック

登録が完了する。

 

次に上部にある「Free Software」をクリック

使用したいSoftwareをクリックして、ユーザーネーム(メールアドレス)、パスワードを入力し「submit」

今回は3dsmax

 

バージョン、言語、OSを選択し、「Next」

Softwareをダウンロードしてインストールするだけです。

アクティベーションは日本語なのでどうにかなりますよね。

3dsmaxに関しては他にも書いてますのでぜひ見てくださいね。

 

3dsmax, maxscript 1 Comment

MaxScript – 3dsmax – 変数、文字列の出力

リスナー上へ変数や文字列を出力させる。

print

a=1
print a

実行結果

1

1

 

print 2

a=1
print ("数字は" + a as string)
実行結果
"数字は1"
"数字は1"

format

format "%" a

実行結果

1

format 2

a=1
format "数字は%です。\n" a

実行結果

数字は1です。

 

3dsmax, maxscript Leave a comment