import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useEngineState } from '@xrengine/engine/src/ecs/classes/EngineState' import { getComponent, useComponent } from '@xrengine/engine/src/ecs/functions/ComponentFunctions' import { EnvmapComponent, SCENE_COMPONENT_ENVMAP } from '@xrengine/engine/src/scene/components/EnvmapComponent' import { ErrorComponent, getEntityErrors } from '@xrengine/engine/src/scene/components/ErrorComponent' import { EnvMapSourceType, EnvMapTextureType } from '@xrengine/engine/src/scene/constants/EnvMapEnum' import { deserializeEnvMap } from '@xrengine/engine/src/scene/functions/loaders/EnvMapFunctions' import ColorInput from '../inputs/ColorInput' import CompoundNumericInput from '../inputs/CompoundNumericInput' import FolderInput from '../inputs/FolderInput' import ImagePreviewInput from '../inputs/ImagePreviewInput' import InputGroup from '../inputs/InputGroup' import SelectInput from '../inputs/SelectInput' import NodeEditor from './NodeEditor' import { EditorComponentType, updateProperties, updateProperty } from './Util' /** * EnvMapSourceOptions array containing SourceOptions for Envmap */ const EnvMapSourceOptions = Object.values(EnvMapSourceType).map((value) => { return { label: value, value } }) /** * EnvMapSourceOptions array containing SourceOptions for Envmap */ const EnvMapTextureOptions = Object.values(EnvMapTextureType).map((value) => { return { label: value, value } }) /** * EnvMapEditor provides the editor view for environment map property customization. * * @param props * @constructor */ export const EnvMapEditor: EditorComponentType = (props) => { const { t } = useTranslation() const entity = props.entity const onChangeCubemapURLSource = useCallback((value) => { const directory = value[value.length - 1] === '/' ? value.substring(0, value.length - 1) : value if (directory !== envmapComponent.envMapSourceURL) { updateProperties(EnvmapComponent, { envMapSourceURL: directory }) } }, []) let envmapComponent = useComponent(entity, EnvmapComponent) const errors = getEntityErrors(props.entity, EnvmapComponent) return ( {envmapComponent.type.value === EnvMapSourceType.Color && ( )} {envmapComponent.type.value === EnvMapSourceType.Texture && (
{envmapComponent.envMapTextureType.value === EnvMapTextureType.Cubemap && ( )} {envmapComponent.envMapTextureType.value === EnvMapTextureType.Equirectangular && ( )} {errors?.MISSING_FILE && (
{t('editor:properties.scene.error-url')}
)}
)} {envmapComponent.type.value !== EnvMapSourceType.None && ( )}
) } export default EnvMapEditor