From 2045961e8b45cb7615e70c07f3d051bbcc653ee4 Mon Sep 17 00:00:00 2001 From: David Gordon <94419856+dinomut1@users.noreply.github.com> Date: Thu, 20 Jun 2024 12:50:15 -0700 Subject: [PATCH] clear ecs data from 'userData' after it is loaded to prevent duplicate ecs data on export (#10402) --- .../engine/src/scene/functions/loadGLTFModel.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/engine/src/scene/functions/loadGLTFModel.ts b/packages/engine/src/scene/functions/loadGLTFModel.ts index 6ea4b9af0f..bc6f668c56 100644 --- a/packages/engine/src/scene/functions/loadGLTFModel.ts +++ b/packages/engine/src/scene/functions/loadGLTFModel.ts @@ -60,14 +60,16 @@ import { createMaterialInstance } from '../materials/functions/materialSourcingF import { ComponentJsonType, EntityJsonType } from '../types/SceneTypes' import { getModelSceneID } from './loaders/ModelFunctions' -export const parseECSData = (data: [string, any][]): ComponentJsonType[] => { +export const parseECSData = (userData: Record): ComponentJsonType[] => { const components: { [key: string]: any } = {} const prefabs: { [key: string]: any } = {} - + const keysToRemove: string[] = [] + const data = [...Object.entries(userData)] for (const [key, value] of data) { const parts = key.split('.') if (parts.length > 1) { if (parts[0] === 'xrengine') { + keysToRemove.push(key) const componentExists = ComponentMap.has(parts[1]) const _toLoad = componentExists ? components : prefabs if (typeof _toLoad[parts[1]] === 'undefined') { @@ -83,6 +85,11 @@ export const parseECSData = (data: [string, any][]): ComponentJsonType[] => { } } + // remove keys that have been processed as they will be exported in different format + for (const key of keysToRemove) { + delete userData[key] + } + const result: ComponentJsonType[] = [] for (const [key, value] of Object.entries(components)) { const component = ComponentMap.get(key) @@ -106,7 +113,7 @@ export const parseECSData = (data: [string, any][]): ComponentJsonType[] => { } export const createObjectEntityFromGLTF = (obj3d: Object3D): ComponentJsonType[] => { - return parseECSData(Object.entries(obj3d.userData)) + return parseECSData(obj3d.userData) } export const parseObjectComponentsFromGLTF = (