Skip to content

Commit 2aea1e8

Browse files
doc++
1 parent c13ca5c commit 2aea1e8

File tree

3 files changed

+91
-26
lines changed

3 files changed

+91
-26
lines changed

Diff for: docs/api.md

+89-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ AR API
33

44
[🔙](../README.md)
55

6-
TODO all features of ARCommonNode, ARAddOptions, ARImageTrackingActions, etc
7-
86
The easiest way to obtain a reference to the `AR` object is by grabbing it from the `arLoaded` event you bind in the view:
97

108
```typescript
@@ -19,21 +17,23 @@ class MyModel {
1917
}
2018
```
2119

22-
Then call one of the functions below, like `this.ar.addModel({})`:
20+
Then call one of the 'add*' functions below, like `this.ar.addModel()`:
2321

2422
- [add*](#add)
25-
2623
- [addNode](#addnode)
2724
- [addModel](#addmodel)
2825
- [addBox](#addbox)
26+
- [addPlane](#addplane)
2927
- [addSphere](#addsphere)
3028
- [addTube](#addtube)
3129
- [addText](#addtext)
3230
- [addImage](#addimage)
31+
- [addVideo](#addvideo)
3332
- [addUIView](#adduiview)
3433

34+
Or one of the other functions:
35+
- [trackImage](#trackimage)
3536
- [isSupported](#issupported-static)
36-
3737
- [grabScreenshot](#grabscreenshot-ios)
3838

3939
## `add*`
@@ -54,6 +54,11 @@ position: ARPosition = {
5454
}
5555
```
5656

57+
#### `parentNode`
58+
Instead of adding a node relative to the camera, you can add it to another node that's already part of the scene.
59+
60+
We leverage this feature in the Solar System demo by [adding life to planets](https://github.com/EddyVerbruggen/nativescript-ar/blob/77d1d4585f0f92aa2d6f6de494c528f7895e2b28/demo-solarsystem/app/components/App.vue#L350).
61+
5762
#### `scale` (optional)
5863
This can either be a `number` or an `ARScale`:
5964

@@ -83,7 +88,16 @@ rotation: ARRotation = {
8388
}
8489
```
8590

86-
#### `mass` (optional, iOS only)
91+
#### `draggingEnabled`
92+
Set this to `true` to enable moving objects around.
93+
94+
#### `rotatingEnabled`
95+
Set this to `true` to enable rotating objects.
96+
97+
#### `scalingEnabled`
98+
Set this to `true` to enable scaling of objects.
99+
100+
#### `mass` (iOS only)
87101
By default objects don't have a mass so they're not subject to gravity and don't 'fall'.
88102

89103
If you want the object to fall you may also want to increase the `position.y` (for a higher drop).
@@ -269,6 +283,23 @@ ar.addBox({
269283
}).then(arNode => console.log("Box was added"));
270284
```
271285

286+
## `addPlane`
287+
Add
288+
```typescript
289+
import { ARNodeInteraction } from "nativescript-ar";
290+
import { Color } from "tns-core-modules/color";
291+
292+
ar.addPlane({
293+
position: {
294+
x: 1,
295+
y: 1,
296+
z: 1
297+
},
298+
dimensions: 1,
299+
materials: [new Color("green")],
300+
});
301+
```
302+
272303
## `addSphere`
273304
<img src="images/scnsphere.png" width="316px"/>
274305

@@ -382,6 +413,32 @@ ar.addImage({
382413
});
383414
```
384415

416+
## `addVideo`
417+
418+
```typescript
419+
import { isIOS } from "tns-core-modules/platform";
420+
421+
ar.addVideo({
422+
position: {
423+
x: args.position.x,
424+
y: args.position.y + 0.7,
425+
z: args.position.z
426+
},
427+
// you can use either a local or remote video, but beware: sometimes sample-videos.com is down, or your device can have slow Internet
428+
video: isIOS ? "art.scnassets/celebration.mp4" : "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_5mb.mp4",
429+
onTap: (interaction: ARNodeInteraction) => {
430+
const node = <ARVideoNode>interaction.node;
431+
if (node.isPlaying()) {
432+
node.pause();
433+
} else {
434+
node.play();
435+
}
436+
}
437+
}).catch(console.error);
438+
```
439+
440+
As you can see in the example above, the returned `ARVideoNode` provides these methods for further interaction: `isPlaying`, `pause`, `play`.
441+
385442
## `addUIView`
386443
This one is a bit tricky and requires some tinkering with sizes and positioning because the rendered view may differ a bit between platforms.
387444

@@ -434,6 +491,32 @@ ar.addUIView({
434491

435492
For more details, please see [this implementation](https://github.com/EddyVerbruggen/nativescript-ar/blob/master/demo-solarsystem/app/components/App.vue) in the Solar System demo app.
436493

494+
## `trackImage`
495+
You can either track images by providing an image bundle [like so](https://github.com/EddyVerbruggen/nativescript-ar/blob/c13ca5c000a660069ee74506330be41e74b565e3/demo-pokemon/src/app/search-by-card/search-by-card.component.html#L38),
496+
but also non-bundled images (even from the web!) by using this `trackImage` function.
497+
498+
> On iOS this is supported with `trackingMode` either `WORLD` or `IMAGE`. On Android only with `IMAGE`.
499+
500+
```typescript
501+
import { ARTrackingImageDetectedEventData } from "nativescript-ar";
502+
import { isIOS } from "tns-core-modules/platform";
503+
504+
ar.trackImage({
505+
image: "https://raw.githubusercontent.com/EddyVerbruggen/nativescript-ar/master/demo/app/App_Resources/Android/src/main/assets/tnsgranite-diffuse.png",
506+
onDetectedImage: (args: ARTrackingImageDetectedEventData) => {
507+
args.imageTrackingActions.addModel({
508+
name: isIOS ? "Models.scnassets/Car.dae" : "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF-Binary/DamagedHelmet.glb",
509+
position: {
510+
x: args.position.x,
511+
y: args.position.y,
512+
z: args.position.z - 0.1
513+
},
514+
scale: 0.1
515+
});
516+
}
517+
});
518+
```
519+
437520
## `isSupported` (static)
438521
Check whether or not the device is AR-capable.
439522

Diff for: src/ar-common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export abstract class AR extends ContentView {
381381

382382
abstract addNode(options: ARAddOptions): Promise<ARCommonNode>;
383383

384-
abstract addPlane(options: ARAddOptions): Promise<ARCommonNode>;
384+
abstract addPlane(options: ARAddPlaneOptions): Promise<ARCommonNode>;
385385

386386
abstract addModel(options: ARAddModelOptions): Promise<ARCommonNode>;
387387

Diff for: src/imagefragment.android.ts

+1-19
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
5656
return true;
5757
}
5858

59-
6059
public addImagesInFolder(name: string, imageWidthMeters?: number) {
61-
console.log("Add folder: " + name);
62-
63-
6460
let width = imageWidthMeters || -1;
6561

6662
const context = utils.ad.getApplicationContext();
@@ -72,17 +68,14 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
7268
list = assetManager.list(name);
7369
}
7470

75-
console.log(list.length + ": " + name);
7671
let path;
7772
let file;
7873

79-
8074
for (let i = 0; i < list.length; i++) {
8175
file = list[i];
8276
path = name + "/" + file;
8377

8478
if (path.indexOf('.imgdb') > 0) {
85-
8679
this.loadImgDatabase(path);
8780
return;
8881
}
@@ -106,28 +99,20 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
10699
path = name + "/" + file;
107100

108101
if (path.indexOf('.jpg') > 0 || path.indexOf('.png') > 0) {
109-
110102
let assetName = path.split('/').pop().split('.').slice(0, -1).join('.');
111103
this.addImage(path, assetName, width);
112104

113105
} else {
114-
115106
let length = assetManager.list(path).length;
116-
console.log(path + ": " + length);
117107
if (length) {
118108
this.addImagesInFolder(path, width);
119109
}
120110
}
121111
}
122-
123112
}
124113

125-
126114
private loadImgDatabase(asset: string) {
127115
try {
128-
129-
console.log("found asset db");
130-
131116
const context = utils.ad.getApplicationContext();
132117
const assetManager = context.getAssets();
133118
let is = assetManager.open(asset);
@@ -136,11 +121,9 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
136121
this.session.configure(this.config);
137122
return;
138123

139-
140124
} catch (e) {
141125
console.error(e);
142126
}
143-
144127
}
145128

146129
private readContentWidth(asset: string) {
@@ -188,7 +171,6 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
188171
}
189172

190173
private addBitmap(augmentedImageBitmap, name: string, imageWidthMeters: number) {
191-
console.log("augmentedImageBitmap: " + augmentedImageBitmap);
192174
if (augmentedImageBitmap == null) {
193175
console.log('error loading asset: ' + name);
194176
return;
@@ -251,4 +233,4 @@ export class TNSArFragmentForImageDetection extends com.google.ar.sceneform.ux.A
251233
}));
252234

253235
}
254-
}
236+
}

0 commit comments

Comments
 (0)