commonCameraPropertyGridComponent.tsx 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as React from "react";
  2. import { Camera } from "babylonjs/Cameras/camera";
  3. import { Observable } from "babylonjs/Misc/observable";
  4. import { PropertyChangedEvent } from "../../../../propertyChangedEvent";
  5. import { SliderLineComponent } from "../../../lines/sliderLineComponent";
  6. import { LineContainerComponent } from "../../../lineContainerComponent";
  7. import { FloatLineComponent } from "../../../lines/floatLineComponent";
  8. import { TextLineComponent } from "../../../lines/textLineComponent";
  9. import { OptionsLineComponent } from "../../../lines/optionsLineComponent";
  10. import { LockObject } from "../lockObject";
  11. import { GlobalState } from '../../../../globalState';
  12. interface ICommonCameraPropertyGridComponentProps {
  13. globalState: GlobalState;
  14. camera: Camera;
  15. lockObject: LockObject;
  16. onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
  17. }
  18. export class CommonCameraPropertyGridComponent extends React.Component<ICommonCameraPropertyGridComponentProps, { mode: number }> {
  19. constructor(props: ICommonCameraPropertyGridComponentProps) {
  20. super(props);
  21. this.state = { mode: this.props.camera.mode };
  22. }
  23. render() {
  24. const camera = this.props.camera;
  25. var modeOptions = [
  26. { label: "Perspective", value: Camera.PERSPECTIVE_CAMERA },
  27. { label: "Orthographic", value: Camera.ORTHOGRAPHIC_CAMERA }
  28. ];
  29. return (
  30. <LineContainerComponent globalState={this.props.globalState} title="GENERAL">
  31. <TextLineComponent label="ID" value={camera.id} />
  32. <TextLineComponent label="Unique ID" value={camera.uniqueId.toString()} />
  33. <TextLineComponent label="Class" value={camera.getClassName()} />
  34. <FloatLineComponent lockObject={this.props.lockObject} label="Near plane" target={camera} propertyName="minZ" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  35. <FloatLineComponent lockObject={this.props.lockObject} label="Far plane" target={camera} propertyName="maxZ" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  36. <SliderLineComponent label="Inertia" target={camera} propertyName="inertia" minimum={0} maximum={1} step={0.01} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  37. <OptionsLineComponent label="Mode" options={modeOptions} target={camera} propertyName="mode" onPropertyChangedObservable={this.props.onPropertyChangedObservable} onSelect={(value) => this.setState({ mode: value })} />
  38. {
  39. camera.mode === Camera.PERSPECTIVE_CAMERA &&
  40. <SliderLineComponent label="Field of view" target={camera} propertyName="fov" minimum={0.1} maximum={Math.PI} step={0.1} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  41. }
  42. {
  43. camera.mode === Camera.ORTHOGRAPHIC_CAMERA &&
  44. <FloatLineComponent lockObject={this.props.lockObject} label="Left" target={camera} propertyName="orthoLeft" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  45. }
  46. {
  47. camera.mode === Camera.ORTHOGRAPHIC_CAMERA &&
  48. <FloatLineComponent lockObject={this.props.lockObject} label="Top" target={camera} propertyName="orthoTop" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  49. }
  50. {
  51. camera.mode === Camera.ORTHOGRAPHIC_CAMERA &&
  52. <FloatLineComponent lockObject={this.props.lockObject} label="Right" target={camera} propertyName="orthoRight" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  53. }
  54. {
  55. camera.mode === Camera.ORTHOGRAPHIC_CAMERA &&
  56. <FloatLineComponent lockObject={this.props.lockObject} label="Bottom" target={camera} propertyName="orthoBottom" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  57. }
  58. </LineContainerComponent>
  59. );
  60. }
  61. }