Sidebar

Home



Knowledge Base


Guides & Tutorials

Projects

Samples

kb:tutorials:advanced:use_3d_object_visualization_in_tng_software

Use 3D object visualization in TNG software

TNG software offers visualization/display of 3D models in the workspace area. 3D models can represent either workpiece, tool sensors, milling vise or even a CNC machine. User is able to create fully movable 3D model that recreates his exact machine and simulates machine movement.

Example of a 3D model of generic desktop CNC machine:

How to start

TNG uses dedicated file which contains the 3D model configuration. File should be located in user profile root folder. It is recommended to use a dedicated folder.

In order to be recognized by the software, user needs to insert sub-folder path and filename in settings:

File/Settings/User Interface/3D/View -> Model

In this case, dedicated folder is located in user profile and named “3dObj” and filename is “small_cnc.txt”:


In order that visualization is enabled, make sure that “Model” option is enabled under View/Show:

3D configuration file

As mentioned at the beginning, entire 3D model visualization is stored and configured within a main XML file.

Which means:

  • file needs XML declaration at the beginning: <?xml version=“1.0” encoding=“UTF-8”?>
  • use of XML elements, tags and attributes
  • structured hierarchy

NOTE: Main file can use dependency files, which can be external .stl files, or other 3D configuration XML files. But there can be only one main file.

Elements, tags and attributes

Bellow is the list of all elements and their attributes:

Model

Description


Expr

Description


Color

Description


Transform

Description


Assembly

Description


Items

Description


Part

Description


Include

Description


Mesh

Description


Cuboid

Description


Sphere

Description


Cylinder

Description


Poly

Description


Move

Description


MoveKin

Description


Example

Here is an example on how to create a complete 3D model of a simple CNC machine.

A 3D model of a CNC machine, much like its real-life counterpart, is composed of various parts. We need to create multiple parts so that a functional assembly is created.

To ensure clear assembly transparency and better file organization, each part will be represented by its own model file. Ultimately, a single CNC.txt file will compile all these individual part files.

To simplify development and testing of 3D object visualization, we recommend that users create a shortcut key for the “View/Show Model” feature. This allows users to quickly refresh the 3D view in the TNG software, making it easier to see changes made to the script code in real-time


Below is a table that describes the assembly and all sub assembly parts of the 3D model.

Main Assembly Sub-Assembly Sub-Assembly Part
3D CNC Spindle “Tool”
“Body”
“Axis X”
“Axis Y”
Table “Top”
“Front”
“Back”
Gantry “Left”
“Right”
“Back”
“Rail”
“Rail”
Carriage X “Block”
“Top”
“Bottom”
“Rail”
“Rail”
Carriage Z “Block”
“Arm”

Carriage Z should be part of the Carriage X assembly, but since this is a beginners tutorial and we wanted to avoid nesting this models structure, Carriage Z is its own sub-assembly.


3D CNC

CNC contains several assemblies. Spindle will be included as first one, other will be added later in this tutorial.

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Here we will include all machine parts -->
    </Items>
  </Assembly>
</Model>

Spindle

Spindle sub-assembly short description


Spindle has two cylinder objects. Main body and tool clamp. In addition, we will add X and Y axis indicators. They might be handy if this model is used in complex multi axis machine.

“Tool” cylinder has radius 3 and is 35mm long. It is positioned 10mm above zero to left room for TNG yellow tool cone.
“Body” cylinder has radius 27.5 and is 120mm long.
“Axis X and Y indicators” are on top of spindle body

“Spindle” assembly will move in X, Y and Z directions.

All object sizes are parametrized and are easily changed. Below is a table with parameter description:

prameter name parameter description
spnd_tool_rad tool cylinder radius
spnd_tool_size tool cylinder length
spnd_tool_bottom position at the bottom of tool cylinder. Value in example code is 10 because we want to make the yellow cone visible
spnd_body_rad spindle cylinder radius
spnd_body_size spindle cylinder length
spnd_body_bottom position at the bottom of spindle cylinder
spnd_body_top position at the top of spindle cylinder

Spindle.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
spnd_tool_rad = 3;
spnd_tool_size = 35;
spnd_tool_bottom = 10;
 
