Mesh Custom Texture Mapping

Eyeshot has four texture mapping types: Plate, Cubic, Cylindrical and Spherical. In order to apply a texture on a custom mesh, try rearranging the texture coordinates like in this example.

CustomMeshBrickTexture.png

Source code:

// creates and adds material
Material mat = new Material(bricks.jpg);
viewportLayout1.Materials.Add("Bricks", mat);

// defines some variables
int slices = 16;
double tol = 0.1;
double radius = 10;
double bendRadius = 20;

// creates Mesh
Circle c1 = new Circle(Plane.ZX, radius);
Mesh mesh = c1.RevolveAsMesh(0, Utility.DegToRad(90), Vector3D.AxisX, new Point3D(0, 0, bendRadius), slices, tol, Mesh.natureType.ColorSmooth);
// adds whatsoever mapping
mesh.ApplyMaterial("Bricks", textureMappingType.Cubic, 1, 1);
int offset = Utility.NumberOfSegments(radius, Utility.TWO_PI, tol);
// adjusts texture coordinates generated above
for (int j = 0; j < slices + 1; j++)
{
   for (int i = 0; i < offset; i++)
   {
       mesh.TextureCoords[i + j * offset] = new PointF((float)i / (offset - 1), (float)j / slices);
   }
}
// adjusts triangle texture indices
for (int i = 0; i < mesh.Triangles.Length; i += 2)
{
   RichSmoothTriangle rst1 = (RichSmoothTriangle)mesh.Triangles[i];
   rst1.T1 = i / 2;
   rst1.T3 = i / 2 + 1;
   rst1.T2 = i / 2 + 1 + offset;
   RichSmoothTriangle rst2 = (RichSmoothTriangle)mesh.Triangles[i + 1];
   rst2.T1 = i / 2;
   rst2.T3 = i / 2 + 1 + offset;
   rst2.T2 = i / 2 + offset;
}
// adds the mesh to the scene
viewportLayout1.Entities.Add(mesh);

// some useful flags during debugging
// viewportLayout1.Rendered.ShowInternalWires = true;
// viewportLayout1.ShowVertexIndices = true;
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.