summaryrefslogtreecommitdiff
path: root/src/SomhairlesDream.Frontend/Bindings.fs
blob: df94777c2546aaf63333f432859c91a765807532 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
module SomhairlesDream.Frontend.Bindings

open Fable.Core

[<Erase>]
type ThreeVector =
    abstract set: x: float * y: float * z: float -> ThreeVector
    abstract x: float with get, set
    abstract y: float with get, set
    abstract z: float with get, set
    abstract length: unit -> float

[<Erase>]
type ThreeNode =
    abstract add: child: ThreeNode -> unit
    abstract clear: unit -> unit
    abstract lookAt: x: float * y: float * z: float -> unit
    abstract position: ThreeVector with get
    abstract rotation: ThreeVector with get
    abstract background: obj with get, set
    abstract children: ThreeNode array with get

[<Emit("$0.traverse(function (o) { if (o.geometry && o.geometry.dispose) { o.geometry.dispose(); } var mats = Array.isArray(o.material) ? o.material : (o.material ? [o.material] : []); mats.forEach(function (m) { ['map','normalMap','roughnessMap','metalnessMap','aoMap','emissiveMap'].forEach(function (key) { var t = m[key]; if (t && t.dispose) { t.dispose(); } }); if (m.dispose) { m.dispose(); } }); })")>]
let disposeNodeResources (node: ThreeNode) : unit = jsNative

[<Erase>]
type ThreeBox3 =
    abstract setFromObject: node: ThreeNode -> ThreeBox3
    abstract isEmpty: unit -> bool
    abstract getCenter: target: ThreeVector -> ThreeVector
    abstract getSize: target: ThreeVector -> ThreeVector

[<Erase>]
type ThreeCamera =
    inherit ThreeNode
    abstract fov: float with get, set
    abstract aspect: float with get, set
    abstract near: float with get, set
    abstract far: float with get, set
    abstract updateProjectionMatrix: unit -> unit

[<Erase>]
type ThreeRenderer =
    abstract setPixelRatio: ratio: float -> unit
    abstract setSize: width: float * height: float * updateStyle: bool -> unit
    abstract render: scene: ThreeNode * camera: ThreeNode -> unit

[<Erase>]
type ThreeGeometry =
    abstract setAttribute: name: string * attribute: obj -> ThreeGeometry
    abstract setIndex: attribute: obj -> ThreeGeometry
    abstract computeVertexNormals: unit -> unit

[<Erase>]
type ServerEvent =
    abstract data: string with get

[<Erase>]
type GLTFScene =
    abstract scene: ThreeNode with get

[<Emit("new THREE.PointsMaterial({ color: $0, size: $1, sizeAttenuation: true, transparent: true, opacity: $2, depthWrite: false })")>]
let createPointsMaterial (color: string) (size: float) (opacity: float) : obj = jsNative

[<Emit("new THREE.Points($0, $1)")>]
let createPoints (geometry: obj) (material: obj) : ThreeNode = jsNative

[<Emit("new DRACOLoader()")>]
let createDRACOLoader () : obj = jsNative

[<Emit("$0.setDecoderPath($1)")>]
let setDracoDecoderPath (draco: obj) (path: string) : unit = jsNative

[<Emit("$0.setDRACOLoader($1)")>]
let attachDracoLoader (loader: obj) (draco: obj) : unit = jsNative

[<Emit("new GLTFLoader()")>]
let createGLTFLoader () : obj = jsNative

[<Emit("$0.load($1, $2, null, $3)")>]
let loadGLTF (loader: obj) (url: string) (onLoad: GLTFScene -> unit) (onError: obj -> unit) : unit = jsNative

[<Emit("new OrbitControls($0, $1)")>]
let createOrbitControls (camera: obj) (canvas: obj) : obj = jsNative

[<Emit("$0.target.copy({ x: $1, y: $2, z: $3 })")>]
let setControlsTarget (controls: obj) (x: float) (y: float) (z: float) : unit = jsNative

[<Emit("$0.enableDamping = $1")>]
let setControlsDamping (controls: obj) (enabled: bool) : unit = jsNative

[<Emit("$0.autoRotate = $1")>]
let setControlsAutoRotate (controls: obj) (auto: bool) : unit = jsNative

[<Emit("$0.autoRotateSpeed = $1")>]
let setControlsAutoRotateSpeed (controls: obj) (speed: float) : unit = jsNative

[<Emit("$0.update()")>]
let updateControls (controls: obj) : unit = jsNative

[<Emit("new URLSearchParams(window.location.search).get($0)")>]
let queryParam (name: string) : string = jsNative

[<Erase>]
type EventSource =
    abstract onerror: (obj -> unit) with get, set
    abstract onmessage: (ServerEvent -> unit) with get, set
    abstract close: unit -> unit

[<Erase>]
type FetchResponse =
    abstract ok: bool with get
    abstract status: int with get
    abstract json: unit -> JS.Promise<obj>

