-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewportUtility.ms
More file actions
68 lines (60 loc) · 1.93 KB
/
ViewportUtility.ms
File metadata and controls
68 lines (60 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*! © 2022 imaoki | MIT License | https://github.com/imaoki */
/*-
ビューポート用の追加メソッドを提供する。
*/
struct ViewportUtilityStruct (
/*
public fn GetDistancePerPixel = (),
public fn PixelDistance v1 v2 = (),
*/
/*-
アクティブビューポートのスクリーン座標系における1ピクセル辺りのワールド距離を取得する。
@returns <Float>
@remarks スケール係数がビューの縦サイズと一致する時、ワールド距離の`1.0`は`1`ピクセルになる。
*/
public fn GetDistancePerPixel = (
1.0 / ((getViewSize()).Y / (getScreenScaleFactor [0, 0, 0]))
),
/*-
ワールド座標系の2ベクトル間の距離からスクリーン座標系におけるピクセル距離を算出する。
@param v1 <Point3>
@param v2 <Point3>
@returns <Float>
*/
public fn PixelDistance v1 v2 = (
local result = 0.0
if classOf v1 == Point3 and classOf v2 == Point3 do (
local viewTM = getViewTM()
local p1 = v1 * viewTM * [1, 1, 0]
local p2 = v2 * viewTM * [1, 1, 0]
local worldDist = distance p1 p2
result = worldDist / this.GetDistancePerPixel()
)
result
),
/*- @returns <Name> */
public fn StructName = #ViewportUtilityStruct,
/*-
@param indent: <String>
@param out: <FileStream|StringStream|WindowStream> 出力先。既定値は`listener`。
@returns <OkClass>
*/
public fn Dump indent:"" out:listener = (
format "%ViewportUtilityStruct\n" indent to:out
ok
),
/*-
@param obj <Any>
@returns <BooleanClass>
@remarks 大文字と小文字を区別する。
*/
public fn Equals obj = (
local isEqualStructName = isStruct obj \
and isProperty obj #StructName \
and classOf obj.StructName == MAXScriptFunction \
and obj.StructName() == this.StructName()
local isEqualProperties = true
isEqualStructName and isEqualProperties
),
on Create do ()
)