|
1203 | 1203 | layers.splice(layers.indexOf(xrIframe), 1); |
1204 | 1204 | xrIframe.destroy(); |
1205 | 1205 | scene.remove(moveMesh); |
| 1206 | + scene.remove(moveMesh.labelMesh); |
1206 | 1207 | moveMeshes.splice(moveMeshes.indexOf(moveMesh), 1); |
1207 | 1208 | currentMoveMeshes[i] = null; |
1208 | 1209 | } |
|
1769 | 1770 | return object; |
1770 | 1771 | }; |
1771 | 1772 |
|
1772 | | -const _makeLabelMesh = s => { |
1773 | | - const width = 2; |
1774 | | - const height = 0.2; |
1775 | | - const geometry = new THREE.PlaneBufferGeometry(width, height); |
1776 | | - const labelVsh = ` |
1777 | | - varying vec2 vUv; |
1778 | | - void main() { |
1779 | | - gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.); |
1780 | | - vUv = uv; |
1781 | | - } |
1782 | | - `; |
1783 | | - const labelFsh = ` |
1784 | | - varying vec2 vUv; |
1785 | | - // vec4 color = vec4(${new THREE.Color(0x1976d2).toArray().map(n => n.toFixed(8)).join(',')}, 1.0); |
1786 | | - vec4 color = vec4(${new THREE.Color(0x333333).toArray().map(n => n.toFixed(8)).join(',')}, 1.0); |
1787 | | - void main() { |
1788 | | - if ((vUv.x < 0.005 || vUv.x > 0.995) || (vUv.y < 0.03 || vUv.y > 0.97)) { |
1789 | | - // gl_FragColor = vec4(vec3(0.11055276381909548, 0.27638190954773867, 0.4103852596314908) * 2.0, 1.0); |
1790 | | - gl_FragColor = color; |
1791 | | - } else { |
1792 | | - // gl_FragColor = vec4(vUv.x, vUv.y, 0.0, 0.5); |
1793 | | - gl_FragColor = vec4(1., 1., 1., 1.); |
1794 | | - } |
1795 | | - } |
1796 | | - `; |
1797 | | - const material = new THREE.ShaderMaterial({ |
1798 | | - vertexShader: labelVsh, |
1799 | | - fragmentShader: labelFsh, |
1800 | | - transparent: true, |
1801 | | - side: THREE.DoubleSide, |
1802 | | - // depthWrite: false, |
| 1773 | +const _makeLabelMesh = () => { |
| 1774 | + const geometry = new THREE.PlaneBufferGeometry(1, 0.1); |
| 1775 | + const material = new THREE.MeshBasicMaterial({ |
| 1776 | + color: 0x000080, |
1803 | 1777 | }); |
1804 | 1778 | const mesh = new THREE.Mesh(geometry, material); |
1805 | | - mesh.width = width; |
1806 | | - mesh.height = height; |
1807 | 1779 | mesh.frustumCulled = false; |
1808 | | - mesh.getGlyphs = () => { |
1809 | | - const glyphs = textMesh.geometry.layout.glyphs.slice(); |
1810 | | - if (glyphs.length > 0) { |
1811 | | - const lastGlyph = glyphs[glyphs.length - 1]; |
1812 | | - glyphs.push({x: lastGlyph.x + lastGlyph.data.width}); |
1813 | | - } |
1814 | | - return glyphs; |
1815 | | - }; |
1816 | | - mesh.plane = new THREE.Plane(); |
1817 | | - mesh.leftLine = new THREE.Line3(); |
1818 | | - mesh.topLine = new THREE.Line3(); |
1819 | | - mesh.update = () => { |
1820 | | - const menuWorldWidth = width; |
1821 | | - const menuWorldHeight = height; |
1822 | | - mesh.leftLine.start |
1823 | | - .set(-menuWorldWidth/2, menuWorldHeight/2, 0) |
1824 | | - .applyMatrix4(mesh.matrixWorld); |
1825 | | - mesh.leftLine.end |
1826 | | - .set(-menuWorldWidth/2, -menuWorldHeight/2, 0) |
1827 | | - .applyMatrix4(mesh.matrixWorld); |
1828 | | - |
1829 | | - mesh.topLine.start |
1830 | | - .set(-menuWorldWidth/2, menuWorldHeight/2, 0) |
1831 | | - .applyMatrix4(mesh.matrixWorld); |
1832 | | - mesh.topLine.end |
1833 | | - .set(menuWorldWidth/2, menuWorldHeight / 2, 0) |
1834 | | - .applyMatrix4(mesh.matrixWorld); |
1835 | | - |
1836 | | - mesh.plane.setFromCoplanarPoints( |
1837 | | - mesh.leftLine.start, |
1838 | | - mesh.leftLine.end, |
1839 | | - mesh.topLine.end |
1840 | | - ); |
1841 | | - }; |
1842 | | - mesh.intersect = ray => { |
1843 | | - const intersectionPoint = ray.intersectPlane(mesh.plane, localVector); |
1844 | | - if (intersectionPoint) { |
1845 | | - const leftIntersectionPoint = mesh.leftLine.closestPointToPoint(intersectionPoint, true, localVector2); |
1846 | | - const topIntersectionPoint = mesh.topLine.closestPointToPoint(intersectionPoint, true, localVector3); |
1847 | | - |
1848 | | - const xFactor = topIntersectionPoint.distanceTo(mesh.topLine.start) / mesh.width; |
1849 | | - const yFactor = leftIntersectionPoint.distanceTo(mesh.leftLine.start) / mesh.height; |
1850 | | - const distance = ray.origin.distanceTo(intersectionPoint); |
1851 | | - |
1852 | | - if (xFactor > 0 && xFactor < 0.99999 && yFactor > 0 && yFactor < 0.99999 && distance < rayDistance) { |
1853 | | - const xScale = mesh.width / mesh.textMesh.scale.x; |
1854 | | - const x = xFactor * xScale; |
1855 | | - const yScale = mesh.height; |
1856 | | - const y = yFactor * yScale; |
1857 | | - return { |
1858 | | - type: 'label', |
1859 | | - mesh, |
1860 | | - distance, |
1861 | | - cancel: true, |
1862 | | - x, |
1863 | | - y, |
1864 | | - xScale, |
1865 | | - yScale, |
1866 | | - }; |
1867 | | - } |
1868 | | - } |
1869 | | - return null; |
1870 | | - }; |
1871 | | - |
1872 | | - const textMesh = _makeTextMesh(s, 0x000000); |
1873 | | - textMesh.position.x -= width/2; |
1874 | | - // textMesh.position.x += -0.45; |
1875 | | - textMesh.position.y += 0.02; |
1876 | | - textMesh.position.z += 0.001; |
1877 | | - mesh.add(textMesh); |
1878 | | - mesh.textMesh = textMesh; |
1879 | | - |
1880 | | - const caretMesh = _makeCaretMesh(mesh, 0x000000); |
1881 | | - mesh.add(caretMesh); |
1882 | | - mesh.caretMesh = caretMesh; |
1883 | | - |
1884 | 1780 | return mesh; |
1885 | 1781 | }; |
1886 | 1782 |
|
|
3520 | 3416 | scene.add(moveMesh); |
3521 | 3417 | moveMeshes.push(moveMesh); |
3522 | 3418 | currentMoveMeshes[controllerIndex] = moveMesh; |
| 3419 | + |
| 3420 | + const labelMesh = _makeLabelMesh(); |
| 3421 | + scene.add(labelMesh); |
| 3422 | + moveMesh.labelMesh = labelMesh; |
3523 | 3423 | } /* else { |
3524 | 3424 | console.log('no match', intersectionSpec, new Error().stack); |
3525 | 3425 | } */ |
|
5541 | 5441 | for (let i = 0; i < moveMeshes.length; i++) { |
5542 | 5442 | const moveMesh = moveMeshes[i]; |
5543 | 5443 | moveMesh.scale.set(menuFactor, menuFactor, menuFactor); |
5544 | | - moveMesh.updateMatrixWorld(); |
5545 | 5444 | moveMesh.visible = true; |
| 5445 | + moveMesh.labelMesh.scale.set(menuFactor, menuFactor, menuFactor); |
| 5446 | + moveMesh.labelMesh.visible = true; |
| 5447 | + // moveMesh.updateMatrixWorld(); |
5546 | 5448 | } |
5547 | 5449 | for (let i = 0; i < controllerMeshes.length; i++) { |
5548 | 5450 | const controllerMesh = controllerMeshes[i]; |
|
5573 | 5475 | if (end.factor === 0) { |
5574 | 5476 | screenMesh.visible = false; |
5575 | 5477 | for (let i = 0; i < moveMeshes.length; i++) { |
5576 | | - moveMeshes[i].visible = false; |
| 5478 | + const moveMesh = moveMeshes[i]; |
| 5479 | + moveMesh.visible = false; |
| 5480 | + moveMesh.labelMesh.visible = false; |
5577 | 5481 | } |
5578 | 5482 | for (let i = 0; i < controllerMeshes.length; i++) { |
5579 | 5483 | controllerMeshes[i].rayMesh.visible = false; |
|
5614 | 5518 | moveMesh.scale.multiplyScalar(1 + (1-Math.cos(angle))*0.2); |
5615 | 5519 | } |
5616 | 5520 | } |
| 5521 | + |
| 5522 | + const {labelMesh} = moveMesh; |
| 5523 | + labelMesh.position.copy(moveMesh.position).add(localVector.set(0, 1, 0)); |
| 5524 | + const vrCamera = renderer.vr.enabled ? renderer.vr.getCamera(camera).cameras[0] : camera; |
| 5525 | + labelMesh.quaternion.copy(vrCamera.quaternion); |
5617 | 5526 | } |
5618 | 5527 | } |
5619 | 5528 | }; |
|
0 commit comments