|
2425 | 2425 | return type => {
|
2426 | 2426 | switch (type) {
|
2427 | 2427 | case 'browser': return _makeBrowserMesh();
|
2428 |
| - case 'volume': return _makeVolumeMesh(); |
| 2428 | + case 'volume': |
| 2429 | + case 'model': |
| 2430 | + return _makeVolumeMesh(); |
2429 | 2431 | default: return null;
|
2430 | 2432 | }
|
2431 | 2433 | };
|
|
2504 | 2506 | const mesh = new THREE.Mesh(geometry, material);
|
2505 | 2507 | mesh.frustumCulled = false;
|
2506 | 2508 | mesh.localVisible = true;
|
| 2509 | + mesh.iframe = null; |
| 2510 | + mesh.model = null; |
2507 | 2511 |
|
2508 |
| - if (url && type) { |
| 2512 | + if (url && ['browser', 'volume'].includes(type)) { |
2509 | 2513 | const iframe = _makeIframe(url, type);
|
2510 | 2514 |
|
2511 | 2515 | if (type === 'browser' || type === 'volume') {
|
|
2515 | 2519 | } else {
|
2516 | 2520 | throw new Error(`unknown iframe type ${type}`);
|
2517 | 2521 | }
|
2518 |
| - } else { |
2519 |
| - mesh.iframe = null; |
| 2522 | + } else if (url && type === 'model') { |
| 2523 | + console.log('load model', url); |
| 2524 | + |
| 2525 | + const model = new THREE.Object3D(); |
| 2526 | + mesh.model = model; |
| 2527 | + |
| 2528 | + mesh.moveMesh = _makeMoveMesh(type); |
| 2529 | + |
| 2530 | + const loader = new THREE.GLTFLoader(); |
| 2531 | + function onload(object) { |
| 2532 | + object = object.scene; |
| 2533 | + |
| 2534 | + model.add(object); |
| 2535 | + |
| 2536 | + /* var box = new THREE.Box3(); |
| 2537 | + box.setFromObject( object ); |
| 2538 | +
|
| 2539 | + // re-center |
| 2540 | +
|
| 2541 | + var center = box.getCenter(); |
| 2542 | + center.y = box.min.y; |
| 2543 | + object.position.sub( center ); |
| 2544 | +
|
| 2545 | + // scale |
| 2546 | +
|
| 2547 | + var scaler = new THREE.Group(); |
| 2548 | + scaler.add( object ); |
| 2549 | + scaler.scale.setScalar( 6 / box.getSize().length() ); |
| 2550 | + scene.add( scaler ); */ |
| 2551 | + } |
| 2552 | + loader.load(url, onload, xhr => {}, err => { |
| 2553 | + const loader = new THREE.LegacyGLTFLoader(); |
| 2554 | + loader.load(url, onload, xhr => {}, err => { |
| 2555 | + console.warn(err.stack); |
| 2556 | + }); |
| 2557 | + }); |
2520 | 2558 | }
|
2521 | 2559 | if (type) {
|
2522 | 2560 | const material2 = material.clone();
|
2523 | 2561 | const typeImg = (() => {
|
2524 | 2562 | switch (type) {
|
2525 | 2563 | case 'browser': return browserImg;
|
2526 | 2564 | case 'volume': return diceImg;
|
| 2565 | + case 'model': return dice2Img; |
2527 | 2566 | default: return null;
|
2528 | 2567 | }
|
2529 | 2568 | })();
|
|
2747 | 2786 | }, true);
|
2748 | 2787 |
|
2749 | 2788 | _addApp(iconMesh);
|
2750 |
| - _moveApp(iconMesh, i); |
| 2789 | + if (i !== -1) { |
| 2790 | + _moveApp(iconMesh, i); |
| 2791 | + } |
2751 | 2792 |
|
2752 | 2793 | selectedIconMesh = trayMesh.appIconMeshes;
|
2753 | 2794 | selectedIconCoord.set(iconMesh.x, 0);
|
|
2770 | 2811 | if (iconMesh.iframe) {
|
2771 | 2812 | layers.push(iconMesh.iframe);
|
2772 | 2813 | }
|
2773 |
| - |
| 2814 | + if (iconMesh.model) { |
| 2815 | + scene.add(iconMesh.model); |
| 2816 | + } |
2774 | 2817 | if (iconMesh.moveMesh) {
|
2775 | 2818 | scene.add(iconMesh.moveMesh);
|
2776 | 2819 | }
|
|
2792 | 2835 | }
|
2793 | 2836 | trayMesh.appIconMeshes.remove(iconMesh);
|
2794 | 2837 |
|
2795 |
| - if (iconMesh.moveMesh) { |
2796 |
| - scene.remove(iconMesh.moveMesh); |
2797 |
| - } |
2798 |
| - |
2799 | 2838 | if (iconMesh.iframe) {
|
2800 | 2839 | layers.splice(layers.indexOf(iconMesh.iframe), 1);
|
2801 | 2840 | }
|
| 2841 | + if (iconMesh.model) { |
| 2842 | + scene.remove(iconMesh.model); |
| 2843 | + } |
| 2844 | + if (iconMesh.moveMesh) { |
| 2845 | + scene.remove(iconMesh.moveMesh); |
| 2846 | + } |
2802 | 2847 |
|
2803 | 2848 | // if (!trayMesh.appIconMeshes.children.some(iconMesh => iconMesh.x === selectedIconCoord.x && iconMesh.y === selectedIconCoord.y)) {
|
2804 | 2849 | if (selectedIconMesh === trayMesh.appIconMeshes) {
|
|
4896 | 4941 | const gamepad = gamepads[i];
|
4897 | 4942 | if (gamepad) {
|
4898 | 4943 | const {iconMesh} = moveSpec;
|
4899 |
| - const {type, iframe, moveMesh} = iconMesh; |
| 4944 | + const {type, iframe, model, moveMesh} = iconMesh; |
4900 | 4945 |
|
4901 | 4946 | localVector.fromArray(gamepad.pose.position);
|
4902 | 4947 | localQuaternion.fromArray(gamepad.pose.orientation);
|
|
4937 | 4982 | iframe.position = localVector.toArray();
|
4938 | 4983 | iframe.orientation = localQuaternion.toArray();
|
4939 | 4984 | }
|
| 4985 | + if (model) { |
| 4986 | + model.position.copy(localVector); |
| 4987 | + model.quaternion.copy(localQuaternion); |
| 4988 | + } |
4940 | 4989 | }
|
4941 | 4990 | }
|
4942 | 4991 | }
|
|
0 commit comments