This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Ir 2543 create prefab #10384
Merged
Merged
Ir 2543 create prefab #10384
Changes from 22 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 cb079fb
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y 2b87c8f
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y 5b4a6f4
change add component function
JT00y 51558b7
delete changes for modelcomponent
JT00y 0a5c46d
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y 55ad610
add pass tag to static resource and clean up state
JT00y 23ff84b
clean up
JT00y 59256c7
change state to hookstate and add await to export
JT00y cce1d1b
fix import
JT00y f92cca7
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 059023b
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y 7322748
fix path for folder
JT00y 4e7729c
Merge branch 'ir-2543-create-prefab' of https://github.com/EtherealEn…
dinomut1 543f911
fix exporting non-model entities
dinomut1 7533f55
remove add model component
JT00y 2121655
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
JT00y def85bf
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 05bedac
fix upload
dinomut1 6207bc1
Merge branch 'dev' of https://github.com/EtherealEngine/etherealengin…
dinomut1 dd7f4cb
create dud prefab entity for export so child is not lost
dinomut1 0d645db
prefab parenting preserved
dinomut1 78f7423
update selection on create prefab
dinomut1 e35209b
Merge branch 'dev' into ir-2543-create-prefab
dinomut1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
packages/editor/src/components/dialogs/CreatePrefabPanelDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/* | ||
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 config from '@etherealengine/common/src/config' | ||
import { staticResourcePath } from '@etherealengine/common/src/schema.type.module' | ||
import { pathJoin } from '@etherealengine/common/src/utils/miscUtils' | ||
import { Engine, Entity, createEntity, getComponent, removeEntity, setComponent } from '@etherealengine/ecs' | ||
import { ModelComponent } from '@etherealengine/engine/src/scene/components/ModelComponent' | ||
import { proxifyParentChildRelationships } from '@etherealengine/engine/src/scene/functions/loadGLTFModel' | ||
import { getState, useHookstate } from '@etherealengine/hyperflux' | ||
import { NameComponent } from '@etherealengine/spatial/src/common/NameComponent' | ||
import { addObjectToGroup } from '@etherealengine/spatial/src/renderer/components/GroupComponent' | ||
import { EntityTreeComponent } from '@etherealengine/spatial/src/transform/components/EntityTree' | ||
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 from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { Scene } from 'three' | ||
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 = useHookstate<string>('assets/custom-prefabs') | ||
const prefabName = useHookstate<string>('prefab') | ||
const prefabTag = useHookstate<string[]>([]) | ||
const { t } = useTranslation() | ||
|
||
const onExportPrefab = async () => { | ||
const editorState = getState(EditorState) | ||
const fileName = defaultPrefabFolder.value + '/' + prefabName.value + '.gltf' | ||
const srcProject = editorState.projectName! | ||
const fileURL = pathJoin(config.client.fileServer, 'projects', srcProject, fileName) | ||
try { | ||
const parentEntity = getComponent(entity, EntityTreeComponent).parentEntity | ||
const prefabEntity = createEntity() | ||
const obj = new Scene() | ||
addObjectToGroup(prefabEntity, obj) | ||
proxifyParentChildRelationships(obj) | ||
setComponent(prefabEntity, EntityTreeComponent, { parentEntity }) | ||
setComponent(prefabEntity, NameComponent, prefabName.value) | ||
setComponent(entity, EntityTreeComponent, { parentEntity: prefabEntity }) | ||
|
||
await exportRelativeGLTF(prefabEntity, srcProject, fileName) | ||
//await exportRelativeGLTF(entity, srcProject, fileName) | ||
//pass tags to static resource | ||
const resources = await Engine.instance.api.service(staticResourcePath).find({ | ||
query: { key: 'projects/' + srcProject + '/' + fileName } | ||
}) | ||
if (resources.data.length === 0) { | ||
throw new Error('User not found') | ||
} | ||
const resource = resources.data[0] | ||
const tags = [...prefabTag.value] | ||
await Engine.instance.api.service(staticResourcePath).patch(resource.id, { tags: tags }) | ||
PopoverState.hidePopupover() | ||
defaultPrefabFolder.set('assets/custom-prefabs') | ||
prefabName.set('prefab') | ||
prefabTag.set([]) | ||
removeEntity(prefabEntity) | ||
EditorControlFunctions.createObjectFromSceneElement( | ||
[{ name: ModelComponent.jsonID, props: { src: fileURL } }], | ||
parentEntity | ||
) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
return ( | ||
<Modal | ||
title="Create Prefab" | ||
onSubmit={onExportPrefab} | ||
className="w-[50vw] max-w-2xl" | ||
onClose={PopoverState.hidePopupover} | ||
> | ||
<Input | ||
value={defaultPrefabFolder.value} | ||
onChange={(event) => defaultPrefabFolder.set(event.target.value)} | ||
label="Default Save Folder" | ||
/> | ||
<Input value={prefabName.value} onChange={(event) => prefabName.set(event.target.value)} label="Name" /> | ||
|
||
<Button | ||
size="small" | ||
variant="outline" | ||
className="text-left text-xs" | ||
onClick={() => { | ||
prefabTag.set([...(prefabTag.value ?? []), '']) | ||
}} | ||
> | ||
{t('editor:layout.filebrowser.fileProperties.addTag')} | ||
</Button> | ||
<div> | ||
{(prefabTag.value ?? []).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) => { | ||
const tags = [...prefabTag.value] | ||
tags[index] = event.target.value | ||
prefabTag.set(tags) | ||
}} | ||
value={prefabTag.value[index]} | ||
/> | ||
<Button | ||
onClick={() => { | ||
prefabTag.set(prefabTag.value.filter((_, i) => i !== index)) | ||
}} | ||
size="small" | ||
variant="outline" | ||
className="text-left text-xs" | ||
> | ||
{' '} | ||
x{' '} | ||
</Button> | ||
</div> | ||
))} | ||
</div> | ||
</Modal> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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