Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Csg component #9422

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
92 changes: 92 additions & 0 deletions packages/editor/src/components/properties/CsgNodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<NodeEditor
{...props}
name={t('editor:properties.primitiveGeometry.name')}
description={t('editor:properties.primitiveGeometry.description')}
>
<InputGroup name="Operation Type" label={t('editor:properties.primitiveGeometry.lbl-geometryType')}>
<SelectInput
key={props.entity}
options={OperationOption}
value={csg.operationType.value}
onChange={(value) => {
commitProperty(CsgComponent, 'operationType')(value as any)
}}
/>
</InputGroup>
</NodeEditor>
)
}

CsgNodeEditor.iconComponent = InterestsIcon

export default CsgNodeEditor
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import NodeEditor from './NodeEditor'
import { EditorComponentType, commitProperty } from './Util'

/**
* Types of skyboxes
* Types of geometry
*
* @type {Array}
*/
Expand Down
66 changes: 66 additions & 0 deletions packages/engine/src/scene/components/CsgComponent.ts
Original file line number Diff line number Diff line change
@@ -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
}