previewAreaComponent.tsx 5.3 KB

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