kovacsv / assimpjs

The emscripten interface for the assimp library that allows you to import 40+ 3D file formats in the browser.
MIT License
111 stars 18 forks source link

Coverting gltf2 files #2

Open Abhiram3 opened 2 years ago

Abhiram3 commented 2 years ago

Hi, I am trying to convert a gltf2 file into glb2 by adding all the files to the filelist. But the resultant "glb" file still has uri's to texture files.

I used http://3dviewer.net/index.html to visualize the models.

GLTF2 view of model

gltf_view

converted the gltf2 file with the following code. `assimpjs.then ((ajs) => { let fileList = new ajs.FileList (); fileList.AddFile ( 'scene.gltf', fs.readFileSync ("/home/3d-viewer/Microservice-Template/testFiles/breakfast_gltf/scene.gltf") );

fileList.AddFile (
    'scene.bin',
    fs.readFileSync ("/home/3d-viewer/Microservice-Template/testFiles/breakfast_gltf/scene.bin")
);

fileList.AddFile (
    'lambert1_baseColor.png',
    fs.readFileSync ("/home/3d-viewer/Microservice-Template/testFiles/breakfast_gltf/textures/lambert1_baseColor.png")
);

fileList.AddFile (
    'lambert1_metallicRoughness.png',
    fs.readFileSync ("/home/3d-viewer/Microservice-Template/testFiles/breakfast_gltf/textures/lambert1_metallicRoughness.png")
);

fileList.AddFile (
    'lambert1_normal.png',
    fs.readFileSync ("/home/3d-viewer/Microservice-Template/testFiles/breakfast_gltf/textures/lambert1_normal.png")
);

// convert file list to assimp json
let result = ajs.ConvertFileList (fileList, 'glb2');

// check if the conversion succeeded
if (!result.IsSuccess () || result.FileCount () == 0) {
    const errorCode = result.GetErrorCode ()
    console.log("errorCode", errorCode)
    return
}

// get the result file, and convert to string
let resultFile = result.GetFile (0);
    fs.writeFile(`breakfastTestGltf.glb`, resultFile.GetContent(), (e) => {
        if (e) {
            const errorCode = result.GetErrorCode ()
            console.log("error", e, errorCode);
        } else {
            console.log("success");
        }
    })

});`

The generated glb file gave the following view. It missed the texture files. 3dViewer mentioned regarding the missing files and glb file still had some urls of texture files.

breakfast_gltf

Is this not the right way to do it?

kovacsv commented 2 years ago

I think that's an error in assimp's glb exporter so you should probably report the issue there. Side note: https://3dviewer.net can export to glb, and probably it does a better job.