import * as React from "react"; import { GlobalState } from '../../globalState'; import { Color3, Color4 } from 'babylonjs/Maths/math.color'; import { PreviewMeshType } from './previewMeshType'; import { DataStorage } from '../../dataStorage'; import { OptionsLineComponent } from '../../sharedComponents/optionsLineComponent'; import * as ReactDOM from 'react-dom'; const popUpIcon: string = require("./svgs/popOut.svg"); const colorPicker: string = require("./svgs/colorPicker.svg"); const pauseIcon: string = require("./svgs/pauseIcon.svg"); const playIcon: string = require("./svgs/playIcon.svg"); interface IPreviewMeshControlComponent { globalState: GlobalState; togglePreviewAreaComponent: () => void; } export class PreviewMeshControlComponent extends React.Component { private colorInputRef: React.RefObject; constructor(props: IPreviewMeshControlComponent) { super(props); this.colorInputRef = React.createRef(); } changeMeshType(newOne: PreviewMeshType) { if (this.props.globalState.previewMeshType === newOne) { return; } this.props.globalState.previewMeshType = newOne; this.props.globalState.onPreviewCommandActivated.notifyObservers(); DataStorage.StoreNumber("PreviewMeshType", newOne); this.forceUpdate(); } useCustomMesh(evt: any) { var files: File[] = evt.target.files; if (files && files.length) { let file = files[0]; this.props.globalState.previewMeshFile = file; this.props.globalState.previewMeshType = PreviewMeshType.Custom; this.props.globalState.onPreviewCommandActivated.notifyObservers(); this.forceUpdate(); } (ReactDOM.findDOMNode(this.refs["file-picker"]) as HTMLInputElement).value = ""; } onPopUp() { this.props.togglePreviewAreaComponent(); } changeAnimation() { this.props.globalState.rotatePreview = !this.props.globalState.rotatePreview; this.props.globalState.onAnimationCommandActivated.notifyObservers(); this.forceUpdate(); } changeBackground(value: string) { const newColor = Color3.FromHexString(value); DataStorage.StoreNumber("BackgroundColorR", newColor.r); DataStorage.StoreNumber("BackgroundColorG", newColor.g); DataStorage.StoreNumber("BackgroundColorB", newColor.b); const newBackgroundColor = Color4.FromColor3(newColor, 1.0); this.props.globalState.backgroundColor = newBackgroundColor; this.props.globalState.onPreviewBackgroundChanged.notifyObservers(); } changeBackgroundClick() { this.colorInputRef.current?.click(); } render() { var meshTypeOptions = [ { label: "Cube", value: PreviewMeshType.Box }, { label: "Cylinder", value: PreviewMeshType.Cylinder }, { label: "Plane", value: PreviewMeshType.Plane }, { label: "Shader ball", value: PreviewMeshType.ShaderBall }, { label: "Sphere", value: PreviewMeshType.Sphere }, { label: "Load...", value: PreviewMeshType.Custom + 1 } ]; if (this.props.globalState.previewMeshType === PreviewMeshType.Custom) { meshTypeOptions.splice(0, 0, { label: "Custom", value: PreviewMeshType.Custom }); } return (
{ if (value !== PreviewMeshType.Custom + 1) { this.changeMeshType(value); } else { (ReactDOM.findDOMNode(this.refs["file-picker"]) as HTMLElement).click(); } }} />
this.useCustomMesh(evt)} accept=".gltf, .glb, .babylon, .obj"/>
this.changeAnimation()} className="button" id="play-button"> {this.props.globalState.rotatePreview ? : }
this.changeBackgroundClick()} > this.changeBackground(evt.target.value)} />
this.onPopUp()} className="button">
); } }