03-08-2024, 06:35 AM
(This post was last modified: 03-08-2024, 06:36 AM by kanta8819@cadian.com.)
I read the data using Reader3DS and wrote the code below, but something went wrong and the basic shape came out fine, but the triangular face came out broken.
help
for (int i = 0; i < model3D.Children.Count; i++)
{
switch (model3D.Children[i].GetType().Name)
{
case "GeometryModel3D":
foreach (var item in ((model3D.Children[i] as GeometryModel3D).Geometry as MeshGeometry3D).Positions)
{
double x = item.X; double y = item.Y; double z = item.Z;
mesh.Positions.Add(new Point3D(x, y, z));
}
foreach (int item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).TriangleIndices)
{
mesh.TriangleIndices.Add(item);
//double x = item.X; double y = item.Y; double z = item.Z;
//mesh.Positions.Add(new Point3D(x, y, z));
}
foreach (var item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).Normals)
{
double x = item.X; double y = item.Y; double z = item.Z;
mesh.Normals.Add(new System.Windows.Media.Media3D.Vector3D(x, y, z));
}
foreach (var item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).TextureCoordinates)
{
double x = item.X; double y = item.Y;
mesh.TextureCoordinates.Add(new Point(x, y));
}
gmodel.Material = ((GeometryModel3D)model3D.Children[i]).Material;
gmodel.Geometry = mesh;
break;
case "Model3DGroup":
break;
default:
break;
}
}
thank you
help
for (int i = 0; i < model3D.Children.Count; i++)
{
switch (model3D.Children[i].GetType().Name)
{
case "GeometryModel3D":
foreach (var item in ((model3D.Children[i] as GeometryModel3D).Geometry as MeshGeometry3D).Positions)
{
double x = item.X; double y = item.Y; double z = item.Z;
mesh.Positions.Add(new Point3D(x, y, z));
}
foreach (int item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).TriangleIndices)
{
mesh.TriangleIndices.Add(item);
//double x = item.X; double y = item.Y; double z = item.Z;
//mesh.Positions.Add(new Point3D(x, y, z));
}
foreach (var item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).Normals)
{
double x = item.X; double y = item.Y; double z = item.Z;
mesh.Normals.Add(new System.Windows.Media.Media3D.Vector3D(x, y, z));
}
foreach (var item in ((MeshGeometry3D)((GeometryModel3D)model3D.Children[i]).Geometry).TextureCoordinates)
{
double x = item.X; double y = item.Y;
mesh.TextureCoordinates.Add(new Point(x, y));
}
gmodel.Material = ((GeometryModel3D)model3D.Children[i]).Material;
gmodel.Geometry = mesh;
break;
case "Model3DGroup":
break;
default:
break;
}
}
thank you