/
ImageTracking.tsx
104 lines (96 loc) · 2.93 KB
/
ImageTracking.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from 'react';
import { Scene as AScene } from 'aframe';
import { Camera, GLTFModel, Plane, Assets, Item } from 'aframe-react-component';
import ImageTracking from '../provider/ImageTracking';
import { Entity, Marker, Scene } from '../components';
import useARManager from '../utils/useARManager';
const ExampleImageTracking = () => {
const [enabled, setEnabled] = React.useState(false);
const sceneRef = React.useRef<AScene>();
const { startAR, stopAR } = useARManager(sceneRef);
const onClick = () => {
if (enabled) {
stopAR();
} else {
startAR();
}
setEnabled((curr) => !curr);
};
const rotationSettings = {
enabled: true,
rotationFactor: 5,
};
const scaleSettings = {
enabled: true,
minScale: 0.3,
maxScale: 8,
};
return (
<ImageTracking>
<button onClick={onClick} style={{ position: 'absolute', zIndex: 999 }}>
{enabled ? 'Stop' : 'Start'}
</button>
<Scene
mindARImage={{
imageTargetSrc:
'https://cdn.jsdelivr.net/gh/hiukim/mind-ar-js@1.0.0/examples/image-tracking/assets/card-example/card.mind',
autoStart: false,
}}
color-space="sRGB"
mouse-detector
gesture-detector
embedded
renderer="colorManagement: true, physicallyCorrectLights"
orientationUI
stats={enabled}
ref={sceneRef}
>
<Assets>
<img
id="card"
src="https://cdn.jsdelivr.net/gh/hiukim/mind-ar-js@1.1.4/examples/image-tracking/assets/card-example/card.png"
alt=""
/>
<Item
id="avatarModel"
src="https://cdn.jsdelivr.net/gh/hiukim/mind-ar-js@1.1.4/examples/image-tracking/assets/card-example/softmind/scene.gltf"
/>
</Assets>
<Camera position={{ x: 0, y: 0, z: 0 }} look-controls={false} />
<Entity visible={enabled}>
<Marker targetIndex={0}>
<Entity
mouse-rotation={rotationSettings}
mouse-scale={scaleSettings}
gesture-rotation={rotationSettings}
gesture-scale={scaleSettings}
>
<Plane
src="#card"
position={[0, 0, 0]}
height={0.552}
width={1}
rotation={[0, 0, 0]}
/>
<GLTFModel
rotation={[0, 0, 0]}
position={[0, 0, 0.1]}
scale={[0.005, 0.005, 0.005]}
animation={{
property: 'position',
to: '0 0.1 0.1',
dur: 1000,
easing: 'easeInOutQuad',
loop: true,
dir: 'alternate',
}}
src="#avatarModel"
/>
</Entity>
</Marker>
</Entity>
</Scene>
</ImageTracking>
);
};
export default ExampleImageTracking;