@srsergio/taptapp-ar 1.0.99 → 1.0.100
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 +80 -11
- package/dist/react/types.d.ts +1 -0
- package/dist/react/use-ar.js +2 -1
- package/package.json +1 -1
- package/src/react/types.ts +1 -0
- package/src/react/use-ar.ts +2 -1
package/README.md
CHANGED
|
@@ -123,32 +123,101 @@ export const MyARScene = () => (
|
|
|
123
123
|
);
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
### 2.
|
|
126
|
+
### 2. High-Performance React Hook: `useAR` 🪝
|
|
127
127
|
|
|
128
|
-
For
|
|
128
|
+
For more control over the AR state or custom UI overlays:
|
|
129
129
|
|
|
130
|
-
```
|
|
131
|
-
import {
|
|
130
|
+
```tsx
|
|
131
|
+
import { useAR } from '@srsergio/taptapp-ar/react';
|
|
132
|
+
|
|
133
|
+
const MyCustomAR = () => {
|
|
134
|
+
const {
|
|
135
|
+
containerRef,
|
|
136
|
+
overlayRef,
|
|
137
|
+
status,
|
|
138
|
+
trackedPoints,
|
|
139
|
+
error
|
|
140
|
+
} = useAR({
|
|
141
|
+
targetImageSrc: "target.png",
|
|
142
|
+
scale: 1.0
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<div ref={containerRef} style={{ width: '100%', height: '100vh' }}>
|
|
147
|
+
{/* Your custom 3D or 2D overlay */}
|
|
148
|
+
<video ref={overlayRef} src="content.mp4" />
|
|
149
|
+
|
|
150
|
+
{/* Use trackedPoints for custom visualizations */}
|
|
151
|
+
{trackedPoints.map((p, i) => (
|
|
152
|
+
<div key={i} style={{ position: 'absolute', left: p.x, top: p.y }} />
|
|
153
|
+
))}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
```
|
|
132
158
|
|
|
159
|
+
### 3. Native API: `startTracking`
|
|
160
|
+
|
|
161
|
+
For vanilla JS or custom integrations:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
133
164
|
const tracker = await startTracking({
|
|
134
|
-
targetSrc: './assets/target.jpg',
|
|
165
|
+
targetSrc: './assets/target.jpg',
|
|
135
166
|
container: document.getElementById('ar-container'),
|
|
136
167
|
overlay: document.getElementById('overlay-element'),
|
|
137
168
|
|
|
138
|
-
//
|
|
169
|
+
// 📸 Custom Camera Config
|
|
170
|
+
cameraConfig: {
|
|
171
|
+
facingMode: 'environment', // Use back camera
|
|
172
|
+
width: { ideal: 1920 }, // Request Full HD
|
|
173
|
+
height: { ideal: 1080 }
|
|
174
|
+
},
|
|
175
|
+
|
|
139
176
|
callbacks: {
|
|
140
|
-
onFound: () => console.log("Target Found!
|
|
141
|
-
onLost: () => console.log("Target Lost 👋"),
|
|
177
|
+
onFound: () => console.log("Target Found!"),
|
|
142
178
|
onUpdate: (data) => {
|
|
143
|
-
console.log(
|
|
179
|
+
console.log(`Stability: ${data.avgStability}`);
|
|
144
180
|
}
|
|
145
181
|
}
|
|
146
182
|
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 4. Custom Overlays (Beyond Video/Images) 🧩
|
|
147
186
|
|
|
148
|
-
|
|
149
|
-
|
|
187
|
+
The `overlay` isn't limited to images or videos. You can use **any HTML element** (divs, buttons, canvas, etc.). The engine will apply the transformation matrix automatically to align it with the target.
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
// Using an interactive HTML overlay in React
|
|
191
|
+
const InteractiveAR = () => {
|
|
192
|
+
const { containerRef, overlayRef, status } = useAR({
|
|
193
|
+
targetImageSrc: "map.jpg",
|
|
194
|
+
scale: 1.0
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<div ref={containerRef}>
|
|
199
|
+
{/* 🚀 This div will be pinned and skewed to the physical target */}
|
|
200
|
+
<div
|
|
201
|
+
ref={overlayRef as any}
|
|
202
|
+
style={{ background: 'white', padding: '10px', borderRadius: '8px' }}
|
|
203
|
+
>
|
|
204
|
+
<h4>Dynamic UI</h4>
|
|
205
|
+
<button onClick={() => alert('Clicked!')}>Interacción AR</button>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
};
|
|
150
210
|
```
|
|
151
211
|
|
|
212
|
+
#### `TrackingUpdate` Data Object
|
|
213
|
+
The `onUpdate` callback provides a rich data object:
|
|
214
|
+
- `isTracking`: Boolean status.
|
|
215
|
+
- `avgReliability`: (0-1) Confidence of the match.
|
|
216
|
+
- `avgStability`: (0-1) Movement smoothness.
|
|
217
|
+
- `screenCoords`: Array of `{x, y, id}` of tracked points.
|
|
218
|
+
- `worldMatrix`: 4x4 matrix for WebGL/Three.js integration.
|
|
219
|
+
- `targetDimensions`: `[width, height]` of the source target.
|
|
220
|
+
|
|
152
221
|
### 3. Advanced Integration (Three.js / A-Frame)
|
|
153
222
|
|
|
154
223
|
We still provide wrappers for 3D engines if you need to render complex 3D models instead of DOM overlays.
|
package/dist/react/types.d.ts
CHANGED
package/dist/react/use-ar.js
CHANGED
|
@@ -41,6 +41,7 @@ export const useAR = (config) => {
|
|
|
41
41
|
targetSrc: config.targetTaarSrc || config.targetImageSrc,
|
|
42
42
|
overlay: overlayRef.current,
|
|
43
43
|
scale: config.scale,
|
|
44
|
+
cameraConfig: config.cameraConfig,
|
|
44
45
|
debugMode: false,
|
|
45
46
|
callbacks: {
|
|
46
47
|
onUpdate: (data) => {
|
|
@@ -104,7 +105,7 @@ export const useAR = (config) => {
|
|
|
104
105
|
arInstanceRef.current?.stop();
|
|
105
106
|
arInstanceRef.current = null;
|
|
106
107
|
};
|
|
107
|
-
}, [config.targetTaarSrc, config.targetImageSrc, config.scale]);
|
|
108
|
+
}, [config.targetTaarSrc, config.targetImageSrc, config.scale, config.cameraConfig]);
|
|
108
109
|
return {
|
|
109
110
|
containerRef,
|
|
110
111
|
overlayRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srsergio/taptapp-ar",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.100",
|
|
4
4
|
"description": "Ultra-fast Augmented Reality (AR) SDK for Node.js and Browser. Image tracking with 100% pure JavaScript, zero-dependencies, and high-performance compilation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augmented reality",
|
package/src/react/types.ts
CHANGED
package/src/react/use-ar.ts
CHANGED
|
@@ -65,6 +65,7 @@ export const useAR = (config: ARConfig): UseARReturn => {
|
|
|
65
65
|
targetSrc: config.targetTaarSrc || config.targetImageSrc,
|
|
66
66
|
overlay: overlayRef.current!,
|
|
67
67
|
scale: config.scale,
|
|
68
|
+
cameraConfig: config.cameraConfig,
|
|
68
69
|
debugMode: false,
|
|
69
70
|
callbacks: {
|
|
70
71
|
onUpdate: (data) => {
|
|
@@ -129,7 +130,7 @@ export const useAR = (config: ARConfig): UseARReturn => {
|
|
|
129
130
|
arInstanceRef.current?.stop();
|
|
130
131
|
arInstanceRef.current = null;
|
|
131
132
|
};
|
|
132
|
-
}, [config.targetTaarSrc, config.targetImageSrc, config.scale]);
|
|
133
|
+
}, [config.targetTaarSrc, config.targetImageSrc, config.scale, config.cameraConfig]);
|
|
133
134
|
|
|
134
135
|
return {
|
|
135
136
|
containerRef,
|