    

 ## On this page

  

 

 # Test012

 Last update: 16.07.2025 

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. &lt;script src="/ansys/nexus/viewer-loader.js"&gt;&lt;/script&gt;

/\*

 \* 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 &lt;vector&gt;

 

\#include "GLTFWriter.h"

\#include "test.h"

 

using namespace ANSYS::Nexus;

 

// Lighted solid colored sphere

TESTFUNC(ClipPlane)

{

 <a id="_a0" name="_a0"></a>[GLTFWriter::GLTF](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml) *gltf = GLTFWriter::GLTF::Create("MyApp", "1.0", functionName.c_str(), type);

 if (!gltf)

 throw std::runtime_error("Can't create GLTF");

 

 // SCENE

 <a id="_a1" name="_a1"></a>[GLTFWriter::Scene](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml) *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-&gt;<a id="a2" name="a2"></a>[SetClipPlane](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#a1de67b73e229a59c58113807e04af2dd)(0, 0, 0.2F, 1, 0, 0.2F, 1, 1, 0.2F);

 

 // LIGHTS

 {

 // LIGHT NODE

 <a id="_a3" name="_a3"></a>[GLTFWriter::Node](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml) *lightNode = GLTFWriter::Node::CreateLight(gltf);

 if (!lightNode || !scene-&gt;<a id="a4" name="a4"></a>[SetLight](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#ad59f57e366c5376b197aed0b10de4f71)(lightNode)) {

 GLTFWriter::GLTF::Destroy(gltf);

 throw std::runtime_error("Can't create light");

 }

 

 // LIGHTS

 <a id="_a5" name="_a5"></a>[GLTFWriter::Light](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_light.xhtml) *light1 = GLTFWriter::Light::CreateAmbient(gltf);

 lightNode-&gt;<a id="a6" name="a6"></a>[AppendLight](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml#a229725aed9694dd14f7023d5445bbc72)(light1);

 

 [GLTFWriter::Light](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_light.xhtml) *light2 = GLTFWriter::Light::CreateDirectional(gltf, 1, 1, 1, -1, -1, -3);

 lightNode-&gt;[AppendLight](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml#a229725aed9694dd14f7023d5445bbc72)(light2);

 }

 

 // CAMERA

 {

 // CAMERA

 <a id="_a7" name="_a7"></a>[GLTFWriter::Camera](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_camera.xhtml) *camera = GLTFWriter::Camera::CreatePerspective(gltf);

 // CAMERA NODE

 std::vector&lt;double&gt; 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](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml) *cameraNode = GLTFWriter::Node::CreateCamera(gltf, camera, "TestCamera", &amp;mat[0]);

 scene-&gt;<a id="a8" name="a8"></a>[SetCamera](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#a032a02e7ff85707f8ae02dce0ec11ce4)(cameraNode);

 }

 

 // MESH NODE

 {

 // NODE

 [GLTFWriter::Node](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml) *node = GLTFWriter::Node::CreateMesh(gltf, "3D Sphere");

 if (!node || !scene-&gt;<a id="a9" name="a9"></a>[AppendMesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#adea272bb6570744737a12f7f639e40fd)(node)) {

 GLTFWriter::GLTF::Destroy(gltf);

 throw std::runtime_error("Can't create mesh node");

 }

 

 // MESH

 <a id="_a10" name="_a10"></a>[GLTFWriter::Mesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml) *mesh = GLTFWriter::Mesh::Create(gltf);

 if (!mesh || !node-&gt;<a id="a11" name="a11"></a>[AppendMesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml#a29e43db3c3bd933a51c2e99e223e41bd)(mesh)) {

 GLTFWriter::GLTF::Destroy(gltf);

 throw std::runtime_error("Can't create mesh");

 }

 

 // PRIMITIVE

 std::pair&lt;GLTFWriter::Primitive *, GLTFWriter::Material *&gt; pm = GLTFWriter::Test::CreateSolidColoredSpherePrimitive(gltf, 0, 0, 0, 0.5, 16, 1.0, 0.0, 0.0, 1.0);

 mesh-&gt;<a id="a12" name="a12"></a>[AppendPrimitive](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml#a392eddd58e41d83d7df11e7e48ed4798)(pm.first);

 }

 

 if (!gltf-&gt;<a id="a13" name="a13"></a>[Write](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a7a468ecf1f594b411023782d18f08823)()) {

 GLTFWriter::GLTF::Destroy(gltf);

 throw std::runtime_error("Error creating file");

 }

 

 [GLTFWriter::GLTF::GLTFError](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#acf83a4d185d959503cb9f3f2c2e9fafe) error = gltf-&gt;<a id="a14" name="a14"></a>[GetError](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a812b885f21ed48bad70fea6b03e76913)();

 

 GLTFWriter::GLTF::Destroy(gltf);

 

 if (error != GLTFWriter::GLTF::GLTF_ERROR_NONE)

 throw std::runtime_error("Error creating file");

}

[ANSYS::Nexus::GLTFWriter::Camera](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_camera.xhtml)

Cameras define an orthographic or perspective projection of the scene.

**Definition:** [GLTFCamera.h:28](_g_l_t_f_camera_8h_source.xhtml#l00027)



[ANSYS::Nexus::GLTFWriter::GLTF](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml)

This is the main class of the GLTFWriter.

**Definition:** [GLTFGLTF.h:32](_g_l_t_f_g_l_t_f_8h_source.xhtml#l00031)



[ANSYS::Nexus::GLTFWriter::GLTF::Write](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a7a468ecf1f594b411023782d18f08823)

virtual bool Write(bool formatJSON=false)=0



[ANSYS::Nexus::GLTFWriter::GLTF::GetError](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a812b885f21ed48bad70fea6b03e76913)

virtual GLTFError GetError()=0



[ANSYS::Nexus::GLTFWriter::GLTF::GLTFError](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#acf83a4d185d959503cb9f3f2c2e9fafe)

GLTFError

**Definition:** [GLTFGLTF.h:35](_g_l_t_f_g_l_t_f_8h_source.xhtml#l00035)



[ANSYS::Nexus::GLTFWriter::Light](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_light.xhtml)

Lights define the light objects that can be added to a light node.

**Definition:** [GLTFLight.h:31](_g_l_t_f_light_8h_source.xhtml#l00030)



[ANSYS::Nexus::GLTFWriter::Mesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml)

Meshes define the renderable objects that can be added to a node.

**Definition:** [GLTFMesh.h:104](_g_l_t_f_mesh_8h_source.xhtml#l00103)



[ANSYS::Nexus::GLTFWriter::Mesh::AppendPrimitive](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml#a392eddd58e41d83d7df11e7e48ed4798)

virtual bool AppendPrimitive(Primitive *primitive)=0



[ANSYS::Nexus::GLTFWriter::Node](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml)

Nodes are the GLTFWriter class that contain the data that is defined in the GLTF file.

**Definition:** [GLTFNode.h:31](_g_l_t_f_node_8h_source.xhtml#l00030)



[ANSYS::Nexus::GLTFWriter::Node::AppendLight](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml#a229725aed9694dd14f7023d5445bbc72)

virtual bool AppendLight(Light *light)=0



[ANSYS::Nexus::GLTFWriter::Node::AppendMesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_node.xhtml#a29e43db3c3bd933a51c2e99e223e41bd)

virtual bool AppendMesh(Mesh *mesh)=0



[ANSYS::Nexus::GLTFWriter::Scene](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml)

Scenes are the GLTFWriter class that create the view of the data that is defined in the GLTF file.

**Definition:** [GLTFScene.h:29](_g_l_t_f_scene_8h_source.xhtml#l00028)



[ANSYS::Nexus::GLTFWriter::Scene::SetCamera](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#a032a02e7ff85707f8ae02dce0ec11ce4)

virtual bool SetCamera(Node *camera)=0



[ANSYS::Nexus::GLTFWriter::Scene::SetClipPlane](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#a1de67b73e229a59c58113807e04af2dd)

virtual void SetClipPlane(float p0x, float p0y, float p0z, float p1x, float p1y, float p1z, float p2x, float p2y, float p2z)=0



[ANSYS::Nexus::GLTFWriter::Scene::SetLight](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#ad59f57e366c5376b197aed0b10de4f71)

virtual bool SetLight(Node *light)=0



[ANSYS::Nexus::GLTFWriter::Scene::AppendMesh](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#adea272bb6570744737a12f7f639e40fd)

virtual bool AppendMesh(Node *mesh)=0