import React from 'react' import { useTranslation } from 'react-i18next' import { Color } from 'three' import { useEngineState } from '@xrengine/engine/src/ecs/classes/EngineState' import { ComponentType, getComponent, hasComponent, useComponent } from '@xrengine/engine/src/ecs/functions/ComponentFunctions' import { ErrorComponent, getEntityErrors } from '@xrengine/engine/src/scene/components/ErrorComponent' import { SkyboxComponent } from '@xrengine/engine/src/scene/components/SkyboxComponent' import { SkyTypeEnum } from '@xrengine/engine/src/scene/constants/SkyTypeEnum' import CloudIcon from '@mui/icons-material/Cloud' import ColorInput from '../inputs/ColorInput' import CompoundNumericInput from '../inputs/CompoundNumericInput' import FolderInput from '../inputs/FolderInput' import ImageInput from '../inputs/ImageInput' import InputGroup from '../inputs/InputGroup' import NumericInputGroup from '../inputs/NumericInputGroup' import RadianNumericInputGroup from '../inputs/RadianNumericInputGroup' import SelectInput from '../inputs/SelectInput' import NodeEditor from './NodeEditor' import { EditorComponentType, updateProperties, updateProperty } from './Util' const hoursToRadians = (hours: number) => hours / 24 const radiansToHours = (rads: number) => rads * 24 /** * Types of skyboxes * * @type {Array} */ const SkyOption = [ { label: 'Color', value: SkyTypeEnum.color }, { label: 'Skybox', value: SkyTypeEnum.skybox }, { label: 'Cubemap', value: SkyTypeEnum.cubemap }, { label: 'Equirectangular', value: SkyTypeEnum.equirectangular } ] /** * SkyboxNodeEditor component class used to render editor view to customize component property. * * @type {class component} */ export const SkyboxNodeEditor: EditorComponentType = (props) => { const { t } = useTranslation() const entity = props.entity const hasError = getEntityErrors(entity, SkyboxComponent) const skyboxComponent = useComponent(entity, SkyboxComponent) const onChangeEquirectangularPathOption = (equirectangularPath) => { if (equirectangularPath !== skyboxComponent.equirectangularPath.value) { updateProperties(SkyboxComponent, { equirectangularPath }) } } const onChangeCubemapPathOption = (path) => { const directory = path[path.length - 1] === '/' ? path.substring(0, path.length - 1) : path if (directory !== skyboxComponent.cubemapPath.value) { updateProperties(SkyboxComponent, { cubemapPath: directory }) } } const renderSkyboxSettings = () => ( <> > ) // creating editor view for equirectangular Settings const renderEquirectangularSettings = () => ( {hasError && {t('editor:properties.skybox.error-url')}} ) // creating editor view for cubemap Settings const renderCubemapSettings = () => ( {hasError && {t('editor:properties.skybox.error-url')}} ) // creating editor view for color Settings const renderColorSettings = () => ( ) // creating editor view for skybox Properties const renderSkyBoxProps = () => { switch (skyboxComponent.backgroundType.value) { case SkyTypeEnum.equirectangular: return renderEquirectangularSettings() case SkyTypeEnum.cubemap: return renderCubemapSettings() case SkyTypeEnum.color: return renderColorSettings() default: return renderSkyboxSettings() } } return ( {renderSkyBoxProps()} ) } SkyboxNodeEditor.iconComponent = CloudIcon export default SkyboxNodeEditor