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

Commit

Permalink
fix click root scene entity crash (#10266)
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField authored May 29, 2024
1 parent 82bf263 commit a314b7c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { Popover } from '@mui/material'
import React from 'react'
import { useTranslation } from 'react-i18next'

import { EntityUUID, UUIDComponent, entityExists } from '@etherealengine/ecs'
import { EntityUUID, UUIDComponent } from '@etherealengine/ecs'
import { Component, ComponentJSONIDMap, useOptionalComponent } from '@etherealengine/ecs/src/ComponentFunctions'
import { MaterialSelectionState } from '@etherealengine/engine/src/scene/materials/MaterialLibraryState'
import { NO_PROXY, getMutableState, getState, useHookstate } from '@etherealengine/hyperflux'
Expand Down Expand Up @@ -67,7 +67,6 @@ const EntityEditor = (props: { entityUUID: EntityUUID; multiEdit: boolean }) =>
if (!componentEditors[component.name]) continue
components.push(component)
}
//const components = useAllComponents(entity).filter((c) => !!getState(ComponentEditorsState)[c.name])

const open = !!anchorEl.value

Expand Down Expand Up @@ -113,6 +112,13 @@ const EntityEditor = (props: { entityUUID: EntityUUID; multiEdit: boolean }) =>
)
}

const NodeEditor = (props: { entityUUID: EntityUUID; multiEdit: boolean }) => {
const entity = UUIDComponent.useEntityByUUID(props.entityUUID)
const node = GLTFNodeState.useMutableNode(entity)
if (!node) return null
return <EntityEditor entityUUID={props.entityUUID} multiEdit={props.multiEdit} />
}

/**
* PropertiesPanelContainer used to render editor view to customize property of selected element.
*/
Expand All @@ -134,10 +140,12 @@ export const PropertiesPanelContainer = () => {
height: '100%'
}}
>
{materialUUID ? (
<MaterialEditor materialUUID={materialUUID} />
) : uuid && entity && entityExists(entity) ? (
<EntityEditor entityUUID={uuid} key={uuid} multiEdit={multiEdit} />
{entity ? (
materialUUID ? (
<MaterialEditor materialUUID={materialUUID} />
) : (
<NodeEditor entityUUID={uuid} key={uuid} multiEdit={multiEdit} />
)
) : (
<div
style={{
Expand Down
15 changes: 13 additions & 2 deletions packages/engine/src/gltf/GLTFDocumentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { GLTF } from '@gltf-transform/core'
import matches, { Validator } from 'ts-matches'

import multiLogger from '@etherealengine/common/src/logger'
import { Entity, EntityUUID, UUIDComponent, getComponent } from '@etherealengine/ecs'
import { State, defineAction, defineState, getMutableState, getState } from '@etherealengine/hyperflux'
import { Entity, EntityUUID, UUIDComponent, getComponent, useOptionalComponent } from '@etherealengine/ecs'
import { State, defineAction, defineState, getMutableState, getState, useHookstate } from '@etherealengine/hyperflux'
import { SourceComponent } from '../scene/components/SourceComponent'

export const GLTFDocumentState = defineState({
Expand Down Expand Up @@ -64,6 +64,17 @@ export const GLTFNodeState = defineState({
return gltf.nodes![nodeLookup.nodeIndex]
},

useMutableNode(entity: Entity): GLTF.INode | undefined {
const nodeState = useHookstate(getMutableState(GLTFNodeState))
const source = useOptionalComponent(entity, SourceComponent)?.value
const uuid = useOptionalComponent(entity, UUIDComponent)?.value
if (!source) return
if (!uuid) return
const nodeLookup = nodeState.value[source][uuid]
if (!nodeLookup) return
return getState(GLTFDocumentState)[source].nodes?.[nodeLookup.nodeIndex]
},

convertGltfToNodeDictionary: (gltf: GLTF.IGLTF) => {
const nodes: Record<string, { nodeIndex: number; childIndex: number; parentUUID: EntityUUID | null }> = {}

Expand Down

0 comments on commit a314b7c

Please sign in to comment.