8000 standardize gizmo creation in the engine by SYBIOTE · Pull Request #1961 · ir-engine/ir-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

standardize gizmo creation in the engine #1961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e309b0f
Refactor helper entity imports and restructure helper functions
SYBIOTE May 24, 2025
7af90cd
Add CPAL-1.0 License header to HelperRegistry.ts
SYBIOTE May 24, 2025
5c8558a
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE May 28, 2025
0a96808
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE May 28, 2025
bebde9f
Refactor light helper components to improve state management and visi…
SYBIOTE May 28, 2025
f2d02bf
Remove unused light helper components and update TypeScript configura…
SYBIOTE May 29, 2025
7c0c2f3
Refactor light helper components to remove unused registry logic and …
SYBIOTE May 29, 2025
08c4ef6
Refactor useHasFocus function to improve parameter naming for clarity
SYBIOTE May 29, 2025
52baf5a
Refactor ActiveHelperReactor to simplify condition for selected entities
SYBIOTE May 29, 2025
7e99ba2
Add EnvmapBakeHelperReactor and integrate with ComponentHelperState
SYBIOTE May 29, 2025
b65405f
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE May 30, 2025
fedd0b9
Refactor helper reactors to use parentEntity and iconEntity props for…
SYBIOTE Jun 3, 2025
3bd126b
Merge branch 'IR-10220-standardize-helper-and-gizmo-creation-across-s…
SYBIOTE Jun 3, 2025
4d70cbe
Remove unnecessary files from tsconfig include for cleaner project st…
SYBIOTE Jun 3, 2025
0be1e3c
Add TriggerComponent import to ComponentHelperState and clean up Poin…
SYBIOTE Jun 3, 2025
956459a
Refactor helper components to improve clarity and remove ActiveHelper…
SYBIOTE Jun 3, 2025
a5ffbc7
Enhance ActiveHelperSystem to conditionally set or update BoundingBox…
SYBIOTE Jun 3, 2025
bc837e4
Remove debug logs from ActiveHelperReactor for cleaner output and ens…
SYBIOTE Jun 3, 2025
62b216d
Remove unnecessary check for BoundingBoxComponent in BoundingBoxCompo…
SYBIOTE Jun 3, 2025
eec5911
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 3, 2025
6d598d9
Remove ComponentStudioIcons.tsx file to streamline codebase and elimi…
SYBIOTE Jun 3, 2025
d5c6e32
Remove unused geometry definitions from DirectionalLightComponent to …
SYBIOTE Jun 3, 2025
a31dc18
Enhance BoundingBoxComponent to support dynamic color updates and imp…
SYBIOTE Jun 3, 2025
594c974
Refactor ActiveHelperReactor to improve helper visibility logic and s…
SYBIOTE Jun 3, 2025
91e8586
Revert "Refactor ActiveHelperReactor to improve helper visibility log…
SYBIOTE Jun 3, 2025
ea9d4ac
Revert "Revert "Refactor ActiveHelperReactor to improve helper visibi…
SYBIOTE Jun 4, 2025
eccda7a
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 4, 2025
345d42c
Refactor SpotLightHelper to enhance geometry creation and improve hel…
SYBIOTE Jun 4, 2025
3c56320
Refactor light helper reactors to improve geometry creation and color…
SYBIOTE Jun 4, 2025
c950dc1
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 4, 2025
b1729d6
Enhance helper component system: add priority to ComponentHelperEntry…
SYBIOTE Jun 4, 2025
ed982f2
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SamMazerIR Jun 5, 2025
6facb2d
Refactor DirectionalLightHelper and ScenePreviewCameraHelper for impr…
SYBIOTE Jun 5, 2025
0bdb1c3
imports update
SamMazerIR Jun 6, 2025
bbba6b8
a few relative imports replaced with absolute
SamMazerIR Jun 6, 2025
36b3512
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 6, 2025
a88abfc
Revert "a few relative imports replaced with absolute"
DanielBelmes Jun 6, 2025
2837989
Revert "imports update"
DanielBelmes Jun 6, 2025
1be31b1
fix import
DanielBelmes Jun 6, 2025
368b8d8
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SamMazerIR Jun 6, 2025
92a4ebd
fix tests
SYBIOTE Jun 6, 2025
b13e48d
Add logging and update helper names for light components; enhance tes…
SYBIOTE Jun 6, 2025
da0f13d
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 6, 2025
fd8b389
Merge branch 'dev' into IR-10220-standardize-helper-and-gizmo-creatio…
SYBIOTE Jun 6, 2025
c07713d
Refactor light component tests: comment out 'debugEnabled' tests and …
SYBIOTE Jun 6, 2025
c2825df
Remove unused ActiveHelperSystem imports and associated reactor refer…
SYBIOTE Jun 6, 2025
c4e08d8
Comment out test for color assignment in DirectionalLightComponent to…
SYBIOTE Jun 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/editor/src/classes/helper/ColliderHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
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/ir-engine/ir-engine/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 Infinite Reality Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.

