Skip to content

Commit 8925f75

Browse files
committed
add documentation and rename to tiling visualization
1 parent 23c3082 commit 8925f75

File tree

6 files changed

+88
-106
lines changed

6 files changed

+88
-106
lines changed

src/app.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Sandbox } from './pages/Sandbox';
2222
import { SynthesisExplorer } from './pages/SynthesisExplorer';
2323
import { MPContribsSearch } from './pages/MPContribsSearch';
2424
import { CatalystExplorer } from './pages/CatalystExplorer';
25-
import { PhononVisualization } from './pages/PhononVisualization';
25+
import { TilingVisualization } from './pages/TilingVisualization';
2626
import { Navbar } from './components/navigation/Navbar';
2727
import periodicTableImage from './assets/images/periodictable.png';
2828
import { MofExplorer } from './pages/MofExplorer';
@@ -72,8 +72,8 @@ ReactDOM.render(
7272
href: '/xas'
7373
},
7474
{
75-
label: 'Phonon Visualization',
76-
href: '/phonon'
75+
label: 'Tiling Visualization',
76+
href: '/tiling'
7777
},
7878
{
7979
label: 'More',
@@ -145,8 +145,8 @@ ReactDOM.render(
145145
<Route path="/matscholar">
146146
<MatscholarMaterialsExplorer />
147147
</Route>
148-
<Route path="/phonon">
149-
<PhononVisualization />
148+
<Route path="/tiling">
149+
<TilingVisualization />
150150
</Route>
151151
<Route path="/">
152152
<MaterialsExplorer />

src/components/crystal-toolkit/scene/Scene.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,7 @@ export default class Scene {
534534
Each scene is added to the arrayOfTilesRoots, it can be accessed by indexing through the
535535
arrayOfTileRoots. e.g. scene = arrayOfTileRoots[x][y][z][0].
536536
*/
537-
const traverseTiles = (
538-
o: SceneJsonObject,
539-
root: THREE.Object3D,
540-
tiles: number[][]
541-
// arrayOfTileRoots: number[][][][]
542-
) => {
537+
const traverseTiles = (o: SceneJsonObject, root: THREE.Object3D, tiles: number[][]) => {
543538
// @ts-ignore
544539
let lattice = o.lattice ? o.lattice : emptyLattice;
545540

@@ -624,20 +619,19 @@ export default class Scene {
624619
// TODO: does it make sense to split this code into two cases? NO!
625620
// set up the threeObjects and containers
626621
const rootObject = new THREE.Object3D();
627-
if (this.maxTiling > 0) {
628-
// if needed, create a parent for all Scene objects
629-
rootObject.name = 'root';
630-
rootObject.visible = true;
631-
const maxTilingArray = [this.maxTiling, this.maxTiling, this.maxTiling];
632-
let tiles = _getTiles(maxTilingArray);
633-
traverseTiles(sceneJson, rootObject, tiles);
634-
this.updateTiles(this.tiling);
635-
console.log(this.arrayOfTileRoots);
636-
} else {
637-
rootObject.name = sceneJson.name!;
638-
sceneJson.visible && (rootObject.visible = sceneJson.visible);
639-
traverseScene(sceneJson, rootObject, emptyLattice, '');
640-
} // TODO: take this out, hope things dont break, fix if they do
622+
// if (this.maxTiling > 0) {
623+
// if needed, create a parent for all Scene objects
624+
rootObject.name = 'root';
625+
rootObject.visible = true;
626+
const maxTilingArray = [this.maxTiling, this.maxTiling, this.maxTiling];
627+
let tiles = _getTiles(maxTilingArray);
628+
traverseTiles(sceneJson, rootObject, tiles);
629+
this.updateTiles(this.tiling);
630+
// } else {
631+
// rootObject.name = sceneJson.name!;
632+
// sceneJson.visible && (rootObject.visible = sceneJson.visible);
633+
// traverseScene(sceneJson, rootObject, emptyLattice, '');
634+
// } // TODO: take this out, hope things dont break, fix if they do
641635

642636
// can cause memory leak
643637
this.scene.add(rootObject);

src/pages/PhononVisualization/PhononVisualization.tsx

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/pages/PhononVisualization/index.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { crystalScene } from '../../components/crystal-toolkit/scene/simple-scene';
3+
import { Renderer } from '../../components/crystal-toolkit/scene/constants';
4+
import { CrystalToolkitScene } from '../../components/crystal-toolkit/CrystalToolkitScene/CrystalToolkitScene';
5+
import { RangeSlider } from '../../components/data-entry/RangeSlider';
6+
7+
/**
8+
* TilingVisualization shows off the new tiling functionality added to CrystalToolkitScene.
9+
*
10+
* It uses the useState hook to attach the tiling variables to the state of the sliders.
11+
* These are then passed to CrystalToolkitScene as props that can be dynamically changed.
12+
*
13+
* For a diagram of how the props are organized, see here:
14+
* https://oac-misc.s3.us-west-1.amazonaws.com/mp/programming_plan_v2.pdf
15+
*/
16+
export const TilingVisualization: React.FC = () => {
17+
// the tiling hooks allows state to be easily set with the sliders
18+
const [tilingX, setTilingX] = useState<any>(2);
19+
const [tilingY, setTilingY] = useState<any>(1);
20+
const [tilingZ, setTilingZ] = useState<any>(0);
21+
// this sets the maximum tiling, unseen tilings are present but not visible
22+
const maxTiling: number = 3;
23+
24+
return (
25+
<div>
26+
<CrystalToolkitScene
27+
settings={{
28+
renderer: Renderer.WEBGL,
29+
extractAxis: false,
30+
zoomToFit2D: true
31+
}}
32+
data={crystalScene}
33+
tiling={[tilingX, tilingY, tilingZ]}
34+
maxTiling={maxTiling}
35+
sceneSize="100%"
36+
debug={false}
37+
toggleVisibility={{}}
38+
/>
39+
{/* X slider*/}
40+
<RangeSlider
41+
domain={[0, maxTiling || 1]}
42+
value={tilingX}
43+
onChange={(values) => {
44+
setTilingX(values[0]);
45+
console.log(values);
46+
}}
47+
/>
48+
{/* Y slider*/}
49+
<RangeSlider
50+
domain={[0, maxTiling || 1]}
51+
value={tilingY}
52+
onChange={(values) => {
53+
setTilingY(values[0]);
54+
console.log(values);
55+
}}
56+
/>
57+
{/* Z slider*/}
58+
<RangeSlider
59+
domain={[0, maxTiling || 1]}
60+
value={tilingZ}
61+
onChange={(values) => {
62+
setTilingZ(values[0]);
63+
console.log(values);
64+
}}
65+
/>
66+
</div>
67+
);
68+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TilingVisualization } from './TilingVisualization';

0 commit comments

Comments
 (0)