previewMeshControlComponent.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 } from '@fortawesome/free-solid-svg-icons';
  5. import { PreviewMeshType } from './previewMeshType';
  6. import { DataStorage } from '../../dataStorage';
  7. interface IPreviewMeshControlComponent {
  8. globalState: GlobalState;
  9. }
  10. export class PreviewMeshControlComponent extends React.Component<IPreviewMeshControlComponent> {
  11. changeMeshType(newOne: PreviewMeshType) {
  12. if (this.props.globalState.previewMeshType === newOne) {
  13. return;
  14. }
  15. this.props.globalState.previewMeshType = newOne;
  16. this.props.globalState.onPreviewCommandActivated.notifyObservers();
  17. DataStorage.StoreNumber("PreviewMeshType", newOne);
  18. this.forceUpdate();
  19. }
  20. useCustomMesh(evt: any) {
  21. var files: File[] = evt.target.files;
  22. if (files && files.length) {
  23. let file = files[0];
  24. this.props.globalState.previewMeshFile = file;
  25. this.props.globalState.previewMeshType = PreviewMeshType.Custom;
  26. this.props.globalState.onPreviewCommandActivated.notifyObservers();
  27. this.forceUpdate();
  28. }
  29. (document.getElementById("file-picker")! as HTMLInputElement).value = "";
  30. }
  31. render() {
  32. return (
  33. <div id="preview-mesh-bar">
  34. <div onClick={() => this.changeMeshType(PreviewMeshType.Box)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Box ? " selected" : "")}>
  35. <FontAwesomeIcon icon={faCube} />
  36. </div>
  37. <div onClick={() => this.changeMeshType(PreviewMeshType.Sphere)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Sphere ? " selected" : "")}>
  38. <FontAwesomeIcon icon={faCircle} />
  39. </div>
  40. <div onClick={() => this.changeMeshType(PreviewMeshType.Torus)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Torus ? " selected" : "")}>
  41. <FontAwesomeIcon icon={faRing} />
  42. </div>
  43. <div onClick={() => this.changeMeshType(PreviewMeshType.Cylinder)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Cylinder ? " selected" : "")}>
  44. <FontAwesomeIcon icon={faHockeyPuck} />
  45. </div>
  46. <div onClick={() => this.changeMeshType(PreviewMeshType.Plane)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.Plane ? " selected" : "")}>
  47. <FontAwesomeIcon icon={faSquareFull} />
  48. </div>
  49. <div onClick={() => this.changeMeshType(PreviewMeshType.ShaderBall)} className={"button" + (this.props.globalState.previewMeshType === PreviewMeshType.ShaderBall ? " selected" : "")}>
  50. <FontAwesomeIcon icon={faDotCircle} />
  51. </div>
  52. <div className={"button align"}>
  53. <label htmlFor="file-picker" id="file-picker-label">
  54. <FontAwesomeIcon icon={faPlus} />
  55. </label>
  56. <input ref="file-picker" id="file-picker" type="file" onChange={evt => this.useCustomMesh(evt)} accept=".gltf, .glb, .babylon, .obj"/>
  57. </div>
  58. </div>
  59. );
  60. }
  61. }