AMCAX Kernel 1.0.0.0
A T-Mesh Spline Modeling Sample

Overview

This tutorial provides the basic usage of using T-Mesh Spline modeling. It is Similar to subdivision modeling, also starts with creating a primitive and generates a result surface through stretching, transformation, subdivision, etc.

Construction of primitive shapes

The module supports the construction of various primitive geometries, for example, makeing a cube with a side length of 3 and dividing 2 segments in each direction. The code is as follows.

AMCAX::TMS::TMSplineMakeCube makeCube(frame, 3, 3, 3, 2, 2, 2);
AMCAX::TMS::TMSpline* tsp = makeCube.BuildSpline();
Class of TMSpline structure The Low Level API functions are not exported for this version.
Definition: TMSpline.hpp:30
Class of TMSpline API for make a cube.
Definition: TMSplineMakeCube.hpp:15

You can also use the MeshMakeCone to construct a frustum with a base radius of 4, an upper radius of 2, and a height of 4. By default, it is divided into 8 segments along the rotation direction and 4 segments along the height direction

AMCAX::TMS::TMSplineMakeCone makeCone(frame, r1, r2, h);
AMCAX::TMS::TMSpline* tsp = makeCone.BuildSpline();
Class of TMSpline API for make a cone.
Definition: TMSplineMakeCone.hpp:16

Build a vortex model

Model Preview

This tutorial uses a simple vortex model to show some of the main modeling functions in the T-Mesh Spline modeling module The model is shown in the figure below:

The vortex model

Using namespace

using namespace AMCAX;
using namespace TMS;
Namespace of all interface in the AMCAX kernel.
Definition: misc.docu:8

Build Bottom faces

Start by constructing a plane.

Frame3 frame;
TMSplineMakeRectangle mkRect(frame, 3, 3, 3, 3);
TMSpline* tsp = mkRect.BuildSpline();
FrameT< double, 3 > Frame3
3D frame
Definition: FrameT.hpp:841

Click here example1 to get the complete source code for the above example, which you can download according to your learning needs.

Extrude faces and apply transformations

Extrude the middle face to form a peak. Only change the topology, the new result is coincide the old result, and use MeshTransform to move the new result

TMSplineExtrude extrude;
std::vector<int> face_id = {4};
std::vector<int> face_id_new;
if (extrude.CanExtrudeFaces(tsp, face_id))
{
extrude.ExtrudeFaces(tsp, face_id, face_id_new);
}

Apply translation and rotation transformations to the newly generated faces. Unlike subdivision modules, post-processing is required after transformation.

Vector3 vh(frame.Direction().Coord() * h);
TMSplineTransform trsfF;
Transformation3 trsfMove;
trsfMove.SetTranslation(vh);
trsfF.SetTransformation(trsfMove);
trsfF.TransformTMSplineFaces(tsp, face_id_new);
trsfRot.SetRotation(Axis3(Point3(1.5, 1.5, 0.), Direction3(0., 0., 1.)), M_PI / 4);
trsfF.SetTransformation(trsfRot);
trsfF.TransformTMSplineFaces(tsp, face_id_new);
trsfF.TransformReprocessing(tsp);
void SetTranslation(const VectorT< OtherScalar, DIM > &vec)
Set the transformation as the translation.
Definition: TransformationT.hpp:311
void SetRotation(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &angle)
Set the transformation as rotation around a point with an angle in 2D.
Definition: TransformationT.hpp:138
VectorT< double, 3 > Vector3
3D vector
Definition: VectorT.hpp:698
AxisT< double, 3 > Axis3
3D axis
Definition: AxisT.hpp:423
PointT< double, 3 > Point3
3D point
Definition: PointT.hpp:459
DirectionT< double, 3 > Direction3
3D direction
Definition: DirectionT.hpp:569
TransformationT< double, 3 > Transformation3
3D transformation
Definition: TransformationT.hpp:1054

Click here example2 to get the complete source code for the above example, which you can download according to your learning needs.

Delete top face

TMSpelineReduce provides tools for simplifying meshes such as deleting faces, the remove method will not leave any holes

TMSplineReduce reduce;
reduce.DeleteFaces(tsp, face_id_new);

Click here example3 to get the complete source code for the above example, which you can download according to your learning needs.

Extrude edges and apply transformations

Extrude the edges left by the deleted face towards all sides to construct a new top faces.

std::vector<int> edgeid;
std::vector<int> edge_id_new;
for (int i = 0; i < tsp->numEdges(); ++i)
{
if (TMSplineCheck::IsEdgeBoundary(tsp, i))
{
int v0, v1;
TMSplineTool::EdgeVertexIndexs(tsp, i, v0, v1);
Point3 pv0 = TMSplineTool::ControlPosition(tsp, v0);
Point3 pv1 = TMSplineTool::ControlPosition(tsp, v1);
if (pv0.Z() > 0.9 * h && pv1.Z() > 0.9 * h)
{
edgeid.push_back(i);
}
}
}
extrude.CanExtrudeEdges(tsp, edgeid);
extrude.ExtrudeEdges(tsp, edgeid, edge_id_new);
TMSplineTransform trsfE;
Transformation3 trsfScale;
trsfScale.SetScale(Point3(1.5, 1.5, h), 3);
trsfE.SetTransformation(trsfScale);
trsfE.TransformTMSplineEdges(tsp, edge_id_new);
trsfE.TransformReprocessing(tsp);
void SetScale(const PointT< OtherScalar, DIM > &point, const OtherScalar2 &s)
Set the transformation as the scaling from a point.
Definition: TransformationT.hpp:224

