glasses-tryon-core 1.1.0
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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +564 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +527 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 brusae
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# glasses-tryon-core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic AR engine for virtual glasses try-on.
|
|
4
|
+
|
|
5
|
+
Uses MediaPipe FaceMesh and Three.js to detect facial landmarks, estimate head pose, and overlay 3D glasses models in real time via webcam.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install glasses-tryon-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
See the main repository README for full usage and integration examples.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
interface CameraIntrinsics {
|
|
4
|
+
fx: number;
|
|
5
|
+
fy: number;
|
|
6
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** A single normalized landmark from MediaPipe FaceMesh. */
|
|
11
|
+
interface FaceLandmark {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pose data in pixel space, ready to apply directly to a Three.js model.
|
|
19
|
+
*/
|
|
20
|
+
interface FacePose {
|
|
21
|
+
/** Eye midpoint position in pixel coords (negated for Three.js ortho scene) */
|
|
22
|
+
position: THREE.Vector3;
|
|
23
|
+
/** Orientation quaternion built from real face axes */
|
|
24
|
+
quaternion: THREE.Quaternion;
|
|
25
|
+
/** Uniform scale factor for the glasses model */
|
|
26
|
+
scale: number;
|
|
27
|
+
}
|
|
28
|
+
/** Optional overrides consumers can pass in. */
|
|
29
|
+
interface AlignmentConfig {
|
|
30
|
+
glassesScaleFactor?: number;
|
|
31
|
+
glassesZ?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface GlassesViewerOptions {
|
|
35
|
+
container: HTMLElement;
|
|
36
|
+
model?: {
|
|
37
|
+
url: string;
|
|
38
|
+
scale?: number;
|
|
39
|
+
offset?: {
|
|
40
|
+
x?: number;
|
|
41
|
+
y?: number;
|
|
42
|
+
z?: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
tracking?: {
|
|
46
|
+
smoothingFactor?: number;
|
|
47
|
+
};
|
|
48
|
+
render?: {
|
|
49
|
+
maxFPS?: number;
|
|
50
|
+
pixelRatio?: number;
|
|
51
|
+
};
|
|
52
|
+
debug?: boolean;
|
|
53
|
+
alignmentConfig?: AlignmentConfig;
|
|
54
|
+
}
|
|
55
|
+
declare class GlassesViewer {
|
|
56
|
+
options: GlassesViewerOptions;
|
|
57
|
+
private camera?;
|
|
58
|
+
private calibration?;
|
|
59
|
+
private faceMeshRunner?;
|
|
60
|
+
private geometryEstimator?;
|
|
61
|
+
private sceneManager?;
|
|
62
|
+
private listeners;
|
|
63
|
+
private _lastFaceState;
|
|
64
|
+
private _running;
|
|
65
|
+
private _rafId;
|
|
66
|
+
private _maxFPS;
|
|
67
|
+
private _lastFrameTime;
|
|
68
|
+
constructor(options: GlassesViewerOptions);
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
private loadModel;
|
|
71
|
+
private loop;
|
|
72
|
+
destroy(): void;
|
|
73
|
+
on(event: string, cb: (...args: unknown[]) => void): void;
|
|
74
|
+
off(event: string, cb: (...args: unknown[]) => void): void;
|
|
75
|
+
private emit;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type AlignmentConfig, type CameraIntrinsics, type FaceLandmark, type FacePose, GlassesViewer, type GlassesViewerOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
interface CameraIntrinsics {
|
|
4
|
+
fx: number;
|
|
5
|
+
fy: number;
|
|
6
|
+
cx: number;
|
|
7
|
+
cy: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** A single normalized landmark from MediaPipe FaceMesh. */
|
|
11
|
+
interface FaceLandmark {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Pose data in pixel space, ready to apply directly to a Three.js model.
|
|
19
|
+
*/
|
|
20
|
+
interface FacePose {
|
|
21
|
+
/** Eye midpoint position in pixel coords (negated for Three.js ortho scene) */
|
|
22
|
+
position: THREE.Vector3;
|
|
23
|
+
/** Orientation quaternion built from real face axes */
|
|
24
|
+
quaternion: THREE.Quaternion;
|
|
25
|
+
/** Uniform scale factor for the glasses model */
|
|
26
|
+
scale: number;
|
|
27
|
+
}
|
|
28
|
+
/** Optional overrides consumers can pass in. */
|
|
29
|
+
interface AlignmentConfig {
|
|
30
|
+
glassesScaleFactor?: number;
|
|
31
|
+
glassesZ?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface GlassesViewerOptions {
|
|
35
|
+
container: HTMLElement;
|
|
36
|
+
model?: {
|
|
37
|
+
url: string;
|
|
38
|
+
scale?: number;
|
|
39
|
+
offset?: {
|
|
40
|
+
x?: number;
|
|
41
|
+
y?: number;
|
|
42
|
+
z?: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
tracking?: {
|
|
46
|
+
smoothingFactor?: number;
|
|
47
|
+
};
|
|
48
|
+
render?: {
|
|
49
|
+
maxFPS?: number;
|
|
50
|
+
pixelRatio?: number;
|
|
51
|
+
};
|
|
52
|
+
debug?: boolean;
|
|
53
|
+
alignmentConfig?: AlignmentConfig;
|
|
54
|
+
}
|
|
55
|
+
declare class GlassesViewer {
|
|
56
|
+
options: GlassesViewerOptions;
|
|
57
|
+
private camera?;
|
|
58
|
+
private calibration?;
|
|
59
|
+
private faceMeshRunner?;
|
|
60
|
+
private geometryEstimator?;
|
|
61
|
+
private sceneManager?;
|
|
62
|
+
private listeners;
|
|
63
|
+
private _lastFaceState;
|
|
64
|
+
private _running;
|
|
65
|
+
private _rafId;
|
|
66
|
+
private _maxFPS;
|
|
67
|
+
private _lastFrameTime;
|
|
68
|
+
constructor(options: GlassesViewerOptions);
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
private loadModel;
|
|
71
|
+
private loop;
|
|
72
|
+
destroy(): void;
|
|
73
|
+
on(event: string, cb: (...args: unknown[]) => void): void;
|
|
74
|
+
off(event: string, cb: (...args: unknown[]) => void): void;
|
|
75
|
+
private emit;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { type AlignmentConfig, type CameraIntrinsics, type FaceLandmark, type FacePose, GlassesViewer, type GlassesViewerOptions };
|