Delete ThreeVersion
Browse files- ThreeVersion/appThree.js +0 -220
- ThreeVersion/indexThree.html +0 -40
ThreeVersion/appThree.js
DELETED
@@ -1,220 +0,0 @@
|
|
1 |
-
//import ------------------------------------------------------
|
2 |
-
|
3 |
-
var unityContainer = document.getElementById("unityContainer")
|
4 |
-
let unityInstance = UnityLoader.instantiate("unityContainer", "Build/WebGLtest.json", {onProgress: unityProgress});
|
5 |
-
|
6 |
-
var unityCanvas = document.getElementsByTagName('canvas')[0];
|
7 |
-
|
8 |
-
function unityProgress(unityInstance, progress) {
|
9 |
-
if (!unityInstance.Module)
|
10 |
-
return;
|
11 |
-
if (!unityInstance.logo) {
|
12 |
-
unityInstance.logo = document.createElement("div");
|
13 |
-
unityInstance.logo.className = "logo " + unityInstance.Module.splashScreenStyle;
|
14 |
-
unityInstance.container.appendChild(unityInstance.logo);
|
15 |
-
}
|
16 |
-
if (!unityInstance.progress) {
|
17 |
-
unityInstance.progress = document.createElement("div");
|
18 |
-
unityInstance.progress.className = "progress " + unityInstance.Module.splashScreenStyle;
|
19 |
-
unityInstance.progress.empty = document.createElement("div");
|
20 |
-
unityInstance.progress.empty.className = "empty";
|
21 |
-
unityInstance.progress.appendChild(unityInstance.progress.empty);
|
22 |
-
unityInstance.progress.full = document.createElement("div");
|
23 |
-
unityInstance.progress.full.className = "full";
|
24 |
-
unityInstance.progress.appendChild(unityInstance.progress.full);
|
25 |
-
unityInstance.container.appendChild(unityInstance.progress);
|
26 |
-
}
|
27 |
-
unityInstance.progress.full.style.width = (100 * progress) + "%";
|
28 |
-
unityInstance.progress.empty.style.width = (100 * (1 - progress)) + "%";
|
29 |
-
|
30 |
-
onResize()
|
31 |
-
|
32 |
-
if (progress < 1){
|
33 |
-
arToolkitSource.domElement.style.opacity = 0
|
34 |
-
}
|
35 |
-
|
36 |
-
if (progress == 1){
|
37 |
-
arToolkitSource.domElement.style.opacity = 1
|
38 |
-
unityInstance.logo.style.display = unityInstance.progress.style.display = "none";
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
//three base ------------------------------------------------------
|
43 |
-
|
44 |
-
var onRenderFcts= [];
|
45 |
-
|
46 |
-
var scene = new THREE.Scene();
|
47 |
-
|
48 |
-
var camera = new THREE.PerspectiveCamera( 60, window.innerWidth/window.innerHeight, 0.1, 1000 );
|
49 |
-
|
50 |
-
var renderer = new THREE.WebGLRenderer({
|
51 |
-
antialias: true,
|
52 |
-
alpha: true
|
53 |
-
});
|
54 |
-
|
55 |
-
renderer.setClearColor(new THREE.Color('lightgrey'), 0)
|
56 |
-
|
57 |
-
renderer.setSize( window.innerWidth, window.innerHeight );
|
58 |
-
// renderer.domElement.style.position = 'absolute'
|
59 |
-
// renderer.domElement.style.top = '0px'
|
60 |
-
// renderer.domElement.style.left = '0px'
|
61 |
-
|
62 |
-
document.body.appendChild( renderer.domElement );
|
63 |
-
|
64 |
-
//artoolkit ------------------------------------------------------
|
65 |
-
|
66 |
-
var arToolkitSource = new THREEx.ArToolkitSource({
|
67 |
-
sourceType : 'webcam',
|
68 |
-
})
|
69 |
-
|
70 |
-
arToolkitSource.init(function onReady(){
|
71 |
-
onResize()
|
72 |
-
})
|
73 |
-
|
74 |
-
window.addEventListener('resize', function(){
|
75 |
-
onResize()
|
76 |
-
})
|
77 |
-
|
78 |
-
function onResize(){
|
79 |
-
arToolkitSource.onResizeElement()
|
80 |
-
arToolkitSource.copyElementSizeTo(renderer.domElement)
|
81 |
-
arToolkitSource.copyElementSizeTo(unityCanvas)
|
82 |
-
|
83 |
-
if( arToolkitContext.arController !== null ){
|
84 |
-
arToolkitSource.copyElementSizeTo(arToolkitContext.arController.canvas)
|
85 |
-
|
86 |
-
}
|
87 |
-
}
|
88 |
-
|
89 |
-
var arToolkitContext = new THREEx.ArToolkitContext({
|
90 |
-
cameraParametersUrl: 'data/camera/camera_para.dat',
|
91 |
-
detectionMode: 'mono',
|
92 |
-
})
|
93 |
-
|
94 |
-
arToolkitContext.init(function onCompleted(){
|
95 |
-
camera.projectionMatrix.copy( arToolkitContext.getProjectionMatrix() );
|
96 |
-
})
|
97 |
-
|
98 |
-
|
99 |
-
onRenderFcts.push(function(){
|
100 |
-
if( arToolkitSource.ready === false ) return
|
101 |
-
|
102 |
-
arToolkitContext.update( arToolkitSource.domElement )
|
103 |
-
})
|
104 |
-
|
105 |
-
//3d els ------------------------------------------------------
|
106 |
-
|
107 |
-
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
|
108 |
-
var material = new THREE.MeshNormalMaterial({
|
109 |
-
transparent : true,
|
110 |
-
opacity: 0.5,
|
111 |
-
side: THREE.DoubleSide
|
112 |
-
});
|
113 |
-
|
114 |
-
var cube = new THREE.Mesh( geometry, material );
|
115 |
-
|
116 |
-
// cube.position.x = 6;
|
117 |
-
// cube.position.y = 4;
|
118 |
-
// cube.position.z = -13;
|
119 |
-
|
120 |
-
scene.add( cube );
|
121 |
-
|
122 |
-
var artoolkitMarker = new THREEx.ArMarkerControls(arToolkitContext, cube, {
|
123 |
-
type : 'pattern',
|
124 |
-
patternUrl : '/data/markers/patt.hiro',
|
125 |
-
})
|
126 |
-
|
127 |
-
|
128 |
-
var render = function () {
|
129 |
-
requestAnimationFrame( render );
|
130 |
-
|
131 |
-
// cube.rotation.x += 0.01;
|
132 |
-
// cube.rotation.y += 0.01;
|
133 |
-
|
134 |
-
renderer.render(scene, camera);
|
135 |
-
};
|
136 |
-
|
137 |
-
render();
|
138 |
-
|
139 |
-
var lastTimeMsec= null
|
140 |
-
requestAnimationFrame(function animate(nowMsec){
|
141 |
-
// keep looping
|
142 |
-
requestAnimationFrame( animate );
|
143 |
-
// measure time
|
144 |
-
lastTimeMsec = lastTimeMsec || nowMsec-1000/60
|
145 |
-
var deltaMsec = Math.min(200, nowMsec - lastTimeMsec)
|
146 |
-
lastTimeMsec = nowMsec
|
147 |
-
// call each update function
|
148 |
-
onRenderFcts.forEach(function(onRenderFct){
|
149 |
-
onRenderFct(deltaMsec/1000, nowMsec/1000)
|
150 |
-
})
|
151 |
-
})
|
152 |
-
|
153 |
-
//Unity ------------------------------------------------------
|
154 |
-
|
155 |
-
onResize()
|
156 |
-
|
157 |
-
window.STATUSCUBE = false;
|
158 |
-
window.STATUSCAM = false;
|
159 |
-
|
160 |
-
function camControlReady(){
|
161 |
-
window.STATUSCAM = true;
|
162 |
-
}
|
163 |
-
|
164 |
-
function cubeControlReady(){
|
165 |
-
window.STATUSCUBE = true;
|
166 |
-
}
|
167 |
-
|
168 |
-
|
169 |
-
function createUnityMatrix(el){
|
170 |
-
var m = el.matrix.clone();
|
171 |
-
var zFlipped = new THREE.Matrix4().makeScale(1, 1, -1).multiply(m);
|
172 |
-
var rotated = zFlipped.multiply(new THREE.Matrix4().makeRotationX(-Math.PI/2));
|
173 |
-
return rotated;
|
174 |
-
}
|
175 |
-
|
176 |
-
onRenderFcts.push(function(){
|
177 |
-
|
178 |
-
var camtr = new THREE.Vector3(),
|
179 |
-
camro = new THREE.Quaternion(),
|
180 |
-
camsc = new THREE.Vector3();
|
181 |
-
|
182 |
-
camera.matrix.clone().decompose(camtr, camro, camsc);
|
183 |
-
|
184 |
-
let projection = camera.projectionMatrix.clone();
|
185 |
-
let tosend = `${[...projection.elements]}`
|
186 |
-
|
187 |
-
let posCam = `${[...camtr.toArray()]}`
|
188 |
-
let rotCam = `${[...camro.toArray()]}`
|
189 |
-
|
190 |
-
if(window.STATUSCAM){
|
191 |
-
unityInstance.SendMessage("Main Camera", "setProjection", tosend);
|
192 |
-
unityInstance.SendMessage("Main Camera", "setAspect", camera.aspect);
|
193 |
-
|
194 |
-
unityInstance.SendMessage("Main Camera", "setPosition", posCam);
|
195 |
-
unityInstance.SendMessage("Main Camera", "setRotation", rotCam);
|
196 |
-
}
|
197 |
-
|
198 |
-
|
199 |
-
var tr = new THREE.Vector3(),
|
200 |
-
ro = new THREE.Quaternion(),
|
201 |
-
sc = new THREE.Vector3();
|
202 |
-
// var m = createUnityMatrix(cube);
|
203 |
-
// console.log(m);
|
204 |
-
// console.log(JSON.stringify(m.elements));
|
205 |
-
// let tosend = `${[...m.elements]}`
|
206 |
-
createUnityMatrix(cube).decompose(tr, ro, sc);
|
207 |
-
|
208 |
-
// console.log(camera.fov, camera.getFocalLength(), camera.getEffectiveFOV(), camera.zoom)
|
209 |
-
|
210 |
-
var posCube = tr.x.toString().concat(",", tr.y.toString(), ",", tr.z.toString());
|
211 |
-
var scaleCube = sc.x.toString().concat(",", sc.y.toString(), ",", sc.z.toString());
|
212 |
-
var rotCube = ro.x.toString().concat(",", ro.y.toString(), ",", ro.z.toString(), ",", ro.w.toString());
|
213 |
-
|
214 |
-
|
215 |
-
if(window.STATUSCUBE){
|
216 |
-
unityInstance.SendMessage("Cube", "setRotation", rotCube);
|
217 |
-
unityInstance.SendMessage("Cube", "setScale", scaleCube);
|
218 |
-
unityInstance.SendMessage("Cube", "setPosition", posCube);
|
219 |
-
}
|
220 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ThreeVersion/indexThree.html
DELETED
@@ -1,40 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en-us">
|
3 |
-
<head>
|
4 |
-
<meta charset="utf-8">
|
5 |
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
6 |
-
<title>Unity WebGL Player | WebGL Test AR</title>
|
7 |
-
<script src="https://threejs.org/build/three.js"></script>
|
8 |
-
<script src="js/lib/ar.js"></script>
|
9 |
-
<script src="Build/UnityLoader.js"></script>
|
10 |
-
|
11 |
-
<style>
|
12 |
-
body{
|
13 |
-
margin: 0;
|
14 |
-
}
|
15 |
-
|
16 |
-
/* html, body{
|
17 |
-
width: 100vw;
|
18 |
-
min-height: -webkit-fill-available;
|
19 |
-
} */
|
20 |
-
|
21 |
-
#unityContainer{
|
22 |
-
margin: 0;
|
23 |
-
width: 100%;
|
24 |
-
height: 100%;
|
25 |
-
}
|
26 |
-
|
27 |
-
canvas{
|
28 |
-
margin: 0;
|
29 |
-
width: 100%;
|
30 |
-
height: 100%;
|
31 |
-
}
|
32 |
-
|
33 |
-
</style>
|
34 |
-
</head>
|
35 |
-
|
36 |
-
<body>
|
37 |
-
<div id="unityContainer"></div>
|
38 |
-
<script src="ThreeVersion/appThree.js"></script>
|
39 |
-
</body>
|
40 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|