Skip to content

Commit

Permalink
added history support on scene preview camera node (#4872)
Browse files Browse the repository at this point in the history
* added history support on scene preview camera node

* resolved feedback

* improved the code

* improved the code

Co-authored-by: Nayan Patel <[email protected]>
  • Loading branch information
FabriceIRANKUNDA and NPatel10 authored Jan 24, 2022
1 parent 01622ed commit 6dac0a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@xrengine/matchmaking": "^0.4.13",
"@xrengine/projects": "^0.4.13",
"classnames": "2.3.1",
"ethereal": "^3.0.3",
"file-regex": "3.1.0",
"i18next": "21.6.7",
"i18next-browser-languagedetector": "6.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react'
import NodeEditor from './NodeEditor'
import { Vector3, Quaternion } from 'three'
import { PropertiesPanelButton } from '../inputs/Button'
import { useTranslation } from 'react-i18next'
import { updateScenePreviewCamera } from '@xrengine/engine/src/scene/functions/loaders/ScenePreviewCameraFunctions'
import { updateCameraTransform } from '@xrengine/engine/src/scene/functions/loaders/ScenePreviewCameraFunctions'
import CameraAltIcon from '@mui/icons-material/CameraAlt'
import { EditorComponentType } from './Util'
import { CommandManager } from '../../managers/CommandManager'
import { TransformComponent } from '@xrengine/engine/src/transform/components/TransformComponent'

/**
* ScenePreviewCameraNodeEditor provides the editor view to customize properties.
Expand All @@ -16,7 +19,16 @@ export const ScenePreviewCameraNodeEditor: EditorComponentType = (props) => {
const { t } = useTranslation()

const onSetFromViewport = () => {
updateScenePreviewCamera(props.node.entity)
const updatedTransform = updateCameraTransform(props.node.entity)
const position = new Vector3()
const rotation = new Quaternion()
const scale = new Vector3()

updatedTransform.decompose(position, rotation, scale)
CommandManager.instance.setProperty([props.node], {
component: TransformComponent,
properties: { position, rotation }
})
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ export const deserializeScenePreviewCamera: ComponentDeserializeFunction = (enti
}
}

export const updateScenePreviewCamera: ComponentUpdateFunction = (entity: Entity) => {
export const updateCameraTransform = (entity: Entity) => {
const obj3d = getComponent(entity, Object3DComponent).value
const transformComponent = getComponent(entity, TransformComponent)

new Matrix4()
return new Matrix4()
.copy(obj3d.parent!.matrixWorld)
.invert()
.multiply(Engine.camera.matrixWorld)
.decompose(transformComponent.position, transformComponent.rotation, transformComponent.scale)
}

export const updateScenePreviewCamera: ComponentUpdateFunction = (entity: Entity) => {}

export const serializeScenePreviewCamera: ComponentSerializeFunction = (entity) => {
if (hasComponent(entity, ScenePreviewCameraTagComponent)) {
return {
Expand Down

0 comments on commit 6dac0a4

Please sign in to comment.