Ejemplo n.º 1
0
        public void CreateElement(string groupel, string ingroupel, string iningroupel, double getPosX, double getPosY, double getPosZ, double getLenX, double getLenY, double getLenZ, int getAngleX, int getAngleY, int getAngleZ, int idmaterial, ModelUIElement3D thisobject1, double otx, double oty, double otz, string text = "-1", int id = -1)
        {
            if (text == "-1")
            {
                text = win.soureseDefault;
            }
            if (id == -1)
            {
                id = win.iddefaultB;
            }
            ModelImporter importer  = new ModelImporter();
            Material      material1 = new DiffuseMaterial(win.defcolor);

            importer.DefaultMaterial = material1;
            string           request          = "select sourse from elements where id=" + idmaterial;
            NpgsqlConnection npgSqlConnection = new NpgsqlConnection(win.connectionString);

            npgSqlConnection.Open();
            NpgsqlCommand    npgSqlCommand = new NpgsqlCommand(request, npgSqlConnection);
            NpgsqlDataReader reader        = npgSqlCommand.ExecuteReader();
            string           str           = "";

            while (reader.Read())
            {
                str = reader.GetString(0);
            }
            Model3DGroup model = new Model3DGroup();

            model = importer.Load(str);
            double maxx = 0;
            int    idd  = win.rand.Next(0, 100000);
            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 = model.Children[i] as GeometryModel3D;
                MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                Point3DCollection p3dc   = mmodel.Positions;
                gmodel.Material = new DiffuseMaterial(win.defcolor);
                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;
                ElementCabinet tempmodel = new ElementCabinet(modelUI, 1, 1, 1, 0, 0, 0);
                tempmodel.idtexture   = id;
                tempmodel.groupel     = groupel;
                tempmodel.ingroupel   = ingroupel;
                tempmodel.iningroupel = iningroupel;
                tempmodel.hashtable   = win.CreatedElements;
                win.CreatedElements.Add(modelUI.GetHashCode(), tempmodel);
                win.container.Children.Add(modelUI);
                modelUI.MouseUp += win.ClickOnModel;
                tempmodel.LenZ   = 2;
                tempmodel.changeObjectLen(getLenX, getLenY, getLenZ);
                tempmodel.changeObjectPos(getPosX, getPosY, getPosZ);
                tempmodel.ChangeAngleX(getAngleX);
                tempmodel.ChangeAngleY(getAngleY);
                tempmodel.ChangeAngleZ(getAngleZ);
                tempmodel.idelement          = idmaterial;
                tempmodel.select             = win.CreatedElements[thisobject1.GetHashCode()] as ElementCabinet;
                tempmodel.otsx               = otx;
                tempmodel.otsy               = oty;
                tempmodel.otsz               = otz;
                tempmodel.thismodel.Material = new DiffuseMaterial(new SolidColorBrush(win.defcolor.Color));
            }
        }
Ejemplo n.º 2
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));
                }
            }
        }