.NET で 3D プレゼンテーションを作成

概要

通常、3D PowerPoint プレゼンテーションはどのように作成しますか?

Microsoft PowerPoint では、3D モデルを追加したり、図形に 3D 効果を適用したり、3D テキストを作成したり、プレゼンテーションに 3D グラフィックスをアップロードしたり、PowerPoint の 3D アニメーションを作成したりして、3D プレゼンテーションを作成できます。

3D 効果を作成することで、プレゼンテーションを 3D に変える大きなインパクトが得られ、3D プレゼンテーションを実装する最も簡単な方法となる場合があります。

Aspose.Slides 20.9 バージョン以降、新しい クロスプラットフォーム 3D エンジン が追加されました。この新しい 3D エンジンは、3D 効果を持つ図形やテキストをエクスポートおよびラスター化できるようにします。以前のバージョンでは、3D 効果が適用された Slides の図形は平面的にレンダリングされていました。しかし、現在は 本格的な 3D で図形をレンダリングできるようになりました。

さらに、Slides の公開 API を介して 3D 効果を持つ図形を作成できるようになりました。

Aspose.Slides API では、図形を PowerPoint の 3D 図形にするために IShape.ThreeDFormat プロパティを使用します。このプロパティは IThreeDFormat インターフェイスの機能を継承しています。

  • BevelBottomBevelTop: 図形にベベルを設定し、ベベルの種類(例: Angle、Circle、SoftRound)や高さと幅を定義します。
  • Camera: オブジェクトの周囲でのカメラの動きを模倣するために使用されます。つまり、回転、ズーム、その他のプロパティを設定することで、PowerPoint の 3D モデルのように図形を操作できます。
  • ContourColorContourWidth: 図形が 3D PowerPoint 図形のように見えるように輪郭のプロパティを設定します。
  • DepthExtrusionColor および ExtrusionHeight: 図形を三次元化するために使用されます。つまり、深さを設定したり押し出したりして、2D 図形を 3D 図形に変換します。
  • LightRig: 3D 図形に光効果を作成できます。このプロパティのロジックは Camera に似ており、光の回転を 3D 図形に対して設定し、光の種類を選択できます。
  • Material: 3D 図形の素材タイプを設定すると、よりリアルな効果を得られます。このプロパティは Metal、Plastic、Powder、Matte などの事前定義された素材のセットを提供します。

すべての 3D 機能は図形とテキストの両方に適用できます。上記のプロパティへのアクセス方法を見て、ステップバイステップで詳細を確認しましょう。

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);
}

レンダリングされたサムネイルは次のようになります:

todo:image_alt_text

3D 回転

PowerPoint の 3D 図形は 3D 平面で回転させることができ、インタラクティブ性が向上します。PowerPoint で 3D 図形を回転させるには、通常以下のメニューを使用します:

todo:image_alt_text

Aspose.Slides API では、3D 図形の回転は IThreeDFormat.Camera プロパティを使用して管理できます:

IAutoShape shape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.ThreeDFormat.Camera.SetRotation(20, 30, 40);
// ... 他の 3D シーン パラメータを設定

using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
    thumbnail.Save("sample_3d.png");
}

3D 深度と押し出し

図形に第3の次元を加えて 3D 図形にするには、IThreeDFormat.ExtrusionHeightIThreeDFormat.ExtrusionColor.Color プロパティを使用します:

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;
// ... 他の 3D シーン パラメータを設定

using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
    thumbnail.Save("sample_3d.png");
}

通常、PowerPoint の Depth メニューを使用して PowerPoint 3D 図形の深さを設定します:

todo:image_alt_text

3D グラデーション

グラデーションは PowerPoint の 3D 図形の色を塗りつぶすために使用できます。ここでは、グラデーション塗りつぶしの図形を作成し、3D 効果を適用してみましょう:

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");
    }
}

結果は以下の通りです:

todo:image_alt_text

グラデーション塗りつぶしに加えて、画像で図形を塗りつぶすことも可能です:

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;
    // ... 3D を設定: shape.ThreeDFormat.Camera、shape.ThreeDFormat.LightRig、shape.ThreeDFormat.Extrusion* プロパティ

using (IImage thumbnail = slide.GetImage(imageScale, imageScale))
{
    thumbnail.Save("sample_3d.png");
}

以下のようになります:

todo:image_alt_text

3D テキスト (WordArt)

Aspose.Slides ではテキストにも 3D を適用できます。3D テキストを作成するには、WordArt の変形効果を使用できます:

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;
    // "Arch Up" の WordArt 変形効果を設定
    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);
}

結果は以下の通りです:

todo:image_alt_text

よくある質問

プレゼンテーションを画像/PDF/HTML にエクスポートする際に、3D 効果は保持されますか?

はい。Slides の 3D エンジンは、対応フォーマットへエクスポートする際に 3D 効果をレンダリングします(imagesPDFHTML など)。

テーマや継承などを考慮した「実効的」な(最終的な)3D パラメータ値を取得できますか?

はい。Slides は 実効値の読み取り 用の API を提供しており(3D の照明やベベルなどを含む)、最終的に適用された設定を確認できます。

プレゼンテーションをビデオに変換する際に、3D 効果は機能しますか?

はい。ビデオ用フレームを生成する際、3D 効果は エクスポートされた画像 と同様にレンダリングされます。