This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
5 changed files
with
193 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useLoadEngineWithScene, useNetwork } from '@etherealengine/client-core/src/components/World/EngineHooks' | ||
import { Engine, getComponent, setComponent } from '@etherealengine/ecs' | ||
import { getMutableState, useHookstate, useImmediateEffect } from '@etherealengine/hyperflux' | ||
import { TransformComponent } from '@etherealengine/spatial' | ||
import { CameraComponent } from '@etherealengine/spatial/src/camera/components/CameraComponent' | ||
import { CameraOrbitComponent } from '@etherealengine/spatial/src/camera/components/CameraOrbitComponent' | ||
import { InputComponent } from '@etherealengine/spatial/src/input/components/InputComponent' | ||
import { RendererState } from '@etherealengine/spatial/src/renderer/RendererState' | ||
import { updateWorldOriginFromScenePlacement } from '@etherealengine/spatial/src/transform/updateWorldOrigin' | ||
import { XRState } from '@etherealengine/spatial/src/xr/XRState' | ||
import React, { useEffect } from 'react' | ||
import { Quaternion, Vector3 } from 'three' | ||
import { useRouteScene } from '../sceneRoute' | ||
import { Transform } from './utils/transform' | ||
|
||
export default function ScenePlacement() { | ||
const sceneEntity = useRouteScene('default-project', 'public/scenes/apartment.gltf') | ||
useNetwork({ online: false }) | ||
useLoadEngineWithScene() | ||
|
||
useImmediateEffect(() => { | ||
getMutableState(RendererState).gridVisibility.set(true) | ||
getMutableState(RendererState).physicsDebug.set(true) | ||
const entity = Engine.instance.viewerEntity | ||
setComponent(entity, CameraOrbitComponent) | ||
setComponent(entity, InputComponent) | ||
getComponent(entity, CameraComponent).position.set(0, 3, 4) | ||
}, []) | ||
|
||
/** Origin Transform */ | ||
const transformState = useHookstate({ | ||
position: new Vector3(), | ||
rotation: new Quaternion(), | ||
scale: new Vector3(1, 1, 1) | ||
}) | ||
|
||
useEffect(() => { | ||
const xrState = getMutableState(XRState) | ||
xrState.scenePosition.value.copy(transformState.position.value) | ||
xrState.sceneRotation.value.copy(transformState.rotation.value) | ||
xrState.sceneScale.set(transformState.scale.value.x) | ||
updateWorldOriginFromScenePlacement() | ||
}, [transformState.position, transformState.rotation, transformState.scale]) | ||
|
||
/** Scene Transform */ | ||
const transformState2 = useHookstate({ | ||
position: new Vector3(2, 0, 2), | ||
rotation: new Quaternion(), | ||
scale: new Vector3().setScalar(0.1) | ||
}) | ||
|
||
useEffect(() => { | ||
if (!sceneEntity.value) return | ||
setComponent(sceneEntity.value, TransformComponent, { | ||
position: transformState2.position.value, | ||
rotation: transformState2.rotation.value, | ||
scale: transformState2.scale.value | ||
}) | ||
}, [sceneEntity, transformState2.position, transformState2.rotation, transformState2.scale]) | ||
|
||
return ( | ||
<div className="pointer-events-auto absolute right-0 w-fit flex flex-col flex-grid justify-start gap-1.5"> | ||
<Transform title={'Origin'} transformState={transformState} /> | ||
<Transform title={'Scene'} transformState={transformState2} /> | ||
</div> | ||
) | ||
} | ||
|
||
/** | ||
* Scene placement | ||
* - | ||
*/ |
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,46 @@ | ||
import { State } from '@etherealengine/hyperflux' | ||
import EulerInput from '@etherealengine/ui/src/components/editor/input/Euler' | ||
import InputGroup from '@etherealengine/ui/src/components/editor/input/Group' | ||
import Vector3Input from '@etherealengine/ui/src/components/editor/input/Vector3' | ||
import PropertyGroup from '@etherealengine/ui/src/components/editor/properties/group' | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Euler, Quaternion, Vector3 } from 'three' | ||
|
||
export const Transform = (props: { | ||
title?: string | ||
transformState: State<{ position: Vector3; rotation: Quaternion; scale: Vector3 }> | ||
}) => { | ||
const { transformState } = props | ||
const { t } = useTranslation() | ||
|
||
const { position, rotation, scale } = transformState.value | ||
|
||
const onChangePosition = (value: Vector3) => transformState.position.set(new Vector3().copy(value)) | ||
const onChangeRotation = (value: Euler) => transformState.rotation.set(new Quaternion().setFromEuler(value)) | ||
const onChangeScale = (value: Vector3) => transformState.scale.set(new Vector3().copy(value)) | ||
|
||
return ( | ||
<PropertyGroup | ||
minimizedDefault={false} | ||
name={props.title ?? t('editor:properties.transform.title')} | ||
> | ||
<InputGroup name="Position" label={t('editor:properties.transform.lbl-position')}> | ||
<Vector3Input smallStep={0.01} mediumStep={0.1} largeStep={1} value={position} onChange={onChangePosition} /> | ||
</InputGroup> | ||
<InputGroup name="Rotation" label={t('editor:properties.transform.lbl-rotation')}> | ||
<EulerInput quaternion={rotation} onChange={onChangeRotation} unit="°" /> | ||
</InputGroup> | ||
<InputGroup name="Scale" label={t('editor:properties.transform.lbl-scale')}> | ||
<Vector3Input | ||
uniformScaling | ||
smallStep={0.01} | ||
mediumStep={0.1} | ||
largeStep={1} | ||
value={scale} | ||
onChange={onChangeScale} | ||
/> | ||
</InputGroup> | ||
</PropertyGroup> | ||
) | ||
} |
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