Erstellen Sie 3D‑Präsentationen in C++
Übersicht
Seit Aspose.Slides 20.9 ist es möglich, PowerPoint‑3D‑Modelle zu erstellen und zu bearbeiten. Dies kann erreicht werden, indem 2D‑Formen eine Reihe von 3D‑Effekten verliehen werden. Durch Erzeugen einer Kameraperspektive auf der Form können Sie sie um die Achse drehen. Durch Erstellen einer Extrusion oder Tiefe an der Form wird die Form von einer 2D‑Form in ein 3D‑Modell umgewandelt. Das Einstellen des Lichteffekts auf der 3D‑Form oder das Ändern der Materialien lässt sie lebendiger aussehen. Das Ändern der Farben von 3D‑Modellen zu einem 3D‑Verlauf, das Modifizieren der Kontur von Formen und das Hinzufügen einer Abschrägung verleihen dem 3D‑Modell mehr Volumen. Alle 3D‑Effekte können sowohl auf PowerPoint‑3D‑Modelle als auch auf Texte angewendet werden.
Betrachten wir das erste Beispiel für die Erstellung von 3D‑Modellen, das alle oben genannten Funktionen enthält:
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();
Das resultierende PowerPoint‑3D‑Modell:

3D‑Drehung
In PowerPoint ist die Formrotation verfügbar über:

Um PowerPoint‑3D‑Modelle zu drehen, muss eine Kameraperspektive auf der Form erstellt werden. Dies erfolgt mit der Methode IThreeDFormat.get_Camera() . Die Rotationsmethode wird aus der Kamera‑Klasse aufgerufen, als würden Sie die Kamera drehen. Tatsächlich drehen Sie die Form in der 3D‑Ebene, wenn Sie die Kamera relativ zur Form drehen.
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);
// ... weitere 3D‑Szenenparameter setzen
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
3D‑Tiefe und Extrusion
Um Tiefen‑ und Extrusionsinformationen zu einem PowerPoint‑3D‑Modell hinzuzufügen, verwenden Sie die Methode IThreeDFormat.set_ExtrusionHeight() . Um die Extrusionsfarbe zu ändern, verwenden Sie die Methode 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());
// ... weitere 3D-Szenenparameter setzen
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
Tiefen‑Menü in PowerPoint:

3D‑Verlauf
Einen 3D‑Verlauf auf einem PowerPoint‑3D‑Modell kann man mit der Methode Shape.get_FillFormat().get_GradientFormat() zeichnen:
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‑Modell mit 3D‑Verlauf:

Um einen Bildverlauf zu erstellen, verwenden Sie die Methode 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 einrichten: Kamera, LightRig, Extrusion
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
3D‑Modell mit Bildverlauf:

3D‑Text (WordArt)
Um Rotation, Extrusion, Licht und Verlauf auf Text anzuwenden und ihn zu einem 3D‑Text (WordArt) zu machen, müssen Sie die Methode IAutoShape.get_TextFrame().get_TextFrameFormat().get_ThreeDFormat() aufrufen:
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();
// Einrichten des WordArt-Transformations-Effekts "Arch Up"
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();
Ein Beispiel für 3D‑Text (WordArt):

FAQ
Werden 3D‑Effekte beim Export einer Präsentation in Bilder/PDF/HTML erhalten bleiben?
Ja. Die Slides‑3D‑Engine rendert 3D‑Effekte beim Export in unterstützte Formate (images, PDF, HTML, usw.).
Kann ich die „effektiven“ (endgültigen) 3D‑Parameterwerte abrufen, die Themen, Vererbung usw. berücksichtigen?
Ja. Slides stellt APIs zum read effective values bereit (einschließlich für 3D – Beleuchtung, Abschrägungen usw.), sodass Sie die endgültig angewendeten Einstellungen sehen können.
Funktionieren 3D‑Effekte beim Konvertieren einer Präsentation in ein Video?
Ja. Beim generating frames for the video werden 3D‑Effekte genau wie bei exported images gerendert.