1+ import { join } from "path/posix" ;
2+ import { readJSON , writeJSON } from "fs-extra" ;
3+
4+ import { createDirectoryIfNotExist } from "../../tools/fs" ;
5+ import { extractNodeMaterialTextures } from "../../tools/material/extract" ;
6+
7+ import { Editor } from "../../editor/main" ;
8+
9+ import { compressFileToKtx } from "./ktx" ;
10+
111export function configureMaterials ( data : any ) {
212 if ( ! data . materials ) {
313 return ;
@@ -11,3 +21,42 @@ export function configureMaterials(data: any) {
1121 return true ;
1222 } ) ;
1323}
24+
25+ export type ComputeExportedMaterialOptions = {
26+ force : boolean ;
27+ scenePath : string ;
28+ exportedAssets : string [ ] ;
29+ } ;
30+
31+ export async function processExportedMaterial ( editor : Editor , absolutePath : string , options : ComputeExportedMaterialOptions ) {
32+ const materialData = await readJSON ( absolutePath ) ;
33+ if ( materialData . customType !== "BABYLON.NodeMaterial" ) {
34+ return ;
35+ }
36+
37+ const extractedTexturesOutputPath = join ( options . scenePath , "assets" , "editor-generated_extracted-textures" ) ;
38+
39+ await createDirectoryIfNotExist ( extractedTexturesOutputPath ) ;
40+
41+ const relativePaths = await extractNodeMaterialTextures ( editor , {
42+ materialData,
43+ assetsDirectory : join ( options . scenePath , "assets" , "editor-generated_extracted-textures" ) ,
44+ } ) ;
45+
46+ await writeJSON ( absolutePath , materialData , {
47+ encoding : "utf-8" ,
48+ } ) ;
49+
50+ await Promise . all (
51+ relativePaths . map ( async ( relativePath ) => {
52+ const finalPath = join ( options . scenePath , relativePath ) ;
53+
54+ options . exportedAssets . push ( finalPath ) ;
55+
56+ await compressFileToKtx ( editor , finalPath , {
57+ force : options . force ,
58+ exportedAssets : options . exportedAssets ,
59+ } ) ;
60+ } )
61+ ) ;
62+ }
0 commit comments