|
@@ -4,21 +4,21 @@ import { IExplorerExtensibilityGroup } from "babylonjs/Debug/debugLayer";
|
|
import { Camera } from "babylonjs/Cameras/camera";
|
|
import { Camera } from "babylonjs/Cameras/camera";
|
|
import { Scene } from "babylonjs/scene";
|
|
import { Scene } from "babylonjs/scene";
|
|
|
|
|
|
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
-import { faVideo, faCamera, faEye } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
+import { faVideo, faCamera, faEye } from "@fortawesome/free-solid-svg-icons";
|
|
import { TreeItemLabelComponent } from "../treeItemLabelComponent";
|
|
import { TreeItemLabelComponent } from "../treeItemLabelComponent";
|
|
import { ExtensionsComponent } from "../extensionsComponent";
|
|
import { ExtensionsComponent } from "../extensionsComponent";
|
|
import * as React from "react";
|
|
import * as React from "react";
|
|
import { GlobalState } from "../../globalState";
|
|
import { GlobalState } from "../../globalState";
|
|
|
|
|
|
interface ICameraTreeItemComponentProps {
|
|
interface ICameraTreeItemComponentProps {
|
|
- camera: Camera,
|
|
|
|
- extensibilityGroups?: IExplorerExtensibilityGroup[],
|
|
|
|
- onClick: () => void,
|
|
|
|
- globalState: GlobalState
|
|
|
|
|
|
+ camera: Camera;
|
|
|
|
+ extensibilityGroups?: IExplorerExtensibilityGroup[];
|
|
|
|
+ onClick: () => void;
|
|
|
|
+ globalState: GlobalState;
|
|
}
|
|
}
|
|
|
|
|
|
-export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComponentProps, { isActive: boolean, isGizmoEnabled:boolean }> {
|
|
|
|
|
|
+export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComponentProps, { isActive: boolean; isGizmoEnabled: boolean }> {
|
|
private _onBeforeRenderObserver: Nullable<Observer<Scene>>;
|
|
private _onBeforeRenderObserver: Nullable<Observer<Scene>>;
|
|
|
|
|
|
constructor(props: ICameraTreeItemComponentProps) {
|
|
constructor(props: ICameraTreeItemComponentProps) {
|
|
@@ -27,7 +27,7 @@ export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComp
|
|
const camera = this.props.camera;
|
|
const camera = this.props.camera;
|
|
const scene = camera.getScene();
|
|
const scene = camera.getScene();
|
|
|
|
|
|
- this.state = { isActive: scene.activeCamera === camera, isGizmoEnabled: (camera.reservedDataStore && camera.reservedDataStore.cameraGizmo) };
|
|
|
|
|
|
+ this.state = { isActive: scene.activeCamera === camera, isGizmoEnabled: camera.reservedDataStore && camera.reservedDataStore.cameraGizmo };
|
|
}
|
|
}
|
|
|
|
|
|
setActive(): void {
|
|
setActive(): void {
|
|
@@ -35,27 +35,26 @@ export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComp
|
|
const scene = camera.getScene();
|
|
const scene = camera.getScene();
|
|
|
|
|
|
scene.activeCamera = camera;
|
|
scene.activeCamera = camera;
|
|
- camera.attachControl(scene.getEngine().getRenderingCanvas()!, true);
|
|
|
|
|
|
+ camera.attachControl(true);
|
|
|
|
|
|
this.setState({ isActive: true });
|
|
this.setState({ isActive: true });
|
|
}
|
|
}
|
|
|
|
|
|
- componentDidMount() {
|
|
|
|
|
|
+ componentDidMount() {
|
|
const scene = this.props.camera.getScene();
|
|
const scene = this.props.camera.getScene();
|
|
|
|
|
|
this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(() => {
|
|
this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(() => {
|
|
const camera = this.props.camera;
|
|
const camera = this.props.camera;
|
|
// This will deactivate the previous camera when the camera is changed. Multiple camera's cycle frequently so only do this for single cameras
|
|
// This will deactivate the previous camera when the camera is changed. Multiple camera's cycle frequently so only do this for single cameras
|
|
if (this.state.isActive && scene.activeCameras.length <= 1 && scene.activeCamera !== camera) {
|
|
if (this.state.isActive && scene.activeCameras.length <= 1 && scene.activeCamera !== camera) {
|
|
- camera.detachControl(scene.getEngine().getRenderingCanvas()!);
|
|
|
|
|
|
+ camera.detachControl();
|
|
}
|
|
}
|
|
- let newState = scene.activeCamera === camera;
|
|
|
|
|
|
+ let newState = scene.activeCamera === camera;
|
|
|
|
|
|
if (newState !== this.state.isActive) {
|
|
if (newState !== this.state.isActive) {
|
|
- this.setState({ isActive: newState});
|
|
|
|
|
|
+ this.setState({ isActive: newState });
|
|
}
|
|
}
|
|
-
|
|
|
|
- })
|
|
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
@@ -69,13 +68,13 @@ export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComp
|
|
|
|
|
|
toggleGizmo(): void {
|
|
toggleGizmo(): void {
|
|
const camera = this.props.camera;
|
|
const camera = this.props.camera;
|
|
- if(camera.reservedDataStore && camera.reservedDataStore.cameraGizmo){
|
|
|
|
|
|
+ if (camera.reservedDataStore && camera.reservedDataStore.cameraGizmo) {
|
|
if (camera.getScene().reservedDataStore && camera.getScene().reservedDataStore.gizmoManager) {
|
|
if (camera.getScene().reservedDataStore && camera.getScene().reservedDataStore.gizmoManager) {
|
|
camera.getScene().reservedDataStore.gizmoManager.attachToMesh(null);
|
|
camera.getScene().reservedDataStore.gizmoManager.attachToMesh(null);
|
|
}
|
|
}
|
|
this.props.globalState.enableCameraGizmo(camera, false);
|
|
this.props.globalState.enableCameraGizmo(camera, false);
|
|
this.setState({ isGizmoEnabled: false });
|
|
this.setState({ isGizmoEnabled: false });
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
this.props.globalState.enableCameraGizmo(camera, true);
|
|
this.props.globalState.enableCameraGizmo(camera, true);
|
|
this.setState({ isGizmoEnabled: true });
|
|
this.setState({ isGizmoEnabled: true });
|
|
}
|
|
}
|
|
@@ -84,21 +83,20 @@ export class CameraTreeItemComponent extends React.Component<ICameraTreeItemComp
|
|
render() {
|
|
render() {
|
|
const isActiveElement = this.state.isActive ? <FontAwesomeIcon icon={faVideo} /> : <FontAwesomeIcon icon={faVideo} className="isNotActive" />;
|
|
const isActiveElement = this.state.isActive ? <FontAwesomeIcon icon={faVideo} /> : <FontAwesomeIcon icon={faVideo} className="isNotActive" />;
|
|
const scene = this.props.camera.getScene()!;
|
|
const scene = this.props.camera.getScene()!;
|
|
- const isGizmoEnabled = (this.state.isGizmoEnabled || (this.props.camera && this.props.camera.reservedDataStore && this.props.camera.reservedDataStore.cameraGizmo)) ? <FontAwesomeIcon icon={faEye} /> : <FontAwesomeIcon icon={faEye} className="isNotActive" />;
|
|
|
|
|
|
+ const isGizmoEnabled = this.state.isGizmoEnabled || (this.props.camera && this.props.camera.reservedDataStore && this.props.camera.reservedDataStore.cameraGizmo) ? <FontAwesomeIcon icon={faEye} /> : <FontAwesomeIcon icon={faEye} className="isNotActive" />;
|
|
return (
|
|
return (
|
|
<div className="cameraTools">
|
|
<div className="cameraTools">
|
|
<TreeItemLabelComponent label={this.props.camera.name} onClick={() => this.props.onClick()} icon={faCamera} color="green" />
|
|
<TreeItemLabelComponent label={this.props.camera.name} onClick={() => this.props.onClick()} icon={faCamera} color="green" />
|
|
- {
|
|
|
|
- (!scene.activeCameras || scene.activeCameras.length === 0) &&
|
|
|
|
|
|
+ {(!scene.activeCameras || scene.activeCameras.length === 0) && (
|
|
<div className="activeCamera icon" onClick={() => this.setActive()} title="Set as main camera and attach to controls">
|
|
<div className="activeCamera icon" onClick={() => this.setActive()} title="Set as main camera and attach to controls">
|
|
{isActiveElement}
|
|
{isActiveElement}
|
|
</div>
|
|
</div>
|
|
- }
|
|
|
|
|
|
+ )}
|
|
<div className="enableGizmo icon" onClick={() => this.toggleGizmo()} title="Turn on/off the camera's gizmo">
|
|
<div className="enableGizmo icon" onClick={() => this.toggleGizmo()} title="Turn on/off the camera's gizmo">
|
|
{isGizmoEnabled}
|
|
{isGizmoEnabled}
|
|
</div>
|
|
</div>
|
|
<ExtensionsComponent target={this.props.camera} extensibilityGroups={this.props.extensibilityGroups} />
|
|
<ExtensionsComponent target={this.props.camera} extensibilityGroups={this.props.extensibilityGroups} />
|
|
</div>
|
|
</div>
|
|
- )
|
|
|
|
|
|
+ );
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|