import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { AdditiveBlending, Blending, CustomBlending, MultiplyBlending, NoBlending, NormalBlending, SubtractiveBlending } from 'three' import { RenderMode } from 'three.quarks/dist/three.quarks' import { useComponent } from '@xrengine/engine/src/ecs/functions/ComponentFunctions' import { ApplyForceBehaviorJSON, BehaviorJSON, CONE_SHAPE_DEFAULT, ConstantColorJSON, DONUT_SHAPE_DEFAULT, MESH_SHAPE_DEFAULT, ParticleSystemComponent, POINT_SHAPE_DEFAULT, SPHERE_SHAPE_DEFAULT, ValueGeneratorJSON } from '@xrengine/engine/src/scene/components/ParticleSystemComponent' import { State } from '@xrengine/hyperflux' import { ScatterPlotOutlined } from '@mui/icons-material' import { Button } from '../inputs/Button' import InputGroup from '../inputs/InputGroup' import ModelInput from '../inputs/ModelInput' import ParameterInput from '../inputs/ParameterInput' import SelectInput from '../inputs/SelectInput' import TexturePreviewInput from '../inputs/TexturePreviewInput' import PaginatedList from '../layout/PaginatedList' import NodeEditor from './NodeEditor' import BehaviorInput from './three.quarks/BehaviorInput' import ColorGenerator from './three.quarks/ColorGenerator' import ValueGenerator from './three.quarks/ValueGenerator' import { EditorComponentType } from './Util' const ParticleSystemNodeEditor: EditorComponentType = (props) => { const { t } = useTranslation() const entity = props.entity const particleSystemState = useComponent(entity, ParticleSystemComponent) const particleSystem = particleSystemState.value const onSetSystemParm = useCallback((field: keyof typeof particleSystem.systemParameters) => { return (value: any) => { const nuParms = JSON.parse(JSON.stringify(particleSystem.systemParameters)) nuParms[field] = value particleSystemState.systemParameters.set(nuParms) particleSystemState._refresh.set(particleSystem._refresh + 1) } }, []) const shapeDefaults = { point: POINT_SHAPE_DEFAULT, sphere: SPHERE_SHAPE_DEFAULT, cone: CONE_SHAPE_DEFAULT, donut: DONUT_SHAPE_DEFAULT, mesh_surface: MESH_SHAPE_DEFAULT } const onChangeShape = useCallback(() => { const onSetShape = onSetSystemParm('shape') return (shape: string) => { onSetShape(shapeDefaults[shape]) } }, []) const onChangeShapeParm = useCallback((field: keyof typeof particleSystem.systemParameters.shape) => { return (value: any) => { const nuParms = JSON.parse(JSON.stringify(particleSystem.systemParameters.shape)) nuParms[field] = value particleSystemState.systemParameters.shape.set(nuParms) particleSystemState._refresh.set((particleSystem._refresh + 1) % 1000) } }, []) const onSetStateParm = useCallback((state: State) => { return (field: keyof typeof state.value) => { if (field === 'value') { return (value: any) => { const nuVals = JSON.parse(JSON.stringify(state.value)) nuVals.value = value state.set(nuVals) particleSystemState._refresh.set((particleSystem._refresh + 1) % 1000) } } else return (value: any) => { state[field].set(value) particleSystemState._refresh.set((particleSystem._refresh + 1) % 1000) } } }, []) const onAddBehavior = useCallback( () => () => { const nuBehavior: ApplyForceBehaviorJSON = { type: 'ApplyForce', direction: [0, 1, 0], magnitude: { type: 'ConstantValue', value: 1 } } particleSystemState.behaviorParameters.set([ ...JSON.parse(JSON.stringify(particleSystem.behaviorParameters)), nuBehavior ]) particleSystemState._refresh.set((particleSystem._refresh + 1) % 1000) }, [] ) const onRemoveBehavior = useCallback( (behavior: BehaviorJSON) => () => { particleSystemState.behaviorParameters.set( JSON.parse(JSON.stringify(particleSystem.behaviorParameters.filter((b) => b !== behavior))) ) particleSystemState._refresh.set((particleSystem._refresh + 1) % 1000) }, [] ) return (

Options

{particleSystem.systemParameters.shape.type === 'mesh_surface' && ( )} {particleSystem.systemParameters.shape.type !== 'mesh_surface' && ( )}

Behaviors

) => { return ( <> ) }} />
) } ParticleSystemNodeEditor.iconComponent = ScatterPlotOutlined export default ParticleSystemNodeEditor