spnd_body_rad = 27.5;
spnd_body_size = 120;
spnd_body_bottom = spnd_tool_bottom + spnd_tool_size;
spnd_body_top = spnd_body_bottom + spnd_body_size;
  </Expr>
  <Assembly Name="Spindle">
    <Move X="1" Y="1" Z="1"/>
    <Items>
      <Part Name="Tool">
        <Color Value="fff5deb3"/>
        <Cylinder R1="spnd_tool_rad" R2="spnd_tool_rad" Size="spnd_tool_size" X="0" Y="0" Z="spnd_tool_bottom"/>
      </Part>	
      <Part Name="Body">
        <Color Value="fff5deb3"/>
        <Cylinder R1="spnd_body_rad" R2="spnd_body_rad" Size="spnd_body_size" X="0" Y="0" Z="spnd_body_bottom" />
      </Part>	
      <Part Name="AxisX">
        <Color Value="AxisX"/>
        <Cuboid X="0" Y="-2" Z="spnd_body_top-3" W="spnd_body_rad+0.5" L="4" H="4"/>
      </Part>	
      <Part Name="AxisY">
        <Color Value="AxisY"/>
        <Cuboid X="-2" Y="0" Z="spnd_body_top-3" W="4" L="spnd_body_rad+0.5" H="4"/>
      </Part>	
    </Items>
  </Assembly>
</Model>

Spindle added to CNC

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Spindle assembly -->
      <Assembly Name="Spindle">
        <Items>
          <Include Filename="Spindle.txt"/>
        </Items>
      </Assembly>
 
    </Items>
  </Assembly>
</Model>

Table

Table sub-assembly short description


Table has 3 cuboids, Table top, front and back panel.

Table assembly will not move. Its origin is at bottom left corner. It is positioned slightly below Z zero so that it will not interfere with other 4D objects drawn at Z zero. All CNC object will be shifted slightly so that table is at correct machine position.

Spindle.txt model created previously is included.

All sizes are parametrized and ere easily changed.

prameter name parameter description
table_sizex table width value
table_sizey table length value
table_thick thickness value of top, front and back panels
table_height front and back panel height value

Table.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
table_sizex = 240;
table_sizey = 440;
table_thick = 15;
table_height = 40;
  </Expr>
  <Assembly Name="Table">
    <Items>
      <Part Name="Top">
        <Color Value="ffaaaacc"/>
        <Cuboid X="0" Y="0" Z="-0.5" W="table_sizex" L="table_sizey" H="-table_thick"/>
      </Part>	
      <Part Name="Front">
        <Color Value="ff9999bb"/>
        <Cuboid X="0" Y="0" Z="-table_thick" W="table_sizex" L="table_thick" H="-table_height"/>
      </Part>
      <Part Name="Back">
        <Color Value="ff9999bb"/>
        <Cuboid X="0" Y="table_sizey" Z="-table_thick" W="table_sizex" L="-table_thick" H="-table_height"/>
      </Part>	
    </Items>
  </Assembly>
</Model>

Table added to CNC

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
offset_x = -35;
offset_y = -5;
  </Expr>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Spindle assembly -->
      <Assembly Name="Spindle">
        <Items>
          <Include Filename="Spindle.txt"/>
        </Items>
      </Assembly>
 
      <!-- Table assembly -->
      <Assembly Name="Table">
        <Transform X="offset_x" Y="offset_y"/>
        <Items>
          <Include Filename="Table.txt"/>
        </Items>
      </Assembly>
 
    </Items>
  </Assembly>
</Model>

Gantry

Gantry has two side polygons and back cuboid. In addition we'll draw two cylinders representing linear rails.

Gantry will move in Y direction.

Gantry.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
gantry_sizey = 100;
gantry_top = 180;
gantry_bottom = -table_thick - table_height/2;
gantry_gap = 24;
gantry_thick = 12;
gantry_posl = 0 - gantry_gap;
gantry_posr = table_sizex + gantry_gap;
gantry_sizex = table_sizex + 2*gantry_gap;
 
