previewAreaComponent.tsx 4.9 KB

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