Skip to main content

Post-processing tools 2025 R1

Test012

Last update: 16.07.2025

/// <script src="./ansys251/nexus/viewer-loader.js"></script> /// ///

Clipping plane.

This example demonstrates a clipping plane attached to the scene.

The clipping plane is created from three points, that are specified in object space coordinates.

/*
* Copyright 2018-2021 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.
*
* Restricted Rights Legend
*
* Use, duplication, or disclosure of this
* software and its documentation by the
* Government is subject to restrictions as
* set forth in subdivision [(b)(3)(ii)] of
* the Rights in Technical Data and Computer
* Software clause at 52.227-7013.
*/
#include <vector>
#include "GLTFWriter.h"
#include "test.h"
using namespace ANSYS::AVZ;
// Lighted solid colored sphere
TESTFUNC(ClipPlane)
{
GLTFWriter::GLTF *gltf = GLTFWriter::GLTF::Create("MyApp", "1.0", functionName.c_str(), type);
if (!gltf)
throw std::runtime_error("Can't create GLTF");
// SCENE
GLTFWriter::Scene *scene = GLTFWriter::Scene::Create(gltf, "TestScene", "m", 1.0, GLTFWriter::Scene::BT_SOLID, 0.5, 0.5, 0.5);
if (!scene) {
GLTFWriter::GLTF::Destroy(gltf);
throw std::runtime_error("Can't create scene");
}
// CLIP PLANE
scene->SetClipPlane(0, 0, 0.2F, 1, 0, 0.2F, 1, 1, 0.2F);
// LIGHTS
{
// LIGHT NODE
GLTFWriter::Node *lightNode = GLTFWriter::Node::CreateLight(gltf);
if (!lightNode || !scene->SetLight(lightNode)) {
GLTFWriter::GLTF::Destroy(gltf);
throw std::runtime_error("Can't create light");
}
// LIGHTS
GLTFWriter::Light *light1 = GLTFWriter::Light::CreateAmbient(gltf);
lightNode->AppendLight(light1);
GLTFWriter::Light *light2 = GLTFWriter::Light::CreateDirectional(gltf, 1, 1, 1, -1, -1, -3);
lightNode->AppendLight(light2);
}
// CAMERA
{
// CAMERA
GLTFWriter::Camera *camera = GLTFWriter::Camera::CreatePerspective(gltf);
// CAMERA NODE
std::vector<double> mat(16);
mat[0] = 1;
mat[1] = 0;
mat[2] = 0;
mat[3] = 0;
mat[4] = 0;
mat[5] = 1;
mat[6] = 0;
mat[7] = 0;
mat[8] = 0;
mat[9] = 0;
mat[10] = 1;
mat[11] = 0;
mat[12] = 0;
mat[13] = 0;
mat[14] = 0;
mat[15] = 1;
GLTFWriter::Node *cameraNode = GLTFWriter::Node::CreateCamera(gltf, camera, "TestCamera", &mat[0]);
scene->SetCamera(cameraNode);
}
// MESH NODE
{
// NODE
GLTFWriter::Node *node = GLTFWriter::Node::CreateMesh(gltf, "3D Sphere");
if (!node || !scene->AppendMesh(node)) {
GLTFWriter::GLTF::Destroy(gltf);
throw std::runtime_error("Can't create mesh node");
}
// MESH
GLTFWriter::Mesh *mesh = GLTFWriter::Mesh::Create(gltf);
if (!mesh || !node->AppendMesh(mesh)) {
GLTFWriter::GLTF::Destroy(gltf);
throw std::runtime_error("Can't create mesh");
}
// PRIMITIVE
std::pair<GLTFWriter::Primitive *, GLTFWriter::Material *> pm = GLTFWriter::Test::CreateSolidColoredSpherePrimitive(gltf, 0, 0, 0, 0.5, 16, 1.0, 0.0, 0.0, 1.0);
mesh->AppendPrimitive(pm.first);
}
if (!gltf->Write()) {
GLTFWriter::GLTF::Destroy(gltf);
throw std::runtime_error("Error creating file");
}
GLTFWriter::GLTF::Destroy(gltf);
if (error != GLTFWriter::GLTF::GLTF_ERROR_NONE)
throw std::runtime_error("Error creating file");
}
Cameras define an orthographic or perspective projection of the scene.
Definition GLTFCamera.h:28
This is the main class of the GLTFWriter.
Definition GLTFGLTF.h:32
virtual bool Write(bool formatJSON=false)=0
virtual GLTFError GetError()=0
Lights define the light objects that can be added to a light node.
Definition GLTFLight.h:31
Meshes define the renderable objects that can be added to a node.
Definition GLTFMesh.h:104
virtual bool AppendPrimitive(Primitive *primitive)=0
Nodes are the GLTFWriter class that contain the data that is defined in the GLTF file.
Definition GLTFNode.h:31
virtual bool AppendLight(Light *light)=0
virtual bool AppendMesh(Mesh *mesh)=0
Scenes are the GLTFWriter class that create the view of the data that is defined in the GLTF file.
Definition GLTFScene.h:29
virtual bool AppendMesh(Node *mesh)=0
virtual void SetClipPlane(float p0x, float p0y, float p0z, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z)=0
virtual bool SetLight(Node *light)=0
virtual bool SetCamera(Node *camera)=0

Connect with Ansys