3D Presentation
Overview
How do you usually create a 3D PowerPoint presentation? Microsoft PowerPoint enables to create 3D presentations in terms that we may add 3D models there, apply 3D effects on shapes, create 3D text, upload 3D graphics into presentation, create PowerPoint 3D animations.
Creating 3D effects makes a big impact into improving your presentation to a 3D presentation, and may be the easiest implementation of 3D presentation. Since Aspose.Slides 20.9 version, a new cross-platform 3D engine has been added. The new 3D engine enables to export and rasterize shapes and text with 3D effects. In the previous versions, Slides shapes with 3D effects applied, had been rendered flat. But, now it’s possible to render shapes with a full-fledged 3D. Moreover, now it’s possible to create shapes with 3D effects via Slides public API.
In Aspose.Slides API, to make a shape become a PowerPoint 3D shape use IShape.ThreeDFormat property, which inherits the features of IThreeDFormat interface:
- BevelBottom and BevelTop: set bevel to the shape, define bevel type (e.g. Angle, Circle, SoftRound), define height and width of bevel.
- Camera: is used to imitate camera movements around the object. In other words, by setting came rotation, zoom and other properties - you may entertain with your shapes as with the 3D model in PowerPoint.
- ContourColor and ContourWidth: set contour properties to make the shape look like 3D PowerPoint shape.
- Depth, ExtrusionColor and ExtrusionHeight: are used to make the shape three-dimension, which means to convert a 2D shape into a 3D shape, by setting its depth or extrusing it.
- LightRig: can create a light effect on a 3D shape. The logic of this property is closed to Camera, you can set the rotation of the light in relation to the #D shape and choose the light type.
- Material: setting the type of 3D shape material can bring more alive effect into it. The property provides a set of predefined materials, like: Metal, Plastic, Powder, Matte, etc.
All 3D features can be applied to both shapes and text. Let us see how to access the properties mentioned above and then look on them in details step by step:
const float imageScale = 2;
using (Presentation presentation = new Presentation())
{
ISlide slide = presentation.Slides[0];
IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.TextFrame.Text = "3D";
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 64;
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Flat;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
shape.ThreeDFormat.Material = MaterialPresetType.Flat;
shape.ThreeDFormat.ExtrusionHeight = 100;
shape.ThreeDFormat.ExtrusionColor.Color = Color.Blue;
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("sample_3d.png");
}
presentation.Save("sandbox_3d.pptx", SaveFormat.Pptx);
}
The rendered thumbnail looks like that:
3D Rotation
It’s possible to rotate PowerPoint 3D shapes in 3D plane, which brings more interactivity. To rotate 3D shape in PowerPoint, you usually use the following menu:
In Aspose.Slides API 3D shape rotation can be managed using IThreeDFormat.Camera property:
IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
// ... set other 3D scene parameters
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("sample_3d.png");
}
3D Depth and Extrusion
To bring the third dimension to your shape and make it a 3D shape, use IThreeDFormat.ExtrusionHeight and IThreeDFormat.ExtrusionColor.Color properties:
IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
shape.ThreeDFormat.ExtrusionHeight = 100;
shape.ThreeDFormat.ExtrusionColor.Color = Color.Purple;
// ... set other 3D scene parameters
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("sample_3d.png");
}
Usually, you use Depth menu in PowerPoint to set Depth for PowerPoint 3D shape:
3D Gradient
Gradient can be used to fill the color of PowerPoint 3D shape. Let us create a shape with gradient fill color and apply a 3D effect on it:
const float imageScale = 2;
using (Presentation presentation = new Presentation())
{
ISlide slide = presentation.Slides[0];
IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 250, 250);
shape.TextFrame.Text = "3D Gradient";
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 64;
shape.FillFormat.FillType = FillType.Gradient;
shape.FillFormat.GradientFormat.GradientStops.Add(0, Color.Blue);
shape.FillFormat.GradientFormat.GradientStops.Add(100, Color.Orange);
shape.ThreeDFormat.Camera.CameraType = CameraPresetType.OrthographicFront;
shape.ThreeDFormat.Camera.SetRotation(10, 20, 30);
shape.ThreeDFormat.LightRig.LightType = LightRigPresetType.Flat;
shape.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
shape.ThreeDFormat.ExtrusionHeight = 150;
shape.ThreeDFormat.ExtrusionColor.Color = Color.DarkOrange;
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("sample_3d.png");
}
}
And here is the result:
Except a gradient fill color, its possible to fill shapes with an image:
byte[] imageData = File.ReadAllBytes("image.jpg");
IPPImage image = presentation.Images.AddImage(imageData);
shape.FillFormat.FillType = FillType.Picture;
shape.FillFormat.PictureFillFormat.Picture.Image = image;
shape.FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
// ... setup 3D: shape.ThreeDFormat.Camera, shape.ThreeDFormat.LightRig, shape.ThreeDFormat.Extrusion* properties
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("sample_3d.png");
}
That’s how it looks like:
3D Text (WordArt)
Aspose.Slides allows to apply 3D on text too. For creating a 3D text its possible to use WordArt transform effect:
const float imageScale = 2;
using (Presentation presentation = new Presentation())
{
ISlide slide = presentation.Slides[0];
IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 250, 250);
shape.FillFormat.FillType = FillType.NoFill;
shape.LineFormat.FillFormat.FillType = FillType.NoFill;
shape.TextFrame.Text = "3D Text";
Portion portion = (Portion)shape.TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Pattern;
portion.PortionFormat.FillFormat.PatternFormat.ForeColor.Color = Color.DarkOrange;
portion.PortionFormat.FillFormat.PatternFormat.BackColor.Color = Color.White;
portion.PortionFormat.FillFormat.PatternFormat.PatternStyle = PatternStyle.LargeGrid;
shape.TextFrame.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 128;
ITextFrameFormat textFrameFormat = shape.TextFrame.TextFrameFormat;
// set the "Arch Up" WordArt transform effect
textFrameFormat.Transform = TextShapeType.ArchUp;
textFrameFormat.ThreeDFormat.ExtrusionHeight = 3.5f;
textFrameFormat.ThreeDFormat.Depth = 3;
textFrameFormat.ThreeDFormat.Material = MaterialPresetType.Plastic;
textFrameFormat.ThreeDFormat.LightRig.Direction = LightingDirection.Top;
textFrameFormat.ThreeDFormat.LightRig.LightType = LightRigPresetType.Balanced;
textFrameFormat.ThreeDFormat.LightRig.SetRotation(0, 0, 40);
textFrameFormat.ThreeDFormat.Camera.CameraType = CameraPresetType.PerspectiveContrastingRightFacing;
using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
thumbnail.Save("text3d.png");
}
presentation.Save("text3d.pptx", SaveFormat.Pptx);
}
Here is the result:
Not Supported - Coming Soon
The following PowerPoint 3D features are not supported yet:
- Bevel
- Material
- Contour
- Lighting
We continue to improve our 3D Engine, and these features are the subject of further implementation.