Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
IR-1579-Resource-tracker (#10423)
Browse files Browse the repository at this point in the history
* Fix gizmo leaking

* return scene ID from useLoadScene

* Remove returning scene id when loading scene
  • Loading branch information
MichaelEstes authored Jun 27, 2024
1 parent 1ea101d commit 5a2972c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const useLoadLocation = (props: { locationName: string }) => {
export const useLoadScene = (props: { projectName: string; sceneName: string }) => {
const sceneKey = `projects/${props.projectName}/${props.sceneName}`
const assetID = useFind(staticResourcePath, { query: { key: sceneKey, type: 'scene' } })

useEffect(() => {
if (!props.sceneName || !props.projectName) return
if (!assetID.data.length) return
Expand Down
53 changes: 35 additions & 18 deletions packages/editor/src/classes/TransformGizmoVisualComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import {
useEntityContext
} from '@etherealengine/ecs'
import { TransformMode } from '@etherealengine/engine/src/scene/constants/transformConstants'
import { useHookstate } from '@etherealengine/hyperflux'
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { InputComponent } from '@etherealengine/spatial/src/input/components/InputComponent'
import { addObjectToGroup, removeObjectFromGroup } from '@etherealengine/spatial/src/renderer/components/GroupComponent'
import { VisibleComponent } from '@etherealengine/spatial/src/renderer/components/VisibleComponent'
import { EntityTreeComponent } from '@etherealengine/spatial/src/transform/components/EntityTree'
import { TransformGizmoTagComponent } from '@etherealengine/spatial/src/transform/components/TransformComponent'
import { Mesh, Object3D } from 'three'
import {
gizmoRotate,
gizmoScale,
Expand All @@ -55,6 +57,33 @@ import {
setupGizmo
} from '../constants/GizmoPresets'

const useTranslateRotateScaleEntities = () => {
const translate = useHookstate(createEntity)
const rotate = useHookstate(createEntity)
const scale = useHookstate(createEntity)

useEffect(() => {
return () => {
removeEntity(translate.value)
removeEntity(rotate.value)
removeEntity(scale.value)
}
}, [])

return {
translate: translate.value,
rotate: rotate.value,
scale: scale.value
}
}

const cleanupGizmo = (gizmoObj: Object3D) => {
for (const child of gizmoObj.children as Mesh[]) {
// Only dispose cloned geometry from setupGizmo
if (child.geometry) child.geometry.dispose()
}
}

export const TransformGizmoVisualComponent = defineComponent({
name: 'TransformGizmoVisual',

Expand Down Expand Up @@ -92,21 +121,9 @@ export const TransformGizmoVisualComponent = defineComponent({
reactor: function (props) {
const gizmoVisualEntity = useEntityContext()
const visualComponent = useComponent(gizmoVisualEntity, TransformGizmoVisualComponent)
const gizmo = {
translate: createEntity(),
rotate: createEntity(),
scale: createEntity()
}
const picker = {
translate: createEntity(),
rotate: createEntity(),
scale: createEntity()
}
const helper = {
translate: createEntity(),
rotate: createEntity(),
scale: createEntity()
}
const gizmo = useTranslateRotateScaleEntities()
const picker = useTranslateRotateScaleEntities()
const helper = useTranslateRotateScaleEntities()

useEffect(() => {
// Gizmo creation
Expand Down Expand Up @@ -157,11 +174,11 @@ export const TransformGizmoVisualComponent = defineComponent({
return () => {
for (const mode in TransformMode) {
removeObjectFromGroup(gizmo[mode], gizmoObject[mode])
cleanupGizmo(gizmoObject[mode])
removeObjectFromGroup(picker[mode], pickerObject[mode])
cleanupGizmo(pickerObject[mode])
removeObjectFromGroup(helper[mode], helperObject[mode])
removeEntity(gizmo[mode])
removeEntity(picker[mode])
removeEntity(helper[mode])
cleanupGizmo(helperObject[mode])
}
}
}, [])
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/constants/GizmoPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ const gizmoRotate = {
}

const helperRotate = {
AXIS: [[new Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']]
AXIS: [[new Line(lineGeometry, matHelper), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']]
}

const pickerRotate = {
Expand Down

0 comments on commit 5a2972c

Please sign in to comment.