Skip to content

Commit c85a1ae

Browse files
authored
Use layout color for the cube (#18)
* Use layout color for the cube * Iterate on cube appearance
1 parent 2b8f2be commit c85a1ae

File tree

1 file changed

+20
-57
lines changed

1 file changed

+20
-57
lines changed

src/arCube.ts

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import {
66
import * as THREEx from '@ar-js-org/ar.js/three.js/build/ar-threex.js';
77
import { Signal } from '@lumino/signaling';
88
import * as THREE from 'three';
9+
import { RoundedBoxGeometry } from 'three/examples/jsm/geometries/RoundedBoxGeometry';
910
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
1011
import { hmsActions, hmsStore } from './hms';
1112
import { IModelRegistryData } from './registry';
13+
1214
const FIRST_SCENE = 0;
1315
const SECOND_SCENE = 1;
1416

@@ -205,6 +207,13 @@ class ArCube {
205207
this.arToolkitSource.init();
206208
}
207209

210+
getThemeColor() {
211+
const layoutColor = getComputedStyle(document.body);
212+
const cubeColorValue = layoutColor.getPropertyValue('--jp-layout-color0');
213+
214+
return cubeColorValue;
215+
}
216+
208217
// updateSource() {
209218
// const deviceId = hmsStore.getState(selectAppData('videoDeviceId'));
210219

@@ -324,72 +333,26 @@ class ArCube {
324333
sceneGroup.scale.set(1.75 / 2, 1.75 / 2, 1.75 / 2);
325334
sceneGroup.name = `scene${sceneNumber}`;
326335

336+
const cubeColor = this.getThemeColor();
337+
327338
// reversed cube
328339
//TODO: Can probably just have one cube and add it to scenes as needed
329-
sceneGroup.add(
330-
new THREE.Mesh(
331-
new THREE.BoxGeometry(2, 2, 2),
332-
new THREE.MeshBasicMaterial({
333-
color: '#2EEEFF',
334-
side: THREE.BackSide
335-
})
336-
)
337-
);
338340

339-
// cube edges
340-
const edgeGroup = new THREE.Group();
341-
const edgeGeometry = new THREE.CylinderGeometry(0.03, 0.03, 2, 32);
342-
343-
const edgeCenters = [
344-
new THREE.Vector3(0, -1, -1),
345-
new THREE.Vector3(0, 1, -1),
346-
new THREE.Vector3(0, -1, 1),
347-
new THREE.Vector3(0, 1, 1),
348-
new THREE.Vector3(-1, 0, -1),
349-
new THREE.Vector3(1, 0, -1),
350-
new THREE.Vector3(-1, 0, 1),
351-
new THREE.Vector3(1, 0, 1),
352-
new THREE.Vector3(-1, -1, 0),
353-
new THREE.Vector3(1, -1, 0),
354-
new THREE.Vector3(-1, 1, 0),
355-
new THREE.Vector3(1, 1, 0)
356-
];
357-
358-
const edgeRotations = [
359-
new THREE.Vector3(0, 0, Math.PI / 2),
360-
new THREE.Vector3(0, 0, Math.PI / 2),
361-
new THREE.Vector3(0, 0, Math.PI / 2),
362-
new THREE.Vector3(0, 0, Math.PI / 2),
363-
new THREE.Vector3(0, 0, 0),
364-
new THREE.Vector3(0, 0, 0),
365-
new THREE.Vector3(0, 0, 0),
366-
new THREE.Vector3(0, 0, 0),
367-
new THREE.Vector3(Math.PI / 2, 0, 0),
368-
new THREE.Vector3(Math.PI / 2, 0, 0),
369-
new THREE.Vector3(Math.PI / 2, 0, 0),
370-
new THREE.Vector3(Math.PI / 2, 0, 0)
371-
];
372-
373-
for (let i = 0; i < 12; i++) {
374-
const edge = new THREE.Mesh(
375-
edgeGeometry,
376-
new THREE.MeshLambertMaterial({
377-
color: '#262626'
378-
})
379-
);
380-
edge.position.copy(edgeCenters[i]);
381-
edge.rotation.setFromVector3(edgeRotations[i]);
341+
const bgCube = new THREE.Mesh(
342+
new RoundedBoxGeometry(2, 2, 2, 7, 0.1),
343+
new THREE.MeshBasicMaterial({
344+
color: cubeColor,
345+
side: THREE.BackSide
346+
})
347+
);
382348

383-
edgeGroup.add(edge);
384-
}
349+
sceneGroup.add(bgCube);
385350

386-
edgeGroup.name = 'edge-group';
387-
sceneGroup.add(edgeGroup);
388351
this.sceneGroups.push(sceneGroup);
389352

390353
// Set up BG cubes bounding box and center
391354
if (!this.bgCubeBoundingBox) {
392-
this.bgCubeBoundingBox = new THREE.Box3().setFromObject(edgeGroup);
355+
this.bgCubeBoundingBox = new THREE.Box3().setFromObject(bgCube);
393356
this.bgCubeBoundingBox.getCenter(this.bgCubeCenter);
394357
}
395358

0 commit comments

Comments
 (0)