C++で3Dプレゼンテーションを作成する

概要

Aspose.Slides 20.9 以降、PowerPoint の 3D モデルを作成および変更することが可能です。これは、2D 形状に一連の 3D 効果を付与することで実現できます。形状にカメラビューを作成することで、軸に沿って回転させることができます。形状に押し出しや奥行きを設定すると、2D 形状が 3D モデルに変換されます。3D 形状に光効果を設定したり、素材を変更したりすることで、よりリアルに見せることができます。3D モデルの色を 3D グラデーションに変更したり、形状の輪郭を修正したり、ベベルを追加したりすると、より立体感が得られます。すべての 3D 効果は、PowerPoint の 3D モデルとテキストの両方に適用できます。

以下に、前述のすべての機能を含む 3D モデル作成の最初の例を示します:

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto imageScale = 2;

auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 150.0f, 200.0f, 200.0f);
shape->get_TextFrame()->set_Text(u"3D");
shape->get_TextFrame()->get_Paragraphs()->idx_get(0)->get_ParagraphFormat()->get_DefaultPortionFormat()->set_FontHeight(64.0f);

shape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::OrthographicFront);
shape->get_ThreeDFormat()->get_Camera()->SetRotation(20.0f, 30.0f, 40.0f);
shape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::ThreePt);
shape->get_ThreeDFormat()->get_LightRig()->set_Direction(LightingDirection::Top);
shape->get_ThreeDFormat()->set_Material(MaterialPresetType::Matte);
shape->get_ThreeDFormat()->set_ExtrusionHeight(100);
shape->get_ThreeDFormat()->get_ExtrusionColor()->set_Color(System::Drawing::Color::get_Blue());

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();

presentation->Save(u"sandbox_3d.pptx", Export::SaveFormat::Pptx);
presentation->Dispose();

結果として得られる PowerPoint の 3D モデル:

todo:image_alt_text

3D 回転

PowerPoint の形状回転は以下のように利用できます:

todo:image_alt_text

PowerPoint の 3D モデルを回転させるには、形状にカメラビューを作成する必要があります。これはIThreeDFormat.get_Camera()メソッドで行います。回転メソッドはカメラ クラスから呼び出され、カメラを回転させるかのように動作します。実際には、形状に対してカメラを回転させることで、3D 平面上で形状が回転します。

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 150.0f, 200.0f, 200.0f);
shape->get_ThreeDFormat()->get_Camera()->SetRotation(20.0f, 30.0f, 40.0f);
// ... 他の3Dシーンパラメータを設定

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();

3D 奥行きと押し出し

PowerPoint の 3D モデルに奥行きと押し出しを追加するには、IThreeDFormat.set_ExtrusionHeight()メソッドを使用します。押し出しの色を変更するには、IThreeDFormat.get_ExtrusionColor()メソッドを使用します:

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 150.0f, 200.0f, 200.0f);
shape->get_ThreeDFormat()->get_Camera()->SetRotation(20.0f, 30.0f, 40.0f);
shape->get_ThreeDFormat()->set_ExtrusionHeight(100.0);
shape->get_ThreeDFormat()->get_ExtrusionColor()->set_Color(System::Drawing::Color::get_Purple());
// ... 他の 3D シーン パラメータを設定

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();

PowerPoint の奥行きメニュー:

todo:image_alt_text

3D グラデーション

PowerPoint の 3D モデルに 3D グラデーションを描画するには、Shape.get_FillFormat().get_GradientFormat()メソッドを使用します:

using namespace Aspose::Slides;

auto imageScale = 2;

auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 150.0f, 250.0f, 250.0f);
shape->get_TextFrame()->set_Text(u"3D Gradient");
shape->get_TextFrame()->get_Paragraph(0)->get_ParagraphFormat()->get_DefaultPortionFormat()->set_FontHeight(64.0f);

shape->get_FillFormat()->set_FillType(FillType::Gradient);
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(0, System::Drawing::Color::get_Blue());
shape->get_FillFormat()->get_GradientFormat()->get_GradientStops()->Add(100.0f, System::Drawing::Color::get_Orange());

