Skip to content

Commit 551d432

Browse files
authored
fix several issues with import files (#1059)
* fix race condition when validating models on import * add 'VALUE_NOT_IN_RANGE' to ignored model errors * fix import button on asset explorer styles * move feeded fs example model to Models/example/model.glb * reset the FileInput value so the same file can be selected again
1 parent a60db93 commit 551d432

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

packages/@dcl/inspector/src/components/Assets/Assets.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@
7070
margin-left: 8px;
7171
display: flex;
7272
align-items: center;
73+
padding: 8px 9px;
74+
font-weight: 600;
75+
border-radius: 6px;
7376
}
7477

7578
.Assets .Assets-buttons > button:first-child svg {
7679
margin-right: 5px;
80+
stroke-width: 3;
7781
}
7882

7983
.Assets .Assets-content {

packages/@dcl/inspector/src/components/FileInput/FileInput.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export const FileInput = React.forwardRef<InputRef, React.PropsWithChildren<Prop
4444
(e: React.ChangeEvent<HTMLInputElement>): void => {
4545
const files = Array.from(e.target.files ?? [])
4646
onDrop && onDrop(files)
47+
// Reset the input value so the same file can be selected again
48+
e.target.value = ''
4749
},
4850
[onDrop]
4951
)

packages/@dcl/inspector/src/components/ImportAsset/Error/Error.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { ValidationError } from '../types'
1111

1212
export function Error({ assets, onSubmit }: PropTypes) {
1313
const getErrorMessage = useCallback((error: ValidationError): string => {
14-
if (!error) return 'Unknown error'
15-
16-
switch (error.type) {
14+
switch (error?.type) {
1715
case 'type':
1816
return 'File type not supported'
1917
case 'model':
@@ -30,9 +28,7 @@ export function Error({ assets, onSubmit }: PropTypes) {
3028
<div className="alert-icon"></div>
3129
<h2>Asset failed to import</h2>
3230
<div className="errors">
33-
{assets.map(($, i) => (
34-
<ErrorMessage key={i} asset={$} message={getErrorMessage($.error)} />
35-
))}
31+
{assets.map(($, i) => $.error && <ErrorMessage key={i} asset={$} message={getErrorMessage($.error)} />)}
3632
</div>
3733
<Button type="danger" size="big" onClick={onSubmit}>
3834
OK

packages/@dcl/inspector/src/components/ImportAsset/utils.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ const MODEL_EXTENSIONS = ACCEPTED_FILE_TYPES['model/gltf-binary']
115115
const IGNORED_ERROR_CODES = [
116116
'ACCESSOR_WEIGHTS_NON_NORMALIZED',
117117
'MESH_PRIMITIVE_TOO_FEW_TEXCOORDS',
118-
'ACCESSOR_VECTOR3_NON_UNIT'
118+
'ACCESSOR_VECTOR3_NON_UNIT',
119+
'VALUE_NOT_IN_RANGE'
119120
]
120121

121122
async function getGltf(file: File, getExternalResource: (uri: string) => Promise<Uint8Array>): Promise<Gltf> {
@@ -209,32 +210,34 @@ async function getModel(asset: BaseAsset, fileMap: Map<string, BaseAsset>): Prom
209210
for (const resource of gltf.info.resources || []) {
210211
if (resource.storage === 'external') {
211212
const normalizedName = normalizeFileName(resource.uri)
212-
const uri = fileMap.get(normalizedName)!
213-
if (resource.pointer.includes('buffer')) buffers.push(uri)
214-
if (resource.pointer.includes('image')) images.push(uri)
215-
fileMap.delete(normalizedName)
213+
const uri = fileMap.get(normalizedName)
214+
if (uri) {
215+
if (resource.pointer.includes('buffer')) buffers.push(uri)
216+
if (resource.pointer.includes('image')) images.push(uri)
217+
fileMap.delete(normalizedName)
218+
}
216219
}
217220
}
218221

219222
fileMap.delete(formatFileName(asset))
220223

221-
return { ...asset, gltf, buffers, images }
224+
const model = { ...asset, gltf, buffers, images }
225+
const error = await validateModelWithDependencies(model)
226+
227+
return { ...model, error }
222228
}
223229

224230
async function processModels(files: BaseAsset[]): Promise<Asset[]> {
225231
const fileMap = new Map(files.map((file) => [formatFileName(file), file]))
226232

227-
const modelPromises = files
228-
.filter((asset) => MODEL_EXTENSIONS.includes(`.${asset.extension}`))
229-
.map(async (asset): Promise<ModelAsset> => {
230-
const model = await getModel(asset, fileMap)
231-
const error = await validateModelWithDependencies(model)
232-
return { ...model, error }
233-
})
233+
const gltfAssets: ModelAsset[] = []
234+
const modelAssets = files.filter((asset) => MODEL_EXTENSIONS.includes(`.${asset.extension}`))
235+
// we need to run models sequentially to avoid race conditions on fileMap
236+
for (const asset of modelAssets) {
237+
gltfAssets.push(await getModel(asset, fileMap))
238+
}
234239

235-
const gltfAssets = await Promise.all(modelPromises)
236240
const remainingAssets = Array.from(fileMap.values())
237-
238241
return [...gltfAssets, ...remainingAssets]
239242
}
240243

packages/@dcl/inspector/src/lib/data-layer/client/feeded-local-fs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function generateFeededComposite({ engine, components }: TempEngine, scen
105105
z: 8
106106
}
107107
})
108-
components.GltfContainer.create(gltfEntity, { src: 'assets/scene/models/example.glb' })
108+
components.GltfContainer.create(gltfEntity, { src: 'assets/scene/Models/example/model.glb' })
109109
cubeIdComponent.create(gltfEntity)
110110
components.Name.create(gltfEntity, { value: 'Gltf Test' })
111111

@@ -130,7 +130,7 @@ export function generateFeededComposite({ engine, components }: TempEngine, scen
130130
export const getMinimalComposite = () => generateMinimalComposite(createTempEngineContext())
131131

132132
const builderMappings: Record<string, string> = {
133-
'assets/scene/models/example.glb': 'bafkreibzw3d2aziiw2yhq7eoihytxthsulbihbr2ds2zegmsreaycy4h7e'
133+
'assets/scene/Models/example/model.glb': 'bafkreibzw3d2aziiw2yhq7eoihytxthsulbihbr2ds2zegmsreaycy4h7e'
134134
}
135135

136136
function getFeededEngineAndComposite(scene: Scene) {

0 commit comments

Comments
 (0)