1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
namespace Visu3D
{
public partial class Visu3D_Controls : Grid
{
GeometryModel3D geo_cube = new GeometryModel3D();
int longueur;
int largeur;
int hauteur;
public void SetValue (int h_longueur, int h_largeur, int h_hauteur)
{
longueur = h_longueur;
largeur = h_largeur;
hauteur = h_hauteur;
}
/******************************************* PARAMETRAGE DU CARTON *******************************************/
private MeshGeometry3D MeshCube()
{
MeshGeometry3D mesh = new MeshGeometry3D();
Point3DCollection corners = new Point3DCollection();
Int32Collection TrianglesCollec = new Int32Collection();
corners.Add(new Point3D(longueur, hauteur, largeur));
corners.Add(new Point3D(0, hauteur, largeur));
corners.Add(new Point3D(0, 0, largeur));
corners.Add(new Point3D(longueur, 0, largeur));
corners.Add(new Point3D(longueur, hauteur, 0));
corners.Add(new Point3D(0, hauteur, 0));
corners.Add(new Point3D(0, 0, 0));
corners.Add(new Point3D(longueur, 0, 0));
mesh.Positions = corners;
mesh.TextureCoordinates.Add(new Point(1, 0));
mesh.TextureCoordinates.Add(new Point(0, 0));
mesh.TextureCoordinates.Add(new Point(0, 1));
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(0, 0));
mesh.TextureCoordinates.Add(new Point(1, 0));
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(0, 1));
mesh.TextureCoordinates.Add(new Point(1, 0));
mesh.TextureCoordinates.Add(new Point(0, 0));
mesh.TextureCoordinates.Add(new Point(0, 1));
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(0, 0));
mesh.TextureCoordinates.Add(new Point(1, 0));
mesh.TextureCoordinates.Add(new Point(1, 1));
mesh.TextureCoordinates.Add(new Point(0, 1));
Int32[] indices ={
//Front
0,1,2,
0,2,3,
//Back
4,7,6,
4,6,5,
//Right
4,0,3,
4,3,7,
//Left
1,5,6,
1,6,2,
//Top
1,0,4,
1,4,5,
//Bottom
2,6,7,
2,7,3
};
foreach (Int32 index in indices)
{
TrianglesCollec.Add(index);
}
mesh.TriangleIndices = TrianglesCollec;
return mesh;
}
/******************************************* ASSEMBLAGE ET AFFICHAGE DU CARTON *******************************************/
private void Carton_Click(object sender, RoutedEventArgs e)
{
MeshGeometry3D cubeMesh = MeshCube();
geo_cube.Geometry = cubeMesh;
geo_cube.Material = new DiffuseMaterial(new SolidColorBrush(Colors.Red));
ModelVisual3D carton = new ModelVisual3D();
carton.Content = geo_cube;
this.cubeView3D.Children.Add(carton);
}
}
} |
Partager