@@ -9,7 +9,7 @@ import React, {
99} from 'react' ;
1010import Scene from '../scene/Scene' ;
1111import { subscribe } from '../scene/download-event' ;
12- import './CrystalToolkitAnimationScene .less' ;
12+ import './PhononAnimationScene .less' ;
1313import {
1414 AnimationStyle ,
1515 DEBUG_STYLE ,
@@ -102,6 +102,13 @@ export interface PhononAnimationSceneProps {
102102 * defaultZoom: 1, // 1 will zoom to fit object exactly, <1 will add padding between object and box bounds
103103 * zoomToFit2D: false // if true, will zoom to fit object only along the X and Y axes (not Z)
104104 * extractAxis: false // will remove the axis from the main scene
105+ * omega: 0.0 // The eigen frequency
106+ * phases: [0, 0] // Per-atom phase theta_i = q · R_i (radians). Length should equal number of atoms.
107+ * amplitude: 150 //The amplitude of vibration
108+ * eigenVectors: [[[2.369e-7, 0], [-6.908e-7, 0], [-0.002, 0]], [[2.369e-7, 0], [-6.908e-7, 0], [-0.002, 0]]] // The eigenvectors for each atom with the given wave vector and frequency
109+ * velocity: 0.5 // The velocity coef, scale 0 to 1
110+ *
111+ *
105112 * }
106113 * There are several additional options used for debugging and testing,
107114 * please consult the source code directly for these.
@@ -235,23 +242,6 @@ export interface PhononAnimationSceneProps {
235242 * @default true
236243 */
237244 showPositionButton ?: boolean ;
238- /**
239- * The eigen frequency
240- */
241- omega : number ;
242- /**
243- * Per-atom phase theta_i = q · R_i (radians).
244- * Length should equal number of atoms.
245- */
246- phases : number [ ] ;
247- /**
248- * The amplitude of vibration
249- */
250- amplitude : number ;
251- /**
252- * The eigenvectors for each atom with the given wave vector and frequency
253- */
254- eigenVectors : number [ ] ;
255245}
256246
257247/**
@@ -410,6 +400,10 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
410400
411401 // called after the component is mounted, so refs are correctly populated
412402 useEffect ( ( ) => {
403+ if ( ! props . data || ! props . data . name || ! props . data . contents ) {
404+ return ;
405+ }
406+
413407 const _s = ( scene . current = new Scene (
414408 props . data ,
415409 mountNodeRef . current ! ,
@@ -437,7 +431,9 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
437431 mountNodeDebugRef . current !
438432 ) ) ;
439433 _s . removeListener ( ) ;
440- _s . animate ( ) ;
434+ if ( props . data !== undefined && props . data !== null ) {
435+ _s . animate ( ) ;
436+ }
441437
442438 /**
443439 * I believe this can be removed because image requesting is now handled by
@@ -450,17 +446,18 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
450446 subscription . unsubscribe ( ) ;
451447 _s . onDestroy ( ) ;
452448 } ;
453- } , [ ] ) ;
449+ } , [ props . data ] ) ;
454450
455451 // Note(chab) those hooks will be executed sequentially at mount time, and on change of the deps array elements
456- useEffect (
457- ( ) => scene . current ! . enableDebug ( props . debug ! , mountNodeDebugRef . current ) ,
458- [ props . debug ]
459- ) ;
452+ useEffect ( ( ) => {
453+ if ( ! scene . current ) return ;
454+ scene . current ! . enableDebug ( props . debug ! , mountNodeDebugRef . current ) ;
455+ } , [ props . debug ] ) ;
460456 // An interesting classical react issue that we fixed : look at the stories, we do not pass anymore an empty object,
461457 // but a reference to an empty object, otherwise, it will be a different reference, and treated as a different object, thus
462458 // triggering the effect
463459 useEffect ( ( ) => {
460+ if ( ! scene . current ) return ;
464461 if ( ! props . data || ! ( props . data as any ) . name || ! ( props . data as any ) . contents ) {
465462 console . warn (
466463 'no data passed ( or missing name /content ), scene will not be updated' ,
@@ -470,25 +467,28 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
470467 }
471468
472469 //FIXME(chab) we have to much calls to renderScene
473- ! ! props . data && scene . current ! . addToScene ( props . data , false ) ;
470+ //!!props.data && scene.current!.addToScene(props.data, false);
471+ scene . current . addToScene ( props . data , false ) ;
474472 // !!props.data && scene.current!.addToScene(props.data, false);
475473 // scene.current!.animate();
476474 scene . current ! . toggleVisibility ( props . toggleVisibility as any ) ;
477475 } , [ props . data ] ) ;
478- useEffect (
479- ( ) => scene . current ! . toggleVisibility ( props . toggleVisibility as any ) ,
480- [ props . toggleVisibility ]
481- ) ;
482- useEffect (
483- ( ) => scene . current ! . updateInsetSettings ( props . inletSize ! , props . inletPadding ! , props . axisView ) ,
484- [ props . inletSize , props . inletPadding , props . axisView ]
485- ) ;
476+ useEffect ( ( ) => {
477+ if ( ! scene . current ) return ;
478+ scene . current ! . toggleVisibility ( props . toggleVisibility as any ) ;
479+ } , [ props . toggleVisibility ] ) ;
480+ useEffect ( ( ) => {
481+ if ( ! scene . current ) return ;
482+ scene . current ! . updateInsetSettings ( props . inletSize ! , props . inletPadding ! , props . axisView ) ;
483+ } , [ props . inletSize , props . inletPadding , props . axisView ] ) ;
486484
487485 useEffect ( ( ) => {
486+ if ( ! scene . current ) return ;
488487 scene . current ! . resizeRendererToDisplaySize ( ) ;
489488 } , [ props . sceneSize ] ) ;
490489
491490 useEffect ( ( ) => {
491+ if ( ! scene . current ) return ;
492492 const { filetype } = props . imageRequest ;
493493 if ( filetype ) {
494494 requestImage ( filetype , scene . current ! ) ;
@@ -505,6 +505,7 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
505505 const cameraDispatch = cameraContext ? cameraContext . dispatch : cameraReducerDispatch ;
506506 if ( cameraState ) {
507507 useEffect ( ( ) => {
508+ if ( ! scene . current ) return ;
508509 props . setProps ( { currentCameraState : cameraState } ) ;
509510
510511 if ( cameraState && cameraState . position && cameraState . quaternion && cameraState . zoom ) {
@@ -528,6 +529,7 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
528529 * and save the new state into the cameraState
529530 */
530531 useEffect ( ( ) => {
532+ if ( ! scene . current ) return ;
531533 if ( props . customCameraState ) {
532534 const { position : p , quaternion : q , zoom } = props . customCameraState ;
533535 /**
@@ -554,6 +556,7 @@ export const PhononAnimationScene: React.FC<PhononAnimationSceneProps> = ({
554556 } , [ props . customCameraState ] ) ;
555557
556558 useEffect ( ( ) => {
559+ if ( ! scene . current ) return ;
557560 props . animation && scene . current ! . updateAnimationStyle ( props . animation as AnimationStyle ) ;
558561 } , [ props . animation ] ) ;
559562
0 commit comments