Skip to content

build export

laurel Lin edited this page Aug 22, 2026 · 2 revisions

src/build/export.ts — Track model export

The export layer: exports the groups under the current workspace's track parent group (named after the workspace) in four modes (new_java / classic_java / bedrock / obj) to a user-chosen folder.

Export configuration is collected in a single large dialog (config on the left, per-texture resource paths on the right): export mode / namespace / track id from the user; the export root is the directory holding the resource pack's assets/{namespace} (everything is written there under models/ textures/ blockstates/); the model resource path is what blockstates reference ({namespace}:path/ file, default block/track/{trackId}), and each texture has its own resource path too. All path fields are editable and pre-filled with defaults; in-file references use these resource paths directly.

File writing uses Blockbench's scoped require('fs', { scope }) (desktop; requests "folder access" the first time). Node smoke tests substitute a global.require stub. Eligibility checks and per-format serialization live in the pure logic layer src/logic/export.ts.

Constants

export const TRACK_PARENT_NAME = '机械动力轨道';  // the track parent group's name

Types

export interface ExportOptions {
	mode: ExportMode;
	namespace: string;
	trackId: string;
	root: string;        // export root (directory holding the resource pack's assets/{namespace})
	modelPath: string;   // model resource path ({namespace}:path/file used by blockstate references)
	texturePaths: Record<string, string>;  // texture key → texture resource path
}

// smoke-test driver hook for the export dialog (not used by real Blockbench)
export interface ExportDriver {
	setMode(mode: ExportMode): void;
	setNamespace(v: string): void;
	setTrackId(v: string): void;
	setRoot(v: string): void;
	setModelPath(v: string): void;
	setTexturePath(key: string, v: string): void;
	confirm(): boolean;
	getState(): ExportFormState;
}

Styles

// inject / clean up the export dialog styles (when a document exists; safely skipped in Node smoke tests)
export function injectExportStyles(): void;
export function disposeExportStyles(): void;

Export dialog

// export config dialog (two columns, editable paths with "Browse…" / "Reset" buttons); null when cancelled
export function promptExportOptions(
	defaultTrackId: string,
	textures: ExportTexture[]
): Promise<ExportOptions | null>;

Export flow

// finds the track parent group in the current workspace (named after the workspace)
export function findTrackGroup(): Group | null;

// bakes one group's cubes/meshes into a single merged OBJ + MTL (one `o` object, Forge-loader-readable),
// textures via usemtl m_<key> + MTL map_Kd {ns}:block/track/{id}/{res}; coordinates in block units (px/16)
export function exportGroupAsObj(opts: {
	group: Group;
	mtlName: string;
	namespace: string;
	trackId: string;
	texInfos: ExportTexture[];
	keyOf: Map<Texture, string>;
	texturePathOf?: Record<string, string>;
}): { obj: string; mtl: string };

// exports the groups under the track parent group per `mode` into the configured directory:
// Java → element model JSON + textures (unexportable groups fall back to OBJ); obj → every group baked
// into a merged OBJ mesh (.obj + .mtl + forge:obj reference JSON); bedrock → minecraft:geometry +
// blocks.json + textures (unexportable groups fall back to OBJ). Java/OBJ write blockstates to root,
// Bedrock writes blocks.json. Returns statistics (files, skipped groups, warnings).
export function writeTrackExport(opts: ExportOptions & {
	subgroups: Group[];
	texInfos: ExportTexture[];
	keyOf: Map<Texture, string>;
}): { files: number; skipped: string[]; warnings: string[] };

// the export entry flow: find the track group → collect textures → dialog → write files → summary
export async function runTrackExport(): Promise<void>;

← Back to English API Reference

Clone this wiki locally