gantry_clear = 80;
gantry_rail_size = 8;
gantry_rail_posy = gantry_sizey - gantry_thick - 2*gantry_rail_size;
gantry_rail_posz1 = gantry_clear + 10;
gantry_rail_posz2 = gantry_top - 10;
  </Expr>
  <Assembly Name="Gantry">
    <Move Y="1"/>
    <Items>
      <Part Name="Left">
        <Color Value="ff8e6767"/>
        <Poly 
          X1="gantry_bottom" Y1="gantry_bottom" 
          X2="gantry_bottom + 0.3*gantry_top" Y2="gantry_bottom"
          X3="gantry_top" Y3="0.4*gantry_sizey"
          X4="gantry_top" Y4="gantry_sizey"
          X5="gantry_bottom" Y5="gantry_sizey"
          Reverse="false"
          Size="-gantry_thick " X="gantry_posl" Y="0" Z="0" RY="-90"/>
      </Part>	
 
      <Part Name="Right">
        <Color Value="ff8e6767"/>
        <Poly 
          X1="gantry_bottom" Y1="gantry_bottom" 
          X2="gantry_bottom + 0.3*gantry_top" Y2="gantry_bottom"
          X3="gantry_top" Y3="0.4*gantry_sizey"
          X4="gantry_top" Y4="gantry_sizey"
          X5="gantry_bottom" Y5="gantry_sizey"
          Reverse="false"
          Size="+gantry_thick" X="gantry_posr" Y="0" Z="0" RY="-90"/>
      </Part>
 
      <Part Name="Back">
        <Color Value="ff8e6767"/>
        <Cuboid X="-gantry_gap" Y="gantry_sizey" Z="gantry_clear" W="gantry_sizex" L="-gantry_thick" H="gantry_top - gantry_clear"/>
      </Part>
 
      <Part Name="Rail">
        <Color Value="ff008080"/>
        <Cylinder X="gantry_posl" Y="gantry_rail_posy" Z="gantry_rail_posz1" R1="gantry_rail_size" R2="gantry_rail_size" Size="gantry_sizex" RY="90"/>
      </Part>
 
      <Part Name="Rail">
        <Color Value="ff008080"/>
        <Cylinder X="gantry_posl" Y="gantry_rail_posy" Z="gantry_rail_posz2" R1="gantry_rail_size" R2="gantry_rail_size" Size="gantry_sizex" RY="90"/>
      </Part>
 
    </Items>
  </Assembly>
</Model>

Gantry added to CNC

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
offset_x = -35;
offset_y = -5;
offset_gantry_y = 22;
  </Expr>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Spindle assembly -->
      <Assembly Name="Spindle">
        <Items>
          <Include Filename="Spindle.txt"/>
        </Items>
      </Assembly>
 
      <!-- Table assembly -->
      <Assembly Name="Table">
        <Transform X="offset_x" Y="offset_y"/>
        <Items>
          <Include Filename="Table.txt"/>
        </Items>
      </Assembly>
 
      <!-- Gantry assembly -->
      <Assembly Name="Gantry">
        <Transform X="offset_x" Y="offset_y+offset_gantry_y"/>
        <Items>
          <Include Filename="Gantry.txt"/>
        </Items>
      </Assembly>
 
    </Items>
  </Assembly>
</Model>

Carriage X

Carriage X assembly slides in linear rails on gantry frame. It is simple cuboid with additional two cuboids for Z axis linear rail holders.

CarriageX.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
carriagex_sizex = 90;
carriagex_sizey = 30;
carriagex_sizez = 115;
 
carriagex_bot = gantry_clear;
carriagex_top = carriagex_bot + carriagex_sizez;
carriagex_posy = gantry_sizey - gantry_thick - 2;
 
carriagex_arm_posy = carriagex_posy-carriagex_sizey;
carriagex_arm_sizey = 30;
carriagex_arm_sizez = 10;
 
carriagex_rail_size = 6;
carriagex_rail_posy = carriagex_arm_posy - carriagex_arm_sizey/2;
carriagex_rail_offx = 1.5*carriagex_rail_size;
  </Expr>
  <Assembly Name="Carriage X">
    <Move X="1" Y="1"/>
	<Transform X="-carriagex_sizex/2"/>
    <Items>
      <Part Name="Block">
        <Color Value="ffaaaacc"/>
        <Cuboid X="0" Y="carriagex_posy" Z="carriagex_top" W="carriagex_sizex" L="-carriagex_sizey" H="-carriagex_sizez"/>
      </Part>
 
      <Part Name="Top">
        <Color Value="ff9999bb"/>
        <Cuboid X="0" Y="carriagex_arm_posy" Z="carriagex_top" W="carriagex_sizex" L="-carriagex_arm_sizey" H="-carriagex_arm_sizez"/>
      </Part>	
      <Part Name="Bottom">
        <Color Value="ff9999bb"/>
        <Cuboid X="0" Y="carriagex_arm_posy" Z="carriagex_bot" W="carriagex_sizex" L="-carriagex_arm_sizey" H="+carriagex_arm_sizez"/>
      </Part>
 
      <Part Name="Rail">
        <Color Value="ff008080"/>
        <Cylinder X="0+carriagex_rail_offx" Y="carriagex_rail_posy" Z="carriagex_top" R1="carriagex_rail_size" R2="carriagex_rail_size" Size="-carriagex_sizez"/>
      </Part>	
      <Part Name="Rail">
        <Color Value="ff008080"/>
        <Cylinder X="carriagex_sizex-carriagex_rail_offx" Y="carriagex_rail_posy" Z="carriagex_top" R1="carriagex_rail_size" R2="carriagex_rail_size" Size="-carriagex_sizez"/>
      </Part>
 
    </Items>
  </Assembly>