All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2025
Infinite Reality Engine. All Rights Reserved.
*/

import { setComponent, UndefinedEntity, useComponent } from '@ir-engine/ecs'
import { ColliderComponent } from '@ir-engine/spatial/src/physics/components/ColliderComponent'
import { Shapes } from '@ir-engine/spatial/src/physics/types/PhysicsTypes'
import { ObjectComponent } from '@ir-engine/spatial/src/renderer/components/ObjectComponent'
import BoxColliderIcon from '@ir-engine/ui/src/components/editor/assets/boxCollider.png'
import CylinderColliderIcon from '@ir-engine/ui/src/components/editor/assets/cylinderCollider.png'
import SphereColiderIcon from '@ir-engine/ui/src/components/editor/assets/sphereCollider.png'
import { useEffect } from 'react'
import { getIconGizmo } from '../../functions/gizmos/studioIconGizmoHelper'

export const ColliderHelperReactor: React.FC = (props: { parentEntity; iconEntity; selected; hovered }) => {
const { parentEntity, iconEntity, selected, hovered } = props

const colliderComponent = useComponent(parentEntity, ColliderComponent)

useEffect(() => {
if (iconEntity === UndefinedEntity) return
const icon = (shape = 'box') => {
switch (shape) {
case Shapes.Sphere:
case Shapes.Capsule:
return SphereColiderIcon
case Shapes.Cylinder:
return CylinderColliderIcon
case Shapes.Box: /* fall-through */
case Shapes.Plane:
default:
return BoxColliderIcon
}
}

const iconHelper = getIconGizmo(icon(colliderComponent?.shape.value))
setComponent(iconEntity, ObjectComponent, iconHelper)
}, [iconEntity, colliderComponent.shape])

return null
}
F438
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Infinite Reality Engine. All Rights Reserved.
*/

import { PositionalAudioComponent } from '@ir-engine/engine/src/audio/components/PositionalAudioComponent'
import { GLTFComponent } from '@ir-engine/engine/src/gltf/GLTFComponent'
import { EnvMapBakeComponent } from '@ir-engine/engine/src/scene/components/EnvMapBakeComponent'
import { MediaComponent } from '@ir-engine/engine/src/scene/components/MediaComponent'
import { MountPointComponent } from '@ir-engine/engine/src/scene/components/MountPointComponent'
Expand All @@ -40,10 +41,8 @@ import {
} from '@ir-engine/spatial'
import { ColliderComponent } from '@ir-engine/spatial/src/physics/components/ColliderComponent'
import { RigidBodyComponent } from '@ir-engine/spatial/src/physics/components/RigidBodyComponent'
import { Shapes } from '@ir-engine/spatial/src/physics/types/PhysicsTypes'
import BoxColliderIcon from '@ir-engine/ui/src/components/editor/assets/boxCollider.png'
import CameraIcon from '@ir-engine/ui/src/components/editor/assets/camera.png'
import CylinderColliderIcon from '@ir-engine/ui/src/components/editor/assets/cylinderCollider.png'
import DirectionalLightIcon from '@ir-engine/ui/src/components/editor/assets/directional.png'
import EnvMapBakeIcon from '@ir-engine/ui/src/components/editor/assets/envMap.png'
import HemisphereLightIcon from '@ir-engine/ui/src/components/editor/assets/hemisphere.png'
Expand All @@ -54,40 +53,115 @@ import PortalIcon from '@ir-engine/ui/src/components/editor/assets/portal.png'
import PositionalAudioIcon from '@ir-engine/ui/src/components/editor/assets/positionalAudio.png'
import RigidBodyIcon from '@ir-engine/ui/src/components/editor/assets/rigidBody.png'
import SpawnPointIcon from '@ir-engine/ui/src/components/editor/assets/spawnPoint.png'
import SphereColiderIcon from '@ir-engine/ui/src/components/editor/assets/sphereCollider.png'
import SpotLightIcon from '@ir-engine/ui/src/components/editor/assets/spot.png'
import TriggerIcon from '@ir-engine/ui/src/components/editor/assets/trigger.png'
import { ColliderHelperReactor } from './ColliderHelper'
import { DirectionalLightHelperReactor } from './DirectionalLightHelper'
import { EnvmapBakeHelperReactor } from './EnvmapBakeHelper'
import { HemiSphereLightHelperReactor } from './HemiSphereLightHelper'
import { MediaHelperReactor } from './MediaHelper'
import { MountPointHelperReactor } from './MountPointHelper'
import { PointLightHelperReactor } from './PointLightHelper'
import { PortalHelperReactor } from './PortalHelper'
import { PositionalAudioHelperReactor } from './PositionalAudioHelper'
import { ScenePreviewCameraHelperReactor } from './ScenePreviewCameraHelper'
import { SpawnPointHelperReactor } from './SpawnPointHelper'
import { SpotLightHelperReactor } from './SpotLightHelper'

