|
611 | 611 | interfaceHtml, |
612 | 612 | labelHtml, |
613 | 613 | searchSitesJson, |
| 614 | + searchScenesJson, |
614 | 615 | keyboardHighlightCanvasCtx, |
615 | 616 | keyMap, |
616 | 617 | fontJson, |
|
668 | 669 | } |
669 | 670 | }; |
670 | 671 | }), |
| 672 | + fetch('scenes.json') |
| 673 | + .then(res => res.json()) |
| 674 | + .then(scenesJson => { |
| 675 | + return s => { |
| 676 | + console.log("scenes.json"); |
| 677 | + const maxResults = 12; |
| 678 | + if (s) { |
| 679 | + const regexps = s.split(/\s/).filter(s => !!s).map(s => new RegExp(escapeRegExp(s), 'i')); |
| 680 | + const results = []; |
| 681 | + for (let i = 0; i < scenesJson.length; i++) { |
| 682 | + const site = scenesJson[i]; |
| 683 | + if (regexps.some(regexp => regexp.test(site.label) || regexp.test(site.url))) { |
| 684 | + results.push(site); |
| 685 | + if (results.length >= maxResults) { |
| 686 | + break; |
| 687 | + } |
| 688 | + } |
| 689 | + } |
| 690 | + return results; |
| 691 | + } else { |
| 692 | + return scenesJson.slice(0, maxResults); |
| 693 | + } |
| 694 | + }; |
| 695 | + }), |
671 | 696 | new Promise((accept, reject) => { |
672 | 697 | const img = new Image(); |
673 | 698 | img.crossOrigin = 'Anonymous'; |
|
3276 | 3301 | } |
3277 | 3302 | }; |
3278 | 3303 |
|
3279 | | - const searchResults = searchSitesJson(searchString); |
| 3304 | + console.log(" ------ selectedTab = " + selectedTab); |
| 3305 | + if (selectedTab === 1) { |
| 3306 | + var searchResults = searchSitesJson(searchString); |
| 3307 | + } else if (selectedTab === 2) { |
| 3308 | + var searchResults = searchScenesJson(searchString); |
| 3309 | + } |
3280 | 3310 |
|
3281 | 3311 | uiIframe.contentWindow.postMessage({ |
3282 | 3312 | method: 'render', |
|
3372 | 3402 |
|
3373 | 3403 | let items = []; |
3374 | 3404 | let text = 'https://'; |
3375 | | - const measures = []; |
3376 | | - let cursor = text.length; |
| 3405 | + let sceneText = ''; |
| 3406 | + const urlMeasures = []; |
| 3407 | + const sceneMeasures = []; |
| 3408 | + let urlCursor = text.length; |
| 3409 | + let sceneCursor = sceneText.length; |
3377 | 3410 | const canvas = document.createElement('canvas'); |
3378 | 3411 | canvas.width = uiSize; |
3379 | 3412 | canvas.height = uiSize; |
3380 | 3413 | const ctx = canvas.getContext('2d'); |
3381 | 3414 | ctx.font = '300 80px Open Sans'; |
3382 | | - const _updateMeasures = () => { |
3383 | | - measures.length = 0; |
3384 | | - measures.push(0); |
| 3415 | + const _updateUrlMeasures = () => { |
| 3416 | + urlMeasures.length = 0; |
| 3417 | + urlMeasures.push(0); |
3385 | 3418 | const {width: barWidth} = ctx.measureText('['); |
3386 | 3419 | for (let i = 1; i <= text.length; i++) { |
3387 | 3420 | const {width} = ctx.measureText('[' + text.slice(0, i) + ']'); |
3388 | | - measures.push(width - barWidth*2); |
| 3421 | + urlMeasures.push(width - barWidth*2); |
| 3422 | + } |
| 3423 | + }; |
| 3424 | + _updateUrlMeasures(); |
| 3425 | + const _updateSceneMeasures = () => { |
| 3426 | + sceneMeasures.length = 0; |
| 3427 | + sceneMeasures.push(0); |
| 3428 | + const {width: barWidth} = ctx.measureText('['); |
| 3429 | + for (let i = 1; i <= sceneText.length; i++) { |
| 3430 | + const {width} = ctx.measureText('[' + sceneText.slice(0, i) + ']'); |
| 3431 | + sceneMeasures.push(width - barWidth*2); |
3389 | 3432 | } |
3390 | 3433 | }; |
3391 | | - _updateMeasures(); |
| 3434 | + _updateSceneMeasures(); |
3392 | 3435 |
|
3393 | 3436 | const urlInputPadding = [40, 53]; |
| 3437 | + const sceneInputPadding = [40, 53]; |
3394 | 3438 | const _updateTextureStatic = () => { |
3395 | | - const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3396 | 3439 |
|
| 3440 | + const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3397 | 3441 | if (urlInputAnchor) { |
3398 | 3442 | ctx.fillStyle = '#f2f3f5'; |
3399 | 3443 | ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6); |
|
3403 | 3447 | ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]); |
3404 | 3448 |
|
3405 | 3449 | if (keyboardFocus) { |
3406 | | - ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3450 | + ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + urlMeasures[urlCursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3451 | + } |
| 3452 | + } |
| 3453 | + |
| 3454 | + const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input'); |
| 3455 | + if (sceneInputAnchor) { |
| 3456 | + ctx.fillStyle = '#f2f3f5'; |
| 3457 | + ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, sceneInputAnchor.width - sceneInputPadding[0]*2 + 4, sceneInputAnchor.height*0.6); |
| 3458 | + |
| 3459 | + ctx.fillStyle = 'black'; |
| 3460 | + ctx.textBaseline = 'bottom'; |
| 3461 | + ctx.fillText(sceneText, sceneInputAnchor.x + sceneInputPadding[0], sceneInputAnchor.bottom - sceneInputPadding[1]); |
| 3462 | + |
| 3463 | + if (keyboardFocus) { |
| 3464 | + ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] + sceneMeasures[sceneCursor] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, 6, sceneInputAnchor.height*0.6); |
3407 | 3465 | } |
3408 | 3466 | } |
3409 | 3467 |
|
|
3612 | 3670 |
|
3613 | 3671 | const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3614 | 3672 | const xOffset = x - urlInputAnchor.x - urlInputPadding[0]; |
3615 | | - cursor = measures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
| 3673 | + urlCursor = urlMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
| 3674 | + } else if (id === 'scene-input') { |
| 3675 | + const {x, y} = intersectionSpec; |
| 3676 | + |
| 3677 | + keyboardFocus = { |
| 3678 | + textMesh: mesh, |
| 3679 | + caretMesh: mesh, |
| 3680 | + }; |
| 3681 | + |
| 3682 | + const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input'); |
| 3683 | + const xOffset = x - sceneInputAnchor.x - sceneInputPadding[0]; |
| 3684 | + sceneCursor = sceneMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
3616 | 3685 | } else if (id === 'tab-1') { |
3617 | 3686 | _selectTab(1); |
3618 | 3687 | } else if (id === 'tab-2') { |
|
3702 | 3771 | } */ |
3703 | 3772 | }; |
3704 | 3773 |
|
3705 | | - mesh.getText = () => text; |
| 3774 | + mesh.getText = () => { |
| 3775 | + if (selectedTab === 1){ |
| 3776 | + return text; |
| 3777 | + } else if (selectedTab === 2) { |
| 3778 | + return sceneText; |
| 3779 | + } |
| 3780 | + } |
3706 | 3781 | mesh.setText = newText => { |
3707 | | - text = newText; |
3708 | | - _updateMeasures(); |
| 3782 | + if (selectedTab === 1){ |
| 3783 | + text = newText; |
| 3784 | + _updateUrlMeasures(); |
| 3785 | + } else if (selectedTab === 2) { |
| 3786 | + sceneText = newText; |
| 3787 | + _updateSceneMeasures(); |
| 3788 | + } |
3709 | 3789 | _updateTextureDynamic(); |
3710 | 3790 | }; |
3711 | | - mesh.getValue = () => cursor; |
| 3791 | + mesh.getValue = () => { |
| 3792 | + if (selectedTab === 1){ |
| 3793 | + console.log("getValue of urlCursor = " + urlCursor); |
| 3794 | + return urlCursor; |
| 3795 | + } else if (selectedTab === 2) { |
| 3796 | + console.log("getValue of sceneCursor = " + sceneCursor); |
| 3797 | + return sceneCursor; |
| 3798 | + } |
| 3799 | + }; |
3712 | 3800 | mesh.setValue = newValue => { |
3713 | | - cursor = newValue; |
| 3801 | + if (selectedTab === 1){ |
| 3802 | + urlCursor = newValue; |
| 3803 | + console.log("set urlCursor = " + newValue); |
| 3804 | + } else if (selectedTab === 2) { |
| 3805 | + sceneCursor = newValue; |
| 3806 | + console.log("set sceneCursor = " + newValue); |
| 3807 | + } |
3714 | 3808 | _updateTextureStatic(); |
3715 | 3809 | }; |
3716 | 3810 | mesh.refresh = _updateTextureStatic; |
|
3868 | 3962 |
|
3869 | 3963 | return object; |
3870 | 3964 | })(); |
3871 | | - mesh.add(keyboardMesh); |
| 3965 | + if (fakeXrDisplay) { |
| 3966 | + mesh.add(keyboardMesh); |
| 3967 | + } |
3872 | 3968 |
|
3873 | 3969 | const appIconMeshes = new THREE.Object3D(); |
3874 | 3970 | scene.add(appIconMeshes); |
|
0 commit comments