previewAreaComponent.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import * as React from "react";
  2. import { GlobalState } from '../../globalState';
  3. import { DataStorage } from 'babylonjs/Misc/dataStorage';
  4. import { Observer } from 'babylonjs/Misc/observable';
  5. import { Nullable } from 'babylonjs/types';
  6. import { NodeMaterialModes } from 'babylonjs/Materials/Node/Enums/nodeMaterialModes';
  7. const doubleSided: string = require("./svgs/doubleSided.svg");
  8. const depthPass: string = require("./svgs/depthPass.svg");
  9. const omni: string = require("./svgs/omni.svg");
  10. const directionalRight: string = require("./svgs/directionalRight.svg");
  11. const directionalLeft: string = require("./svgs/directionalLeft.svg");
  12. interface IPreviewAreaComponentProps {
  13. globalState: GlobalState;
  14. width: number;
  15. }
  16. export class PreviewAreaComponent extends React.Component<IPreviewAreaComponentProps, {isLoading: boolean}> {
  17. private _onIsLoadingChangedObserver: Nullable<Observer<boolean>>;
  18. private _onResetRequiredObserver: Nullable<Observer<void>>;
  19. constructor(props: IPreviewAreaComponentProps) {
  20. super(props);
  21. this.state = {isLoading: true};
  22. this._onIsLoadingChangedObserver = this.props.globalState.onIsLoadingChanged.add((state) => this.setState({isLoading: state}));
  23. this._onResetRequiredObserver = this.props.globalState.onResetRequiredObservable.add(() => {
  24. this.forceUpdate();
  25. });
  26. }
  27. componentWillUnmount() {
  28. this.props.globalState.onIsLoadingChanged.remove(this._onIsLoadingChangedObserver);
  29. this.props.globalState.onResetRequiredObservable.remove(this._onResetRequiredObserver);
  30. }
  31. changeBackFaceCulling(value: boolean) {
  32. this.props.globalState.backFaceCulling = value;
  33. DataStorage.WriteBoolean("BackFaceCulling", value);
  34. this.props.globalState.onBackFaceCullingChanged.notifyObservers();
  35. this.forceUpdate();
  36. }
  37. changeDepthPrePass(value: boolean) {
  38. this.props.globalState.depthPrePass = value;
  39. DataStorage.WriteBoolean("DepthPrePass", value);
  40. this.props.globalState.onDepthPrePassChanged.notifyObservers();
  41. this.forceUpdate();
  42. }
  43. render() {
  44. return (
  45. <>
  46. <div id="preview" style={{height: this.props.width + "px"}}>
  47. <canvas id="preview-canvas"/>
  48. {
  49. <div className={"waitPanel" + (this.state.isLoading ? "" : " hidden")}>
  50. Please wait, loading...
  51. </div>
  52. }
  53. </div>
  54. { this.props.globalState.mode === NodeMaterialModes.Material && <>
  55. <div id="preview-config-bar">
  56. <div
  57. title="Render without back face culling"
  58. onClick={() => this.changeBackFaceCulling(!this.props.globalState.backFaceCulling)} className={"button back-face" + (!this.props.globalState.backFaceCulling ? " selected" : "")}>
  59. <img src={doubleSided} alt=""/>
  60. </div>
  61. <div
  62. title="Render with depth pre-pass"
  63. onClick={() => this.changeDepthPrePass(!this.props.globalState.depthPrePass)} className={"button depth-pass" + (this.props.globalState.depthPrePass ? " selected" : "")}>
  64. <img src={depthPass} alt=""/>
  65. </div>
  66. <div
  67. title="Turn on/off hemispheric light"
  68. onClick={() => {
  69. this.props.globalState.hemisphericLight = !this.props.globalState.hemisphericLight;
  70. DataStorage.WriteBoolean("HemisphericLight", this.props.globalState.hemisphericLight);
  71. this.props.globalState.onLightUpdated.notifyObservers();
  72. this.forceUpdate();
  73. }} className={"button hemispheric-light" + (this.props.globalState.hemisphericLight ? " selected" : "")}>
  74. <img src={omni} alt=""/>
  75. </div>
  76. <div
  77. title="Turn on/off direction light #1"
  78. onClick={() => {
  79. this.props.globalState.directionalLight1 = !this.props.globalState.directionalLight1;
  80. DataStorage.WriteBoolean("DirectionalLight1", this.props.globalState.directionalLight1);
  81. this.props.globalState.onLightUpdated.notifyObservers();
  82. this.forceUpdate();
  83. }} className={"button direction-light-1" + (this.props.globalState.directionalLight1 ? " selected" : "")}>
  84. <img src={directionalRight} alt=""/>
  85. </div>
  86. <div
  87. title="Turn on/off direction light #0"
  88. onClick={() => {
  89. this.props.globalState.directionalLight0 = !this.props.globalState.directionalLight0;
  90. DataStorage.WriteBoolean("DirectionalLight0", this.props.globalState.directionalLight0);
  91. this.props.globalState.onLightUpdated.notifyObservers();
  92. this.forceUpdate();
  93. }} className={"button direction-light-0" + (this.props.globalState.directionalLight0 ? " selected" : "")}>
  94. <img src={directionalLeft} alt=""/>
  95. </div>
  96. </div>
  97. </> }
  98. </>
  99. );
  100. }
  101. }