|
1 | 1 | <!DOCTYPE html>
|
2 | 2 | <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
3 | 3 |
|
4 |
| -<!-- three.js library --> |
5 |
| -<script src='vendor/three.js/build/three.min.js'></script> |
6 |
| -<!-- three.js load GLTF --> |
7 |
| -<script src='vendor/three.js/GLTFLoader.js'></script> |
8 |
| -<!-- ar.js --> |
9 |
| -<script src='../build/ar-threex.js'></script> |
10 |
| - |
11 |
| -<script>THREEx.ArToolkitContext.baseURL = '../'</script> |
| 4 | +<!-- import ar-trheex.moule.js and three.js libraries --> |
| 5 | +<script type="importmap"> |
| 6 | + { |
| 7 | + "imports": { |
| 8 | + "threex": "../build/ar-threex.module.js", |
| 9 | + "three": "./vendor/three.js/build/three.module.min.js", |
| 10 | + "three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/" |
| 11 | + } |
| 12 | + } |
| 13 | +</script> |
12 | 14 |
|
13 | 15 | <body style='position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin : 0px; overflow: hidden;'>
|
14 | 16 | <style>
|
|
54 | 56 | <div class="arjs-loader">
|
55 | 57 | <div class="arjs-loader-spinner"></div>
|
56 | 58 | </div>
|
57 |
| - <script> |
| 59 | + <script type="module"> |
| 60 | + import * as THREE from 'three' |
| 61 | + import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; |
| 62 | + import { ArToolkitProfile, ArToolkitSource, ArToolkitContext, ArMarkerControls } from 'threex' |
| 63 | + |
| 64 | + ArToolkitContext.baseURL = '../' |
| 65 | + |
58 | 66 | //////////////////////////////////////////////////////////////////////////////////
|
59 | 67 | // Init
|
60 | 68 | //////////////////////////////////////////////////////////////////////////////////
|
61 | 69 |
|
62 |
| - var renderer = new THREE.WebGLRenderer({ |
| 70 | + const renderer = new THREE.WebGLRenderer({ |
63 | 71 | antialias: true,
|
64 | 72 | alpha: true,
|
65 | 73 | precision: 'mediump',
|
| 74 | + premultipliedAlpha: true, |
| 75 | + stencil: true, |
| 76 | + depth: true, |
| 77 | + logarithmicDepthBuffer: true, |
66 | 78 | });
|
67 | 79 |
|
68 |
| - var clock = new THREE.Clock(); |
| 80 | + const clock = new THREE.Clock(); |
69 | 81 |
|
70 |
| - var mixers = []; |
| 82 | + const mixers = []; |
71 | 83 |
|
72 | 84 | renderer.setPixelRatio(window.devicePixelRatio);
|
73 | 85 |
|
74 | 86 | renderer.setClearColor(new THREE.Color('lightgrey'), 0)
|
75 | 87 | renderer.setSize( window.innerWidth, window.innerHeight );
|
| 88 | + renderer.outputEncoding = THREE.sRGBEncoding; |
| 89 | + renderer.physicallyCorrectLights = true; |
76 | 90 | renderer.domElement.style.position = 'absolute'
|
77 | 91 | renderer.domElement.style.top = '0px'
|
78 | 92 | renderer.domElement.style.left = '0px'
|
|
86 | 100 | //////////////////////////////////////////////////////////////////////////////////
|
87 | 101 |
|
88 | 102 | // Create a camera
|
89 |
| - var camera = new THREE.Camera(); |
| 103 | + let fov = (0.8 * 180) / Math.PI; |
| 104 | + let ratio = 640 / 480; |
| 105 | + const camera = new THREE.PerspectiveCamera(fov, ratio); |
90 | 106 | scene.add(camera);
|
91 | 107 |
|
92 |
| - var light = new THREE.AmbientLight(0xffffff); |
| 108 | + const light = new THREE.AmbientLight(0xffffff); |
93 | 109 | scene.add(light);
|
94 | 110 |
|
| 111 | + let directionalLight = new THREE.DirectionalLight("#fff", 0.4); |
| 112 | + directionalLight.position.set(0.5, 0, 0.866); |
| 113 | + scene.add(directionalLight); |
| 114 | + |
95 | 115 | ////////////////////////////////////////////////////////////////////////////////
|
96 | 116 | // handle arToolkitSource
|
97 | 117 | ////////////////////////////////////////////////////////////////////////////////
|
98 | 118 |
|
99 |
| - var arToolkitSource = new THREEx.ArToolkitSource({ |
| 119 | + const arToolkitSource = new ArToolkitSource({ |
100 | 120 | sourceType : 'webcam',
|
101 | 121 | sourceWidth: 480,
|
102 | 122 | sourceHeight: 640,
|
|
132 | 152 | ////////////////////////////////////////////////////////////////////////////////
|
133 | 153 |
|
134 | 154 | // create atToolkitContext
|
135 |
| - var arToolkitContext = new THREEx.ArToolkitContext({ |
| 155 | + const arToolkitContext = new ArToolkitContext({ |
136 | 156 | detectionMode: 'mono',
|
137 | 157 | canvasWidth: 480,
|
138 | 158 | canvasHeight: 640,
|
|
152 | 172 | ////////////////////////////////////////////////////////////////////////////////
|
153 | 173 |
|
154 | 174 | // init controls for camera
|
155 |
| - var markerControls = new THREEx.ArMarkerControls(arToolkitContext, camera, { |
156 |
| - type : 'nft', |
157 |
| - descriptorsUrl : 'data/dataNFT/pinball', |
| 175 | + const markerControls = new ArMarkerControls(arToolkitContext, camera, { |
| 176 | + type: 'nft', |
| 177 | + descriptorsUrl: 'data/dataNFT/pinball', |
158 | 178 | changeMatrixMode: 'cameraTransformMatrix'
|
159 |
| - }) |
| 179 | + }); |
160 | 180 |
|
161 | 181 | scene.visible = false
|
162 | 182 |
|
163 |
| - var root = new THREE.Object3D(); |
| 183 | + const root = new THREE.Object3D(); |
164 | 184 | scene.add(root);
|
165 | 185 |
|
166 | 186 | //////////////////////////////////////////////////////////////////////////////////
|
167 | 187 | // add an object in the scene
|
168 | 188 | //////////////////////////////////////////////////////////////////////////////////
|
169 | 189 |
|
170 |
| - var threeGLTFLoader = new THREE.GLTFLoader(); |
171 |
| - var model; |
| 190 | + const threeGLTFLoader = new GLTFLoader(); |
| 191 | + let model; |
172 | 192 |
|
173 | 193 | threeGLTFLoader.load("./resources/Flamingo.glb", function (gltf) {
|
174 | 194 | model = gltf.scene.children[0];
|
175 |
| - model.name = 'Flamingo'; |
176 |
| - const clips = gltf.animations; |
| 195 | + //model.name = 'Flamingo'; |
| 196 | + //const clips = gltf.animations; |
177 | 197 |
|
178 |
| - var animation = gltf.animations[0]; |
179 |
| - var mixer = new THREE.AnimationMixer(gltf.scene); |
| 198 | + const animation = gltf.animations[0]; |
| 199 | + |
| 200 | + const mixer = new THREE.AnimationMixer(model); |
180 | 201 | mixers.push(mixer);
|
181 |
| - const clip = THREE.AnimationClip.findByName( clips, 'flamingo_flyA_' ); |
182 |
| - var action = mixer.clipAction(clip); |
| 202 | + |
| 203 | + const action = mixer.clipAction(animation); |
183 | 204 | action.play();
|
184 | 205 |
|
185 |
| - root.matrixAutoUpdate = false; |
186 | 206 | root.add(model);
|
187 |
| - |
| 207 | + root.matrixAutoUpdate = false; |
188 | 208 | model.position.z = -100;
|
189 |
| - //model.position.z = 100; |
190 | 209 |
|
191 | 210 | window.addEventListener('arjs-nft-init-data', function(nft) {
|
192 |
| - console.log(nft); |
193 |
| - var msg = nft.detail; |
194 |
| - model.position.y = (msg.height / msg.dpi * 2.54 * 10)/2.0; //y axis? |
195 |
| - model.position.x = (msg.width / msg.dpi * 2.54 * 10)/2.0; //x axis? |
| 211 | + const msg = nft.detail; |
| 212 | + model.position.y = (msg.height / msg.dpi * 2.54 * 10)/2.0; //y axis? |
| 213 | + model.position.x = (msg.width / msg.dpi * 2.54 * 10)/2.0; //x axis? |
196 | 214 | })
|
197 | 215 |
|
198 | 216 |
|
|
204 | 222 | requestAnimationFrame(animate);
|
205 | 223 |
|
206 | 224 | if (mixers.length > 0) {
|
207 |
| - for (var i = 0; i < mixers.length; i++) { |
| 225 | + for (let i = 0; i < mixers.length; i++) { |
208 | 226 | mixers[i].update(clock.getDelta());
|
209 | 227 | }
|
210 | 228 | }
|
|
0 commit comments