|
3806 | 3806 | mesh.updateMatrixWorld(); |
3807 | 3807 | }; |
3808 | 3808 | mesh.update(); |
3809 | | - mesh.getRange = () => [sx, sy, sz, dx, dy, dz]; |
3810 | 3809 | mesh.getCenter = () => [(sx+dx)/2 + 0.5, (sy+dy)/2 + 0.5, (sz+dz)/2 + 0.5]; |
3811 | | - mesh.classify = () => { |
3812 | | - const wx = Math.abs(dx - sx) + 1; |
3813 | | - const wy = Math.abs(dy - sy) + 1; |
3814 | | - const wz = Math.abs(dz - sz) + 1; |
3815 | | - if (wx === 1 && wy === 1 && wz === 1) { |
3816 | | - return 'point'; |
3817 | | - } else if (wx === 1 && wy === 2 && wz === 1) { |
3818 | | - return 'portal'; |
3819 | | - } else { |
3820 | | - const sortedDimensions = [wx, wy, wz].sort((a, b) => a - b); |
3821 | | - if (sortedDimensions[0] === 1 && sortedDimensions[1] > 1 && sortedDimensions[2] > 1) { |
3822 | | - return 'plane'; |
3823 | | - } else { |
3824 | | - return 'volume'; |
3825 | | - } |
3826 | | - } |
3827 | | - }; |
3828 | 3810 | mesh.setEnd = (newDx, newDy, newDz) => { |
3829 | 3811 | dx = newDx; |
3830 | 3812 | dy = newDy; |
|
3883 | 3865 | mesh.quaternion.set(ox, oy, oz, ow); |
3884 | 3866 | }; |
3885 | 3867 | mesh.getCenter = () => mesh.position.toArray(); |
3886 | | - /* mesh.intersect = ray => { |
3887 | | - localMatrix.compose( |
3888 | | - ray.origin, |
3889 | | - localQuaternion.setFromUnitVectors(localVector.set(0, 0, -1), ray.direction), |
3890 | | - localVector2.set(1, 1, 1) |
3891 | | - ).premultiply( |
3892 | | - localMatrix2 |
3893 | | - .copy(mesh.matrixWorld) |
3894 | | - .getInverse(localMatrix2) |
3895 | | - ).decompose(localRay.origin, localQuaternion, localVector); |
3896 | | - localRay.direction.set(0, 0, -1).applyQuaternion(localQuaternion); |
3897 | | - localBox.setFromCenterAndSize(localVector.set(0, 0, 0), localVector2.set(0.1, 0.1, 0.1)); |
3898 | | -
|
3899 | | - const intersectionPoint = localRay.intersectBox(localBox, localVector); |
3900 | | - if (intersectionPoint) { |
3901 | | - const distance = localRay.origin.distanceTo(intersectionPoint); |
3902 | | - return { |
3903 | | - type: 'point', |
3904 | | - distance, |
3905 | | - }; |
3906 | | - } else { |
3907 | | - return null; |
3908 | | - } |
3909 | | - }; */ |
3910 | 3868 |
|
3911 | 3869 | return mesh; |
3912 | 3870 | }; |
|
4070 | 4028 | mesh.updateMatrixWorld(); |
4071 | 4029 | }; |
4072 | 4030 | mesh.update(); |
4073 | | - mesh.getRange = () => [sx, sy, sz, dx, dy, dz]; |
4074 | 4031 | mesh.getCenter = () => [(sx+dx)/2, (sy+dy)/2, (sz+dz)/2]; |
4075 | | - mesh.classify = () => 'volume'; |
4076 | 4032 | mesh.setEnd = (newDx, newDy, newDz) => { |
4077 | 4033 | dx = newDx; |
4078 | 4034 | dy = newDy; |
|
4170 | 4126 | mesh.update(); |
4171 | 4127 | return mesh; |
4172 | 4128 | }; |
4173 | | -const _makeRoomDiagramMesh = (index, type, label, color) => { |
4174 | | - let wx, wy, wz; |
4175 | | - if (type === 'point') { |
4176 | | - wx = 1; |
4177 | | - wy = 1; |
4178 | | - wz = 1; |
4179 | | - } else if (type === 'portal') { |
4180 | | - wx = 1; |
4181 | | - wy = 2; |
4182 | | - wz = 1; |
4183 | | - } else if (type === 'plane') { |
4184 | | - wx = 2; |
4185 | | - wy = 2; |
4186 | | - wz = 1; |
4187 | | - } else /* if (type === 'volume') */ { |
4188 | | - wx = 2; |
4189 | | - wy = 2; |
4190 | | - wz = 2; |
4191 | | - } |
4192 | | - const geometry = new THREE.BoxBufferGeometry(0.1*wx, 0.1*wy, 0.1*wz, wx, wy, wz) |
4193 | | - .applyMatrix(localMatrix.makeTranslation(0.1*wx/2, 0.1*wy/2, 0.1*wz/2)); |
4194 | | - /* const uvs = geometry.attributes.uv.array; |
4195 | | - const baseUvs = Float32Array.from(uvs); |
4196 | | - const _updateUvs = () => { |
4197 | | - for (let i = 0; i < uvs.length; i += 2) { |
4198 | | - uvs[i] = baseUvs[i] * s; |
4199 | | - uvs[i+1] = baseUvs[i+1] * s; |
4200 | | - } |
4201 | | - geometry.attributes.uv.needsUpdate = true; |
4202 | | - }; |
4203 | | - _updateUvs(); */ |
4204 | | - const roomVsh = ` |
4205 | | - varying vec3 vWorldPos; |
4206 | | - varying vec3 vNormal; |
4207 | | - void main() { |
4208 | | - vWorldPos = position; |
4209 | | - gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.); |
4210 | | - vNormal = normal; |
4211 | | - } |
4212 | | - `; |
4213 | | - const roomFsh = ` |
4214 | | - // uniform sampler2D uTex; |
4215 | | - uniform vec3 uColor; |
4216 | | - uniform float uHighlight; |
4217 | | - varying vec3 vWorldPos; |
4218 | | - varying vec3 vNormal; |
4219 | | - void main() { |
4220 | | - // vec2 uv = fract(vUv); |
4221 | | - vec2 uv; |
4222 | | - if (vNormal.x != 0.0) { |
4223 | | - uv = fract(vWorldPos.yz/0.1); |
4224 | | - } else if (vNormal.y != 0.0) { |
4225 | | - uv = fract(vWorldPos.xz/0.1); |
4226 | | - } else /* if (vNormal.z != 0.0) */ { |
4227 | | - uv = fract(vWorldPos.xy/0.1); |
4228 | | - } |
4229 | | - if ((uv.x <= 0.01 || uv.x >= 0.99) || (uv.y <= 0.01 || uv.y >= 0.99)) { |
4230 | | - gl_FragColor = vec4(uColor, 0.5); |
4231 | | - } else if (abs(uv.x - uv.y) <= 0.01) { |
4232 | | - gl_FragColor = vec4(0.2, 0.2, 0.2, 0.5); |
4233 | | - } else { |
4234 | | - gl_FragColor = vec4(0.1, 0.1, 0.1, 0.5); |
4235 | | - } |
4236 | | -
|
4237 | | - // gl_FragColor.rgb += uHighlight; |
4238 | | - } |
4239 | | - `; |
4240 | | - const material = new THREE.ShaderMaterial({ |
4241 | | - uniforms: { |
4242 | | - uColor: { |
4243 | | - type: 'c', |
4244 | | - value: new THREE.Color(color), |
4245 | | - }, |
4246 | | - /* uHighlight: { |
4247 | | - type: 'f', |
4248 | | - value: 0, |
4249 | | - }, */ |
4250 | | - }, |
4251 | | - vertexShader: roomVsh, |
4252 | | - fragmentShader: roomFsh, |
4253 | | - side: THREE.DoubleSide, |
4254 | | - transparent: true, |
4255 | | - }); |
4256 | | - |
4257 | | - const mesh = new THREE.Object3D(); |
4258 | | - mesh.label = label; |
4259 | | - mesh.update = () => { |
4260 | | - mesh.position |
4261 | | - .copy(trayMesh.position) |
4262 | | - .add(localVector.set(-0.8 + index * 0.4, 0.1, 0).applyQuaternion(trayMesh.quaternion)); |
4263 | | - mesh.rotation.y += 0.01; |
4264 | | - mesh.updateMatrixWorld(); |
4265 | | - }; |
4266 | | - mesh.update(); |
4267 | | - |
4268 | | - const innerMesh = new THREE.Mesh(geometry, material); |
4269 | | - innerMesh.position.set(-0.1*wx/2, -0.1*wy/2, -0.1*wz/2); |
4270 | | - innerMesh.frustumCulled = false; |
4271 | | - mesh.add(innerMesh); |
4272 | | - |
4273 | | - return mesh; |
4274 | | -}; |
4275 | 4129 |
|
4276 | 4130 | const portalVsh = ` |
4277 | 4131 | varying vec3 vWorldPos; |
|
5360 | 5214 | console.warn(`unknown intersection type ${type}`); |
5361 | 5215 | } |
5362 | 5216 | } |
5363 | | - } /* else { |
5364 | | - if (window.document.pointerLockElement) { |
5365 | | - if (toolMesh.tool === 'point') { |
5366 | | - if (start) { |
5367 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5368 | | - const p = c.position.clone().add(new THREE.Vector3(0, 0, -1).applyQuaternion(c.quaternion)); |
5369 | | - const point = _makePointMesh(p.x, p.y, p.z, c.quaternion.x, c.quaternion.y, c.quaternion.z, c.quaternion.w); |
5370 | | - scene.add(point); |
5371 | | - pointMeshes.push(point); |
5372 | | - pendingRooms[i] = point; |
5373 | | - } else if (end) { |
5374 | | - const point = pendingRooms[i]; |
5375 | | - if (point) { |
5376 | | - pendingRooms[i] = null; |
5377 | | - const labelMesh = _makeLabelMesh('https://google.com'); |
5378 | | - labelMesh.position.copy(point.position); |
5379 | | - labelMesh.position.y += 0.1; |
5380 | | - labelMesh.rotation.setFromQuaternion(point.quaternion, 'YXZ'); |
5381 | | - labelMesh.rotation.x = 0; |
5382 | | - labelMesh.updateMatrixWorld(); |
5383 | | - labelMesh.update(); |
5384 | | - scene.add(labelMesh); |
5385 | | - roomLabels.push(labelMesh); |
5386 | | -
|
5387 | | - const roomLinkMesh = _makeRoomLinkMesh(roomLinks.length, point); |
5388 | | - scene.add(roomLinkMesh); |
5389 | | - roomLinks.push(roomLinkMesh); |
5390 | | - } |
5391 | | - } else { |
5392 | | - const point = pendingRooms[i]; |
5393 | | - if (point) { |
5394 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5395 | | - const p = c.position.clone().add(new THREE.Vector3(0, 0, -1).applyQuaternion(c.quaternion)); |
5396 | | - point.setEnd(p.x, p.y, p.z, c.quaternion.x, c.quaternion.y, c.quaternion.z, c.quaternion.w); |
5397 | | - // console.log('update room', targetMesh.material.uniforms.worldPos.value.toArray().join(',')); |
5398 | | - } |
5399 | | - } |
5400 | | - } else if (toolMesh.tool === 'browser' || toolMesh.tool === 'portal') { |
5401 | | - if (start) { |
5402 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5403 | | - const p = c.position.clone().add(new THREE.Vector3(0, 0, -1).applyQuaternion(c.quaternion)); |
5404 | | - const browser = _makeBrowserMesh(p.x, p.y, p.z, c.quaternion.x, c.quaternion.y, c.quaternion.z, c.quaternion.w, 0x9ccc65); |
5405 | | - scene.add(browser); |
5406 | | - // rooms.push(browser); |
5407 | | - pendingRooms[i] = browser; |
5408 | | - } else if (end) { |
5409 | | - const browser = pendingRooms[i]; |
5410 | | - if (browser) { |
5411 | | - pendingRooms[i] = null; |
5412 | | - const labelMesh = _makeLabelMesh('https://google.com'); |
5413 | | - labelMesh.position.copy(browser.position); |
5414 | | - labelMesh.position.y += 0.1; |
5415 | | - labelMesh.rotation.setFromQuaternion(browser.quaternion, 'YXZ'); |
5416 | | - labelMesh.rotation.x = 0; |
5417 | | - labelMesh.updateMatrixWorld(); |
5418 | | - labelMesh.update(); |
5419 | | - scene.add(labelMesh); |
5420 | | - roomLabels.push(labelMesh); |
5421 | | -
|
5422 | | - const roomLinkMesh = _makeRoomLinkMesh(roomLinks.length, browser); |
5423 | | - scene.add(roomLinkMesh); |
5424 | | - roomLinks.push(roomLinkMesh); |
5425 | | - } |
5426 | | - } else { |
5427 | | - const browser = pendingRooms[i]; |
5428 | | - if (browser) { |
5429 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5430 | | - browser.setEnd(c.position.x, c.position.y, c.position.z, c.quaternion.x, c.quaternion.y, c.quaternion.z, c.quaternion.w); |
5431 | | - // console.log('update room', targetMesh.material.uniforms.worldPos.value.toArray().join(',')); |
5432 | | - } |
5433 | | - } |
5434 | | - } else { |
5435 | | - if (start) { |
5436 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5437 | | - const p = c.position.clone().add(new THREE.Vector3(0, 0, -1).applyQuaternion(c.quaternion)); |
5438 | | - const room = _makeVolumeMesh(p.x, p.y, p.z, p.x, p.y, p.z, 0x4caf50); |
5439 | | - scene.add(room); |
5440 | | - rooms.push(room); |
5441 | | - pendingRooms[i] = room; |
5442 | | - } else if (end) { |
5443 | | - const room = pendingRooms[i]; |
5444 | | - if (room) { |
5445 | | - // room.setColor(0x5c6bc0); |
5446 | | - pendingRooms[i] = null; |
5447 | | - const roomLinkMesh = _makeRoomLinkMesh(roomLinks.length, room); |
5448 | | - scene.add(roomLinkMesh); |
5449 | | - roomLinks.push(roomLinkMesh); |
5450 | | - const roomDiagramMesh = _makeRoomDiagramMesh(roomDiagrams.length, room.classify(), 'tutorial.html', 0xffee58); |
5451 | | - scene.add(roomDiagramMesh); |
5452 | | - roomDiagrams.push(roomDiagramMesh); |
5453 | | - _addVolume(room); |
5454 | | - // console.log('end room', room.classify(), targetMesh.material.uniforms.worldPos.value.toArray().join(',')); |
5455 | | - } |
5456 | | - } else { |
5457 | | - const room = pendingRooms[i]; |
5458 | | - if (room) { |
5459 | | - const c = renderer.vr.enabled ? renderer.vr.getCamera(camera) : camera; |
5460 | | - const p = c.position.clone().add(new THREE.Vector3(0, 0, -1).applyQuaternion(c.quaternion)); |
5461 | | - room.setEnd(p.x, p.y, p.z); |
5462 | | - // console.log('update room', targetMesh.material.uniforms.worldPos.value.toArray().join(',')); |
5463 | | - } |
5464 | | - } |
5465 | | - } |
5466 | | - } |
5467 | | - } */ |
| 5217 | + } |
5468 | 5218 | } |
5469 | 5219 | }; |
5470 | 5220 | const _makeMenuAnimation = spec => { |
|
0 commit comments