[<Erase>]
type HtmlInput =
    abstract value: string with get
    abstract ``checked``: bool with get

[<Emit("new THREE.Scene()")>]
let createScene () : ThreeNode = jsNative

[<Emit("new THREE.Group()")>]
let createGroup () : ThreeNode = jsNative

[<Emit("new THREE.PerspectiveCamera($0, $1, $2, $3)")>]
let createPerspectiveCamera (fieldOfView: float, aspect: float, nearPlane: float, farPlane: float) : ThreeCamera = jsNative

[<Emit("new THREE.Box3()")>]
let createBox3 () : ThreeBox3 = jsNative

[<Emit("new THREE.Vector3()")>]
let createVector3 () : ThreeVector = jsNative

[<Emit("window.SOMHAIRLES_VIEWER = { camera: $0, scene: $1, group: $2, canvas: $3, controls: $4 }")>]
let exposeViewerDebug (camera: ThreeCamera) (scene: ThreeNode) (group: ThreeNode) (canvas: obj) (controls: obj) : unit = jsNative

[<Emit("var child; while ((child = $0.firstChild)) { $0.removeChild(child); }")>]
let clearChildren (node: obj) : unit = jsNative

[<Emit("new THREE.WebGLRenderer($0)")>]
let createRenderer (options: obj) : ThreeRenderer = jsNative

[<Emit("new THREE.BufferGeometry()")>]
let createBufferGeometry () : ThreeGeometry = jsNative

[<Emit("new THREE.Float32BufferAttribute($0, $1)")>]
let createFloat32BufferAttribute (values: float array, itemSize: int) : obj = jsNative

[<Emit("new THREE.Uint32BufferAttribute($0, 1)")>]
let createUint32BufferAttribute (values: int array) : obj = jsNative

[<Emit("new THREE.Color($0)")>]
let createColor (value: string) : obj = jsNative

[<Emit("new THREE.BoxGeometry($0, $1, $2)")>]
let createBoxGeometry (width: float, height: float, depth: float) : obj = jsNative

[<Emit("new THREE.MeshStandardMaterial($0)")>]
let createMeshStandardMaterial (options: obj) : obj = jsNative

[<Emit("new THREE.Mesh($0, $1)")>]
let createMesh (geometry: obj, material: obj) : ThreeNode = jsNative

[<Emit("new THREE.AmbientLight($0, $1)")>]
let createAmbientLight (color: string, intensity: float) : ThreeNode = jsNative

[<Emit("new THREE.DirectionalLight($0, $1)")>]
let createDirectionalLight (color: string, intensity: float) : ThreeNode = jsNative

[<Emit("new THREE.HemisphereLight($0, $1, $2)")>]
let createHemisphereLight (skyColor: string, groundColor: string, intensity: float) : ThreeNode = jsNative

[<Emit("$0.toneMapping = THREE.ACESFilmicToneMapping")>]
let setToneMappingACES (renderer: obj) : unit = jsNative

[<Emit("$0.toneMappingExposure = $1")>]
let setToneMappingExposure (renderer: obj, exposure: float) : unit = jsNative

[<Emit("new THREE.GridHelper($0, $1, $2, $3)")>]
let createGridHelper (size: float, divisions: int, centerColor: string, edgeColor: string) : ThreeNode = jsNative

[<Emit("$0.position.y = $1")>]
let setNodePositionY (node: ThreeNode, y: float) : unit = jsNative

[<Emit("document.getElementById($0).classList.toggle('is-hidden', $1)")>]
let toggleHidden (id: string, hidden: bool) : unit = jsNative

[<Emit("$0.outputColorSpace = THREE.SRGBColorSpace")>]
let setSRGBOutput (renderer: obj) : unit = jsNative

[<Emit("new THREE.PMREMGenerator($0)")>]
let createPMREMGenerator (renderer: obj) : obj = jsNative

[<Emit("new THREE.Scene()")>]
let createEnvScene () : obj = jsNative

[<Emit("$0.fromScene($1, 0.04).texture")>]
let pmremFromScene (generator: obj, scene: obj) : obj = jsNative

[<Emit("$0.environment = $1")>]
let setSceneEnvironment (scene: obj, texture: obj) : unit = jsNative

[<Emit("$0.environmentIntensity = $1")>]
let setSceneEnvironmentIntensity (scene: obj, intensity: float) : unit = jsNative

[<Emit("new EventSource($0)")>]
let createEventSource (url: string) : EventSource = jsNative

[<Global("fetch")>]
let fetch (url: string, options: obj) : JS.Promise<FetchResponse> = jsNative

[<Global("encodeURIComponent")>]
let encodeURIComponent (value: string) : string = jsNative

[<Global("setInterval")>]
let setInterval (callback: unit -> unit) (milliseconds: int) : int = jsNative

[<Global("clearInterval")>]
let clearInterval (handle: int) : unit = jsNative

[<Global("requestAnimationFrame")>]
let requestAnimationFrame (callback: float -> unit) : int = jsNative