Eyeshot provides four texture mapping types: Plate, Cubic, Cylindrical, and Spherical. In order to apply a texture on a shaped mesh, try rearranging the texture coordinates like in this sample.
Source code:
const string matName = "Bricks";
// Creates and adds a material
Material mat = new Material(matName, new Bitmap("c:\\devdept\\bricks.jpg").ToByteArray()) {
Environment = 0,
Specular = Color.Black
};
design1.Materials.Add(mat);
// Defines some variables
const int slices = 16;
const double tol = 0.1;
const double radius = 10;
const double bendRadius = 20;
// Creates a revolved Mesh
Circle c1 = new Circle(Plane.ZX, radius);
c1.Reverse();
Mesh mesh = c1.RevolveAsMesh(0, devDept.Geometry.Utility.DegToRad(90), Vector3D.AxisX, new Point3D(0, 0, bendRadius), slices, tol, Mesh.natureType.ColorSmooth);
// Adds whatsoever mapping
mesh.ApplyMaterial(matName, textureMappingType.Cubic, 1, 1);
int offset = devDept.Geometry.Utility.NumberOfSegments(radius, devDept.Geometry.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
design1.Entities.Add(mesh);
Some useful debugging flags:
design1.Rendered.ShowInternalWires = true;
design1.ActiveViewport.ShowVertexIndices = true;
Info
The RevolveAsMesh() method returns unique vertices, that's the reason why the resulting mesh has a small defect along the seam curve. For a perfect result, you can build your own revolve method that does not clear duplicated vertices.
FastMesh
Code adaptation for FastMesh class:
FastMesh fm = mesh.ConvertToFastMesh();
fm.MaterialName = matName;
fm.TextureCoordsArray = new float[mesh.Vertices.Length * 2];
int count = 0;
for (int j = 0; j < slices + 1; j++)
{
for (int i = 0; i < offset; i++)
{
fm.TextureCoordsArray[count] = (float)i / (offset - 1);
count++;
fm.TextureCoordsArray[count] = (float)j / slices;
count++;
}
}
design1.Entities.Add(fm);
Comments
Please sign in to leave a comment.