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

Ir 2543 create prefab #10384

Merged
merged 24 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5beb036
add create prefab panel and export for prefab
JT00y Jun 13, 2024
cb079fb
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y Jun 13, 2024
2b87c8f
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y Jun 14, 2024
5b4a6f4
change add component function
JT00y Jun 14, 2024
51558b7
delete changes for modelcomponent
JT00y Jun 15, 2024
0a5c46d
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y Jun 17, 2024
55ad610
add pass tag to static resource and clean up state
JT00y Jun 17, 2024
23ff84b
clean up
JT00y Jun 17, 2024
59256c7
change state to hookstate and add await to export
JT00y Jun 17, 2024
cce1d1b
fix import
JT00y Jun 17, 2024
f92cca7
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 Jun 17, 2024
059023b
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y Jun 17, 2024
7322748
fix path for folder
JT00y Jun 17, 2024
4e7729c
Merge branch 'ir-2543-create-prefab' of https://github.com/EtherealEn…
dinomut1 Jun 17, 2024
543f911
fix exporting non-model entities
dinomut1 Jun 18, 2024
7533f55
remove add model component
JT00y Jun 18, 2024
2121655
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y Jun 18, 2024
def85bf
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 Jun 20, 2024
05bedac
fix upload
dinomut1 Jun 20, 2024
6207bc1
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 Jun 20, 2024
dd7f4cb
create dud prefab entity for export so child is not lost
dinomut1 Jun 20, 2024
0d645db
prefab parenting preserved
dinomut1 Jun 20, 2024
78f7423
update selection on create prefab
dinomut1 Jun 21, 2024
e35209b
Merge branch 'dev' into ir-2543-create-prefab
dinomut1 Jun 21, 2024
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
1 change: 1 addition & 0 deletions packages/client-core/i18n/en/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@
"lbl-collapseAll": "Collapse All",
"lbl-explode": "Explode Objects",
"lbl-addEntity": "Add Entity",
"lbl-createPrefab": "Create Prefab",
"issues": "Issues",
"copy-paste": {
"no-hierarchy-nodes": "No hierarchy nodes found"
Expand Down
124 changes: 124 additions & 0 deletions packages/editor/src/components/dialogs/CreatePrefabPanelDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
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 { PopoverState } from '@etherealengine/client-core/src/common/services/PopoverState'
import { staticResourcePath } from '@etherealengine/common/src/schema.type.module'
import { Engine, Entity, hasComponent, setComponent } from '@etherealengine/ecs'
import { ModelComponent } from '@etherealengine/engine/src/scene/components/ModelComponent'
import { getState } from '@etherealengine/hyperflux'
import Button from '@etherealengine/ui/src/primitives/tailwind/Button'
import Input from '@etherealengine/ui/src/primitives/tailwind/Input'
import Modal from '@etherealengine/ui/src/primitives/tailwind/Modal'
import React, { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { EditorControlFunctions } from '../../functions/EditorControlFunctions'
import { exportRelativeGLTF } from '../../functions/exportGLTF'
import { EditorState } from '../../services/EditorServices'
import { HeirarchyTreeNodeType } from '../hierarchy/HeirarchyTreeWalker'

export default function CreatePrefabPanel({ node }: { node?: HeirarchyTreeNodeType }) {
const entity = node?.entity as Entity
const [defaultPrefabFolder, setDefaultPrefabFolder] = useState<string>('/assets/custom-prefabs')
const [prefabName, setPrefabName] = useState<string>('prefab')
const [prefabTag, setPrefabTag] = useState<string[]>([])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change these to Hookstate objects instead of normal react state

const { t } = useTranslation()

const onExportPrefab = async () => {
if (!hasComponent(entity, ModelComponent)) {
EditorControlFunctions.addOrRemoveComponent([entity], ModelComponent, true)
setComponent(entity, ModelComponent)
}
const editorState = getState(EditorState)
const fileName = defaultPrefabFolder + '/' + prefabName + '.gltf'
const srcProject = editorState.projectName!
try {
exportRelativeGLTF(entity, srcProject, fileName)
//pass static resource
const resources = await Engine.instance.api.service(staticResourcePath).find({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will always fail because the file doesn't exist yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this call, and construct a static resource object to pass for upload

query: { key: 'projects/' + srcProject + fileName }
})
if (resources.data.length === 0) {
throw new Error('User not found')
}
const resource = resources.data[0]
await Engine.instance.api.service(staticResourcePath).patch(resource.id, { tags: prefabTag })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a "create" call instead of "patch"

PopoverState.hidePopupover()
setDefaultPrefabFolder('/assets/custom-prefabs')
setPrefabName('prefab')
setPrefabTag([])
} catch (e) {
console.error(e)
}
}
return (
<Modal
title="Create Prefab"
onSubmit={onExportPrefab}
className="w-[50vw] max-w-2xl"
onClose={PopoverState.hidePopupover}
>
<Input
value={defaultPrefabFolder}
onChange={(event) => setDefaultPrefabFolder(event.target.value)}
label="Default Save Folder"
/>
<Input value={prefabName} onChange={(event) => setPrefabName(event.target.value)} label="Name" />

<Button
size="small"
variant="outline"
className="text-left text-xs"
onClick={() => {
setPrefabTag([...(prefabTag ?? []), ''])
}}
>
{t('editor:layout.filebrowser.fileProperties.addTag')}
</Button>
<div>
{(prefabTag ?? []).map((tag, index) => (
<div style={{ display: 'flex', flexDirection: 'row', margin: '0, 16px 0 0' }}>
<Input
key={index}
label={t('editor:layout.filebrowser.fileProperties.tag')}
onChange={(event) => (prefabTag[index] = event.target.value)}
value={prefabTag.values[index]}
/>
<Button
onClick={() => {
setPrefabTag(prefabTag.filter((_, i) => i !== index))
}}
size="small"
variant="outline"
className="text-left text-xs"
>
{' '}
x{' '}
</Button>
</div>
))}
</div>
</Modal>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ import { NotificationService } from '@etherealengine/client-core/src/common/serv
import { Engine, EntityUUID, UUIDComponent, entityExists } from '@etherealengine/ecs'
import { CameraOrbitComponent } from '@etherealengine/spatial/src/camera/components/CameraOrbitComponent'

import { PopoverState } from '@etherealengine/client-core/src/common/services/PopoverState'
import useUpload from '@etherealengine/editor/src/components/assets/useUpload'
import CreatePrefabPanel from '@etherealengine/editor/src/components/dialogs/CreatePrefabPanelDialog'
import {
HeirarchyTreeNodeType,
heirarchyTreeWalker
Expand Down Expand Up @@ -82,6 +84,7 @@ function HierarchyPanelContents(props: { sceneURL: string; rootEntityUUID: Entit
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null)
const [anchorPosition, setAnchorPosition] = React.useState({ left: 0, top: 0 })
const [anchorPositionPop, setAnchorPositionPop] = React.useState<undefined | PopoverPosition>(undefined)

const [prevClickedNode, setPrevClickedNode] = useState<HeirarchyTreeNodeType | null>(null)
const onUpload = useUpload(uploadOptions)
const [renamingNode, setRenamingNode] = useState<RenameNodeData | null>(null)
Expand All @@ -93,6 +96,9 @@ function HierarchyPanelContents(props: { sceneURL: string; rootEntityUUID: Entit

const rootEntity = UUIDComponent.useEntityByUUID(rootEntityUUID)
const rootEntityTree = useComponent(rootEntity, EntityTreeComponent)
const panel = document.getElementById('propertiesPanel')
const anchorElButton = useHookstate<HTMLButtonElement | null>(null)
const open = !!anchorElButton.value

const MemoTreeNode = useCallback(
(props: HierarchyTreeNodeProps) => (
Expand Down Expand Up @@ -438,9 +444,7 @@ function HierarchyPanelContents(props: { sceneURL: string; rootEntityUUID: Entit
{MemoTreeNode}
</FixedSizeList>
)
const panel = document.getElementById('propertiesPanel')
const anchorElButton = useHookstate<HTMLButtonElement | null>(null)
const open = !!anchorElButton.value

return (
<>
<PopoverContext.Provider
Expand All @@ -460,6 +464,7 @@ function HierarchyPanelContents(props: { sceneURL: string; rootEntityUUID: Entit
className="m-1 rounded bg-theme-primary text-[#A3A3A3]"
startComponent={<HiMagnifyingGlass className="text-white" />}
/>

<Button
startIcon={<HiOutlinePlusCircle />}
variant="transparent"
Expand Down Expand Up @@ -607,6 +612,18 @@ function HierarchyPanelContents(props: { sceneURL: string; rootEntityUUID: Entit
>
{t('editor:hierarchy.lbl-collapseAll')}
</Button>

<Button
fullWidth
size="small"
variant="transparent"
className="text-left text-xs"
onClick={() => PopoverState.showPopupover(<CreatePrefabPanel node={contextSelectedItem!} />)}
>
{t('editor:hierarchy.lbl-createPrefab')}
</Button>

{/* )} */}
</ContextMenu>
</>
)
Expand Down
Loading