forked from Hubs-Foundation/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f48879
commit bd2b001
Showing
7 changed files
with
107 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Matrix4, PerspectiveCamera, CameraHelper } from "three"; | ||
import EditorNodeMixin from "./EditorNodeMixin"; | ||
|
||
export default class ScenePreviewCameraNode extends EditorNodeMixin(PerspectiveCamera) { | ||
static legacyComponentName = "scene-preview-camera"; | ||
|
||
static nodeName = "Scene Preview Camera"; | ||
|
||
static canAddNode(editor) { | ||
return editor.scene.findNodeByType(ScenePreviewCameraNode) === null; | ||
} | ||
|
||
constructor(editor) { | ||
super(editor, 80, 16 / 9, 0.2, 8000); | ||
|
||
const cameraHelper = new CameraHelper(this); | ||
cameraHelper.layers.set(1); | ||
this.helper = cameraHelper; | ||
} | ||
|
||
setFromViewport() { | ||
const matrix = new Matrix4().getInverse(this.parent.matrixWorld).multiply(this.editor.camera.matrixWorld); | ||
matrix.decompose(this.position, this.rotation, this.scale); | ||
this.editor.emit("objectsChanged", [this]); | ||
this.editor.emit("selectionChanged"); | ||
} | ||
|
||
onSelect() { | ||
this.editor.scene.add(this.helper); | ||
this.helper.update(); | ||
} | ||
|
||
onDeselect() { | ||
this.editor.scene.remove(this.helper); | ||
} | ||
|
||
serialize() { | ||
return super.serialize({ "scene-preview-camera": {} }); | ||
} | ||
|
||
prepareForExport() { | ||
super.prepareForExport(); | ||
// This name is required in the current Hubs client. | ||
// It's possible to migrate to the scene-preview-camera component in the future. | ||
this.name = "scene-preview-camera"; | ||
this.addGLTFComponent("scene-preview-camera"); | ||
this.replaceObject(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import NodeEditor from "./NodeEditor"; | ||
import { Camera } from "styled-icons/fa-solid/Camera"; | ||
import { PropertiesPanelButton } from "../inputs/Button"; | ||
|
||
export default class ScenePreviewCameraNodeEditor extends Component { | ||
static propTypes = { | ||
editor: PropTypes.object, | ||
node: PropTypes.object | ||
}; | ||
|
||
static iconComponent = Camera; | ||
|
||
static description = | ||
"The camera used to generate the thumbnail for your scene and the starting position for the preview camera in Hubs."; | ||
|
||
onSetFromViewport = () => { | ||
this.props.node.setFromViewport(); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<NodeEditor {...this.props} description={ScenePreviewCameraNodeEditor.description}> | ||
<PropertiesPanelButton onClick={this.onSetFromViewport}>Set From Viewport</PropertiesPanelButton> | ||
</NodeEditor> | ||
); | ||
} | ||
} |