From 6c6a97e07290b96133c84eb8644c24889baecd5f Mon Sep 17 00:00:00 2001 From: Jiatong Yao Date: Thu, 28 Dec 2023 14:45:30 -0600 Subject: [PATCH 1/9] add save path and drag material on object --- .../src/utils/CommonKnownContentTypes.ts | 4 +- .../common/src/utils/guessContentType.tsx | 4 +- packages/common/src/utils/miscUtils.ts | 18 +++-- .../tests/utils/guessContentType.test.ts | 1 + .../MaterialLibraryPanelContainer.tsx | 8 ++- packages/editor/src/functions/addMediaNode.ts | 69 +++++++++++++++++-- .../engine/src/assets/classes/AssetLoader.ts | 6 ++ packages/engine/src/assets/enum/AssetClass.ts | 1 + packages/engine/src/assets/enum/AssetType.ts | 3 +- .../src/assets/exporters/gltf/GLTFExporter.js | 3 +- .../gltf/extensions/SourceHandlerExtension.ts | 1 + .../extensions/RegisterMaterialsExtension.ts | 35 +++++++++- .../src/renderer/materials/MaterialLibrary.ts | 8 ++- 13 files changed, 139 insertions(+), 22 deletions(-) diff --git a/packages/common/src/utils/CommonKnownContentTypes.ts b/packages/common/src/utils/CommonKnownContentTypes.ts index f8318c1053..b906b98488 100644 --- a/packages/common/src/utils/CommonKnownContentTypes.ts +++ b/packages/common/src/utils/CommonKnownContentTypes.ts @@ -7,7 +7,7 @@ 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, +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, @@ -29,6 +29,7 @@ Ethereal Engine. All Rights Reserved. * @type {Object} */ export const CommonKnownContentTypes = { + material: 'model/material', xre: 'prefab/xre', gltf: 'model/gltf', glb: 'model/gltf-binary', @@ -52,6 +53,7 @@ export const CommonKnownContentTypes = { export const MimeTypeToExtension = { 'prefab/xre': 'xre', + 'model/material': 'material', 'model/gltf': 'gltf', 'model/gltf-binary': 'glb', 'model/vrm': 'vrm', diff --git a/packages/common/src/utils/guessContentType.tsx b/packages/common/src/utils/guessContentType.tsx index 4faf34a264..b93f340f63 100644 --- a/packages/common/src/utils/guessContentType.tsx +++ b/packages/common/src/utils/guessContentType.tsx @@ -34,8 +34,8 @@ import { CommonKnownContentTypes } from './CommonKnownContentTypes' export function guessContentType(url: string): string { const contentPath = new URL(url).pathname //check for xre gltf extension - if (/\.xre\.gltf$/.test(contentPath)) { - return CommonKnownContentTypes.xre + if (/\.material\.gltf$/.test(contentPath)) { + return CommonKnownContentTypes.material } const extension = contentPath.split('.').pop()! return CommonKnownContentTypes[extension] diff --git a/packages/common/src/utils/miscUtils.ts b/packages/common/src/utils/miscUtils.ts index c01fd8ccc8..e73d4ca323 100644 --- a/packages/common/src/utils/miscUtils.ts +++ b/packages/common/src/utils/miscUtils.ts @@ -84,17 +84,21 @@ export function pathJoin(...parts: string[]): string { } // If it's the last part, we only want to remove leading slashes else if (index === parts.length - 1) { - while (part.startsWith(separator)) { - part = part.substring(1) + if (part) { + while (part.startsWith(separator)) { + part = part.substring(1) + } } } // For all other parts, remove leading and trailing slashes else { - while (part.startsWith(separator)) { - part = part.substring(1) - } - while (part.endsWith(separator)) { - part = part.substring(0, part.length - 1) + if (part) { + while (part.startsWith(separator)) { + part = part.substring(1) + } + while (part.endsWith(separator)) { + part = part.substring(0, part.length - 1) + } } } diff --git a/packages/common/tests/utils/guessContentType.test.ts b/packages/common/tests/utils/guessContentType.test.ts index dcbd415934..2e8d3a5d15 100644 --- a/packages/common/tests/utils/guessContentType.test.ts +++ b/packages/common/tests/utils/guessContentType.test.ts @@ -29,6 +29,7 @@ import { guessContentType } from '../../src/utils/guessContentType' describe('guessContentType', () => { it('guessContentType', () => { + assert(guessContentType('https://mydomain.com/myfile.mat'), 'model/material') assert(guessContentType('https://mydomain.com/myfile.gltf'), 'model/gltf') assert(guessContentType('https://mydomain.com/myfile.glb'), 'model/gltf-binary') assert(guessContentType('https://mydomain.com/myfile.png'), 'image/png') diff --git a/packages/editor/src/components/materials/MaterialLibraryPanelContainer.tsx b/packages/editor/src/components/materials/MaterialLibraryPanelContainer.tsx index a5fd834380..cb8ac47f7b 100644 --- a/packages/editor/src/components/materials/MaterialLibraryPanelContainer.tsx +++ b/packages/editor/src/components/materials/MaterialLibraryPanelContainer.tsx @@ -46,6 +46,8 @@ import { uploadProjectFiles } from '../../functions/assetFunctions' import { EditorState } from '../../services/EditorServices' import styles from '../hierarchy/styles.module.scss' import { Button } from '../inputs/Button' +import InputGroup from '../inputs/InputGroup' +import StringInput from '../inputs/StringInput' import MaterialLibraryEntry, { MaterialLibraryEntryType } from './MaterialLibraryEntry' import { MaterialSelectionState } from './MaterialLibraryState' @@ -56,6 +58,7 @@ export default function MaterialLibraryPanel() { const MemoMatLibEntry = memo(MaterialLibraryEntry, areEqual) const nodeChanges = useState(0) const publicPath = getState(EngineState).publicPath + const srcPath = useState('/mat/material-test.material.gltf') const createSrcs = useCallback(() => Object.values(materialLibrary.sources.get(NO_PROXY)), [materialLibrary.sources]) const srcs = useState(createSrcs()) @@ -161,11 +164,14 @@ export default function MaterialLibraryPanel() { > New + + srcPath.set(e.target.value)} /> +