diff --git a/packages/editor/src/components/properties/CsgNodeEditor.tsx b/packages/editor/src/components/properties/CsgNodeEditor.tsx new file mode 100755 index 0000000000..4e6147900a --- /dev/null +++ b/packages/editor/src/components/properties/CsgNodeEditor.tsx @@ -0,0 +1,92 @@ +/* +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 React from 'react' +import { useTranslation } from 'react-i18next' + +import { useComponent } from '@etherealengine/engine/src/ecs/functions/ComponentFunctions' +import { CsgComponent } from '@etherealengine/engine/src/scene/components/CsgComponent' + +import InterestsIcon from '@mui/icons-material/Interests' + +import InputGroup from '../inputs/InputGroup' +import SelectInput from '../inputs/SelectInput' +import NodeEditor from './NodeEditor' +import { EditorComponentType, commitProperty } from './Util' + +/** + * Types of operations + * + * @type {Array} + */ +const OperationOption = [ + { + label: 'Union', + value: 'union' + }, + { + label: 'Intersect', + value: 'intersect' + }, + { + label: 'Difference', + value: 'difference' + } +] + +/** + * SkyboxNodeEditor component class used to render editor view to customize component property. + * + * @type {class component} + */ + +export const CsgNodeEditor: EditorComponentType = (props) => { + const { t } = useTranslation() + const entity = props.entity + const csg = useComponent(entity, CsgComponent) + + return ( + + + { + commitProperty(CsgComponent, 'operationType')(value as any) + }} + /> + + + ) +} + +CsgNodeEditor.iconComponent = InterestsIcon + +export default CsgNodeEditor diff --git a/packages/editor/src/components/properties/PrimitiveGeometryNodeEditor.tsx b/packages/editor/src/components/properties/PrimitiveGeometryNodeEditor.tsx index c602c6521e..724ab85aaf 100755 --- a/packages/editor/src/components/properties/PrimitiveGeometryNodeEditor.tsx +++ b/packages/editor/src/components/properties/PrimitiveGeometryNodeEditor.tsx @@ -41,7 +41,7 @@ import NodeEditor from './NodeEditor' import { EditorComponentType, commitProperty } from './Util' /** - * Types of skyboxes + * Types of geometry * * @type {Array} */ diff --git a/packages/engine/src/scene/components/CsgComponent.ts b/packages/engine/src/scene/components/CsgComponent.ts new file mode 100644 index 0000000000..dd8bdbcbc5 --- /dev/null +++ b/packages/engine/src/scene/components/CsgComponent.ts @@ -0,0 +1,66 @@ +/* +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, useComponent } from '../../ecs/functions/ComponentFunctions' +import { useEntityContext } from '../../ecs/functions/EntityFunctions' + +export const CsgComponent = defineComponent({ + name: 'CsgComponent', + jsonID: 'csg', + + onInit: (entity) => { + return { + operationType: '' as string, + groupA: null, + groupB: null + } + }, + + toJSON: (entity, component) => { + return { + operationType: component.operationType.value, + groupA: component.groupA.value, + groupB: component.groupB.value + } + }, + + onSet: (entity, component, json) => { + if (!json) return + if (typeof json.operationType === 'number') component.operationType.set(json.operationType) + if (typeof json.groupA === 'object') component.groupA.set(json.groupA) + if (typeof json.groupB === 'object') component.groupB.set(json.groupB) + }, + + onRemove: (entity, component) => {}, + + reactor: CsgReactor +}) + +function CsgReactor() { + const entity = useEntityContext() + const csgComponent = useComponent(entity, CsgComponent) + + return null +}