How to Add 3D Models (.glb) to PowerPoint Presentations Using OfficeCLI

OfficeCLI embeds GLB files into PowerPoint by treating the PPTX as an Open XML package, creating an mc:AlternateContent shape with a 3D model reference and a static PNG fallback, accessible via the --type model3d command-line flag.

OfficeCLI is an open-source command-line tool for manipulating Microsoft Office documents programmatically. When you need to add 3D models to PowerPoint presentations, the CLI handles the complex Open XML manipulation required to embed GLB binary data and generate compatibility fallbacks, all exposed through a simple command interface.

Prerequisites and Supported Formats

OfficeCLI exclusively accepts .glb (GL Transmission Format Binary) files for 3D model insertion. According to src/officecli/Core/FileSource.cs (lines 38‑40), the source resolver validates the file extension before processing. The FileSource.Resolve method supports local file paths, HTTP URLs, and data URIs, returning both a readable stream and the confirmed extension.

The Open XML Implementation Strategy

PowerPoint stores 3D models as extended parts within the Open XML package. The implementation in src/officecli/Handlers/Pptx/PowerPointHandler.Add.Model3D.cs follows this workflow:

Input Validation and Source Resolution

The AddModel3D method first validates that the target location follows the /slide[N] pattern (lines 26‑28). It then calls FileSource.Resolve to obtain a stream and confirm the .glb extension before proceeding with embedding.

GLB Metadata Extraction and Binary Embedding

To center the model properly on the slide, ParseGlbBoundingBox reads the binary GLB header to extract dimensional data (lines 45‑47). The CLI then embeds the file as an extended package part using the relationship type model3d and content type model/gltf.binary (lines 48‑53), which is the native storage method for 3D assets in PowerPoint.

Fallback Image Generation

For compatibility with older PowerPoint clients that lack 3D rendering capabilities, the CLI generates a static PNG placeholder using GenerateZoomPlaceholderPng (lines 54‑60). This ensures the slide remains viewable even when 3D support is unavailable.

AlternateContent Shape Construction

The method constructs an mc:AlternateContent element containing two branches:

  • Choice branch: Contains a p:graphicFrame with a:graphicData pointing to the 3D namespace http://schemas.microsoft.com/office/drawing/2017/model3d. The BuildModel3DElement method creates the inner <am3d:model3d> element referencing the embedded GLB part and fallback image (lines 34‑41).
  • Fallback branch: Contains a standard p:pic element displaying the generated PNG placeholder for legacy clients.

Positioning and Registration

Default dimensions are set to 10 cm × 10 cm (3,600,000 EMU). You can override these via the width, height, x, y, left, or top properties (lines 61‑71). The shape receives a unique ID and name before insertion into the slide’s <p:spTree> element (lines 72‑74).

Command-Line Usage

The add command handler in src/officecli/Handlers/Pptx/PowerPointHandler.Add.cs maps the user flags "3dmodel", "model3d", or "glb" to the AddModel3D method (line 96). The schema definition in schemas/help/pptx/model3d.json declares these aliases along with the required src property.

officecli add /slide[2] \
  --type model3d \
  --prop path="models/rocket.glb" \
  --prop name="Rocket" \
  --prop width=5cm \
  --prop height=5cm \
  --prop x=2cm \
  --prop y=3cm

Programmatic Integration (C#)

You can also invoke the handler directly from C# code when extending the iOfficeAI/OfficeCLI library:

var handler = new PowerPointHandler(pptxPath);
var props = new Dictionary<string, string>
{
    ["path"] = "models/rocket.glb",
    ["name"] = "Rocket",
    ["width"] = "5cm",
    ["height"] = "5cm",
    ["x"] = "2cm",
    ["y"] = "3cm"
};

handler.AddModel3D("/slide[2]", null, props);

Summary

  • OfficeCLI validates that 3D models are only added to specific slide targets (/slide[N]) before processing.
  • The tool embeds GLB files using the standard model/gltf.binary content type and creates a PNG fallback for compatibility with older clients.
  • Shape positioning uses EMU units (default 10 cm × 10 cm) and supports custom coordinates via command-line properties.
  • The implementation uses mc:AlternateContent to serve 3D models to supporting clients while displaying static images to legacy viewers.
  • Available command aliases include glb, model, and 3dmodel, as defined in the JSON schema configuration.

Frequently Asked Questions

What file formats are supported for 3D models in OfficeCLI?

OfficeCLI exclusively supports the .glb (GL Transmission Format Binary) extension for 3D model insertion. The FileSource.Resolve method in src/officecli/Core/FileSource.cs explicitly validates this extension (lines 38‑40) and rejects other formats to ensure compatibility with PowerPoint's 3D rendering engine.

How does OfficeCLI handle PowerPoint clients that don't support 3D models?

The CLI generates a static PNG fallback image using GenerateZoomPlaceholderPng and embeds it within an mc:AlternateContent structure. Clients that recognize 3D models display the GLB content from the Choice branch, while older clients render the Fallback branch containing the standard p:pic element with the placeholder PNG.

Can I position the 3D model anywhere on the slide?

Yes. The default position centers a 10 cm × 10 cm model on the slide, but you can specify exact coordinates using the x, y, left, top, width, and height properties. These values are processed in lines 61‑71 of PowerPointHandler.Add.Model3D.cs and converted to EMU (English Metric Units) for the Open XML output.

Where is the 3D model data stored in the PPTX file?

The GLB binary is stored as an extended part with the relationship type model3d and content type model/gltf.binary (lines 48‑53 of PowerPointHandler.Add.Model3D.cs). This follows the Open XML standard for 3D model storage, allowing PowerPoint to access the raw binary data while maintaining package integrity.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →