@zappar/zappar-cv 2.0.0-beta.1 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/additional.d.ts +2 -1
- package/lib/gen/zappar-native.d.ts +5 -0
- package/lib/gen/zappar-native.js +7 -0
- package/lib/gen/zappar.d.ts +3 -0
- package/lib/gen/zappar.js +1 -0
- package/lib/imagetracker-previewmesh.d.ts +2 -0
- package/lib/imagetracker-previewmesh.js +205 -0
- package/lib/imagetracker.d.ts +16 -2
- package/lib/imagetracker.js +81 -40
- package/lib/native.js +11 -3
- package/lib/sequencesource.d.ts +2 -0
- package/lib/sequencesource.js +8 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/zcv.js +18 -18
- package/lib/zcv.wasm +0 -0
- package/package.json +1 -1
- package/umd/{e486cd197ef362198043.wasm → 018ed03cba70f00e68ff.wasm} +0 -0
- package/umd/752.zappar-cv.js +1 -1
- package/umd/zappar-cv.js +1 -1
- package/umd/zappar-cv.worker.js +1 -1
package/README.md
CHANGED
|
@@ -18,8 +18,8 @@ npm i @zappar/zappar-cv
|
|
|
18
18
|
|
|
19
19
|
You can use our CDN from within your HTML:
|
|
20
20
|
```
|
|
21
|
-
<script src="https://libs.zappar.com/zappar-cv/2.0.0-beta.
|
|
21
|
+
<script src="https://libs.zappar.com/zappar-cv/2.0.0-beta.4/zappar-cv.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
Or you can download and host our standalone JavaScript bundle:
|
|
25
|
-
[https://libs.zappar.com/zappar-cv/2.0.0-beta.
|
|
25
|
+
[https://libs.zappar.com/zappar-cv/2.0.0-beta.4/zappar-cv.zip](https://libs.zappar.com/zappar-cv/2.0.0-beta.4/zappar-cv.zip)
|
package/lib/additional.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { zappar_face_mesh_t, zappar_face_tracker_t, zappar_pipeline_t, zappar_image_tracker_t } from "./gen/zappar";
|
|
1
|
+
import { zappar_face_mesh_t, zappar_face_tracker_t, zappar_pipeline_t, zappar_image_tracker_t, zappar_sequence_source_t } from "./gen/zappar";
|
|
2
2
|
export declare type zappar_html_element_source_t = number & {
|
|
3
3
|
_: 'zappar_html_element_source_t';
|
|
4
4
|
};
|
|
@@ -21,4 +21,5 @@ export interface Additional {
|
|
|
21
21
|
html_element_source_destroy(o: zappar_html_element_source_t): void;
|
|
22
22
|
browser_incompatible: () => boolean;
|
|
23
23
|
browser_incompatible_ui: () => void;
|
|
24
|
+
sequence_source_time_set: (o: zappar_sequence_source_t, ms: number) => void;
|
|
24
25
|
}
|
|
@@ -56,6 +56,11 @@ export declare enum frame_pixel_format_t {
|
|
|
56
56
|
FRAME_PIXEL_FORMAT_BGRA = 6,
|
|
57
57
|
FRAME_PIXEL_FORMAT_Y = 7
|
|
58
58
|
}
|
|
59
|
+
export declare enum image_target_type_t {
|
|
60
|
+
IMAGE_TRACKER_TYPE_PLANAR = 0,
|
|
61
|
+
IMAGE_TRACKER_TYPE_CYLINDRICAL = 1,
|
|
62
|
+
IMAGE_TRACKER_TYPE_CONICAL = 2
|
|
63
|
+
}
|
|
59
64
|
export declare type zappar_pipeline_t = number & {
|
|
60
65
|
_: 'zappar_pipeline_t';
|
|
61
66
|
};
|
package/lib/gen/zappar-native.js
CHANGED
|
@@ -66,3 +66,10 @@ export var frame_pixel_format_t;
|
|
|
66
66
|
frame_pixel_format_t[frame_pixel_format_t["FRAME_PIXEL_FORMAT_Y"] = 7] = "FRAME_PIXEL_FORMAT_Y";
|
|
67
67
|
})(frame_pixel_format_t || (frame_pixel_format_t = {}));
|
|
68
68
|
;
|
|
69
|
+
export var image_target_type_t;
|
|
70
|
+
(function (image_target_type_t) {
|
|
71
|
+
image_target_type_t[image_target_type_t["IMAGE_TRACKER_TYPE_PLANAR"] = 0] = "IMAGE_TRACKER_TYPE_PLANAR";
|
|
72
|
+
image_target_type_t[image_target_type_t["IMAGE_TRACKER_TYPE_CYLINDRICAL"] = 1] = "IMAGE_TRACKER_TYPE_CYLINDRICAL";
|
|
73
|
+
image_target_type_t[image_target_type_t["IMAGE_TRACKER_TYPE_CONICAL"] = 2] = "IMAGE_TRACKER_TYPE_CONICAL";
|
|
74
|
+
})(image_target_type_t || (image_target_type_t = {}));
|
|
75
|
+
;
|
package/lib/gen/zappar.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
|
7
7
|
export { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
8
8
|
import { log_level_t } from "./zappar-native";
|
|
9
9
|
export { log_level_t } from "./zappar-native";
|
|
10
|
+
import { image_target_type_t } from "./zappar-native";
|
|
11
|
+
export { image_target_type_t } from "./zappar-native";
|
|
10
12
|
export declare type zappar_pipeline_t = number & {
|
|
11
13
|
_: 'zappar_pipeline_t';
|
|
12
14
|
};
|
|
@@ -95,6 +97,7 @@ export interface zappar {
|
|
|
95
97
|
image_tracker_target_load_from_memory(o: zappar_image_tracker_t, data: ArrayBuffer): void;
|
|
96
98
|
image_tracker_target_loaded_version(o: zappar_image_tracker_t): number;
|
|
97
99
|
image_tracker_target_count(o: zappar_image_tracker_t): number;
|
|
100
|
+
image_tracker_target_type(o: zappar_image_tracker_t, indx: number): image_target_type_t;
|
|
98
101
|
image_tracker_target_radius_top(o: zappar_image_tracker_t, indx: number): number;
|
|
99
102
|
image_tracker_target_radius_bottom(o: zappar_image_tracker_t, indx: number): number;
|
|
100
103
|
image_tracker_target_side_length(o: zappar_image_tracker_t, indx: number): number;
|
package/lib/gen/zappar.js
CHANGED
|
@@ -3,3 +3,4 @@ export { face_landmark_name_t } from "./zappar-native";
|
|
|
3
3
|
export { frame_pixel_format_t } from "./zappar-native";
|
|
4
4
|
export { instant_world_tracker_transform_orientation_t } from "./zappar-native";
|
|
5
5
|
export { log_level_t } from "./zappar-native";
|
|
6
|
+
export { image_target_type_t } from "./zappar-native";
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { vec2 } from "gl-matrix";
|
|
2
|
+
import { image_target_type_t } from "./gen/zappar-native";
|
|
3
|
+
export function getPreviewMesh(info) {
|
|
4
|
+
switch (info.type) {
|
|
5
|
+
case image_target_type_t.IMAGE_TRACKER_TYPE_PLANAR: return planar(info);
|
|
6
|
+
case image_target_type_t.IMAGE_TRACKER_TYPE_CYLINDRICAL: return cylindrical(info);
|
|
7
|
+
case image_target_type_t.IMAGE_TRACKER_TYPE_CONICAL: return conical(info);
|
|
8
|
+
}
|
|
9
|
+
return defaultMesh();
|
|
10
|
+
}
|
|
11
|
+
function planar(info) {
|
|
12
|
+
const aspectRatio = info.trainedWidth / info.trainedHeight;
|
|
13
|
+
if (isNaN(aspectRatio))
|
|
14
|
+
return defaultMesh();
|
|
15
|
+
const vertices = new Float32Array([
|
|
16
|
+
-1.0 * aspectRatio, -1, 0,
|
|
17
|
+
-1.0 * aspectRatio, 1, 0,
|
|
18
|
+
aspectRatio, 1, 0,
|
|
19
|
+
aspectRatio, -1, 0
|
|
20
|
+
]);
|
|
21
|
+
const indices = new Uint16Array([0, 2, 1, 0, 3, 2]);
|
|
22
|
+
const uvs = new Float32Array([
|
|
23
|
+
0, 0,
|
|
24
|
+
0, 1,
|
|
25
|
+
1, 1,
|
|
26
|
+
1, 0
|
|
27
|
+
]);
|
|
28
|
+
const normals = new Float32Array([
|
|
29
|
+
0, 0, 1,
|
|
30
|
+
0, 0, 1,
|
|
31
|
+
0, 0, 1,
|
|
32
|
+
0, 0, 1,
|
|
33
|
+
]);
|
|
34
|
+
return { vertices, indices, uvs, normals };
|
|
35
|
+
}
|
|
36
|
+
function defaultMesh() {
|
|
37
|
+
return {
|
|
38
|
+
indices: new Uint16Array(0),
|
|
39
|
+
vertices: new Float32Array(0),
|
|
40
|
+
normals: new Float32Array(0),
|
|
41
|
+
uvs: new Float32Array(0)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function cylindrical(info) {
|
|
45
|
+
return generalConical(info, 2, false, 0, 0, 0, vec2.create(), info.trainedWidth / info.trainedHeight);
|
|
46
|
+
}
|
|
47
|
+
function conical(info) {
|
|
48
|
+
const radius_diff = info.topRadius - info.bottomRadius;
|
|
49
|
+
const height_3d = Math.sqrt(info.sideLength * info.sideLength - radius_diff * radius_diff);
|
|
50
|
+
const flip = info.bottomRadius > info.topRadius;
|
|
51
|
+
let aspect_ratio = info.trainedWidth / info.trainedHeight;
|
|
52
|
+
if (isNaN(aspect_ratio))
|
|
53
|
+
aspect_ratio = 1;
|
|
54
|
+
const cone = !(info.bottomRadius > 0) || !(info.topRadius > 0);
|
|
55
|
+
const wide = info.sideLength < (2 * Math.abs(info.topRadius - info.bottomRadius));
|
|
56
|
+
const top_corner = vec2.create();
|
|
57
|
+
const bottom_corner = vec2.create();
|
|
58
|
+
const rotation_center = vec2.create();
|
|
59
|
+
if (cone) {
|
|
60
|
+
if (wide) {
|
|
61
|
+
if (flip) {
|
|
62
|
+
rotation_center[1] = aspect_ratio - 1;
|
|
63
|
+
const omega = Math.acos((2 - aspect_ratio) / aspect_ratio);
|
|
64
|
+
top_corner[0] = aspect_ratio * Math.sin(omega);
|
|
65
|
+
top_corner[1] = (aspect_ratio - 1) + aspect_ratio * Math.cos(omega);
|
|
66
|
+
vec2.copy(bottom_corner, rotation_center);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
rotation_center[1] = 1.0 - aspect_ratio;
|
|
70
|
+
const omega = Math.PI + Math.acos((2 - aspect_ratio) / aspect_ratio);
|
|
71
|
+
top_corner[0] = aspect_ratio * Math.sin(omega);
|
|
72
|
+
top_corner[1] = (1 - aspect_ratio) + aspect_ratio * Math.cos(omega);
|
|
73
|
+
vec2.copy(bottom_corner, rotation_center);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (flip) {
|
|
78
|
+
rotation_center[1] = 1;
|
|
79
|
+
vec2.copy(bottom_corner, rotation_center);
|
|
80
|
+
top_corner[0] = aspect_ratio;
|
|
81
|
+
top_corner[1] = 1 - Math.sqrt(4 - Math.pow(aspect_ratio, 2));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
rotation_center[1] = -1;
|
|
85
|
+
vec2.copy(bottom_corner, rotation_center);
|
|
86
|
+
top_corner[0] = -aspect_ratio;
|
|
87
|
+
top_corner[1] = Math.sqrt(4 - Math.pow(aspect_ratio, 2)) - 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (wide) {
|
|
93
|
+
if (flip) {
|
|
94
|
+
rotation_center[1] = aspect_ratio - 1;
|
|
95
|
+
const omega = Math.acos((2 - aspect_ratio) / aspect_ratio);
|
|
96
|
+
top_corner[0] = aspect_ratio * Math.sin(omega);
|
|
97
|
+
top_corner[1] = (aspect_ratio - 1) + aspect_ratio * Math.cos(omega);
|
|
98
|
+
bottom_corner[0] = (aspect_ratio - info.sideLength) * Math.sin(omega);
|
|
99
|
+
bottom_corner[1] = (aspect_ratio - 1) + (aspect_ratio - info.sideLength) * Math.cos(omega);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
rotation_center[1] = 1.0 - aspect_ratio;
|
|
103
|
+
const omega = Math.PI + Math.acos((2 - aspect_ratio) / aspect_ratio);
|
|
104
|
+
top_corner[0] = aspect_ratio * Math.sin(omega);
|
|
105
|
+
top_corner[1] = (1 - aspect_ratio) + aspect_ratio * Math.cos(omega);
|
|
106
|
+
bottom_corner[0] = (aspect_ratio - info.sideLength) * Math.sin(omega);
|
|
107
|
+
bottom_corner[1] = (1 - aspect_ratio) + (aspect_ratio - info.sideLength) * Math.cos(omega);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
const radius_ratio = flip ? (info.topRadius / info.bottomRadius) : (info.bottomRadius / info.topRadius);
|
|
112
|
+
if (flip) {
|
|
113
|
+
bottom_corner[0] = radius_ratio * aspect_ratio;
|
|
114
|
+
bottom_corner[1] = 1;
|
|
115
|
+
top_corner[0] = aspect_ratio;
|
|
116
|
+
top_corner[1] = 1 - Math.sqrt((info.sideLength * info.sideLength) - ((bottom_corner[0] - top_corner[0]) * (bottom_corner[0] - top_corner[0])));
|
|
117
|
+
rotation_center[1] = top_corner[1] + (top_corner[0] / (top_corner[0] - bottom_corner[0])) * (bottom_corner[1] - top_corner[1]);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
bottom_corner[0] = -radius_ratio * aspect_ratio;
|
|
121
|
+
bottom_corner[1] = -1;
|
|
122
|
+
top_corner[0] = -aspect_ratio;
|
|
123
|
+
top_corner[1] = Math.sqrt((info.sideLength * info.sideLength) - ((bottom_corner[0] - top_corner[0]) * (bottom_corner[0] - top_corner[0]))) - 1;
|
|
124
|
+
rotation_center[1] = top_corner[1] - (-top_corner[0] / (bottom_corner[0] - top_corner[0])) * (top_corner[1] - bottom_corner[1]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const top_from_center = vec2.create();
|
|
129
|
+
vec2.subtract(top_from_center, top_corner, rotation_center);
|
|
130
|
+
const bottom_from_center = vec2.create();
|
|
131
|
+
vec2.subtract(bottom_from_center, bottom_corner, rotation_center);
|
|
132
|
+
const top_2d_radius = vec2.length(top_from_center);
|
|
133
|
+
const bottom_2d_radius = vec2.length(bottom_from_center);
|
|
134
|
+
let theta = Math.abs(Math.atan(top_from_center[0] / top_from_center[1]));
|
|
135
|
+
if (wide)
|
|
136
|
+
theta = Math.PI - theta;
|
|
137
|
+
return generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio);
|
|
138
|
+
}
|
|
139
|
+
function generalConical(info, height_3d, flip, theta, bottom_2d_radius, top_2d_radius, rotation_center, aspect_ratio) {
|
|
140
|
+
if (isNaN(aspect_ratio))
|
|
141
|
+
aspect_ratio = 1;
|
|
142
|
+
const vertices = [];
|
|
143
|
+
const uvs = [];
|
|
144
|
+
const scale_factor = 2.0 / height_3d;
|
|
145
|
+
const subdivisons = 64;
|
|
146
|
+
for (let s = 0; s <= subdivisons; ++s) {
|
|
147
|
+
const angle = s * 2.0 * Math.PI / subdivisons;
|
|
148
|
+
const bx = info.bottomRadius * Math.sin(angle) * scale_factor;
|
|
149
|
+
const bz = info.bottomRadius * Math.cos(angle) * scale_factor;
|
|
150
|
+
const tx = info.topRadius * Math.sin(angle) * scale_factor;
|
|
151
|
+
const tz = info.topRadius * Math.cos(angle) * scale_factor;
|
|
152
|
+
const btm = -1;
|
|
153
|
+
const top = 1;
|
|
154
|
+
if (flip) {
|
|
155
|
+
vertices.push(bx, btm, bz);
|
|
156
|
+
vertices.push(tx, top, tz);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
vertices.push(tx, top, -tz);
|
|
160
|
+
vertices.push(bx, btm, -bz);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (let s = 0; s <= subdivisons; ++s) {
|
|
164
|
+
if (info.type == image_target_type_t.IMAGE_TRACKER_TYPE_CYLINDRICAL) {
|
|
165
|
+
const offset = 1 - (s / subdivisons);
|
|
166
|
+
uvs.push(offset, 1);
|
|
167
|
+
uvs.push(offset, 0);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
let angle_2d = -((s / subdivisons) - 0.5) * 2 * theta;
|
|
171
|
+
if (flip) {
|
|
172
|
+
angle_2d = -angle_2d + theta;
|
|
173
|
+
if (angle_2d > theta)
|
|
174
|
+
angle_2d = -theta + (angle_2d - theta);
|
|
175
|
+
}
|
|
176
|
+
const direction = vec2.create();
|
|
177
|
+
direction[0] = Math.sin(angle_2d);
|
|
178
|
+
direction[1] = Math.cos(angle_2d);
|
|
179
|
+
if (flip)
|
|
180
|
+
direction[1] *= -1;
|
|
181
|
+
const bottom_px = vec2.create();
|
|
182
|
+
vec2.copy(bottom_px, direction);
|
|
183
|
+
vec2.scale(bottom_px, bottom_px, bottom_2d_radius);
|
|
184
|
+
vec2.add(bottom_px, rotation_center, bottom_px);
|
|
185
|
+
const top_px = vec2.create();
|
|
186
|
+
vec2.copy(top_px, direction);
|
|
187
|
+
vec2.scale(top_px, top_px, top_2d_radius);
|
|
188
|
+
vec2.add(top_px, rotation_center, top_px);
|
|
189
|
+
uvs.push((top_px[0] + aspect_ratio) / (2 * aspect_ratio), 1 - ((-top_px[1] + 1) / 2));
|
|
190
|
+
uvs.push((bottom_px[0] + aspect_ratio) / (2 * aspect_ratio), 1 - ((-bottom_px[1] + 1) / 2));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const indices = [];
|
|
194
|
+
for (let i = 0; i < subdivisons; ++i) {
|
|
195
|
+
const bi = i * 2;
|
|
196
|
+
indices.push(bi + 1, bi + 2, bi + 3);
|
|
197
|
+
indices.push(bi + 0, bi + 2, bi + 1);
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
vertices: new Float32Array(vertices),
|
|
201
|
+
indices: new Uint16Array(indices),
|
|
202
|
+
normals: new Float32Array(0),
|
|
203
|
+
uvs: new Float32Array(uvs)
|
|
204
|
+
};
|
|
205
|
+
}
|
package/lib/imagetracker.d.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { zappar_image_tracker_t, zappar_pipeline_t } from "./gen/zappar";
|
|
2
|
-
import { zappar_cwrap } from "./gen/zappar-native";
|
|
2
|
+
import { image_target_type_t, zappar_cwrap } from "./gen/zappar-native";
|
|
3
3
|
interface PreviewInfo {
|
|
4
4
|
compressed: Uint8Array;
|
|
5
5
|
mimeType: string;
|
|
6
|
+
image?: HTMLImageElement;
|
|
6
7
|
}
|
|
7
|
-
interface
|
|
8
|
+
export interface PreviewMesh {
|
|
9
|
+
indices: Uint16Array;
|
|
10
|
+
vertices: Float32Array;
|
|
11
|
+
normals: Float32Array;
|
|
12
|
+
uvs: Float32Array;
|
|
13
|
+
}
|
|
14
|
+
export interface ParsedTargetInfo {
|
|
8
15
|
preview?: PreviewInfo;
|
|
16
|
+
previewMesh?: PreviewMesh;
|
|
9
17
|
physicalScaleFactor: number;
|
|
10
18
|
topRadius: number;
|
|
11
19
|
bottomRadius: number;
|
|
12
20
|
sideLength: number;
|
|
21
|
+
type: image_target_type_t;
|
|
22
|
+
trainedWidth: number;
|
|
23
|
+
trainedHeight: number;
|
|
13
24
|
}
|
|
14
25
|
export declare class ImageTracker {
|
|
15
26
|
private _client;
|
|
@@ -23,6 +34,9 @@ export declare class ImageTracker {
|
|
|
23
34
|
targetCount(): number;
|
|
24
35
|
getTargetInfo(i: number): ParsedTargetInfo;
|
|
25
36
|
private _parseOdle;
|
|
37
|
+
private _parseOdleV1;
|
|
38
|
+
private _parseOdleV3;
|
|
26
39
|
getDecodedPreview(i: number): HTMLImageElement | undefined;
|
|
40
|
+
getPreviewMesh(i: number): PreviewMesh;
|
|
27
41
|
}
|
|
28
42
|
export {};
|
package/lib/imagetracker.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { image_target_type_t } from "./gen/zappar-native";
|
|
2
|
+
import { getPreviewMesh } from "./imagetracker-previewmesh";
|
|
1
3
|
import { RiffReader } from "./riff-reader";
|
|
2
4
|
let byId = new Map();
|
|
3
5
|
const decoder = new TextDecoder();
|
|
@@ -34,7 +36,10 @@ export class ImageTracker {
|
|
|
34
36
|
topRadius: -1,
|
|
35
37
|
bottomRadius: -1,
|
|
36
38
|
sideLength: -1,
|
|
37
|
-
physicalScaleFactor: -1
|
|
39
|
+
physicalScaleFactor: -1,
|
|
40
|
+
trainedWidth: 0,
|
|
41
|
+
trainedHeight: 0,
|
|
42
|
+
type: image_target_type_t.IMAGE_TRACKER_TYPE_PLANAR
|
|
38
43
|
};
|
|
39
44
|
try {
|
|
40
45
|
const reader = new RiffReader(current.data, false);
|
|
@@ -59,54 +64,90 @@ export class ImageTracker {
|
|
|
59
64
|
let currentOffset = 0;
|
|
60
65
|
let version = "0";
|
|
61
66
|
[version, currentOffset] = readLine(currentOffset, data);
|
|
62
|
-
if (version === "
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
if (version === "1")
|
|
68
|
+
return this._parseOdleV1(data, currentOffset, info);
|
|
69
|
+
else if (version === "3")
|
|
70
|
+
return this._parseOdleV3(data, currentOffset, info);
|
|
71
|
+
}
|
|
72
|
+
_parseOdleV1(data, currentOffset, info) {
|
|
73
|
+
let treeOrFlat = "0";
|
|
74
|
+
[treeOrFlat, currentOffset] = readLine(currentOffset, data);
|
|
75
|
+
if (treeOrFlat !== "0" && treeOrFlat !== "1")
|
|
76
|
+
return;
|
|
77
|
+
let emptyLine = "";
|
|
78
|
+
[emptyLine, currentOffset] = readLine(currentOffset, data);
|
|
79
|
+
if (emptyLine.length !== 0)
|
|
80
|
+
return;
|
|
81
|
+
let infoLine = "";
|
|
82
|
+
[infoLine, currentOffset] = readLine(currentOffset, data);
|
|
83
|
+
const infoLineParts = infoLine.split(" ");
|
|
84
|
+
if (infoLineParts.length < 5)
|
|
85
|
+
return;
|
|
86
|
+
info.trainedWidth = parseInt(infoLineParts[3].replace("[", ""));
|
|
87
|
+
info.trainedHeight = parseInt(infoLineParts[4].replace("]", ""));
|
|
88
|
+
}
|
|
89
|
+
_parseOdleV3(data, currentOffset, info) {
|
|
90
|
+
let treeOrFlat = "0";
|
|
91
|
+
[treeOrFlat, currentOffset] = readLine(currentOffset, data);
|
|
92
|
+
if (treeOrFlat !== "0" && treeOrFlat !== "1")
|
|
93
|
+
return;
|
|
94
|
+
let numberTargets = "0";
|
|
95
|
+
[numberTargets, currentOffset] = readLine(currentOffset, data);
|
|
96
|
+
const parsedTargets = parseInt(numberTargets);
|
|
97
|
+
if (isNaN(parsedTargets) || parsedTargets < 1)
|
|
98
|
+
return;
|
|
99
|
+
let emptyLine = "";
|
|
100
|
+
[emptyLine, currentOffset] = readLine(currentOffset, data);
|
|
101
|
+
if (emptyLine.length !== 0)
|
|
102
|
+
return;
|
|
103
|
+
let infoLine = "";
|
|
104
|
+
[infoLine, currentOffset] = readLine(currentOffset, data);
|
|
105
|
+
const infoLineParts = infoLine.split(" ");
|
|
106
|
+
if (infoLineParts.length < 6)
|
|
107
|
+
return;
|
|
108
|
+
const targetType = parseInt(infoLineParts[0]);
|
|
109
|
+
if (targetType === 0 || targetType === 1 || targetType === 2)
|
|
110
|
+
info.type = targetType;
|
|
111
|
+
info.trainedWidth = parseInt(infoLineParts[4].replace("[", ""));
|
|
112
|
+
info.trainedHeight = parseInt(infoLineParts[5].replace("]", ""));
|
|
113
|
+
if (infoLineParts.length >= 7) {
|
|
81
114
|
info.physicalScaleFactor = parseFloat(infoLineParts[6]);
|
|
82
115
|
if (isNaN(info.physicalScaleFactor))
|
|
83
116
|
info.physicalScaleFactor = -1;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
info.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
117
|
+
}
|
|
118
|
+
if (infoLineParts.length >= 8) {
|
|
119
|
+
info.topRadius = parseFloat(infoLineParts[7]);
|
|
120
|
+
if (isNaN(info.topRadius))
|
|
121
|
+
info.topRadius = -1;
|
|
122
|
+
info.bottomRadius = info.topRadius;
|
|
123
|
+
}
|
|
124
|
+
if (infoLineParts.length >= 9) {
|
|
125
|
+
info.bottomRadius = parseFloat(infoLineParts[8]);
|
|
126
|
+
if (isNaN(info.bottomRadius))
|
|
127
|
+
info.bottomRadius = -1;
|
|
128
|
+
}
|
|
129
|
+
if (infoLineParts.length >= 10) {
|
|
130
|
+
info.sideLength = parseFloat(infoLineParts[9]);
|
|
131
|
+
if (isNaN(info.sideLength))
|
|
132
|
+
info.sideLength = -1;
|
|
100
133
|
}
|
|
101
134
|
}
|
|
102
135
|
getDecodedPreview(i) {
|
|
103
136
|
const info = this.getTargetInfo(i);
|
|
104
137
|
if (!info.preview)
|
|
105
138
|
return undefined;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
139
|
+
if (!info.preview.image) {
|
|
140
|
+
const blob = new Blob([info.preview.compressed], { type: info.preview.mimeType });
|
|
141
|
+
info.preview.image = new Image();
|
|
142
|
+
info.preview.image.src = URL.createObjectURL(blob);
|
|
143
|
+
}
|
|
144
|
+
return info.preview.image;
|
|
145
|
+
}
|
|
146
|
+
getPreviewMesh(i) {
|
|
147
|
+
const info = this.getTargetInfo(i);
|
|
148
|
+
if (!info.previewMesh)
|
|
149
|
+
info.previewMesh = getPreviewMesh(info);
|
|
150
|
+
return info.previewMesh;
|
|
110
151
|
}
|
|
111
152
|
}
|
|
112
153
|
function readLine(offset, str) {
|
package/lib/native.js
CHANGED
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { image_target_type_t } from "./gen/zappar";
|
|
10
11
|
import { zappar_client } from "./gen/zappar-client";
|
|
11
12
|
import { drawPlane } from "./drawplane";
|
|
12
13
|
import { cameraRotationForScreenOrientation, projectionMatrix } from "./cameramodel";
|
|
@@ -39,7 +40,7 @@ export function initialize(opts) {
|
|
|
39
40
|
d: ab
|
|
40
41
|
}, [ab]);
|
|
41
42
|
});
|
|
42
|
-
if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0) {
|
|
43
|
+
if (window.location.hostname.toLowerCase().indexOf(".zappar.io") > 0 || window.location.hostname.toLowerCase().indexOf(".webar.run") > 0) {
|
|
43
44
|
let pathParts = window.location.pathname.split("/");
|
|
44
45
|
if (pathParts.length > 1 && pathParts[1].length > 0)
|
|
45
46
|
c.impl.analytics_project_id_set(".wiz" + pathParts[1]);
|
|
@@ -165,7 +166,14 @@ export function initialize(opts) {
|
|
|
165
166
|
let rawVec = vec3.create();
|
|
166
167
|
vec3.transformMat4(rawVec, [x, y, z], rotationMat);
|
|
167
168
|
c.impl.instant_world_tracker_anchor_pose_set_from_camera_offset_raw(o, rawVec[0], rawVec[1], rawVec[2], orientation);
|
|
168
|
-
}, image_tracker_create: pipeline => ImageTracker.create(pipeline, c.impl), image_tracker_destroy: t => { var _a; return (_a = ImageTracker.get(t)) === null || _a === void 0 ? void 0 : _a.destroy(); },
|
|
169
|
+
}, image_tracker_create: pipeline => ImageTracker.create(pipeline, c.impl), image_tracker_destroy: t => { var _a; return (_a = ImageTracker.get(t)) === null || _a === void 0 ? void 0 : _a.destroy(); }, image_tracker_target_type: (t, i) => {
|
|
170
|
+
let obj = ImageTracker.get(t);
|
|
171
|
+
if (!obj) {
|
|
172
|
+
zcwarn("attempting to call image_tracker_target_type on a destroyed zappar_image_tracker_t");
|
|
173
|
+
return image_target_type_t.IMAGE_TRACKER_TYPE_PLANAR;
|
|
174
|
+
}
|
|
175
|
+
return obj.getTargetInfo(i).type;
|
|
176
|
+
}, image_tracker_target_count: t => {
|
|
169
177
|
let obj = ImageTracker.get(t);
|
|
170
178
|
if (!obj) {
|
|
171
179
|
zcwarn("attempting to call image_tracker_target_count on a destroyed zappar_image_tracker_t");
|
|
@@ -404,7 +412,7 @@ export function initialize(opts) {
|
|
|
404
412
|
return mat4.create();
|
|
405
413
|
}
|
|
406
414
|
return obj.anchor_pose;
|
|
407
|
-
}, html_element_source_create: (pipeline, elm) => HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_destroy: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permissionGrantedAll, permission_granted_camera: permissionGrantedCamera, permission_granted_motion: permissionGrantedMotion, permission_denied_any: permissionDeniedAny, permission_denied_camera: permissionDeniedCamera, permission_denied_motion: permissionDeniedMotion, permission_request_motion: permissionRequestMotion, permission_request_camera: permissionRequestCamera, permission_request_all: permissionRequestAll, permission_request_ui: permissionRequestUI, permission_request_ui_promise: permissionRequestUI, permission_denied_ui: permissionDeniedUI, browser_incompatible: compatibility.incompatible, browser_incompatible_ui: compatibility.incompatible_ui, log_level_set: l => {
|
|
415
|
+
}, html_element_source_create: (pipeline, elm) => HTMLElementSource.createVideoElementSource(pipeline, elm), html_element_source_start: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.start(); }, html_element_source_pause: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, html_element_source_destroy: o => { var _a; return (_a = HTMLElementSource.getVideoElementSource(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, sequence_source_create: p => SequenceSource.create(p), sequence_source_load_from_memory: (o, data) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.loadFromMemory(data); }, sequence_source_pause: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.pause(); }, sequence_source_start: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.start(); }, sequence_source_max_playback_fps_set: (o, fps) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.maxPlaybackFpsSet(fps); }, sequence_source_time_set: (o, t) => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.setTime(t); }, sequence_source_destroy: o => { var _a; return (_a = SequenceSource.get(o)) === null || _a === void 0 ? void 0 : _a.destroy(); }, permission_granted_all: permissionGrantedAll, permission_granted_camera: permissionGrantedCamera, permission_granted_motion: permissionGrantedMotion, permission_denied_any: permissionDeniedAny, permission_denied_camera: permissionDeniedCamera, permission_denied_motion: permissionDeniedMotion, permission_request_motion: permissionRequestMotion, permission_request_camera: permissionRequestCamera, permission_request_all: permissionRequestAll, permission_request_ui: permissionRequestUI, permission_request_ui_promise: permissionRequestUI, permission_denied_ui: permissionDeniedUI, browser_incompatible: compatibility.incompatible, browser_incompatible_ui: compatibility.incompatible_ui, log_level_set: l => {
|
|
408
416
|
setLogLevel(l);
|
|
409
417
|
c.impl.log_level_set(l);
|
|
410
418
|
} });
|
package/lib/sequencesource.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ export declare class SequenceSource extends Source {
|
|
|
9
9
|
private _decoder;
|
|
10
10
|
private _minFrameGapMs;
|
|
11
11
|
private _lastUpdateTime;
|
|
12
|
+
private _time;
|
|
12
13
|
static create(p: zappar_pipeline_t): zappar_sequence_source_t;
|
|
13
14
|
static get(m: zappar_sequence_source_t): SequenceSource | undefined;
|
|
14
15
|
constructor(_impl: zappar_sequence_source_t, _pipeline: zappar_pipeline_t);
|
|
15
16
|
loadFromMemory(data: ArrayBuffer): void;
|
|
16
17
|
maxPlaybackFpsSet(fps: number): void;
|
|
18
|
+
setTime(t: number): void;
|
|
17
19
|
getFrame(currentlyProcessing: boolean): void;
|
|
18
20
|
destroy(): void;
|
|
19
21
|
start(): void;
|
package/lib/sequencesource.js
CHANGED
|
@@ -42,7 +42,14 @@ export class SequenceSource extends Source {
|
|
|
42
42
|
}
|
|
43
43
|
this._minFrameGapMs = 1000.0 / fps;
|
|
44
44
|
}
|
|
45
|
+
setTime(t) {
|
|
46
|
+
if (t < 0)
|
|
47
|
+
delete this._time;
|
|
48
|
+
else
|
|
49
|
+
this._time = t;
|
|
50
|
+
}
|
|
45
51
|
getFrame(currentlyProcessing) {
|
|
52
|
+
var _a;
|
|
46
53
|
let pipeline = Pipeline.get(this._pipeline);
|
|
47
54
|
if (!pipeline)
|
|
48
55
|
return;
|
|
@@ -53,7 +60,7 @@ export class SequenceSource extends Source {
|
|
|
53
60
|
return;
|
|
54
61
|
if (currentlyProcessing)
|
|
55
62
|
return;
|
|
56
|
-
let curTime = performance.now();
|
|
63
|
+
let curTime = (_a = this._time) !== null && _a !== void 0 ? _a : performance.now();
|
|
57
64
|
if (curTime < this._lastUpdateTime + this._minFrameGapMs)
|
|
58
65
|
return;
|
|
59
66
|
if (this._packetNumber >= this._decoder.numberPackets)
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.4";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.4";
|