    

 ## On this page

  

 

 # Test011

 Last update: 16.07.2025 

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). &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 &lt;cmath&gt;

\#ifdef \_WIN32

\#include &lt;codecvt&gt;

\#endif

 

\#include "GLTFWriter.h"

\#include "test.h"

 

using namespace ANSYS::Nexus;

 

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)

{

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

 if (!gltf)

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

 

 // SCENE

 GLTFWriter::Scene *scene = <a id="a1" name="a1"></a>[GLTFWriter::Scene::Create](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#aac8bcb85d4361abba99053b3c56eb08b)(gltf, "TestScene", "m", 1.0, <a id="a2" name="a2"></a>[GLTFWriter::Scene::BT\_SOLID](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#ac17baf491cdba3613b0aa39719a3dbd8aeea551002921bb989b3ed35678ec982b), 0.5, 0.5, 0.5);

 if (!scene) {

 <a id="a3" name="a3"></a>[GLTFWriter::GLTF::Destroy](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a586171eb8e873e909db02a7eb4d80f5c)(gltf);

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

 }

 

 // MARKUP TITLE

 scene-&gt;Add2DText(gltf, "3D BOX", 0.5F, 0.1F, <a id="a4" name="a4"></a>[GLTFWriter::Markup::MTAT\_N](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#af00d39b7f1008aee7b1f4f56aee12c86a0dc439e663154f063b696b31f675ee13)); // 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;Add3DText(gltf, ConvertToUtf8String(L"Ḉὀrṉḝr").c_str(), 0.5, 0.5, 0.5, <a id="a5" name="a5"></a>[GLTFWriter::Markup::MTAT\_AUTO](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#af00d39b7f1008aee7b1f4f56aee12c86a00c009bc6c57ab36d9f3b0ed458bb5af),

\#else

 scene-&gt;Add3DText(gltf, "Corner", 0.5, 0.5, 0.5, [GLTFWriter::Markup::MTAT\_AUTO](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#af00d39b7f1008aee7b1f4f56aee12c86a00c009bc6c57ab36d9f3b0ed458bb5af),

\#endif

 12, "serif", 25, -25, <a id="a6" name="a6"></a>[GLTFWriter::Markup::MLT\_ARROW](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#ad50873251725f3a325ca393a84ac7bc8aa2935ff21215eb94b6522d1d3167fd4d));

 

 // 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

 GLTFWriter::Mesh *mesh = <a id="a7" name="a7"></a>[GLTFWriter::Mesh::Create](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml#a9f7803b1b1eb72e4005665ca33f42788)(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="a8" name="a8"></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;Write()) {

 GLTFWriter::GLTF::Destroy(gltf);

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

 }

 

 <a id="a9" name="a9"></a>[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;GetError();

 

 [GLTFWriter::GLTF::Destroy](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#a586171eb8e873e909db02a7eb4d80f5c)(gltf);

 

 if (error != <a id="a10" name="a10"></a>[GLTFWriter::GLTF::GLTF\_ERROR\_NONE](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#acf83a4d185d959503cb9f3f2c2e9fafea049c3b804e69ae05c02f4c2dedf4e0ea))

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

}

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

static void Destroy(GLTF *gltf)



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

static GLTF * Create(const char *application, const char *applicationVersion, const char *filePath, OutputType fileType=OT_AVZ)



[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::GLTF::GLTF\_ERROR\_NONE](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_g_l_t_f.xhtml#acf83a4d185d959503cb9f3f2c2e9fafea049c3b804e69ae05c02f4c2dedf4e0ea)

@ GLTF_ERROR_NONE

No Error.

**Definition:** [GLTFGLTF.h:36](_g_l_t_f_g_l_t_f_8h_source.xhtml#l00036)



[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::Mesh::Create](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_mesh.xhtml#a9f7803b1b1eb72e4005665ca33f42788)

static Mesh * Create(GLTF *gltf)



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

static Scene * Create(GLTF *gltf, const char *name=0, const char *units=0, float scale=1, Scene::BackgroundType backgroundType=Scene::BT_NONE, float r1=0, float g1=0, float b1=0, float r2=0, float g2=0, float b2=0)



[ANSYS::Nexus::GLTFWriter::Scene::BT\_SOLID](class_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_scene.xhtml#ac17baf491cdba3613b0aa39719a3dbd8aeea551002921bb989b3ed35678ec982b)

@ BT_SOLID

Make solid color from color 1.

**Definition:** [GLTFScene.h:35](_g_l_t_f_scene_8h_source.xhtml#l00035)



[ANSYS::Nexus::GLTFWriter::Markup::MLT\_ARROW](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#ad50873251725f3a325ca393a84ac7bc8aa2935ff21215eb94b6522d1d3167fd4d)

@ MLT_ARROW

Arrow.

**Definition:** [GLTFMarkup.h:26](_g_l_t_f_markup_8h_source.xhtml#l00026)



[ANSYS::Nexus::GLTFWriter::Markup::MTAT\_AUTO](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#af00d39b7f1008aee7b1f4f56aee12c86a00c009bc6c57ab36d9f3b0ed458bb5af)

@ MTAT_AUTO

Label is automatically positioned relative to x,y.

**Definition:** [GLTFMarkup.h:32](_g_l_t_f_markup_8h_source.xhtml#l00032)



[ANSYS::Nexus::GLTFWriter::Markup::MTAT\_N](namespace_a_n_s_y_s_1_1_nexus_1_1_g_l_t_f_writer_1_1_markup.xhtml#af00d39b7f1008aee7b1f4f56aee12c86a0dc439e663154f063b696b31f675ee13)

@ MTAT_N

Label is centered about x, and below y.

**Definition:** [GLTFMarkup.h:34](_g_l_t_f_markup_8h_source.xhtml#l00034)