AB4D Forum

Full Version: Triangulation method inquiry
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Maybe the 3ds file is broken (the exporter is not working correctly). Yo  can check it by importing it into some other application.
Send me the file (you can use Feedback form: https://www.ab4d.com/Feedback.aspx) so that I can check it.
I got your file and checked it.

Your code is missing two things:
1)
Some GeometryModel3D objects also have Transform property set to a MatrixTransform3D. You need to check that and in case this is set, transform all the Positions.

2)
In case of Model3DGroup, you need to repeat the for loop to go through all the Children of the Model3DGroup.


Otherwise, the model looks fine, except the objects on the wings that seems to have inverted triangle order so that only inner parts of the wings are shown. This can be solved, by setting both Material and BackMaterial to the objects. 

The 3ds model can be also checked in Viewer3ds. To fix the wings, go to Settings tab and check the "Force two sided materials"
Could you please provide example code?

please.
In other web viewers, the inside shape is fully displayed, but the wing shape is being modified, but the inside shape is not showing up. Please check.
(03-11-2024, 06:07 AM)kanta8819@cadian.com Wrote: [ -> ]In other web viewers, the inside shape is fully displayed, but the wing shape is being modified, but the inside shape is not showing up. Please check.

It was not expressed because there was no material. After forcing the material, it worked properly.

However, what should I do to receive a tree like the image below?

Please provide example code.

thank you