Skip to main content

Post-processing tools 2025 R1

Test011

Last update: 16.07.2025

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

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 <vector>
#include <cmath>
#ifdef _WIN32
#include <codecvt>
#endif
#include "GLTFWriter.h"
#include "test.h"
using namespace ANSYS::AVZ;
namespace {
#ifdef _WIN32
std::string
ConvertToUtf8String(const std::wstring& wstr)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.to_bytes(wstr);
}
#endif
};
// Markup
TESTFUNC(Markup)
{
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");
}
// MARKUP TITLE
scene->Add2DText(gltf, "3D BOX", 0.5F, 0.1F, GLTFWriter::Markup::MTAT_N); // MTAT_N -> 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->Add3DText(gltf, ConvertToUtf8String(L"Ḉὀrṉḝr").c_str(), 0.5, 0.5, 0.5, GLTFWriter::Markup::MTAT_AUTO,
#else
scene->Add3DText(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->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");
}
// 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->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");
}
This is the main class of the GLTFWriter.
Definition GLTFGLTF.h:32
virtual bool Write(bool formatJSON=false)=0
virtual GLTFError GetError()=0
Meshes define the renderable objects that can be added to a node.
Definition GLTFMesh.h:104
virtual bool AppendPrimitive(Primitive *primitive)=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 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
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

Connect with Ansys