assimpjs icon indicating copy to clipboard operation
assimpjs copied to clipboard

Coverting gltf2 files

Open Abhiram3 opened this issue 3 years ago • 1 comments

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?

Abhiram3 avatar May 12 '22 11:05 Abhiram3

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.

kovacsv avatar May 14 '22 06:05 kovacsv