Pārlūkot izejas kodu

Document the babylon.js and the three.js plugins

customisations
alemart 8 mēnešus atpakaļ
vecāks
revīzija
a055447041

+ 298
- 0
docs/api/plugin-babylon.md Parādīt failu

@@ -0,0 +1,298 @@
1
+# Babylon.js plugin
2
+
3
+Documentation of the [babylon.js](https://www.babylonjs.com){ ._blank } plugin. Study the [demos](../demos.md) for practical examples.
4
+
5
+*Since:* 0.3.0
6
+
7
+## Basics
8
+
9
+### Lifecycle
10
+
11
+The following diagram shows, in a simplified manner, the lifecycle of an AR experience. The rectangular blocks represent methods of your [ARDemo](#ardemo). Function [encantar](#encantar) starts the magic.
12
+
13
+![Lifecycle of an AR experience](/img/lifecycle-plugin.png)
14
+
15
+!!! tip
16
+
17
+    Use event listeners to detect events such as [finding an image](./image-tracker.md#events) in a camera feed.
18
+
19
+### encantar
20
+
21
+`encantar(demo: ARDemo): Promise<ARSystem>`
22
+
23
+The `encantar` function *enchants* a `demo`, meaning: it starts the [lifecycle](#lifecycle) of the AR experience.
24
+
25
+**Arguments**
26
+
27
+* `demo: ARDemo`. Your demo. See also: [ARDemo](#ardemo)
28
+
29
+**Returns**
30
+
31
+A promise that resolves to an [ARSystem](#arsystem) when the demo starts.
32
+
33
+**Example**
34
+
35
+```js
36
+function main()
37
+{
38
+    const demo = new MyDemo(); // class MyDemo extends ARDemo
39
+
40
+    encantar(demo).catch(error => {
41
+        alert(error.message);
42
+    });
43
+}
44
+
45
+document.addEventListener('DOMContentLoaded', main);
46
+```
47
+
48
+!!! note
49
+
50
+    You should **not** call [session.requestAnimationFrame()](./session.md#requestanimationframe) when using this plugin. The plugin already calls it.
51
+
52
+## ARDemo
53
+
54
+`ARDemo` is the base class for Augmented Reality experiences. It's an abstract class, meaning that you must extend it. It operates within the [lifecycle](#lifecycle) of your AR experience. The plugin will call its methods and control the flow of the program. Simply call [encantar](#encantar) to start the magic!
55
+
56
+### ar
57
+
58
+`demo.ar: ARSystem | null, read-only`
59
+
60
+A reference to the [ARSystem](#arsystem), or `null` if the demo hasn't been started yet. See also: [lifecycle](#lifecycle)
61
+
62
+*Since:* 0.4.0
63
+
64
+### startSession
65
+
66
+`demo.startSession(): Promise<Session> | SpeedyPromise<Session>`
67
+
68
+Start the AR [Session](session.md). This method receives no arguments. It's supposed to call [AR.startSession](session.md#instantiation) with the desired settings.
69
+
70
+**Returns**
71
+
72
+A promise that resolves to a Session.
73
+
74
+!!! warning "Important"
75
+
76
+    This is an abstract method. You **must** implement it.
77
+
78
+!!! info "Fact"
79
+
80
+    The tracking begins when the session is started.
81
+
82
+### init
83
+
84
+`demo.init(): void | Promise<void> | SpeedyPromise<void>`
85
+
86
+Use this method to initialize your 3D scene. See also: [ar](#ar), [preload](#preload)
87
+
88
+**Returns**
89
+
90
+`undefined`, or a promise that resolves to `undefined`.
91
+
92
+**Example**
93
+
94
+```js
95
+class MyDemo extends ARDemo
96
+{
97
+    // ...
98
+
99
+    init()
100
+    {
101
+        const ar = this.ar;
102
+        const scene = ar.scene;
103
+
104
+        // initialize the scene
105
+        // ...
106
+    }
107
+
108
+    // ...
109
+}
110
+```
111
+
112
+!!! tip
113
+
114
+    Load external assets in [preload](#preload). Method `init` shouldn't take too long to run because the session is already started. See also: [lifecycle](#lifecycle)
115
+
116
+### update
117
+
118
+`demo.update(): void`
119
+
120
+Animation step, called during the animation loop. You may want to do something with [ar.session](#session) or [ar.frame](#frame).
121
+
122
+**Example**
123
+
124
+```js
125
+class MyDemo extends ARDemo
126
+{
127
+    // ...
128
+
129
+    update()
130
+    {
131
+        const ar = this.ar;
132
+        const session = ar.session;
133
+        const deltaTime = session.time.delta; // given in seconds
134
+
135
+        // ...
136
+    }
137
+
138
+    // ...
139
+}
140
+```
141
+
142
+### release
143
+
144
+`release(): void`
145
+
146
+Release resources soon after the AR session is ended.
147
+
148
+### preload
149
+
150
+`preload(): Promise<void> | SpeedyPromise<void>`
151
+
152
+Preload resources before starting the AR session. See also: [init](#init), [startSession](#startsession)
153
+
154
+*Since:* 0.4.0
155
+
156
+**Returns**
157
+
158
+A promise that resolves to `undefined`.
159
+
160
+## ARSystem
161
+
162
+`ARSystem` is a helper for creating Augmented Reality experiences. Access it via [ARDemo.ar](#ar).
163
+
164
+### session
165
+
166
+`ar.session: Session, read-only`
167
+
168
+A reference to the AR [Session](session.md).
169
+
170
+### frame
171
+
172
+`ar.frame: Frame | null, read-only`
173
+
174
+A reference to the current [Frame](frame.md). This will be `null` if the demo hasn't been started yet, or if the session has been ended. See also: [lifecycle](#lifecycle)
175
+
176
+### viewer
177
+
178
+`ar.viewer: Viewer | null, read-only`
179
+
180
+A reference to the [Viewer](viewer.md). This will be `null` if the [frame](#frame) is `null`.
181
+
182
+*Since:* 0.4.0
183
+
184
+### pointers
185
+
186
+`ar.pointers: TrackablePointer[], read-only`
187
+
188
+An array of [TrackablePointers](trackable-pointer.md).
189
+
190
+*Since:* 0.4.0
191
+
192
+!!! tip
193
+
194
+    Make sure to add a [PointerTracker](pointer-tracker.md) to your session in order to use these.
195
+
196
+### root
197
+
198
+`ar.root: BABYLON.TransformNode, read-only`
199
+
200
+A node that is automatically aligned to the physical scene.
201
+
202
+!!! warning "Important"
203
+
204
+    In most cases, objects of your virtual scene should be descendants of this node!
205
+
206
+### camera
207
+
208
+`ar.camera: BABYLON.Camera, read-only`
209
+
210
+A camera that is automatically adjusted for AR.
211
+
212
+### scene
213
+
214
+`ar.scene: BABYLON.Scene, read-only`
215
+
216
+The babylon.js scene.
217
+
218
+### engine
219
+
220
+`ar.engine: BABYLON.Engine, read-only`
221
+
222
+The babylon.js engine.
223
+
224
+### utils
225
+
226
+`ar.utils: ARUtils, read-only`
227
+
228
+[Utilities](#arutils) object.
229
+
230
+*Since:* 0.4.0
231
+
232
+## ARUtils
233
+
234
+Utilities object.
235
+
236
+### convertVector2
237
+
238
+`ar.utils.convertVector2(v: Vector2): BABYLON.Vector2`
239
+
240
+Convert a [Vector2](./vector2.md) into a `BABYLON.Vector2`.
241
+
242
+*Since:* 0.4.0
243
+
244
+**Arguments**
245
+
246
+* `v: Vector2`. A 2D vector.
247
+
248
+**Returns**
249
+
250
+A corresponding `BABYLON.Vector2`.
251
+
252
+### convertVector3
253
+
254
+`ar.utils.convertVector3(v: Vector3): BABYLON.Vector3`
255
+
256
+Convert a [Vector3](./vector3.md) into a `BABYLON.Vector3`.
257
+
258
+*Since:* 0.4.0
259
+
260
+**Arguments**
261
+
262
+* `v: Vector3`. A 3D vector.
263
+
264
+**Returns**
265
+
266
+A corresponding `BABYLON.Vector3`.
267
+
268
+### convertQuaternion
269
+
270
+`ar.utils.convertQuaternion(q: Quaternion): BABYLON.Quaternion`
271
+
272
+Convert a [Quaternion](./quaternion.md) into a `BABYLON.Quaternion`.
273
+
274
+*Since:* 0.4.0
275
+
276
+**Arguments**
277
+
278
+* `q: Quaternion`. A quaternion.
279
+
280
+**Returns**
281
+
282
+A corresponding `BABYLON.Quaternion`.
283
+
284
+### convertRay
285
+
286
+`ar.utils.convertRay(r: Ray): BABYLON.Ray`
287
+
288
+Convert a [Ray](./ray.md) into a `BABYLON.Ray`.
289
+
290
+*Since:* 0.4.0
291
+
292
+**Arguments**
293
+
294
+* `r: Ray`. A ray.
295
+
296
+**Returns**
297
+
298
+A corresponding `BABYLON.Ray`.

+ 311
- 0
docs/api/plugin-three.md Parādīt failu

@@ -0,0 +1,311 @@
1
+# Three.js plugin
2
+
3
+Documentation of the [three.js](https://threejs.org){ ._blank } plugin. Study the [demos](../demos.md) for practical examples.
4
+
5
+## Basics
6
+
7
+### Lifecycle
8
+
9
+The following diagram shows, in a simplified manner, the lifecycle of an AR experience. The rectangular blocks represent methods of your [ARDemo](#ardemo). Function [encantar](#encantar) starts the magic.
10
+
11
+![Lifecycle of an AR experience](/img/lifecycle-plugin.png)
12
+
13
+<pre style="display:none">
14
+mermaid
15
+flowchart TD
16
+    _((start)) -->|encantar called| A[preload]
17
+    A --> B[startSession]
18
+    B -->|session started| C[init]
19
+    C -->|demo started| D[update]
20
+    ? -->|animation loop| D
21
+    D --> ?{{Session active?}}
22
+    ? -->|session ended| E[release]
23
+    E -->|demo ended| Z((end))
24
+</pre>
25
+
26
+!!! tip
27
+
28
+    Use event listeners to detect events such as [finding an image](./image-tracker.md#events) in a camera feed.
29
+
30
+### encantar
31
+
32
+`encantar(demo: ARDemo): Promise<ARSystem>`
33
+
34
+The `encantar` function *enchants* a `demo`, meaning: it starts the [lifecycle](#lifecycle) of the AR experience.
35
+
36
+*Since:* 0.3.0
37
+
38
+**Arguments**
39
+
40
+* `demo: ARDemo`. Your demo. See also: [ARDemo](#ardemo)
41
+
42
+**Returns**
43
+
44
+A promise that resolves to an [ARSystem](#arsystem) when the demo starts.
45
+
46
+**Example**
47
+
48
+```js
49
+function main()
50
+{
51
+    const demo = new MyDemo(); // class MyDemo extends ARDemo
52
+
53
+    encantar(demo).catch(error => {
54
+        alert(error.message);
55
+    });
56
+}
57
+
58
+document.addEventListener('DOMContentLoaded', main);
59
+```
60
+
61
+!!! note
62
+
63
+    You should **not** call [session.requestAnimationFrame()](./session.md#requestanimationframe) when using this plugin. The plugin already calls it.
64
+
65
+## ARDemo
66
+
67
+`ARDemo` is the base class for Augmented Reality experiences. It's an abstract class, meaning that you must extend it. It operates within the [lifecycle](#lifecycle) of your AR experience. The plugin will call its methods and control the flow of the program. Simply call [encantar](#encantar) to start the magic!
68
+
69
+### ar
70
+
71
+`demo.ar: ARSystem | null, read-only`
72
+
73
+A reference to the [ARSystem](#arsystem), or `null` if the demo hasn't been started yet. See also: [lifecycle](#lifecycle)
74
+
75
+*Since:* 0.4.0
76
+
77
+### startSession
78
+
79
+`demo.startSession(): Promise<Session> | SpeedyPromise<Session>`
80
+
81
+Start the AR [Session](session.md). This method receives no arguments. It's supposed to call [AR.startSession](session.md#instantiation) with the desired settings.
82
+
83
+**Returns**
84
+
85
+A promise that resolves to a Session.
86
+
87
+!!! warning "Important"
88
+
89
+    This is an abstract method. You **must** implement it.
90
+
91
+!!! info "Fact"
92
+
93
+    The tracking begins when the session is started.
94
+
95
+### init
96
+
97
+`demo.init(): void | Promise<void> | SpeedyPromise<void>`
98
+
99
+Use this method to initialize your 3D scene. See also: [ar](#ar), [preload](#preload)
100
+
101
+**Returns**
102
+
103
+`undefined`, or a promise that resolves to `undefined`.
104
+
105
+**Example**
106
+
107
+```js
108
+class MyDemo extends ARDemo
109
+{
110
+    // ...
111
+
112
+    init()
113
+    {
114
+        const ar = this.ar;
115
+        const scene = ar.scene;
116
+
117
+        // initialize the scene
118
+        // ...
119
+    }
120
+
121
+    // ...
122
+}
123
+```
124
+
125
+!!! tip
126
+
127
+    Load external assets in [preload](#preload). Method `init` shouldn't take too long to run because the session is already started. See also: [lifecycle](#lifecycle)
128
+
129
+### update
130
+
131
+`demo.update(): void`
132
+
133
+Animation step, called during the animation loop. You may want to do something with [ar.session](#session) or [ar.frame](#frame).
134
+
135
+**Example**
136
+
137
+```js
138
+class MyDemo extends ARDemo
139
+{
140
+    // ...
141
+
142
+    update()
143
+    {
144
+        const ar = this.ar;
145
+        const session = ar.session;
146
+        const deltaTime = session.time.delta; // given in seconds
147
+
148
+        // ...
149
+    }
150
+
151
+    // ...
152
+}
153
+```
154
+
155
+### release
156
+
157
+`release(): void`
158
+
159
+Release resources soon after the AR session is ended.
160
+
161
+### preload
162
+
163
+`preload(): Promise<void> | SpeedyPromise<void>`
164
+
165
+Preload resources before starting the AR session. See also: [init](#init), [startSession](#startsession)
166
+
167
+*Since:* 0.4.0
168
+
169
+**Returns**
170
+
171
+A promise that resolves to `undefined`.
172
+
173
+## ARSystem
174
+
175
+`ARSystem` is a helper for creating Augmented Reality experiences. Access it via [ARDemo.ar](#ar).
176
+
177
+### session
178
+
179
+`ar.session: Session, read-only`
180
+
181
+A reference to the AR [Session](session.md).
182
+
183
+### frame
184
+
185
+`ar.frame: Frame | null, read-only`
186
+
187
+A reference to the current [Frame](frame.md). This will be `null` if the demo hasn't been started yet, or if the session has been ended. See also: [lifecycle](#lifecycle)
188
+
189
+### viewer
190
+
191
+`ar.viewer: Viewer | null, read-only`
192
+
193
+A reference to the [Viewer](viewer.md). This will be `null` if the [frame](#frame) is `null`.
194
+
195
+*Since:* 0.4.0
196
+
197
+### pointers
198
+
199
+`ar.pointers: TrackablePointer[], read-only`
200
+
201
+An array of [TrackablePointers](trackable-pointer.md).
202
+
203
+*Since:* 0.4.0
204
+
205
+!!! tip
206
+
207
+    Make sure to add a [PointerTracker](pointer-tracker.md) to your session in order to use these.
208
+
209
+### root
210
+
211
+`ar.root: THREE.Group, read-only`
212
+
213
+A node that is automatically aligned to the physical scene.
214
+
215
+!!! warning "Important"
216
+
217
+    In most cases, objects of your virtual scene should be descendants of this node!
218
+
219
+### camera
220
+
221
+`ar.camera: THREE.Camera, read-only`
222
+
223
+A camera that is automatically adjusted for AR.
224
+
225
+### scene
226
+
227
+`ar.scene: THREE.Scene, read-only`
228
+
229
+The three.js scene.
230
+
231
+### renderer
232
+
233
+`ar.renderer: THREE.WebGLRenderer, read-only`
234
+
235
+The three.js renderer.
236
+
237
+### utils
238
+
239
+`ar.utils: ARUtils, read-only`
240
+
241
+[Utilities](#arutils) object.
242
+
243
+*Since:* 0.4.0
244
+
245
+## ARUtils
246
+
247
+Utilities object.
248
+
249
+### convertVector2
250
+
251
+`ar.utils.convertVector2(v: Vector2): THREE.Vector2`
252
+
253
+Convert a [Vector2](./vector2.md) into a `THREE.Vector2`.
254
+
255
+*Since:* 0.4.0
256
+
257
+**Arguments**
258
+
259
+* `v: Vector2`. A 2D vector.
260
+
261
+**Returns**
262
+
263
+A corresponding `THREE.Vector2`.
264
+
265
+### convertVector3
266
+
267
+`ar.utils.convertVector3(v: Vector3): THREE.Vector3`
268
+
269
+Convert a [Vector3](./vector3.md) into a `THREE.Vector3`.
270
+
271
+*Since:* 0.4.0
272
+
273
+**Arguments**
274
+
275
+* `v: Vector3`. A 3D vector.
276
+
277
+**Returns**
278
+
279
+A corresponding `THREE.Vector3`.
280
+
281
+### convertQuaternion
282
+
283
+`ar.utils.convertQuaternion(q: Quaternion): THREE.Quaternion`
284
+
285
+Convert a [Quaternion](./quaternion.md) into a `THREE.Quaternion`.
286
+
287
+*Since:* 0.4.0
288
+
289
+**Arguments**
290
+
291
+* `q: Quaternion`. A quaternion.
292
+
293
+**Returns**
294
+
295
+A corresponding `THREE.Quaternion`.
296
+
297
+### convertRay
298
+
299
+`ar.utils.convertRay(r: Ray): THREE.Ray`
300
+
301
+Convert a [Ray](./ray.md) into a `THREE.Ray`.
302
+
303
+*Since:* 0.4.0
304
+
305
+**Arguments**
306
+
307
+* `r: Ray`. A ray.
308
+
309
+**Returns**
310
+
311
+A corresponding `THREE.Ray`.

Binārs
docs/img/lifecycle-plugin.png Parādīt failu


+ 4
- 0
docs/tutorial/augment-the-scene.md Parādīt failu

@@ -65,8 +65,12 @@ It's easy to construct a basic augmented scene, and no JavaScript is needed for
65 65
 
66 66
 Babylon.js has an amazing documentation with plenty of learning resources, as well as a helpful and friendly community! Even though it can be used by beginners, it's recommended to have experience with JavaScript before creating projects with it.
67 67
 
68
+[Tell me more!](../api/plugin-babylon.md){ .md-button ._blank }
69
+
68 70
 ### Three.js
69 71
 
70 72
 [Three.js](https://threejs.org){ ._blank } is a popular open-source JavaScript library used to render 3D graphics in web browsers. It has many features, including: scene graphs, cameras, animations, lights, materials, loading of 3D models, mathematical utilities, special effects, and more. It has an active and vibrant community. Many community-made extensions are available.
71 73
 
72 74
 Using Three.js requires more JavaScript experience than using A-Frame in most cases, but it's also a great choice if you're comfortable with coding. Compared to A-Frame, Three.js offers you additional freedom on how you can organize your code, because it's a library, not a framework.
75
+
76
+[Tell me more!](../api/plugin-three.md){ .md-button ._blank }

+ 2
- 0
mkdocs.yml Parādīt failu

@@ -121,6 +121,8 @@ nav:
121 121
       - 'AREventType': 'api/ar-event-type.md'
122 122
     - 'Plugins':
123 123
       - 'A-Frame': 'api/plugin-aframe.md'
124
+      - 'Babylon.js': 'api/plugin-babylon.md'
125
+      - 'Three.js': 'api/plugin-three.md'
124 126
     - 'Speedy':
125 127
       - 'Speedy': 'api/speedy.md'
126 128
       - 'SpeedySize': 'api/speedy-size.md'

Notiek ielāde…
Atcelt
Saglabāt