-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
arNFT_multi_example.html
123 lines (102 loc) · 4.64 KB
/
arNFT_multi_example.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ARnft multi example showing some simple meshes</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=1">
<link rel="stylesheet" href="css/nft-style.css">
</head>
<body>
<a href="https://raw.githubusercontent.com/artoolkitx/artoolkit5/master/doc/Marker%20images/pinball.jpg"
class="ui marker" target="_blank">
🖼 Marker Image
</a>
<script src="js/third_party/three.js/three.min.js"></script>
<script src="js/ARnftThreejs.js"></script>
<script src="../dist/ARnft.js"></script>
<script>
const entities = [
{ name: 'pinball', markerUrl: "examples/DataNFT/pinball" },
{ name: 'kuva', markerUrl: "examples/DataNFT/kuva" },
{ name: 'chalk_multi', markerUrl: "examples/DataNFT/chalk_multi"}
]
ARnft.ARnft.initWithEntities(640, 480, entities, 'config.json', true)
.then((nft) => {
let mat = new THREE.MeshLambertMaterial({
color: 0xff0000
});
let maty = new THREE.MeshLambertMaterial({
color: 0xffff00
});
let matz = new THREE.MeshLambertMaterial({
color: 0x0000ff
});
let boxGeom = new THREE.BoxGeometry(1, 1, 1);
let cube = new THREE.Mesh(boxGeom, mat);
cube.name = 'cube';
cube.position.z = 90;
cube.scale.set(180, 180, 180);
let coneGeom = new THREE.ConeGeometry( 0.5, 1, 32 );
let cone = new THREE.Mesh( coneGeom, maty);
cone.name = 'cone';
cone.rotation.x = 90;
cone.position.z = 90;
cone.scale.set(180, 180, 180);
let sphereGeom = new THREE.SphereGeometry(0.5, 8, 8);
let sphere = new THREE.Mesh(sphereGeom, matz)
sphere.name = 'sphere'
sphere.position.z = 90;
sphere.scale.set(180, 180, 180);
let testEntities = ARnft.ARnft.getEntities();
console.log("entities from getEntities static method: ", testEntities);
document.addEventListener('containerEvent', function (ev) {
let canvas = document.getElementById('canvas');
let fov = 0.8 * 180 / Math.PI;
let ratio = window.clientWidth / window.clientHeight;
let config = {
"renderer": {
"alpha": true,
"antialias": true,
"context": null,
"precision": "mediump",
"premultipliedAlpha": true,
"stencil": true,
"depth": true,
"logarithmicDepthBuffer": true
},
"camera": {
"fov": fov,
"ratio": ratio,
"near": 0.01,
"far": 1000
}
}
let sceneThreejs = new ARnftThreejs.SceneRendererTJS(config, canvas, nft.uuid, true);
sceneThreejs.initRenderer();
document.addEventListener('getMatrixGL_RH-' + nft.uuid + '-pinball', function() {
console.log('this is pinball!!');
})
document.addEventListener('getMatrixGL_RH-' + nft.uuid + '-kuva', function() {
console.log('this is kuva!!');
})
document.addEventListener('getMatrixGL_RH-' + nft.uuid + '-chalk_multi', function() {
console.log('this is chalk_multi!!');
})
let nftAddTJS = new ARnftThreejs.NFTaddTJS(nft.uuid);
nftAddTJS.add(cube, 'pinball', false);
nftAddTJS.add(cone, 'kuva', false);
nftAddTJS.add(sphere, 'chalk_multi', false);
let names = nftAddTJS.getNames();
console.log(names);
const tick = () => {
sceneThreejs.draw();
window.requestAnimationFrame(tick)
}
tick()
})
}).catch((error) => {
console.log(error);
});
</script>
</body>
</html>