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

Commit

Permalink
IR-1652 input sink fixes (#10233)
Browse files Browse the repository at this point in the history
* handling for inputSinks array default value of self, de/serializing as empty and proper displaying when empty in the nodeEditor. Also removing old nodeEditor that should have been moved (deleted and moved) but was only copied somehow

* adding a tag component for XrScenePlacement entity so we can exclude it in some queries at origin
  • Loading branch information
SamMazerIR authored May 24, 2024
1 parent fcc5834 commit 179c0dc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SourceComponent } from '@etherealengine/engine/src/scene/components/Sou
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent'
import { InputComponent } from '@etherealengine/spatial/src/input/components/InputComponent'
import PanToolIcon from '@mui/icons-material/PanTool'
import React, { useEffect } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { EditorControlFunctions } from '../../functions/EditorControlFunctions'
import { PropertiesPanelButton } from '../inputs/Button'
Expand All @@ -56,13 +56,6 @@ export const InputComponentNodeEditor: EditorComponentType = (props) => {
value: getComponent(props.entity, UUIDComponent)
})

useEffect(() => {
//convenience to add a sink if none exist
if (inputComponent.inputSinks.value.length === 0) {
addSink()
}
}, [authoringLayerEntities.length])

const addSink = () => {
const sinks = [...(inputComponent.inputSinks.value ?? []), getComponent(props.entity, UUIDComponent)]

Expand Down Expand Up @@ -100,7 +93,7 @@ export const InputComponentNodeEditor: EditorComponentType = (props) => {
</PropertiesPanelButton>

<div id={`inputSinks-list`}>
{options.length > 1
{options.length > 1 && inputComponent.inputSinks.value?.length > 0
? inputComponent.inputSinks.value.map((sink, index) => {
return (
<div key={index}>
Expand Down
13 changes: 2 additions & 11 deletions packages/spatial/src/input/components/InputComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ import {
getOptionalComponent,
InputSystemGroup,
UndefinedEntity,
useExecute,
UUIDComponent
useExecute
} from '@etherealengine/ecs'
import {
defineComponent,
hasComponent,
removeComponent,
setComponent,
useComponent
Expand Down Expand Up @@ -65,7 +63,7 @@ export const InputComponent = defineComponent({

onInit: () => {
return {
inputSinks: [] as EntityUUID[],
inputSinks: ['Self'] as EntityUUID[],
activationDistance: 2,
highlight: true,
grow: false,
Expand All @@ -78,13 +76,6 @@ export const InputComponent = defineComponent({
},

onSet(entity, component, json) {
if (!json && component.inputSinks.value.length === 0) {
if (hasComponent(entity, UUIDComponent)) {
component.inputSinks.set([getComponent(entity, UUIDComponent)])
} else {
console.warn('no UUIDComponent at entity, cannot add self as InputSink at entity ' + entity)
}
}
if (!json) return
if (typeof json.inputSinks === 'object') component.inputSinks.set(json.inputSinks)
if (typeof json.highlight === 'boolean') component.highlight.set(json.highlight)
Expand Down
141 changes: 0 additions & 141 deletions packages/spatial/src/input/properties/InputComponentNodeEditor.tsx

This file was deleted.

21 changes: 12 additions & 9 deletions packages/spatial/src/input/systems/ClientInputSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { RendererComponent } from '../../renderer/WebGLRendererSystem'
import { BoundingBoxComponent } from '../../transform/components/BoundingBoxComponents'
import { TransformComponent, TransformGizmoTagComponent } from '../../transform/components/TransformComponent'
import { XRSpaceComponent } from '../../xr/XRComponents'
import { XRScenePlacementComponent } from '../../xr/XRScenePlacementComponent'
import { XRControlsState, XRState } from '../../xr/XRState'
import { XRUIComponent } from '../../xrui/components/XRUIComponent'
import { InputComponent } from '../components/InputComponent'
Expand Down Expand Up @@ -132,7 +133,13 @@ const worldPosInputComponent = new Vector3()
const inputXRUIs = defineQuery([InputComponent, VisibleComponent, XRUIComponent])
const inputBoundingBoxes = defineQuery([InputComponent, VisibleComponent, BoundingBoxComponent])
const inputObjects = defineQuery([InputComponent, VisibleComponent, GroupComponent])
const spatialInputObjects = defineQuery([InputComponent, VisibleComponent, TransformComponent, Not(CameraComponent)]) //TODO may be overkill if visible means it always has transform
const spatialInputObjects = defineQuery([
InputComponent,
VisibleComponent,
TransformComponent,
Not(CameraComponent),
Not(XRScenePlacementComponent)
])
/** @todo abstract into heuristic api */
const gizmoPickerObjects = defineQuery([InputComponent, GroupComponent, VisibleComponent, TransformGizmoTagComponent])

Expand Down Expand Up @@ -344,15 +351,11 @@ const setInputSources = (startEntity: Entity, inputSources: Entity[]) => {
const inputEntity = getAncestorWithComponent(startEntity, InputComponent)
if (inputEntity) {
const inputComponent = getMutableComponent(inputEntity, InputComponent)
if (!inputComponent.inputSinks.value || inputComponent.inputSinks.value.length === 0) {
inputComponent.inputSources.merge(inputSources)
} else {
for (const sinkEntityUUID of inputComponent.inputSinks.value) {
const sinkEntity = UUIDComponent.getEntityByUUID(sinkEntityUUID)

const sinkInputComponent = getMutableComponent(sinkEntity, InputComponent)
sinkInputComponent.inputSources.merge(inputSources)
}
for (const sinkEntityUUID of inputComponent.inputSinks.value) {
const sinkEntity = sinkEntityUUID === 'Self' ? inputEntity : UUIDComponent.getEntityByUUID(sinkEntityUUID) //TODO why is this not sending input to my sinks
const sinkInputComponent = getMutableComponent(sinkEntity, InputComponent)
sinkInputComponent.inputSources.merge(inputSources)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/spatial/src/xr/XRAnchorSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { TransformComponent } from '../transform/components/TransformComponent'
import { updateWorldOriginFromScenePlacement } from '../transform/updateWorldOrigin'
import { XRCameraUpdateSystem } from './XRCameraSystem'
import { XRAnchorComponent, XRHitTestComponent } from './XRComponents'
import { XRScenePlacementComponent } from './XRScenePlacementComponent'
import { ReferenceSpace, XRAction, XRState } from './XRState'

export const updateHitTest = (entity: Entity) => {
Expand Down Expand Up @@ -192,6 +193,7 @@ export const XRAnchorSystemState = defineState({
initial: () => {
const scenePlacementEntity = createEntity()
setComponent(scenePlacementEntity, NameComponent, 'xr-scene-placement')
setComponent(scenePlacementEntity, XRScenePlacementComponent)
setComponent(scenePlacementEntity, TransformComponent)
setComponent(scenePlacementEntity, EntityTreeComponent, { parentEntity: Engine.instance.localFloorEntity })
setComponent(scenePlacementEntity, VisibleComponent, true)
Expand Down
28 changes: 28 additions & 0 deletions packages/spatial/src/xr/XRScenePlacementComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import { defineComponent } from '@etherealengine/ecs/src/ComponentFunctions'

export const XRScenePlacementComponent = defineComponent({ name: 'XRScenePlacementComponent' })

0 comments on commit 179c0dc

Please sign in to comment.