|
| 1 | +import { readFileSync } from 'fs'; |
| 2 | +import * as tmp from 'tmp'; |
| 3 | +import * as path from 'path'; |
| 4 | +import * as fbx2gltf from 'fbx2gltf'; |
| 5 | +import { assert, expect } from 'chai'; |
| 6 | +import { validateBytes } from 'gltf-validator'; |
| 7 | + |
| 8 | +interface Model { |
| 9 | + path: string; |
| 10 | + ignoredIssues?: Array<string>; |
| 11 | + args?: Array<string>; |
| 12 | +} |
| 13 | + |
| 14 | +const MODELS :Array<Model> = [ |
| 15 | + { path: 'fromFacebook/Jon/jon_morph' }, |
| 16 | + { |
| 17 | + path: 'fromFacebook/Jon/troll-final', |
| 18 | + ignoredIssues: [ 'ACCESSOR_NON_UNIT' ], |
| 19 | + }, |
| 20 | + { path: 'fromFacebook/Natalie/GlitchRobot' }, |
| 21 | + { path: 'fromFacebook/Ocean/blackvan/blackvan_with_windows' }, |
| 22 | + { path: 'fromFacebook/Ocean/zell_van_vertex_color' }, |
| 23 | + { path: 'fromFacebook/RAZ/RAZ_ape' }, |
| 24 | + { path: 'fromFbxSDK/Box' }, |
| 25 | + { |
| 26 | + path: 'fromFbxSDK/Humanoid', |
| 27 | + ignoredIssues: [ 'UNSUPPORTED_EXTENSION' ], |
| 28 | + }, |
| 29 | + { |
| 30 | + path: 'fromFbxSDK/Camera', |
| 31 | + ignoredIssues: [ 'UNSUPPORTED_EXTENSION' ], |
| 32 | + }, |
| 33 | + { path: 'fromFbxSDK/Normals' }, |
| 34 | + { path: 'fromGltfSamples/BoxVertexColors/BoxVertexColors' }, |
| 35 | + { path: 'fromGltfSamples/WaterBottle/NewWaterBottle' }, |
| 36 | +]; |
| 37 | + |
| 38 | +const CONVERSION_TIMEOUT_MS = 50000; |
| 39 | + |
| 40 | +describe('FBX2glTF', () => { |
| 41 | + const tmpobj = tmp.dirSync(); |
| 42 | + for(let model of MODELS) { |
| 43 | + const modelName = path.basename(model.path); |
| 44 | + describe('Model: ' + modelName, () => { |
| 45 | + const fbxPath = path.join('models', model.path + '.fbx'); |
| 46 | + let glbBytes; |
| 47 | + it('should convert fbx to glb', async () => { |
| 48 | + const glbPath = path.join(tmpobj.name, modelName + '.glb'); |
| 49 | + |
| 50 | + try { |
| 51 | + const destPath = await fbx2gltf(fbxPath, glbPath, model.args || []); |
| 52 | + assert.isNotNull(destPath); |
| 53 | + glbBytes = readFileSync(destPath); |
| 54 | + } catch (err) { |
| 55 | + throw new Error('Conversion failed: ' + err); |
| 56 | + } |
| 57 | + }).timeout(CONVERSION_TIMEOUT_MS); |
| 58 | + |
| 59 | + it('resulting glb should be valid', async() => { |
| 60 | + try { |
| 61 | + let options = <any>{}; |
| 62 | + if (model.ignoredIssues) { |
| 63 | + options.ignoredIssues = model.ignoredIssues; |
| 64 | + } |
| 65 | + const report = await validateBytes(glbBytes, options); |
| 66 | + expect(report.issues.numErrors).to.equal(0); |
| 67 | + expect(report.issues.numWarnings).to.equal(0); |
| 68 | + |
| 69 | + } catch (err) { |
| 70 | + throw new Error('Validation failed: ' + err); |
| 71 | + } |
| 72 | + }); |
| 73 | + }); |
| 74 | + } |
| 75 | + console.log('GLB files may be inspected in: ' + tmpobj.name); |
| 76 | +}); |
0 commit comments