Delete js
Browse files- js/app.js +0 -275
- js/three.min.js +0 -0
js/app.js
DELETED
@@ -1,275 +0,0 @@
|
|
1 |
-
const unityInstance = UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%");
|
2 |
-
let WebXR;
|
3 |
-
window.ARWT = {}
|
4 |
-
|
5 |
-
let gl = null;
|
6 |
-
let unityCanvas = null;
|
7 |
-
let frameDrawer = null;
|
8 |
-
let xrSession = null;
|
9 |
-
let xrRefSpace = null;
|
10 |
-
let xrViewerSpace = null;
|
11 |
-
let xrHitTestSource = null;
|
12 |
-
let isValidHitTest = false;
|
13 |
-
let hitTestPosition = null;
|
14 |
-
let xrTransientInputHitTestSource = null;
|
15 |
-
|
16 |
-
let imgsBitmap = [];
|
17 |
-
let isImgTrackingReady = false;
|
18 |
-
async function initImageTrackign () {
|
19 |
-
// if(WebXR.imageTrackingRequired){
|
20 |
-
// const img = document.getElementById('img');
|
21 |
-
// await img.decode();
|
22 |
-
// imgBitmap = await createImageBitmap(img);
|
23 |
-
// isImgTrackingReady = true;
|
24 |
-
// }
|
25 |
-
|
26 |
-
if(WebXR.imageTrackingRequired){
|
27 |
-
WebXR.imageTracking.images.forEach(async image =>{
|
28 |
-
const img = document.getElementById(image.name);
|
29 |
-
await img.decode();
|
30 |
-
imgsBitmap.push({name: image.name, image: await createImageBitmap(img), widthInMeters: image.width, heightInMeters: image.height});
|
31 |
-
});
|
32 |
-
isImgTrackingReady = true;
|
33 |
-
}
|
34 |
-
}
|
35 |
-
|
36 |
-
function quaternionToUnity(q) {
|
37 |
-
q.x *= -1;
|
38 |
-
q.y *= -1;
|
39 |
-
return q;
|
40 |
-
}
|
41 |
-
|
42 |
-
function vec3ToUnity(v) {
|
43 |
-
v.z *= -1;
|
44 |
-
return v;
|
45 |
-
}
|
46 |
-
|
47 |
-
function initUnity() {
|
48 |
-
gl = unityInstance.Module.ctx;
|
49 |
-
unityCanvas = unityInstance.Module.canvas;
|
50 |
-
unityCanvas.width = document.documentElement.clientWidth;
|
51 |
-
unityCanvas.height = document.documentElement.clientHeight;
|
52 |
-
|
53 |
-
unityInstance.Module.InternalBrowser.requestAnimationFrame = frameInject;
|
54 |
-
WebXR = unityInstance.Module.WebXR;
|
55 |
-
initImageTrackign();
|
56 |
-
// setupObject();
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
// function setupObject() {
|
61 |
-
// let position = new THREE.Vector3(0, 0, -1.5);
|
62 |
-
// let rotation = new THREE.Quaternion(0, 0, 0, 0);
|
63 |
-
// let scale = new THREE.Vector3(.5, .5, .5);
|
64 |
-
|
65 |
-
// position = vec3ToUnity(position);
|
66 |
-
// rotation = quaternionToUnity(rotation);
|
67 |
-
|
68 |
-
// const serializedInfos = `aaa,false,${position.toArray()},${rotation.toArray()},${scale.toArray()}`;
|
69 |
-
// unityInstance.SendMessage("WebXRTransformController", "transofrmInfos", serializedInfos);
|
70 |
-
// }
|
71 |
-
|
72 |
-
window.ARWT.onButtonClicked = () => {
|
73 |
-
if(!xrSession){
|
74 |
-
const options = !WebXR.imageTrackingRequired ?
|
75 |
-
{
|
76 |
-
requiredFeatures: ['local-floor', 'hit-test']
|
77 |
-
}
|
78 |
-
:
|
79 |
-
{
|
80 |
-
requiredFeatures: ['local-floor', 'image-tracking'],
|
81 |
-
trackedImages : imgsBitmap
|
82 |
-
// trackedImages: [
|
83 |
-
// {
|
84 |
-
// image: imgBitmap,
|
85 |
-
// widthInMeters: 0.05
|
86 |
-
// }
|
87 |
-
// ]
|
88 |
-
}
|
89 |
-
navigator.xr.requestSession('immersive-ar', options).then(onSessionStarted, onRequestSessionError);
|
90 |
-
}else{
|
91 |
-
xrSession.end();
|
92 |
-
}
|
93 |
-
}
|
94 |
-
|
95 |
-
function onSessionStarted(session) {
|
96 |
-
xrSession = session;
|
97 |
-
|
98 |
-
session.addEventListener('end', onSessionEnded);
|
99 |
-
session.addEventListener('select', onSelect);
|
100 |
-
|
101 |
-
let glLayer = new XRWebGLLayer(session, gl);
|
102 |
-
session.updateRenderState({ baseLayer: glLayer });
|
103 |
-
|
104 |
-
unityInstance.Module.canvas.width = glLayer.framebufferWidth;
|
105 |
-
unityInstance.Module.canvas.height = glLayer.framebufferHeight;
|
106 |
-
|
107 |
-
|
108 |
-
// session.requestReferenceSpace('viewer').then((refSpace) => {
|
109 |
-
// xrViewerSpace = refSpace;
|
110 |
-
// // session.requestHitTestSource({ space: xrViewerSpace }).then((hitTestSource) => {
|
111 |
-
// // xrHitTestSource = hitTestSource;
|
112 |
-
// // });
|
113 |
-
|
114 |
-
// });
|
115 |
-
|
116 |
-
if(!WebXR.imageTrackingRequired){
|
117 |
-
session.requestReferenceSpace('local').then((refSpace) => {
|
118 |
-
xrRefSpace = refSpace;
|
119 |
-
unityInstance.Module.InternalBrowser.requestAnimationFrame(frameDrawer);
|
120 |
-
|
121 |
-
session.requestHitTestSourceForTransientInput({ profile:'generic-touchscreen' }).then((hitTestSource) => {
|
122 |
-
xrTransientInputHitTestSource = hitTestSource;
|
123 |
-
});
|
124 |
-
|
125 |
-
});
|
126 |
-
}else{
|
127 |
-
session.requestReferenceSpace('viewer').then((refSpace) => {
|
128 |
-
xrRefSpace = refSpace;
|
129 |
-
unityInstance.Module.InternalBrowser.requestAnimationFrame(frameDrawer);
|
130 |
-
});
|
131 |
-
}
|
132 |
-
|
133 |
-
}
|
134 |
-
|
135 |
-
function frameInject(raf) {
|
136 |
-
if (!frameDrawer){
|
137 |
-
frameDrawer = raf;
|
138 |
-
}
|
139 |
-
if(xrSession){
|
140 |
-
return xrSession.requestAnimationFrame((time, xrFrame) => {
|
141 |
-
onXRFrame(xrFrame);
|
142 |
-
raf(time);
|
143 |
-
});
|
144 |
-
}
|
145 |
-
}
|
146 |
-
|
147 |
-
function onSelect(event) {
|
148 |
-
if(isValidHitTest){
|
149 |
-
const serializedPos = `${[hitTestPosition.x, hitTestPosition.y, hitTestPosition.z]}`
|
150 |
-
if(WebXR.isHitProviderReady){
|
151 |
-
unityInstance.SendMessage(WebXR.hitProvider, WebXR.hit.setHit, serializedPos);
|
152 |
-
}
|
153 |
-
}
|
154 |
-
}
|
155 |
-
|
156 |
-
|
157 |
-
function onXRFrame(frame) {
|
158 |
-
let session = frame.session;
|
159 |
-
if (!session) {
|
160 |
-
return;
|
161 |
-
}
|
162 |
-
|
163 |
-
let glLayer = session.renderState.baseLayer;
|
164 |
-
gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
|
165 |
-
gl.dontClearOnFrameStart = true;
|
166 |
-
|
167 |
-
|
168 |
-
let pose = frame.getViewerPose(xrRefSpace);
|
169 |
-
isValidHitTest = false
|
170 |
-
|
171 |
-
if (pose) {
|
172 |
-
|
173 |
-
for (let xrView of pose.views) {
|
174 |
-
let viewport = glLayer.getViewport(xrView);
|
175 |
-
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
176 |
-
|
177 |
-
|
178 |
-
let projection = new THREE.Matrix4();
|
179 |
-
projection.set(...xrView.projectionMatrix);
|
180 |
-
projection.transpose();
|
181 |
-
|
182 |
-
const serializedProj = `${[...projection.toArray()]}`;
|
183 |
-
if(WebXR.isCameraReady){
|
184 |
-
unityInstance.SendMessage(WebXR.cameraProvider, WebXR.camera.setProjection, serializedProj);
|
185 |
-
}
|
186 |
-
let position = xrView.transform.position;
|
187 |
-
let orientation = xrView.transform.orientation;
|
188 |
-
|
189 |
-
let pos = new THREE.Vector3(position.x, position.y, position.z);
|
190 |
-
let rot = new THREE.Quaternion(orientation.x, orientation.y, orientation.z, orientation.w);
|
191 |
-
|
192 |
-
pos = vec3ToUnity(pos);
|
193 |
-
rot = quaternionToUnity(rot);
|
194 |
-
|
195 |
-
const serializedPos = `${[pos.x, pos.y, pos.z]}`
|
196 |
-
const serializedRot = `${[rot.x, rot.y, rot.z, rot.w]}`
|
197 |
-
if(WebXR.isCameraReady){
|
198 |
-
unityInstance.SendMessage(WebXR.cameraProvider, WebXR.camera.setPosition, serializedPos);
|
199 |
-
unityInstance.SendMessage(WebXR.cameraProvider, WebXR.camera.setRotation, serializedRot);
|
200 |
-
}
|
201 |
-
|
202 |
-
// unityInstance.SendMessage("WebXRTransformController", "setVisible", "true");
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
// if(xrHitTestSource){
|
207 |
-
// let hitTestResults = frame.getHitTestResults(xrHitTestSource);
|
208 |
-
// if (hitTestResults.length > 0) {
|
209 |
-
// let p = hitTestResults[0].getPose(xrRefSpace);
|
210 |
-
// let position = p.transform.position;
|
211 |
-
// let pos = new THREE.Vector3(position.x, position.y, position.z);
|
212 |
-
// pos = vec3ToUnity(pos);
|
213 |
-
// isValidHitTest = true
|
214 |
-
// hitTestPosition = pos
|
215 |
-
// }
|
216 |
-
// }
|
217 |
-
|
218 |
-
if(!WebXR.imageTrackingRequired){
|
219 |
-
if(xrTransientInputHitTestSource){
|
220 |
-
let hitTestResults = frame.getHitTestResultsForTransientInput(xrTransientInputHitTestSource);
|
221 |
-
if (hitTestResults.length > 0) {
|
222 |
-
let p = hitTestResults[0].results[0]
|
223 |
-
if(p != null){
|
224 |
-
let newPose = p.getPose(xrRefSpace);
|
225 |
-
let position = newPose.transform.position;
|
226 |
-
let pos = new THREE.Vector3(position.x, position.y, position.z);
|
227 |
-
pos = vec3ToUnity(pos);
|
228 |
-
isValidHitTest = true
|
229 |
-
hitTestPosition = pos
|
230 |
-
}
|
231 |
-
}
|
232 |
-
}
|
233 |
-
}else{
|
234 |
-
if(WebXR.isImageTrackingProviderReady){
|
235 |
-
const results = frame.getImageTrackingResults();
|
236 |
-
for (const result of results) {
|
237 |
-
const imgPose = frame.getPose(result.imageSpace, xrRefSpace);
|
238 |
-
if(imgPose != null){
|
239 |
-
let name = imgsBitmap[result.index].name;
|
240 |
-
let position = imgPose.transform.position;
|
241 |
-
position = new THREE.Vector3(position.x, position.y, position.z);
|
242 |
-
let rotation = imgPose.transform.orientation;
|
243 |
-
rotation = new THREE.Quaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
244 |
-
let scale = new THREE.Vector3(1, 1, 1);
|
245 |
-
|
246 |
-
position = vec3ToUnity(position);
|
247 |
-
rotation = quaternionToUnity(rotation);
|
248 |
-
|
249 |
-
const serializedInfos = `${name},${result.trackingState},${position.toArray()},${rotation.toArray()},${scale.toArray()}`;
|
250 |
-
unityInstance.SendMessage(WebXR.imageTrackingProvider, WebXR.imageTracking.setTrackedImage, serializedInfos);
|
251 |
-
}
|
252 |
-
}
|
253 |
-
}
|
254 |
-
}
|
255 |
-
|
256 |
-
}
|
257 |
-
}
|
258 |
-
|
259 |
-
function onRequestSessionError(ex) {
|
260 |
-
alert("Failed to start immersive AR session.");
|
261 |
-
console.error(ex.message);
|
262 |
-
}
|
263 |
-
|
264 |
-
function onEndSession(session) {
|
265 |
-
xrHitTestSource.cancel();
|
266 |
-
xrHitTestSource = null;
|
267 |
-
session.end();
|
268 |
-
}
|
269 |
-
|
270 |
-
function onSessionEnded(event) {
|
271 |
-
xrSession = null;
|
272 |
-
gl = null;
|
273 |
-
}
|
274 |
-
|
275 |
-
document.addEventListener('UnityLoaded', initUnity, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/three.min.js
DELETED
The diff for this file is too large to render.
See raw diff
|
|