import type { ToolcraftModelSourceBundleTransfer } from "../model-import-types"; import { GLTF_APPEARANCE_JPEG, GLTF_APPEARANCE_PNG, } from "./gltf-appearance-fixtures"; const encoder = new TextEncoder(); export const OBJ_APPEARANCE_SOURCE = encoder.encode(` mtllib materials/main.mtl o Painted v 0 0 0 v 1 0 0 v 0 1 0 v 2 0 0 v 3 0 0 v 2 1 0 vt 0 0 vt 1 0 vt 0 1 vt 0 0 vt 1 0 vt 0 1 usemtl Red f 1/1 2/2 3/3 usemtl Blue f 4/4 5/5 6/6 `); export const OBJ_APPEARANCE_MTL = encoder.encode(` newmtl Red Kd 0.2 0.3 0.4 Ke 0.1 0.2 0.3 d 0.75 Ns 198 map_Kd textures/diffuse.png map_Ke textures/emissive.png map_Bump -bm 0.4 textures/normal.jpg newmtl Blue Kd 0.9 0.8 0.7 Tr 0.25 Ns 0 map_Kd textures/missing.png `); function copyBuffer(bytes: Uint8Array): ArrayBuffer { return bytes.slice().buffer; } export function createObjAppearanceTransfer( options: Readonly<{ materialSource?: Uint8Array; objSource?: Uint8Array; }> = {}, ): ToolcraftModelSourceBundleTransfer { const entries = [ ["models/scene.obj", options.objSource ?? OBJ_APPEARANCE_SOURCE, "model/obj"], ["models/materials/main.mtl", options.materialSource ?? OBJ_APPEARANCE_MTL, "text/plain"], ["models/materials/textures/diffuse.png", GLTF_APPEARANCE_PNG, "image/png"], ["models/materials/textures/emissive.png", GLTF_APPEARANCE_PNG, "image/png"], ["models/materials/textures/normal.jpg", GLTF_APPEARANCE_JPEG, "image/jpeg"], ] as const; return Object.freeze({ aggregateDigest: "fixture-obj-appearance", rootPath: "models/scene.obj", sourceFiles: Object.freeze(entries.map(([path, bytes, mimeType]) => Object.freeze({ bytes: copyBuffer(bytes), contentDigest: `fixture:${path}`, mimeType, path, }) )), }); }