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

Commit

Permalink
clear ecs data from 'userData' after it is loaded to prevent duplicat…
Browse files Browse the repository at this point in the history
…e ecs data on export (#10402)
  • Loading branch information
dinomut1 authored Jun 20, 2024
1 parent 4b640db commit 2045961
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/engine/src/scene/functions/loadGLTFModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>): 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') {
Expand All @@ -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)
Expand All @@ -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 = (
Expand Down

0 comments on commit 2045961

Please sign in to comment.