-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: include resources loaded by GLTF into the custom asset package
- Loading branch information
Showing
3 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
packages/@dcl/inspector/src/lib/babylon/decentraland/get-resources.ts
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,41 @@ | ||
import { NullEngine, Scene } from '@babylonjs/core' | ||
import { getDataLayerInterface } from '../../../redux/data-layer' | ||
import { loadAssetContainer, resourcesByPath } from './sdkComponents/gltf-container' | ||
import future from 'fp-future' | ||
|
||
// This function takes a path to a gltf or glb file, loads it in Babylon, checks for all the resources loaded by the file, and returns them | ||
export async function getResourcesFromModel(path: string) { | ||
const base = path.split('/').slice(0, -1).join('/') | ||
const src = path + '?base=' + encodeURIComponent(base) | ||
const engine = new NullEngine() | ||
const resources: Set<string> = new Set() | ||
const scene = new Scene(engine) | ||
const extension = path.toLowerCase().endsWith('.gltf') ? '.gltf' : '.glb' | ||
const dataLayer = getDataLayerInterface() | ||
if (!dataLayer) { | ||
return resources | ||
} | ||
const { content } = await dataLayer.getFile({ path }) | ||
const file = new File([content], src) | ||
|
||
const load = future<void>() | ||
|
||
loadAssetContainer( | ||
file, | ||
scene, | ||
() => load.resolve(), | ||
() => {}, | ||
(_scene, _error) => load.reject(new Error(_error)), | ||
extension, | ||
path | ||
) | ||
|
||
await load | ||
|
||
return resourcesByPath.get(path) | ||
} | ||
|
||
export async function getResourcesFromModels(paths: string[]): Promise<string[]> { | ||
const results = await Promise.all(paths.map(getResourcesFromModel)) | ||
return results.flatMap((resourceSet) => (resourceSet ? Array.from(resourceSet) : [])) | ||
} |
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