What File Formats Does the CAD Viewer Support? A Complete Technical Guide
The CAD Viewer in the earthtojake/text-to-cad repository supports STEP, GLB, STL, 3MF, DXF, G-code, URDF, JavaScript modules, JSON, PNG, SVG, and Python files, validating each request against a hardcoded extension whitelist in the server backend.
The CAD Viewer is a core component of the earthtojake/text-to-cad open-source project, designed to render 3D models and engineering assets directly in the browser. Understanding what file formats the CAD Viewer supports is essential for developers integrating the tool into their workflows, as the system strictly validates file extensions before serving content from either local storage or Vercel Blob storage.
Backend Extension Validation Logic
The viewer determines file format eligibility through a whitelist-based validation system implemented in the server-side asset backends. When a file is requested, the server extracts the extension using path.posix.extname() and checks it against a series of explicit if statements that define supported types.
Vercel Blob Asset Backend
In viewer/src/server/vercelBlobAssetBackend.mjs, the primary whitelist controls which extensions can be served from the Vercel-backed asset store. The implementation normalizes the file reference, converts the extension to lowercase, and validates against the supported set:
const extension = path.posix.extname(normalizeFileRef(fileRef)).toLowerCase();
if (extension === ".step" || extension === ".stp") { … }
if (extension === ".glb") { … }
if (extension === ".stl") { … }
if (extension === ".3mf") { … }
if (extension === ".dxf") { … }
if (extension === ".gcode") { … }
if (extension === ".js" || extension === ".mjs") { … }
if (extension === ".json") { … }
if (extension === ".urdf" || extension === ".srdf" || extension === ".sdf") { … }
Local Asset Backend
The viewer/src/server/localAssetBackend.mjs file handles direct file serving from the repository filesystem. This module applies the same validation logic with additional support for image assets used in the viewer interface:
if (extension === ".png") { … }
if (extension === ".svg") { … }
Supported File Formats by Category
The CAD Viewer supports a comprehensive range of engineering and 3D model formats. Based on the validation logic in the server backends, the following extensions are whitelisted:
- STEP/STP (
.step,.stp): Standard CAD exchange format (ISO 10303) for precise geometric data exchange between CAD systems. - GLB (
.glb): Binary GLTF format optimized for web-based 3D geometry rendering. - STL (
.stl): Stereolithography format commonly used for 3D printing and rapid prototyping. - 3MF (
.3mf): 3D Manufacturing Format serving as a modern alternative to STL with color and material support. - DXF (
.dxf): AutoCAD Drawing Exchange Format for 2D and 3D vector data interoperability. - G-code (
.gcode): CNC machining instructions for manufacturing workflows. - Robot Description Formats (
.urdf,.srdf,.sdf): XML-based formats from the ROS (Robot Operating System) ecosystem for robot modeling. - JavaScript Modules (
.js,.mjs): Viewer-side scripts and custom implicit CAD definitions. - JSON (
.json): Configuration files, metadata, and generic data structures. - Python (
.py): Helper scripts that may generate.stepfiles on-the-fly or perform geometric calculations. - Images (
.png,.svg): Thumbnails, UI icons, and auxiliary graphics for the viewer interface.
Implicit CAD and Special File Handling
Beyond standard extensions, the viewer recognizes Implicit CAD files identified by specific path patterns rather than extensions alone. Files ending with .implicit.js or similar implicit CAD suffixes are automatically accepted even if they don't match the explicit extension whitelist. This allows the system to load procedural geometry definitions written in JavaScript that generate models dynamically.
Practical Usage Examples
You can request supported assets from the viewer using URL parameters that specify the file path and repository root. Below are examples for loading different format types:
// Load a STEP model for mechanical CAD review
const modelUrl = `${viewerBaseUrl}?file=models/example.step&dir=${repoRoot}`;
window.location = modelUrl;
// Load a GLB model for web-optimized 3D viewing
const glbUrl = `${viewerBaseUrl}?file=models/robot.glb&dir=${repoRoot}`;
window.location = glbUrl;
// Load a URDF robot description for robotics simulation
const urdfUrl = `${viewerBaseUrl}?file=models/robot.urdf&dir=${repoRoot}`;
window.location = urdfUrl;
// Request a generated PNG snapshot from an implicit CAD definition
const pngUrl = `${viewerBaseUrl}?file=tmp/snapshot.png&dir=${repoRoot}`;
window.location = pngUrl;
All requests follow the pattern of the viewer base URL provided by the cad-viewer skill, with ?file= specifying the target asset and ?dir= indicating the absolute repository root path.
Summary
- The CAD Viewer validates all requests against a hardcoded extension whitelist in
viewer/src/server/vercelBlobAssetBackend.mjsandviewer/src/server/localAssetBackend.mjs. - Supported formats include STEP/STP, GLB, STL, 3MF, DXF, G-code, URDF/SRDF/SDF, JavaScript modules, JSON, Python, PNG, and SVG.
- The server extracts extensions using
path.posix.extname()and converts them to lowercase before validation. - Implicit CAD files (
.implicit.js) are accepted based on path patterns rather than standard extensions. - Unsupported file types return a 404 Not Found response to prevent invalid assets from being served.
Frequently Asked Questions
Does the CAD Viewer support STEP files?
Yes, the viewer explicitly supports both .step and .stp extensions as defined in the vercelBlobAssetBackend.mjs whitelist. These ISO 10303 standard formats are validated through a dedicated conditional check that permits their retrieval from either Vercel Blob storage or local filesystems.
Can I view STL files for 3D printing workflows?
Absolutely. The STL format (.stl) is fully supported for stereolithography files commonly used in 3D printing. The backend checks for this extension specifically and serves the binary or ASCII geometry data directly to the viewer's rendering engine.
What are URDF and SRDF formats used for?
URDF (Unified Robot Description Format) and SRDF (Semantic Robot Description Format) are XML-based formats from the ROS ecosystem. The viewer supports .urdf, .srdf, and .sdf files to enable robotics engineers to visualize robot kinematics, links, joints, and semantic planning data within the same interface used for mechanical CAD.
How does the viewer handle unsupported file extensions?
Any file with an extension not present in the whitelist—such as .obj, .fbx, or .blend—receives a 404 Not Found response. The validation occurs early in the request lifecycle within the asset backend modules, ensuring only explicitly approved formats are served to the client-side renderer.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →