3D-Präsentationen in Java erstellen
Übersicht
Seit Aspose.Slides Java 20.9 ist es möglich, 3D in Präsentationen zu erstellen. PowerPoint 3D ist eine Möglichkeit, Präsentationen Leben zu verleihen. Zeigen Sie reale Objekte mit einer 3D‑Präsentation, demonstrieren Sie ein 3D‑Modell Ihres zukünftigen Geschäftsprojekts, ein 3D‑Modell des Gebäudes oder dessen Innenraum, ein 3D‑Modell des Spielcharakters oder einfach eine 3D‑Darstellung Ihrer Daten.
PowerPoint‑3D‑Modelle können aus 2D‑Formen erstellt werden, indem solche Effekte darauf angewendet werden: 3D‑Drehung, 3D‑Tiefe und Extrusion, 3D‑Verlauf, 3D‑Text usw. Die Liste der auf Formen angewendeten 3D‑Funktionen finden Sie in der Klasse ThreeDFormat. Eine Instanz der Klasse kann erhalten werden über:
- Shape.getThreeDFormat() Methode zum Erstellen eines PowerPoint‑3D‑Modells.
- TextFrameFormat.getThreeDFormat() Methode zum Erstellen eines 3D‑Texts (WordArt).
Alle in ThreeDFormat implementierten Effekte können sowohl für Formen als auch für Text verwendet werden. Werfen wir einen kurzen Blick auf die wichtigsten Methoden der Klasse ThreeDFormat. Im nächsten Beispiel erstellen wir eine rechteckige 2D‑Form mit einem Text darauf. Durch das Abrufen der Kameraperspektive auf die Form ändern wir ihre Drehung und lassen sie wie ein 3D‑Modell aussehen. Das Einstellen eines flachen Lichts und dessen Richtung nach oben am 3D‑Modell verleiht dem Modell mehr Volumen. Geänderte Materialien, Extrusionshöhe und Farbe lassen das 3D‑Modell lebendiger wirken.
final float imageScale = 2;
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.getTextFrame().setText("3D");
shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(64);
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
shape.getThreeDFormat().getCamera().setRotation(20, 30, 40);
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Flat);
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
shape.getThreeDFormat().setMaterial(MaterialPresetType.Flat);
shape.getThreeDFormat().setExtrusionHeight(100);
shape.getThreeDFormat().getExtrusionColor().setColor(Color.BLUE);
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("sample_3d.png", ImageFormat.Png);
thumbnail.dispose();
presentation.save("sandbox_3d.pptx", SaveFormat.Pptx);
presentation.dispose();
Hier ist das resultierende 3D‑Modell:

3D‑Drehung
Die Drehung eines 3D‑Modells in PowerPoint kann über das Menü durchgeführt werden:

Um ein 3D‑Modell mit der Aspose.Slides‑API zu drehen, verwenden Sie die Methode IThreeDFormat.getCamera(), setzen Sie die Drehung der Kamera relativ zur 3D‑Form:
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.getThreeDFormat().getCamera().setRotation(20, 30, 40);
// ... weitere 3D-Szenenparameter setzen
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("sample_3d.png", ImageFormat.Png);
thumbnail.dispose();
3D‑Tiefe und Extrusion
Die Methoden IThreeDFormat.getExtrusionHeight() und IThreeDFormat.getExtrusionColor() werden verwendet, um eine Extrusion auf einer Form zu erzeugen:
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.getThreeDFormat().getCamera().setRotation(20, 30, 40);
shape.getThreeDFormat().setExtrusionHeight(100);
shape.getThreeDFormat().getExtrusionColor().setColor(new Color(128, 0, 128));
// ... weitere 3D Szenenparameter setzen
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("sample_3d.png", ImageFormat.Png);
thumbnail.dispose();
In PowerPoint wird die Tiefe der Form festgelegt über:

3D‑Verlauf
Ein 3D‑Verlauf kann einem PowerPoint‑3D‑Objekt mehr Volumen verleihen:
final float imageScale = 2;
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 250, 250);
shape.getTextFrame().setText("3D");
shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(64);
shape.getFillFormat().setFillType(FillType.Gradient);
shape.getFillFormat().getGradientFormat().getGradientStops().add(0, Color.BLUE);
shape.getFillFormat().getGradientFormat().getGradientStops().add(100, Color.ORANGE);
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront);
shape.getThreeDFormat().getCamera().setRotation(10, 20, 30);
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Flat);
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
shape.getThreeDFormat().setExtrusionHeight(150);
shape.getThreeDFormat().getExtrusionColor().setColor(new Color(255, 140, 0));
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("sample_3d.png", ImageFormat.Png);
thumbnail.dispose();
presentation.dispose();
So sieht es aus:

Sie können außerdem einen Bildverlauf erstellen:
byte[] imageData = Files.readAllBytes(Paths.get("image.png"));
IPPImage image = presentation.getImages().addImage(imageData);
shape.getFillFormat().setFillType(FillType.Picture);
shape.getFillFormat().getPictureFillFormat().getPicture().setImage(image);
shape.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch);
// ... 3D einrichten: shape.ThreeDFormat.Camera, shape.ThreeDFormat.LightRig, shape.ThreeDFormat.Extrusion* Eigenschaften
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("sample_3d.png", ImageFormat.Png);
thumbnail.dispose();
Hier ist das Ergebnis:

3D‑Text (WordArt)
Um einen 3D‑Text (WordArt) zu erstellen, führen Sie Folgendes aus:
final float imageScale = 2;
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 150, 200, 200);
shape.getFillFormat().setFillType(FillType.NoFill);
shape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);
shape.getTextFrame().setText("3D Text");
Portion portion = (Portion)shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
portion.getPortionFormat().getFillFormat().setFillType(FillType.Pattern);
portion.getPortionFormat().getFillFormat().getPatternFormat().getForeColor().setColor(new Color(255, 140, 0));
portion.getPortionFormat().getFillFormat().getPatternFormat().getBackColor().setColor(Color.WHITE);
portion.getPortionFormat().getFillFormat().getPatternFormat().setPatternStyle(PatternStyle.LargeGrid);
shape.getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().setFontHeight(128);
ITextFrameFormat textFrameFormat = shape.getTextFrame().getTextFrameFormat();
// setze den "Arch Up" WordArt-Transformations-Effekt
textFrameFormat.setTransform(TextShapeType.ArchUp);
textFrameFormat.getThreeDFormat().setExtrusionHeight(3.5f);
textFrameFormat.getThreeDFormat().setDepth(3);
textFrameFormat.getThreeDFormat().setMaterial(MaterialPresetType.Plastic);
textFrameFormat.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top);
textFrameFormat.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.Balanced);
textFrameFormat.getThreeDFormat().getLightRig().setRotation(0, 0, 40);
textFrameFormat.getThreeDFormat().getCamera().setCameraType(CameraPresetType.PerspectiveContrastingRightFacing);
IImage thumbnail = slide.getImage(imageScale, imageScale);
thumbnail.save("text3d.png", ImageFormat.Png);
thumbnail.dispose();
presentation.save("text3d.pptx", SaveFormat.Pptx);
presentation.dispose();
Hier ist das Ergebnis:

Nicht unterstützt – Demnächst
Die folgenden PowerPoint‑3D‑Funktionen werden derzeit noch nicht unterstützt:
- Bevel
- Material
- Contour
- Lighting