shape->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::OrthographicFront);
shape->get_ThreeDFormat()->get_Camera()->SetRotation(10.0f, 20.0f, 30.0f);
shape->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::Flat);
shape->get_ThreeDFormat()->get_LightRig()->set_Direction(LightingDirection::Top);
shape->get_ThreeDFormat()->set_ExtrusionHeight(150.0);
shape->get_ThreeDFormat()->get_ExtrusionColor()->set_Color(System::Drawing::Color::get_DarkOrange());

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();

3D グラデーションを適用した 3D モデル:

todo:image_alt_text

画像グラデーションを作成するには、Shape.get_FillFormat().get_PictureFillFormat()メソッドを使用します:

auto imageData = System::IO::File::ReadAllBytes(u"image.jpg");
auto image = presentation->get_Images()->AddImage(imageData);

shape->get_FillFormat()->set_FillType(FillType::Picture);
shape->get_FillFormat()->get_PictureFillFormat()->get_Picture()->set_Image(image);
shape->get_FillFormat()->get_PictureFillFormat()->set_PictureFillMode(PictureFillMode::Stretch);
// .. 3Dをセットアップ: カメラ、ライトリグ、押し出し

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();

画像グラデーションを適用した 3D モデル:

todo:image_alt_text

3D テキスト (WordArt)

テキストに回転、押し出し、光、グラデーションを適用して 3D テキスト(WordArt)にするには、IAutoShape.get_TextFrame().get_TextFrameFormat().get_ThreeDFormat()メソッドにアクセスする必要があります:

using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;

auto imageScale = 2;

auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);

auto shape = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 200.0f, 150.0f, 250.0f, 250.0f);
shape->get_FillFormat()->set_FillType(FillType::NoFill);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
shape->get_TextFrame()->set_Text(u"3D Text");

auto portion = shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0);
portion->get_PortionFormat()->get_FillFormat()->set_FillType(FillType::Pattern);
portion->get_PortionFormat()->get_FillFormat()->get_PatternFormat()->get_ForeColor()->set_Color(System::Drawing::Color::get_DarkOrange());
portion->get_PortionFormat()->get_FillFormat()->get_PatternFormat()->get_BackColor()->set_Color(System::Drawing::Color::get_White());
portion->get_PortionFormat()->get_FillFormat()->get_PatternFormat()->set_PatternStyle(PatternStyle::LargeGrid);

shape->get_TextFrame()->get_Paragraph(0)->get_ParagraphFormat()->get_DefaultPortionFormat()->set_FontHeight(128.0f);

auto textFrameFormat = shape->get_TextFrame()->get_TextFrameFormat();
// "Arch Up" WordArt の変形効果を設定
textFrameFormat->set_Transform(TextShapeType::ArchUp);

textFrameFormat->get_ThreeDFormat()->set_ExtrusionHeight(3.5);
textFrameFormat->get_ThreeDFormat()->set_Depth(3.0);
textFrameFormat->get_ThreeDFormat()->set_Material(MaterialPresetType::Plastic);
textFrameFormat->get_ThreeDFormat()->get_LightRig()->set_Direction(LightingDirection::Top);
textFrameFormat->get_ThreeDFormat()->get_LightRig()->set_LightType(LightRigPresetType::Balanced);
textFrameFormat->get_ThreeDFormat()->get_LightRig()->SetRotation(0.0f, 0.0f, 40.0f);

textFrame->get_TextFrameFormat()->get_ThreeDFormat()->get_Camera()->set_CameraType(CameraPresetType::PerspectiveContrastingRightFacing);

auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"text3d.png");
thumbnail->Dispose();

presentation->Save(u"text3d.pptx", SaveFormat::Pptx);
presentation->Dispose();

3D テキスト(WordArt)の例:

todo:image_alt_text

FAQ

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

はい。Slides の 3D エンジンは、サポートされている形式(imagesPDFHTML など)へのエクスポート時に 3D 効果をレンダリングします。

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

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

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

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