maxscript
-- ① カスタムアトリビュート定義(CA)
fn defineCA caType =
(
case caType of
(
#light:
(
attributes LightAttr
(
parameters main rollout:ui
(
sp type:#float default:0
)
rollout ui "Light UI"
(
spinner s "Value:" range:[0,100,0]
)
)
)
#heavy:
(
attributes HeavyAttr
(
parameters main rollout:ui
(
dummy type:#float
)
rollout ui "Heavy UI"
(
angle a "Angle" width:80 across:2 degrees:45 align:#left
slider s "Slider:" orient:#vertical
spinner sp "Spinner:"
group "Group"
(
button b "Button" across:2 width:80 align:#left
checkbutton cb "Checkbutton" width:80 align:#right
mapbutton mb "Map Button" width:80 across:2 align:#left
materialbutton mb2 "Material Button" width:80 align:#right
pickbutton pb "Pickbutton:" width:80
)
checkbox ch "Checkbox" across:2 offset:[0,2]
colorpicker cp "Colorpicker:"
listbox lb "Listbox:" items:#("Item 1","Item 2") height:3 width:80 across:2
multilistbox mlb "Multilistbox:" items:#("Item 1","Item 2") height:3 width:80
dropdownlist ddl "DropDownList:" items:#("Item 1","Item 2") width:80 across:2
combobox cbx "Combobox:" items:#("Item 1","Item 2") height:3 width:80
edittext et "Edittext:"
hyperlink hl "Hyperlink" url:"http://www.autodesk.com" color:red across:2 offset:[10,20]
label l "Label" offset:[0,20]
groupBox gb "Groupbox:" height:40 offset:[0,-40] width:174
progressbar pb2 "Progressbar:" value:50
radiobuttons rb "Radio Buttons" labels:#("Option 1","Option 2")
bitmap bm "Bitmap" width:80 height:50 bitmap:(bitmap 80 50 color:red) align:#left across:2
imgTag it "Bitmap" width:80 height:50 bitmap:(bitmap 80 50 color:green) align:#right
curvecontrol cc "Curvecontrol:" height:150
)
)
)
default: undefined
)
)
-- ② 1000 体のヘルパーを生成する関数
fn generateHelpers count attr =
(
local helpers = #()
for i = 1 to count do
(
local h = point name:("H" + i as string) pos:[mod i 100 * 10, floor(i/100)*10, 0]
if (attr != undefined) then
(
local attrHold = EmptyModifier name:"Attribute_Holder"
addModifier h attrHold
custAttributes.add h.modifiers[#Attribute_Holder] attr
)
append helpers h
)
return helpers
)
-- ③ 擬似 FPS を測定する関数(測定回数を増やし精度向上)
fn measureFPS redrawCount =
(
local tStart = timestamp()
for i = 1 to redrawCount do
redrawViews()
local tEnd = timestamp()
local elapsedSec = (tEnd - tStart) / 1000.0
-- 経過時間が短すぎる場合は最小値を設定
if elapsedSec < 0.001 then elapsedSec = 0.001
local fps = redrawCount / elapsedSec
return fps
)
-- ④ 一括ベンチマーク実行関数(改善版)
fn runAllBenchmarks =
(
clearListener()
format "=== ベンチマーク開始 ===\n\n"
-- 測定回数を増やして精度向上 (500 → 1000)
local testCount = 1000
local helperCount = 1000
-- ----- ベース:空のヘルパーのみ(CA なし) -----
format "🌿 Base (空のヘルパー)\n"
resetMaxFile #noPrompt
disableSceneRedraw()
generateHelpers helperCount undefined
enableSceneRedraw()
redrawViews() -- 追加: 画面更新を確実にする
sleep 0.5
local fpsBase = measureFPS testCount
format "FPS (Base): %.2f\n\n" fpsBase
-- ----- Light UI:最小構成の CA(スピナーのみ) -----
format "🌱 Light UI (最小のカスタム属性)\n"
resetMaxFile #noPrompt
disableSceneRedraw()
local lightCA = defineCA #light
generateHelpers helperCount lightCA
enableSceneRedraw()
redrawViews() -- 追加: 画面更新を確実にする
sleep 0.5
local fpsLight = measureFPS testCount
format "FPS (Light UI): %.2f\n\n" fpsLight
-- ----- Heavy UI:多数の UI 部品を含む CA -----
format "🌳 Heavy UI (大量UI付きカスタム属性)\n"
resetMaxFile #noPrompt
disableSceneRedraw()
local heavyCA = defineCA #heavy
generateHelpers helperCount heavyCA
enableSceneRedraw()
redrawViews() -- 追加: 画面更新を確実にする
sleep 0.5
local fpsHeavy = measureFPS testCount
format "FPS (Heavy UI): %.2f\n" fpsHeavy
format "\n=== ベンチマーク終了 ===\n"
-- 結果比較
format "\n=== 結果比較 ===\n"
format "Base FPS: %.2f\n" fpsBase
format "Light UI FPS: %.2f (Baseの %.1f%%)\n" fpsLight (fpsLight/fpsBase*100)
format "Heavy UI FPS: %.2f (Baseの %.1f%%)\n" fpsHeavy (fpsHeavy/fpsBase*100)
)
-- ⑤ ベンチマーク実行
runAllBenchmarks()