Click here example4 to get the complete source code for the above example, which you can download according to your learning needs.

Perform thickening

Thicken the shape to construct a solid.

TMSplineThicken mkThick;
mkThick.ThickenTMSplins(tsp, 0.2);

Click here example5 to get the complete source code for the above example, which you can download according to your learning needs.

Set crease edge features

You can select some edges to set as crease features. The crease feature will be retained during the face or edge split.

std::vector<int> edgeidC;
for (int i = 0; i < tsp->numEdges(); ++i)
{
int v0, v1;
TMSplineTool::EdgeVertexIndexs(tsp, i, v0, v1);
Point3 pv0 = TMSplineTool::ControlPosition(tsp, v0);
Point3 pv1 = TMSplineTool::ControlPosition(tsp, v1);
if (pv0.Z() < 0.1 && pv1.Z() < 0.1)
{
edgeidC.push_back(i);
}
}
TMSplineCreaseTool crease;
crease.AddCreaseEdge(tsp, edgeidC);

Click here example6 to get the complete source code for the above example, which you can download according to your learning needs.

Apply face split

Perform 1-4 split on all faces of the object. Similar to subdivision modeling, Split loop edges are also supported.

TMSplineSplit split;
face_id.resize(tsp->numFaces());
for (int i = 0; i < face_id.size(); ++i)
{
face_id[i] = i;
}
split.SplitFacesCross(tsp, face_id);

Do Meshing

Convert the resulting surface to a triangular mesh representation. The larger the incoming number, the higher the approximation level.

TMSplineMeshing tspMesh(tsp, 4);
tspMesh.UpdateDrawMesh();

Save Mesh

This module provides the option to save result as OBJ files

TMSplineMeshingIO meshIO;
std::string fileNameOBJ = "sampleResult.obj";
meshIO.ExportToOBJ(fileNameOBJ, tspMesh.GetDrawMesh());

Click here example7 to obtain the complete source code of the T grid spline modeling example, you can download it according to your learning needs.

Appendix

The complete code of this sample is listed here:

void MakeTornado()
{
double h = 2;
Frame3 frame;
TMSplineMakeRectangle mkRect(frame, 3, 3, 3, 3);
TMSpline* tsp = mkRect.BuildSpline();
TMSplineExtrude extrude;
std::vector<int> face_id = {4};
std::vector<int> face_id_new;
if (extrude.CanExtrudeFaces(tsp, face_id))
{
extrude.ExtrudeFaces(tsp, face_id, face_id_new);
}
Vector3 vh(frame.Direction().Coord() * h);
TMSplineTransform trsfF;
Transformation3 trsfMove;
trsfMove.SetTranslation(vh);
trsfF.SetTransformation(trsfMove);
trsfF.TransformTMSplineFaces(tsp, face_id_new);
Transformation3 trsfRot;
trsfRot.SetRotation(Axis3(Point3(1.5, 1.5, 0.), Direction3(0., 0., 1.)), M_PI / 4);
trsfF.SetTransformation(trsfRot);
trsfF.TransformTMSplineFaces(tsp, face_id_new);
trsfF.TransformReprocessing(tsp);
TMSplineReduce reduce;
reduce.DeleteFaces(tsp, face_id_new);
std::vector<int> edgeid;
std::vector<int> edge_id_new;
for (int i = 0; i < tsp->numEdges(); ++i)
{
if (TMSplineCheck::IsEdgeBoundary(tsp, i))
{
int v0, v1;
TMSplineTool::EdgeVertexIndexs(tsp, i, v0, v1);
Point3 pv0 = TMSplineTool::ControlPosition(tsp, v0);
Point3 pv1 = TMSplineTool::ControlPosition(tsp, v1);
if (pv0.Z() > 0.9 * h && pv1.Z() > 0.9 * h)
{
edgeid.push_back(i);
}
}
}
extrude.CanExtrudeEdges(tsp, edgeid);
extrude.ExtrudeEdges(tsp, edgeid, edge_id_new);
TMSplineTransform trsfE;
Transformation3 trsfScale;
trsfScale.SetScale(Point3(1.5, 1.5, h), 3);
trsfE.SetTransformation(trsfScale);
trsfE.TransformTMSplineEdges(tsp, edge_id_new);
trsfE.TransformReprocessing(tsp);
TMSplineThicken mkThick;
mkThick.ThickenTMSplins(tsp, 0.2);
std::vector<int> edgeidC;
for (int i = 0; i < tsp->numEdges(); ++i)
{
int v0, v1;
TMSplineTool::EdgeVertexIndexs(tsp, i, v0, v1);
Point3 pv0 = TMSplineTool::ControlPosition(tsp, v0);
Point3 pv1 = TMSplineTool::ControlPosition(tsp, v1);
if (pv0.Z() < 0.1 && pv1.Z() < 0.1)
{
edgeidC.push_back(i);
}
}
TMSplineCreaseTool crease;
crease.AddCreaseEdge(tsp, edgeidC);
TMSplineSplit split;
face_id.resize(tsp->numFaces());
for (int i = 0; i < face_id.size(); ++i)
{
face_id[i] = i;
}
split.SplitFacesCross(tsp, face_id);
TMSplineMeshing tspMesh(tsp, 4);
tspMesh.UpdateDrawMesh();
TMSplineMeshingIO meshIO;
std::string fileNameOBJ = "sampleResult.obj";
meshIO.ExportToOBJ(fileNameOBJ, tspMesh.GetDrawMesh());
delete tsp;
}