    

 ## On this page

  

 

 # Test011

 Last update: 16.07.2025 

 /// &lt;script src="./ansys251/nexus/viewer-loader.js"&gt;&lt;/script&gt; /// ///

Markup.

This example demonstrates the two different types of markups, 2D and 3D.

2D markups are positioned in the scene by viewport coordinates. Viewport coordinates range from 0 to 1 from left to right and top to bottom. In addition to the viewport location, you can specify how the text string is anchored to the viewport location. The 2D markup in this example locates the markup at 0.5,0.1 and the anchor at N. This means that the text is centered in the XY direction and the top of the text is at 0.1 from the top of the window.

3D markups are positioned in object space coordinates, and require and XYZ location. The anchor works as in the 2D case. The 3D markup can be positioned relative to the object location in pixels. A line is drawn from the offset location to the object location. If a path is provided with the markup, the markup can be transformed with the object. The path is simply the nodeIDs of all nodes from the topmost node, to the node that the markup is attached to, concatenated and separated by ';' (as in Node1;Node2;NodeWithMarkup).

/\*

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

\#ifdef \_WIN32

\#include &lt;codecvt&gt;

\#endif

 

\#include "GLTFWriter.h"

\#include "test.h"

 

using namespace ANSYS::AVZ;

 

namespace {

\#ifdef \_WIN32

 std::string 

 ConvertToUtf8String(const std::wstring&amp; wstr)

 {

 std::wstring_convert&lt;std::codecvt_utf8&lt;wchar_t&gt;&gt; myconv;

 return myconv.to_bytes(wstr);

 }

\#endif

};

 

// Markup

TESTFUNC(Markup)

{

 <a id="_a0" name="_a0"></a>[GLTFWriter::GLTF](class_a_n_s_y_s_1_1_a_v_z_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_a_v_z_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");

 }

 

 // MARKUP TITLE

 scene-&gt;<a id="a2" name="a2"></a>[Add2DText](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_scene.xhtml#a4d7cac02889c439d22def05a361dab49)(gltf, "3D BOX", 0.5F, 0.1F, GLTFWriter::Markup::MTAT_N); // MTAT\_N -&gt; centered in horizontal, top is 0.1 down

 // because we are making a box that is centered at 0,0,0 with dimensions 1,1,1 the corners are at 0.5,0.5,0.5, ...

 // MARKUP OBJECT

\#ifdef \_WIN32

 scene-&gt;<a id="a3" name="a3"></a>[Add3DText](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_scene.xhtml#a4d9685d84f8b3fed30f4c2362fb39d66)(gltf, ConvertToUtf8String(L"Ḉὀrṉḝr").c_str(), 0.5, 0.5, 0.5, GLTFWriter::Markup::MTAT_AUTO,

\#else

 scene-&gt;[Add3DText](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_scene.xhtml#a4d9685d84f8b3fed30f4c2362fb39d66)(gltf, "Corner", 0.5, 0.5, 0.5, GLTFWriter::Markup::MTAT_AUTO,

\#endif

 12, "serif", 25, -25, GLTFWriter::Markup::MLT_ARROW);

 

 // MESH NODE

 {

 // NODE

 GLTFWriter::Node *node = GLTFWriter::Node::CreateMesh(gltf, "3D Box");

 if (!node || !scene-&gt;AppendMesh(node)) {

 GLTFWriter::GLTF::Destroy(gltf);

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

 }

 

 // MESH

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

 if (!mesh || !node-&gt;AppendMesh(mesh)) {

 GLTFWriter::GLTF::Destroy(gltf);

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

 }

 

 // create box centered at 0,0,0 with dimensions 1,1,1 

 GLTFWriter::Test::PrimMat pm = GLTFWriter::Test::CreateColoredBoxPrimitive(gltf, 0, 0, 0, 1, 1, 1);

 mesh-&gt;<a id="a5" name="a5"></a>[AppendPrimitive](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_mesh.xhtml#afb99ec25e2eebb4390c17f8770e4c23b)(pm.first);

 }

 

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

 GLTFWriter::GLTF::Destroy(gltf);

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

 }

 

 [GLTFWriter::GLTF::GLTFError](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a5b8141dc8536bc10d1a72996ad6f98b4) error = gltf-&gt;<a id="a7" name="a7"></a>[GetError](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a63295f8f31619517e94cf27d3a8b9ea8)();

 

 GLTFWriter::GLTF::Destroy(gltf);

 

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

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

}

[ANSYS::AVZ::GLTFWriter::GLTF](class_a_n_s_y_s_1_1_a_v_z_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::AVZ::GLTFWriter::GLTF::Write](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a0bf3a4ec615dc8810776dd82a65eba91)

virtual bool Write(bool formatJSON=false)=0



[ANSYS::AVZ::GLTFWriter::GLTF::GLTFError](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a5b8141dc8536bc10d1a72996ad6f98b4)

GLTFError

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



[ANSYS::AVZ::GLTFWriter::GLTF::GetError](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a63295f8f31619517e94cf27d3a8b9ea8)

virtual GLTFError GetError()=0



[ANSYS::AVZ::GLTFWriter::Mesh](class_a_n_s_y_s_1_1_a_v_z_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::AVZ::GLTFWriter::Mesh::AppendPrimitive](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_mesh.xhtml#afb99ec25e2eebb4390c17f8770e4c23b)

virtual bool AppendPrimitive(Primitive *primitive)=0



[ANSYS::AVZ::GLTFWriter::Scene](class_a_n_s_y_s_1_1_a_v_z_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::AVZ::GLTFWriter::Scene::Add2DText](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_scene.xhtml#a4d7cac02889c439d22def05a361dab49)

virtual bool Add2DText(GLTF *gltf, const char *text, float x, float y, Markup::MarkupTextAttachmentType textAttach=Markup::MTAT_CENTER, float textSize=20, const char *textFont=0, float textR=0, float textG=0, float textB=0, float bgR=1, float bgG=1, float bgB=1, float bgA=0, const char *path=0)=0



[ANSYS::AVZ::GLTFWriter::Scene::Add3DText](class_a_n_s_y_s_1_1_a_v_z_1_1_g_l_t_f_writer_1_1_scene.xhtml#a4d9685d84f8b3fed30f4c2362fb39d66)

virtual bool Add3DText(GLTF *gltf, const char *text, float x, float y, float z, Markup::MarkupTextAttachmentType textAttach=Markup::MTAT_AUTO, float textSize=12, const char *textFont=0, float textOffX=0, float textOffY=0, Markup::MarkupLineType lineShape=Markup::MLT_LINE, float lineR=0, float lineG=0, float lineB=0, float textR=0, float textG=0, float textB=0, float bgR=1, float bgG=1, float bgB=1, float bgA=0.5, const char *path=0)=0