# 3D Annotation

## Content

A 3D annotation embeds interactive 3D artwork in a PDF document. PDF viewers can display the model directly on the page and allow users to interact with predefined views and rendering settings.
Use the [Model3DAnnotation](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.Model3DAnnotation.html) class to add a 3D annotation to a page. The annotation uses a [Model3DStream](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.Model3DStream.html) object to store the embedded 3D model data in U3D or PRC format.
A Model3DStream object can also contain a collection of [Model3DView](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.Model3DView.html) objects. Each view defines camera position, rendering mode, lighting scheme, and other display settings for the 3D model.
![DsPdf demonstrating how to add 3D annotation in a PDF document](https://cdn.mescius.io/document-site-files/images/97fca692-b414-45c7-9329-f7c03d1509a8/3D_Annotation_v2-20260702.83fabc.gif?width=720)
Refer to the following example code to add a 3D annotation to a PDF document:

```auto
GcPdfDocument doc = new GcPdfDocument();
var p = doc.NewPage();
Model3DAnnotation rma = new Model3DAnnotation();
rma.Stream = new Model3DStream(new FileStream(@"../../../CTech.u3d", FileMode.Open, FileAccess.Read, FileShare.Read), Model3DStreamFormat.U3D);
rma.Page = p;
rma.Rect = new RectangleF(10, 10, 300, 200);
rma.ActivationCondition = Model3DActivationCondition.PageBecomesVisible;
rma.DeactivationCondition = Model3DDeactivationCondition.PageBecomesInvisible;
doc.Save(@"SimpleCase.pdf");

//
// Creates a Model3DAnnotation with three Model3DView objects displaying
// the 3D object from top, left, front and isometric perspectives.
//
doc = new GcPdfDocument();
p = doc.NewPage();

// Load the 3D model data
var fs = new FileStream(@"../../../CTech.u3d", FileMode.Open, FileAccess.Read, FileShare.Read);

// Create the 3D annotation
Model3DAnnotation annotation = new Model3DAnnotation();
annotation.Stream = new Model3DStream(fs, Model3DStreamFormat.U3D);
annotation.ActivationCondition = Model3DActivationCondition.PageBecomesVisible;
annotation.DeactivationCondition = Model3DDeactivationCondition.PageBecomesInvisible;
annotation.Page = p;
annotation.Rect = new RectangleF(10, 10, 300, 200);

// Create three predefined views: left, top, front and isometric perspectives
Model3DViewCollection views = annotation.Stream.Views;

// LEFT VIEW
// NOTE: The value "54.9447" is derived from the bounding box of the 3D model stored inside the 3D file.
// DsPdf cannot parse U3D / PRC files, so the user must obtain this value from the file by other means.
Model3DView leftView = new Model3DView(
    uiName: "LeftView",
    cameraDistance: 54.9447f,
    cameraPosition: new Matrix3D(
        0.0f, 1.0f, 0.0f,
        0.0f, 0.0f, 1.0f,
        1.0f, 0.0f, 0.0f,
        -54.9447f, 0.0f, 0.0f));
views.Add(leftView);

// TOP VIEW
Model3DView topView = new Model3DView(
    uiName: "TopView",
    cameraDistance: 54.9447f,
    cameraPosition: new Matrix3D(
        -1.0f, 0.0f, 0.0f,
        0.0f, 1.0f, 0.0f,
        0.0f, 0.0f, -1.0f,
        0.0f, 0.0f, 54.9447f));
views.Add(topView);

// FRONT VIEW
Model3DView frontView = new Model3DView(
    uiName: "FrontView",
    cameraPosition: new Matrix3D(
        -1.0f, 0.0f, 0.0f,
        0.0f, 0.0f, 1.0f,
        0.0f, 1.0f, 0.0f,
        0.0f, -54.9447f, 0.0f));
views.Add(frontView);

// ISOMETRIC VIEW
Model3DView isometricView = new Model3DView(
    uiName: "IsometricView",
    cameraPosition: new Matrix3D(
        0.707107f, -0.707107f, 0.0f,
        -0.5f, -0.5f, 0.707107f,
        -0.5f, -0.5f, -0.707107f,
        27.4724f, 27.4724f, 38.8518f));
views.Add(isometricView);

// Set the default view to Top
annotation.SetDefaultView(topView);
doc.Save("3DViews.pdf");

//
// Change the 3D content
//
doc = new GcPdfDocument();
fs = new FileStream("SimpleCase.pdf", FileMode.Open);
doc.Load(fs);

// get the annotation
Model3DAnnotation an = (Model3DAnnotation)doc.Pages[0].Annotations[0];

// change the stream
an.Set3DContent(new FileStream(@"../../../rgba.u3d", FileMode.Open), Model3DStreamFormat.U3D);
doc.Save("Changed3DContent.pdf");
```

**Limitation**

* DsPdf embeds 3D models in U3D or PRC format but doesn't parse the internal structure of those files. If your application needs information such as the model’s bounding box or camera distance, obtain those values from the source file using external tools before creating the 3D annotation.