import type { ToolcraftModelSourceBundleTransfer } from "../model-import-types"; import { GLTF_APPEARANCE_PNG } from "../test-fixtures/gltf-appearance-fixtures"; import { encodeBinaryFbxFixture, fbxBinaryFixtureProperty as property, type FbxBinaryFixtureNode, } from "./fbx-binary-test-fixture-builder"; const encoder = new TextEncoder(); export const ASCII_FBX_FIXTURE = encoder.encode(`; FBX 7.4.0 project file FBXHeaderExtension: { FBXHeaderVersion: 1003 FBXVersion: 7400 } GlobalSettings: { Version: 1000 Properties70: { P: "UpAxis", "int", "Integer", "",1 P: "UnitScaleFactor", "double", "Number", "",1 } } Objects: { Geometry: 1, "Geometry::Triangle", "Mesh" { Vertices: *9 { a: 10,20,30,12,20,30,10,23,30 } PolygonVertexIndex: *3 { a: 0,1,-3 } } Model: 2, "Model::Triangle", "Mesh" { Version: 232 Properties70: { P: "Lcl Translation", "Lcl Translation", "", "A",0,0,0 P: "Lcl Rotation", "Lcl Rotation", "", "A",0,0,0 P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1 } Shading: T Culling: "CullingOff" } } Connections: { C: "OO",1,2 C: "OO",2,0 } `); export function createBinaryFbxFixture(): Uint8Array { const geometry: FbxBinaryFixtureNode = { children: [ { name: "Vertices", properties: [ property.float64Array([10, 20, 30, 12, 20, 30, 10, 23, 30]), ], }, { name: "PolygonVertexIndex", properties: [property.int32Array([0, 1, -3])], }, ], name: "Geometry", properties: [ property.int64(1), property.string("Geometry::Triangle"), property.string("Mesh"), ], }; const model: FbxBinaryFixtureNode = { name: "Model", properties: [ property.int64(2), property.string("Model::Triangle"), property.string("Mesh"), ], }; const connection = (from: number, to: number): FbxBinaryFixtureNode => ({ name: "C", properties: [ property.string("OO"), property.int64(from), property.int64(to), ], }); return encodeBinaryFbxFixture([ { children: [geometry, model], name: "Objects" }, { children: [connection(1, 2), connection(2, 0)], name: "Connections", }, ]); } export function transferForFbx( bytes: Uint8Array, includeDiffuseTexture = false, ): ToolcraftModelSourceBundleTransfer { const ownedBytes = new Uint8Array(bytes.byteLength); ownedBytes.set(bytes); return Object.freeze({ aggregateDigest: "fixture-fbx", rootPath: "models/scene.fbx", sourceFiles: Object.freeze([ Object.freeze({ bytes: ownedBytes.buffer, contentDigest: "fixture-fbx-root", mimeType: "application/octet-stream", path: "models/scene.fbx", }), ...(includeDiffuseTexture ? [Object.freeze({ bytes: GLTF_APPEARANCE_PNG.slice().buffer, contentDigest: "fixture-fbx-diffuse", mimeType: "image/png", path: "models/textures/diffuse.png", })] : []), ]), }); }