Crear presentaciones 3D en C++
Descripción general
Desde Aspose.Slides 20.9 es posible crear y modificar modelos 3D de PowerPoint. Esto se logra aplicando a formas 2D un conjunto de efectos 3D. Al crear una vista de cámara sobre la forma, puede rotarse alrededor del eje. Crear una extrusión o profundidad en la forma la transforma de una forma 2D a un modelo 3D. Ajustar el efecto de luz en la forma 3D o cambiar los materiales puede hacer que parezca más viva. Cambiar los colores de los modelos 3D a un degradado 3D, modificar el contorno de las formas, agregar un bisel hacen que el modelo 3D tenga más volumen. Todos los efectos 3D pueden aplicarse tanto a modelos 3D de PowerPoint como a textos.
Observemos el primer ejemplo de creación de modelos 3D, que incluye todas las características mencionadas arriba:
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();
El modelo 3D de PowerPoint resultante:

Rotación 3D
En PowerPoint la rotación de formas está disponible a través de:

Para rotar modelos 3D de PowerPoint, es necesario crear una vista de cámara sobre la forma. Esto se hace con el método IThreeDFormat.get_Camera(). El método de rotación se llama desde la clase cámara como si estuviera rotando la cámara. De hecho, cuando rota la cámara respecto a la forma, está rotando la forma en el plano 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);
// ... establecer otros parámetros de la escena 3D
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
Profundidad y Extrusión 3D
Para añadir profundidad y extrusión a un modelo 3D de PowerPoint use el método IThreeDFormat.set_ExtrusionHeight().
Para modificar el color de la extrusión use el método 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());
// ... establecer otros parámetros de la escena 3D
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
Menú de profundidad en PowerPoint:

Gradiente 3D
Dibujar un degradado 3D en un modelo 3D de PowerPoint se puede hacer mediante el método 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();
Modelo 3D con degradado 3D:

Para crear un degradado de imagen use el método 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);
// .. configurar 3D: Cámara, LightRig, Extrusión
auto thumbnail = slide->GetImage(imageScale, imageScale);
thumbnail->Save(u"sample_3d.png");
thumbnail->Dispose();
Modelo 3D con degradado de imagen:

Texto 3D (WordArt)
Para aplicar rotación, extrusión, luz, degradado al texto y convertirlo en texto 3D (WordArt), necesita acceder al método 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();
// configurar efecto de transformación WordArt "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();
Un ejemplo de texto 3D (WordArt):

Preguntas frecuentes
¿Se conservarán los efectos 3D al exportar una presentación a imágenes/PDF/HTML?
Sí. El motor 3D de Slides renderiza los efectos 3D al exportar a formatos compatibles (images, PDF, HTML, etc.).
¿Puedo obtener los valores “efectivos” (finales) de los parámetros 3D que tengan en cuenta temas, herencia, etc.?
Sí. Slides proporciona API para leer valores efectivos (incluidos los de 3D—iluminación, biseles, etc.) de modo que pueda ver la configuración final aplicada.
¿Los efectos 3D funcionan al convertir una presentación a vídeo?
Sí. Cuando se generan fotogramas para el vídeo, los efectos 3D se renderizan igual que para las imágenes exportadas.