</Model>

Carriage X added to CNC

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
offset_x = -35;
offset_y = -5;
offset_gantry_y = 22;
  </Expr>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Spindle assembly -->
      <Assembly Name="Spindle">
        <Items>
          <Include Filename="Spindle.txt"/>
        </Items>
      </Assembly>
 
      <!-- Table assembly -->
      <Assembly Name="Table">
        <Transform X="offset_x" Y="offset_y"/>
        <Items>
          <Include Filename="Table.txt"/>
        </Items>
      </Assembly>
 
      <!-- Gantry assembly -->
      <Assembly Name="Gantry">
        <Transform X="offset_x" Y="offset_y+offset_gantry_y"/>
        <Items>
          <Include Filename="Gantry.txt"/>
        </Items>
      </Assembly>
 
      <!-- Carriage X assembly -->
      <Assembly Name="CarriageX">
        <Transform Y="offset_y+offset_gantry_y"/>
        <Items>
          <Include Filename="CarriageX.txt"/>
        </Items>
      </Assembly>
 
    </Items>
  </Assembly>
</Model>

Carriage Z

CarriageZ.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
carriagez_sizex = carriagex_sizex;
carriagez_sizez = 30;
carriagez_sizey = 32;
 
carriagez_posy = carriagex_arm_posy;
carriagez_posz = carriagex_bot + carriagex_arm_sizez + 1;
 
carriagez_arm_sizez = 80;
carriagez_arm_sizey = 10;
carriagez_arm_posy = carriagez_posy - carriagez_sizey;
carriagez_arm_posz = carriagez_posz + carriagez_sizez;
  </Expr>
  <Assembly Name="Carriage Z">
    <Move X="1" Y="1" Z="1"/>
	<Transform X="-carriagez_sizex/2"/>
    <Items>
      <Part Name="Block">
        <Color Value="ff9999bb"/>
        <Cuboid X="0" Y="carriagez_posy" Z="carriagez_posz" W="carriagez_sizex" L="-carriagez_sizey" H="carriagez_sizez"/>
      </Part>
 
	  <Part Name="Arm">
        <Color Value="ffaaaacc"/>
        <Cuboid X="0" Y="carriagez_arm_posy" Z="carriagez_arm_posz" W="carriagez_sizex" L="-carriagez_arm_sizey" H="-carriagez_arm_sizez"/>
      </Part>
 
    </Items>
  </Assembly>
</Model>

Carriage Z added to CNC

CNC.txt
<?xml version="1.0" encoding="UTF-8"?>
<Model>
  <Expr>
offset_x = -35;
offset_y = -5;
offset_gantry_y = 22;
offset_gantry_z = 5;
  </Expr>
  <!-- Main 'model' assembly -->
  <Assembly>
    <Items>
      <!-- Spindle assembly -->
      <Assembly Name="Spindle">
        <Items>
          <Include Filename="Spindle.txt"/>
        </Items>
      </Assembly>
 
      <!-- Table assembly -->
      <Assembly Name="Table">
        <Transform X="offset_x" Y="offset_y"/>
        <Items>
          <Include Filename="Table.txt"/>
        </Items>
      </Assembly>
 
      <!-- Gantry assembly -->
      <Assembly Name="Gantry">
        <Transform X="offset_x" Y="offset_y+offset_gantry_y"/>
        <Items>
          <Include Filename="Gantry.txt"/>
        </Items>
      </Assembly>
 
      <!-- Carriage X assembly -->
      <Assembly Name="CarriageX">
        <Transform Y="offset_y+offset_gantry_y"/>
        <Items>
          <Include Filename="CarriageX.txt"/>
        </Items>
      </Assembly>
 
      <!-- Carriage Z assembly -->
      <Assembly Name="CarriageZ">
        <Transform Y="offset_y+offset_gantry_y" Z="offset_gantry_z"/>
        <Items>
          <Include Filename="CarriageZ.txt"/>
        </Items>
      </Assembly>
 
    </Items>
  </Assembly>
</Model>
kb/tutorials/advanced/use_3d_object_visualization_in_tng_software.txt · Last modified: 2024/10/10 10:56 by andrej

Page Tools