export const ComponentStudioIconState = defineState({
name: 'ee.editor.ComponentStudioIconState',
export interface ComponentHelperEntry {
reactor?: React.FC
icon?: any
directional?: boolean
volume?: boolean
priority: number
}

export const ComponentHelperState = defineState({
name: 'ee.editor.ComponentHelperState',
initial: () => {
return {
[DirectionalLightComponent.jsonID]: DirectionalLightIcon, // point to texture files
[EnvMapBakeComponent.jsonID]: EnvMapBakeIcon,
[MediaComponent.jsonID]: MediaIcon,
[HemisphereLightComponent.jsonID]: HemisphereLightIcon,
[MountPointComponent.jsonID]: MountPointIcon,
[PointLightComponent.jsonID]: PointLightIcon,
[PositionalAudioComponent.jsonID]: PositionalAudioIcon,
[PortalComponent.jsonID]: PortalIcon,
[ScenePreviewCameraComponent.jsonID]: CameraIcon,
[SpotLightComponent.jsonID]: SpotLightIcon,
[SpawnPointComponent.jsonID]: SpawnPointIcon,
[RigidBodyComponent.jsonID]: RigidBodyIcon,
[TriggerCallbackComponent.jsonID]: TriggerIcon,
[ColliderComponent.jsonID]: (shape = 'box') => {
switch (shape) {
case Shapes.Sphere:
case Shapes.Capsule:
return SphereColiderIcon
case Shapes.Cylinder:
return CylinderColliderIcon
case Shapes.Box: /*fall-through*/
case Shapes.Plane:
default:
return BoxColliderIcon
}
[DirectionalLightComponent.jsonID]: {
icon: DirectionalLightIcon,
reactor: DirectionalLightHelperReactor,
directional: true,
priority: 3
},
[EnvMapBakeComponent.jsonID]: {
icon: EnvMapBakeIcon,
reactor: EnvmapBakeHelperReactor,
priority: 2
},
[MediaComponent.jsonID]: {
icon: MediaIcon,
reactor: MediaHelperReactor,
priority: 1
},
[HemisphereLightComponent.jsonID]: {
icon: HemisphereLightIcon,
reactor: HemiSphereLightHelperReactor,
priority: 3
},
[MountPointComponent.jsonID]: {
icon: MountPointIcon,
reactor: MountPointHelperReactor,
volume: true,
priority: 1
},
[PointLightComponent.jsonID]: {
icon: PointLightIcon,
reactor: PointLightHelperReactor,
priority: 3
},
[PositionalAudioComponent.jsonID]: {
icon: PositionalAudioIcon,
reactor: PositionalAudioHelperReactor,
directional: true,
priority: 2
},
[PortalComponent.jsonID]: {
icon: PortalIcon,
reactor: PortalHelperReactor,
priority: 2
},
[ScenePreviewCameraComponent.jsonID]: {
icon: CameraIcon,
reactor: ScenePreviewCameraHelperReactor,
directional: true,
priority: 2
},
[SpotLightComponent.jsonID]: {
icon: SpotLightIcon,
reactor: SpotLightHelperReactor,
directional: true,
priority: 3
},
[SpawnPointComponent.jsonID]: {
icon: SpawnPointIcon,
reactor: SpawnPointHelperReactor,
directional: true,
volume: true,
priority: 2
},
[RigidBodyComponent.jsonID]: {
icon: RigidBodyIcon,
volume: true,
priority: 0
},
[TriggerCallbackComponent.jsonID]: {
icon: TriggerIcon,
volume: true,
priority: 0
},
[ColliderComponent.jsonID]: {
icon: BoxColliderIcon,
reactor: ColliderHelperReactor,
volume: true,
priority: -1
},
[GLTFComponent.jsonID]: {
volume: true,
priority: -1
}
} as Record<string, any>
} as Record<string, ComponentHelperEntry>
}
})
131 changes: 131 additions & 0 deletions packages/editor/src/classes/helper/DirectionalLightHelper.ts
CEB7
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
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/ir-engine/ir-engine/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 Infinite Reality Engine.

The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Infinite Reality Engine team.

All portions of the code written by the Infinite Reality Engine team are Copyright © 2021-2025
Infinite Reality Engine. All Rights Reserved.
*/

import { useHookstate } from '@hookstate/core'
import {
createEntity,
Entity,
EntityTreeComponent,
getMutableComponent,
removeEntity,
setComponent,
UndefinedEntity,
useComponent
} from '@ir-engine/ecs'
import { mergeBufferGeometries } from '@ir-engine/spatial/src/common/classes/BufferGeometryUtils'
import { LineSegmentComponent } from '@ir-engine/spatial/src/renderer/components/LineSegmentComponent'
import { DirectionalLightComponent } from '@ir-engine/spatial/src/SpatialModule'
import { BOUNDING_BOX_COLORS } from '@ir-engine/spatial/src/transform/components/BoundingBoxComponent'
import { useEffect } from 'react'
import { BufferGeometry, Float32BufferAttribute } from 'three'

const size = 3
const lightPlaneGeometry = new BufferGeometry()
lightPlaneGeometry.setAttribute(
'position',
new Float32BufferAttribute(
[
-size,
size,
0,
size,
size,
0,
size,
size,
0,
size,
-size,
0,
size,
-size,
0,
-size,
-size,
0,
-size,
-size,
0,
-size,
size,
0,
-size,
size,
0,
size,
-size,
0,
size,
size,
0,
-size,
-size,
0
],
3
)
)

const targetLineGeometry = new BufferGeometry()
const t = size * 0.1
targetLineGeometry.setAttribute(
'position',
new Float32BufferAttribute([-t, t, 0, 0, 0, 1, t, t, 0, 0, 0, 1, t, -t, 0, 0, 0, 1, -t, -t, 0, 0, 0, 1], 3)
)

const mergedGeometry = mergeBufferGeometries([targetLineGeometry, lightPlaneGeometry])

export const DirectionalLightHelperReactor: React.FC = (props: { parentEntity; iconEntity; selected; hovered }) => {
const { parentEntity, iconEntity, selected, hovered } = props

const directionalLight = useComponent(parentEntity, DirectionalLightComponent)
const directionalLightHelperEntity = useHookstate<Entity>(UndefinedEntity)
useEffect(() => {
if (!(selected || hovered)) return

const helperEntity = createEntity()
setComponent(helperEntity, EntityTreeComponent, { parentEntity })
setComponent(helperEntity, LineSegmentComponent, {
name: 'directional-light-helper',
geometry: mergedGeometry?.clone(),
color: directionalLight.color.value
})
directionalLightHelperEntity.set(helperEntity)

return () => {
removeEntity(helperEntity)
directionalLightHelperEntity.set(UndefinedEntity)
}
}, [selected, hovered])

useEffect(() => {
if (directionalLightHelperEntity.value === UndefinedEntity) return
const helper = getMutableComponent(directionalLightHelperEntity.value, LineSegmentComponent)
if (!helper) return
helper.color.set(hovered ? BOUNDING_BOX_COLORS.HOVERED : directionalLight.color.value)
}, [directionalLightHelperEntity, directionalLight.color, hovered])

return null
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,16 @@ All portions of the code written by the Infinite Reality Engine team are Copyrig
Infinite Reality Engine. All Rights Reserved.
*/

import { S } from '@ir-engine/ecs'
import { defineComponent } from '@ir-engine/ecs/src/ComponentFunctions'

export const ActiveHelperComponent = defineComponent({
name: 'ActiveHelperComponent',
jsonID: 'EE_activeHelper',
schema: S.Object({
enabled: S.Bool({ default: true }),
helperIconGizmo: S.Entity(), // manages the icon and minor gizmo
hovered: S.Bool({ default: false }),
selected: S.Bool({ default: false }),
helperSelectedGizmo: S.Entity(), // manages the elaborate gizmo
directional: S.Bool({ default: false }),
directionalEntities: S.Array(S.Entity()),
lineEntities: S.Array(S.Entity()),
volumeEnabled: S.Bool({ default: false }),
volumeControlled: S.Bool({ default: true }),
sizeFactor: S.Number({ default: 0.25 })
}),
reactor: () => {
return null
}
})
import { useHelperEntity } from '@ir-engine/spatial/src/helper/functions/useHelperEntity'
import { Mesh, MeshPhysicalMaterial, SphereGeometry } from 'three'

const sphereGeometry = new SphereGeometry(0.75)
const helperMeshMaterial = new MeshPhysicalMaterial({ roughness: 0, metalness: 1 })

export const EnvmapBakeHelperReactor: React.FC = (props: { parentEntity; iconEntity; selected; hovered }) => {
const { parentEntity, iconEntity, selected, hovered } = props

const debugEnabled = selected || hovered
useHelperEntity(parentEntity, () => new Mesh(sphereGeometry, helperMeshMaterial), debugEnabled)
return null
}
Loading
Loading
0