previewMeshControlComponent.tsx 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import * as React from "react";
  2. import { GlobalState } from '../../globalState';
  3. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
  4. import { faCircle, faRing, faCube, faHockeyPuck, faSquareFull, faPlus, faDotCircle, faWindowRestore } from '@fortawesome/free-solid-svg-icons';
  5. import { PreviewMeshType } from './previewMeshType';
  6. import { DataStorage } from '../../dataStorage';
  7. interface IPreviewMeshControlComponent {
  8. globalState: GlobalState;
  9. togglePreviewAreaComponent: () => void;
  10. }
  11. export class PreviewMeshControlComponent extends React.Component<IPreviewMeshControlComponent> {
  12. changeMeshType(newOne: PreviewMeshType) {
  13. if (this.props.globalState.previewMeshType === newOne) {
  14. return;
  15. }
  16. this.props.globalState.previewMeshType = newOne;
  17. this.props.globalState.onPreviewCommandActivated.notifyObservers();
  18. DataStorage.StoreNumber("PreviewMeshType", newOne);
  19. this.forceUpdate();
  20. }
  21. useCustomMesh(evt: any) {
  22. var files: File[] = evt.target.files;
  23. if (files && files.length) {
  24. let file = files[0];
  25. this.props.globalState.previewMeshFile = file;
  26. this.props.globalState.previewMeshType = PreviewMeshType.Custom;
  27. this.props.globalState.onPreviewCommandActivated.notifyObservers();
  28. this.forceUpdate();
  29. }
  30. (document.getElementById("file-picker")! as HTMLInputElement).value = "";
  31. }
  32. onPopUp() {
  33. this.props.togglePreviewAreaComponent();
  34. }
  35. render() {
  36. return (
  37. <div id="preview-mesh-bar">
  38. <div
  39. title="Preview with a cube"
  40. onClick={() => this.changeMeshType(PreviewMeshType.Box)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Box ? " selected" : "")}>
  41. <FontAwesomeIcon icon={faCube} />
  42. </div>
  43. <div
  44. title="Preview with a sphere"
  45. onClick={() => this.changeMeshType(PreviewMeshType.Sphere)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Sphere ? " selected" : "")}>
  46. <FontAwesomeIcon icon={faCircle} />
  47. </div>
  48. <div
  49. title="Preview with a torus"
  50. onClick={() => this.changeMeshType(PreviewMeshType.Torus)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Torus ? " selected" : "")}>
  51. <FontAwesomeIcon icon={faRing} />
  52. </div>
  53. <div
  54. title="Preview with a cylinder"
  55. onClick={() => this.changeMeshType(PreviewMeshType.Cylinder)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Cylinder ? " selected" : "")}>
  56. <FontAwesomeIcon icon={faHockeyPuck} />
  57. </div>
  58. <div
  59. title="Preview with a plane"
  60. onClick={() => this.changeMeshType(PreviewMeshType.Plane)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Plane ? " selected" : "")}>
  61. <FontAwesomeIcon icon={faSquareFull} />
  62. </div>
  63. <div
  64. title="Preview with a shader ball"
  65. onClick={() => this.changeMeshType(PreviewMeshType.ShaderBall)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.ShaderBall ? " selected" : "")}>
  66. <FontAwesomeIcon icon={faDotCircle} />
  67. </div>
  68. <div className={"button align"} title="Preview with a custom mesh" >
  69. <label htmlFor="file-picker" id="file-picker-label">
  70. <FontAwesomeIcon icon={faPlus} />
  71. </label>
  72. <input ref="file-picker" id="file-picker" type="file" onChange={evt => this.useCustomMesh(evt)} accept=".gltf, .glb, .babylon, .obj"/>
  73. </div>
  74. <div
  75. title="Open preview in new window" id="preview-new-window"
  76. onClick={() => this.onPopUp()} className="button">
  77. <FontAwesomeIcon icon={faWindowRestore} />
  78. </div>
  79. </div>
  80. );
  81. }
  82. }