-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·124 lines (77 loc) · 2.49 KB
/
index.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var renderer,
scene,
camera,
container;
var arSource,
arContext,
arMarker = [];
var mesh,
car,
carScene;
init();
function init(){
container = document.getElementById('container');
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
scene = new THREE.Scene();
carScene = new THREE.Object3D();
camera = new THREE.Camera();
renderer.setClearColor(0x000000, 0);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);
scene.add(camera);
scene.visible = false;
mesh = new THREE.Mesh(new THREE.BoxGeometry(1,1,1), new THREE.MeshBasicMaterial({
color: 0xFF00FF,
transparent: true,
opacity: 0.5
}));
scene.add(carScene);
// scene.add(mesh);
carScene.rotation.set(0, Math.PI / 2,0);
carScene.scale.set(2,2,2);
var loadingManager = new THREE.LoadingManager( function() {
carScene.add( car );
} );
// collada
var loader = new THREE.ColladaLoader( loadingManager );
loader.load( './models/car.dae', function ( collada ) {
car = collada.scene;
} );
arSource = new THREEx.ArToolkitSource({
sourceType : 'webcam',
});
arContext = new THREEx.ArToolkitContext({
cameraParametersUrl: './assets/data/camera_para.dat',
detectionMode: 'mono',
imageSmoothingEnabled : true,
maxDetectionRate: 60,
});
arMarker[0] = new THREEx.ArMarkerControls(arContext, camera, {
type : 'pattern',
patternUrl : './assets/data/car.patt',
changeMatrixMode: 'cameraTransformMatrix'
});
arMarker[1] = new THREEx.ArMarkerControls(arContext, camera, {
type : 'pattern',
patternUrl : './assets/data/patt.hiro',
changeMatrixMode: 'cameraTransformMatrix'
});
/* handle */
arSource.init(function(){
arSource.onResize();
arSource.copySizeTo(renderer.domElement);
if(arContext.arController !== null) arSource.copySizeTo(arContext.arController.canvas);
});
arContext.init(function onCompleted(){
camera.projectionMatrix.copy(arContext.getProjectionMatrix());
});
render();
}
function render(){
requestAnimationFrame(render);
renderer.render(scene,camera);
if(arSource.ready === false) return;
arContext.update(arSource.domElement);
scene.visible = camera.visible;
mesh.rotateX(.1);
}