-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnft_threads_cesium.html
158 lines (128 loc) · 4.84 KB
/
nft_threads_cesium.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<html>
<head>
<title>NFT marker example with Three.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<style>
html,body {
margin: 0;
padding: 0;
width: 100%;
text-align: center;
overflow-x: hidden;
}
.portrait canvas {
transform-origin: 0 0;
transform: rotate(-90deg) translateX(-100%);
}
.desktop canvas {
transform: scale(-1, 1);
}
</style>
</head>
<body>
<h1>NFT marker example with Three.js</h1>
<p>On Chrome on Android, tap the screen to start playing video stream.</p>
<p>Show <a href="https://github.com/artoolkit/artoolkit5/blob/master/doc/Marker%20images/pinball.jpg">Pinball image</a> to camera to display a colorful object on top of it. Tap the screen to rotate the object.
<p>← <a href="../index.html">Back to examples</a></p>
<script src="../resources/jsartoolkit5/threaded/artoolkitNft_td.min.js"></script>
<script src="../resources/three.js"></script>
<script src="../resources/js/GLTFLoader.js"></script>
<script src="../resources/jsartoolkit5/artoolkit/artoolkit.three.js"></script>
<script>
alert("To use this Nft example, enable the SharedArrayBuffer option in the browser! Use carefully, see the Spectre issue!")
window.ARThreeOnLoad = function() {
ARController.getUserMediaThreeScene({maxARVideoSize: 320, cameraParam: '../resources/data/camera_para-iPhone 5 rear 640x480 1.0m.dat',
onSuccess: function(arScene, arController, arCamera) {
document.body.className = arController.orientation;
var renderer = new THREE.WebGLRenderer({antialias: true, precision: 'mediump'});
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
if (arController.orientation === 'portrait') {
var w = (window.innerWidth / arController.videoHeight) * arController.videoWidth;
var h = window.innerWidth;
renderer.setSize(w, h);
renderer.domElement.style.paddingBottom = (w-h) + 'px';
} else {
if (/Android|mobile|iPad|iPhone/i.test(navigator.userAgent)) {
renderer.setSize(window.innerWidth, (window.innerWidth / arController.videoWidth) * arController.videoHeight);
} else {
renderer.setSize(arController.videoWidth, arController.videoHeight);
document.body.className += ' desktop';
}
}
document.body.insertBefore(renderer.domElement, document.body.firstChild);
var rotationV = 0;
var rotationTarget = 0;
renderer.domElement.addEventListener('click', function(ev) {
ev.preventDefault();
rotationTarget += 1;
}, false);
var sphere = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 8, 8),
new THREE.MeshNormalMaterial()
);
var ambient = new THREE.AmbientLight( 0x222222 );
arScene.scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0xdddddd, 4 );
directionalLight.position.set( 0, 0, 1 ).normalize();
arScene.scene.add( directionalLight );
sphere.material.flatShading;
sphere.position.z = 40;
sphere.position.x = 80;
sphere.position.y = 80;
sphere.scale.set(80,80,80);
arController.loadNFTMarker('../resources/dataNFT/pinball', function(markerId) {
var markerRoot = arController.createThreeNFTMarker(markerId);
var loader = new THREE.GLTFLoader();
loader.load( '../resources/models/CesiumMan/glTF/CesiumMan.glb', function ( gltf ) {
gltf.scene.rotation.x = 0.5*Math.PI;
gltf.scene.position.z = 40;
gltf.scene.position.x = 80;
gltf.scene.position.y = 80;
gltf.scene.scale.set(80,80,80);
markerRoot.add( gltf.scene );
} , undefined, function ( error ) {
console.error( error );
});
arScene.scene.add(markerRoot);
});
const mixers = [];
const clock = new THREE.Clock();
arController.loadMarker('../resources/data/patt.kanji', function(markerId) {
var markerRoot = arController.createThreeMarker(markerId);
var loader = new THREE.GLTFLoader();
loader.load( '../resources/models/CesiumMan/glTF/CesiumMan.gltf', function ( gltf ) {
gltf.scene.rotation.x = 0.5*Math.PI;
gltf.animations.duration = 2;
var mixer = new THREE.AnimationMixer( gltf.scene.children[ 0 ] );
mixers.push( mixer );
var action = mixer.clipAction( gltf.animations[0] );
action.play();
markerRoot.add( gltf.scene );
} , undefined, function ( error ) {
console.error( error );
});
arScene.scene.add(markerRoot);
});
const delta = clock.getDelta();
for ( const mixer of mixers ) {
mixer.update( delta );
}
var tick = function() {
arScene.process();
rotationV += (rotationTarget - sphere.rotation.z) * 0.05;
sphere.rotation.z += rotationV;
rotationV *= 0.8;
arScene.renderOn(renderer);
requestAnimationFrame(tick);
};
tick();
}});
delete window.ARThreeOnLoad;
};
if (window.ARController && ARController.getUserMediaThreeScene) {
ARThreeOnLoad();
}
</script>
</body>
</html>