Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit ed35d22

Browse files
author
Avaer Kazmer
committed
Hook in model mesh loading
1 parent e1919aa commit ed35d22

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

index.html

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,7 +2425,9 @@
24252425
return type => {
24262426
switch (type) {
24272427
case 'browser': return _makeBrowserMesh();
2428-
case 'volume': return _makeVolumeMesh();
2428+
case 'volume':
2429+
case 'model':
2430+
return _makeVolumeMesh();
24292431
default: return null;
24302432
}
24312433
};
@@ -2504,8 +2506,10 @@
25042506
const mesh = new THREE.Mesh(geometry, material);
25052507
mesh.frustumCulled = false;
25062508
mesh.localVisible = true;
2509+
mesh.iframe = null;
2510+
mesh.model = null;
25072511

2508-
if (url && type) {
2512+
if (url && ['browser', 'volume'].includes(type)) {
25092513
const iframe = _makeIframe(url, type);
25102514

25112515
if (type === 'browser' || type === 'volume') {
@@ -2515,15 +2519,50 @@
25152519
} else {
25162520
throw new Error(`unknown iframe type ${type}`);
25172521
}
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+
});
25202558
}
25212559
if (type) {
25222560
const material2 = material.clone();
25232561
const typeImg = (() => {
25242562
switch (type) {
25252563
case 'browser': return browserImg;
25262564
case 'volume': return diceImg;
2565+
case 'model': return dice2Img;
25272566
default: return null;
25282567
}
25292568
})();
@@ -2747,7 +2786,9 @@
27472786
}, true);
27482787

27492788
_addApp(iconMesh);
2750-
_moveApp(iconMesh, i);
2789+
if (i !== -1) {
2790+
_moveApp(iconMesh, i);
2791+
}
27512792

27522793
selectedIconMesh = trayMesh.appIconMeshes;
27532794
selectedIconCoord.set(iconMesh.x, 0);
@@ -2770,7 +2811,9 @@
27702811
if (iconMesh.iframe) {
27712812
layers.push(iconMesh.iframe);
27722813
}
2773-
2814+
if (iconMesh.model) {
2815+
scene.add(iconMesh.model);
2816+
}
27742817
if (iconMesh.moveMesh) {
27752818
scene.add(iconMesh.moveMesh);
27762819
}
@@ -2792,13 +2835,15 @@
27922835
}
27932836
trayMesh.appIconMeshes.remove(iconMesh);
27942837

2795-
if (iconMesh.moveMesh) {
2796-
scene.remove(iconMesh.moveMesh);
2797-
}
2798-
27992838
if (iconMesh.iframe) {
28002839
layers.splice(layers.indexOf(iconMesh.iframe), 1);
28012840
}
2841+
if (iconMesh.model) {
2842+
scene.remove(iconMesh.model);
2843+
}
2844+
if (iconMesh.moveMesh) {
2845+
scene.remove(iconMesh.moveMesh);
2846+
}
28022847

28032848
// if (!trayMesh.appIconMeshes.children.some(iconMesh => iconMesh.x === selectedIconCoord.x && iconMesh.y === selectedIconCoord.y)) {
28042849
if (selectedIconMesh === trayMesh.appIconMeshes) {
@@ -4896,7 +4941,7 @@
48964941
const gamepad = gamepads[i];
48974942
if (gamepad) {
48984943
const {iconMesh} = moveSpec;
4899-
const {type, iframe, moveMesh} = iconMesh;
4944+
const {type, iframe, model, moveMesh} = iconMesh;
49004945

49014946
localVector.fromArray(gamepad.pose.position);
49024947
localQuaternion.fromArray(gamepad.pose.orientation);
@@ -4937,6 +4982,10 @@
49374982
iframe.position = localVector.toArray();
49384983
iframe.orientation = localQuaternion.toArray();
49394984
}
4985+
if (model) {
4986+
model.position.copy(localVector);
4987+
model.quaternion.copy(localQuaternion);
4988+
}
49404989
}
49414990
}
49424991
}

0 commit comments

Comments
 (0)