Exemplo n.º 1
0
        public void AddElement(string smodel, string simg, int simgid, int id, ModelUIElement3D mod)
        {
            if (simg == "")
            {
                simg = win.soureseDefaultB;
            }
            if (id == 0)
            {
                id = win.iddefaultB;
            }
            if (smodel == "")
            {
                return;
            }
            ModelImporter importer  = new ModelImporter();
            Material      material1 = new DiffuseMaterial(win.defcolor);

            importer.DefaultMaterial = material1;
            double maxx = 0;

            ModelUIElement3D[] masel = new ModelUIElement3D[4];
            masel[0] = win.selectedobject;
            masel[1] = win.twoselectedobject;
            masel[2] = win.threeselectedobject;
            masel[3] = win.fourselectedobject;
            int countmasel = 0;

            for (int i = 0; i < 4; i++)
            {
                if (masel[i] != null)
                {
                    countmasel++;
                }
            }
            for (int j = 0; j < countmasel; j++)
            {
                Model3DGroup model = importer.Load(smodel);
                int          idd   = win.rand.Next(0, 100000);
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                    Point3DCollection p3dc   = mmodel.Positions;
                }
                double xx = 9999;
                double yy = 9999;
                double zz = 9999;
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                    Point3DCollection p3dc   = mmodel.Positions;
                    if (gmodel.Bounds.SizeX > maxx)
                    {
                        maxx = gmodel.Bounds.SizeX;
                    }
                    if (gmodel.Bounds.SizeY > maxx)
                    {
                        maxx = gmodel.Bounds.SizeY;
                    }
                    if (gmodel.Bounds.SizeZ > maxx)
                    {
                        maxx = gmodel.Bounds.SizeZ;
                    }
                    if (gmodel.Bounds.X < xx)
                    {
                        xx = gmodel.Bounds.X;
                    }
                    if (gmodel.Bounds.Y < yy)
                    {
                        yy = gmodel.Bounds.Y;
                    }
                    if (gmodel.Bounds.Z < zz)
                    {
                        zz = gmodel.Bounds.Z;
                    }
                }
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D gmodel = new GeometryModel3D();
                    gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D mmodel = (MeshGeometry3D)gmodel.Geometry;
                    gmodel.Material = new DiffuseMaterial(win.defcolor);
                    Point3DCollection p3dc = mmodel.Positions;
                    for (int ii = 0; ii < p3dc.Count; ii++)
                    {
                        Point3D tp = p3dc[ii];
                        tp.X     = tp.X / maxx;
                        tp.Y     = tp.Y / maxx;
                        tp.Z     = tp.Z / maxx;
                        p3dc[ii] = tp;
                    }
                    for (int ii = 0; ii < p3dc.Count; ii++)
                    {
                        Point3D tp = p3dc[ii];
                        tp.X     = tp.X - xx / maxx;
                        tp.Y     = tp.Y - yy / maxx;
                        tp.Z     = tp.Z - zz / maxx;
                        p3dc[ii] = tp;
                    }
                    ModelUIElement3D modelUI = new ModelUIElement3D();
                    modelUI.Model = gmodel;
                    _3DObject      tempmodel1 = win.CreatedElements[mod.GetHashCode()] as _3DObject;
                    ElementCabinet tempmodel  = new ElementCabinet(modelUI, 1, 1, 1, 0, 0, 0);
                    tempmodel.idtexture   = simgid;
                    tempmodel.groupel     = tempmodel1.groupel;
                    tempmodel.ingroupel   = "Element-" + idd;
                    tempmodel.iningroupel = "El";
                    tempmodel.hashtable   = win.CreatedElements;
                    win.CreatedElements.Add(modelUI.GetHashCode(), tempmodel);
                    win.container.Children.Add(modelUI);
                    modelUI.MouseUp    += win.ClickOnModel;
                    tempmodel.LenZ      = 2;
                    tempmodel.idelement = id;
                    ElementCabinet tmp = win.CreatedElements[masel[j].GetHashCode()] as ElementCabinet;
                    tempmodel.select = tmp;
                    tempmodel.changeObjectLen(0.1, 0.1, 0.1);
                    tempmodel.changeObjectPos(tmp.getPosX() + tmp.getLenX() / 2, tmp.getPosY() + tmp.getLenY() / 2, tmp.getPosZ() + tmp.getLenZ() / 2);
                    tempmodel.otsx = tmp.getLenX() / 2;
                    tempmodel.otsy = tmp.getLenY() / 2;
                    tempmodel.otsz = tmp.getLenZ() / 2;
                    tempmodel.thismodel.Material = new DiffuseMaterial(new SolidColorBrush(win.defcolor.Color));
                }
            }
        }