Ejemplo n.º 1
0
        //private async void Read3Dxml(string fileName)
        //{
        //    Model3Dxml model = await Read3dxml.Read3Dxml(fileName);
        //}


        //private async void writetoglTF(string fileName)
        //{
        //    Model3Dxml model = await Read3dxml.Read3Dxml(fileName);



        //    ToVertex modeldata = new ToVertex(model.ProductStructure.Instance3DList, model.ProductStructure.ReferenceRepList);

        //    modeldata.getprimitivelist();
        //    ThreedxmlTogltf changefile = new ThreedxmlTogltf();
        //    changefile.getfromprimitivedata(modeldata.allvertexindex, modeldata.allvertexpostion, model.Header.Title);
        //    GltfModel _model = changefile.writeToGLtf();
        //    var json = _model.ToJson(_model);

        //    //  文件保存路径

        //    var file = @"C:\Users\gxh-PC\Desktop\001.gltf";    // 保存的文件路径

        //    File.WriteAllText(file, json);

        //}

        private async void button2_Click(object sender, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog();

            sd.Filter = "3D Object (*.gltf)|*.gltf";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                label2.Text = sd.FileName;
            }

            Model3Dxml model = await Read3dxml.Read3Dxml(label1.Text);

            textBox1.AppendText("已读取3dxml文件数据!  \r\n\n");

            ToVertex modeldata = new ToVertex(model.ProductStructure.Instance3DList, model.ProductStructure.ReferenceRepList);

            modeldata.getprimitivelist();

            ThreedxmlTogltf changefile = new ThreedxmlTogltf();

            changefile.getfromprimitivedata(modeldata.allvertexindex, modeldata.allvertexpostion, model.Header.Title);

            GltfModel _model = changefile.writeToGLtf();
            var       json   = _model.ToJson(_model);

            //  文件保存路径

            //var file = @"C:\Users\gxh-PC\Desktop\001.gltf";    // 保存的文件路径
            var file = label2.Text;

            File.WriteAllText(file, json);
            textBox1.AppendText("写入gltf文档成功!  \r\n\n");
        }
Ejemplo n.º 2
0
        //该方法是将Net3DXmlReader中的ReadAsync方法再次封装
        public static async Task <Model3Dxml> Read3Dxml(string fileName)
        {
            Net3DXmlReader net3DXmlReader = new Net3DXmlReader();
            Model3Dxml     model3Dxml     = await net3DXmlReader.ReadAsync(fileName);

            return(model3Dxml);
            //ReadModel(model3Dxml);
        }
Ejemplo n.º 3
0
        //该方法貌似没用到
        public Model3Dxml Read(string path)
        {
            try
            {
                _cacheDirPath = ReadPackage(path);

                _manifest   = ReadManifestXml(_cacheDirPath + "\\Manifest.xml");
                _model3Dxml = Read3DXmlStructure(Path.Combine(_cacheDirPath, _manifest.RootXmlStruPath));
                foreach (ReferenceRepType referenceRepType in _model3Dxml.ProductStructure.ReferenceRepList)
                {
                    string model3DRepXmlFile = Path.Combine(_cacheDirPath, referenceRepType.AssociatedFile.Split(':')[2]);
                    referenceRepType.MeshGeometry = Read3Drep(model3DRepXmlFile);
                }
                DeleteDirectory(_cacheDirPath);
                return(_model3Dxml);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public async Task <Model3Dxml> ReadAsync(string path)
        {
            try
            {
                var result = await Task.Run(async() =>
                {
                    _cacheDirPath   = ReadPackage(path);
                    _manifest       = ReadManifestXml(_cacheDirPath + "Manifest.xml");        //获得Manifest.xml中根节点文件的信息
                    string filePath = Path.Combine(_cacheDirPath, _manifest.RootXmlStruPath); //找到根节点文件的绝对路径
                    //string filePath = Path.Combine(_cacheDirPath+ "AssembleFile.3dxml");

                    _model3Dxml = Read3DXmlStructure(filePath);

                    List <Task> tasks = new List <Task>();
                    //_model3Dxml.ProductStructure.Instance3DList.ForEach((referenceRepType) =>
                    //{
                    //    //urn: 3DXML: Reference: ext: AB01C--1FA - PLATE1.3dxml#1
                    //    string fileName = referenceRepType.IsInstanceOf.Split(':')[4];
                    //    string file = fileName.Split('#')[0];
                    //    var model3DRepXmlFile = Path.Combine(_cacheDirPath, referenceRepType.IsInstanceOf.Split(':')[2]);
                    //    var stas = Read3DrepAsync2(file);
                    //});

                    //instance3DType是ProductStructure中,以待解决
                    //如果ProductStructure中包含的是<Instance3D>,以下代码可以运行并将数据放入Instance3DList中
                    _model3Dxml.ProductStructure.Instance3DList.ForEach((instance3DType) =>
                    {
                        var task = Task.Run(async() =>
                        {
                            string fileName             = instance3DType.IsInstanceOf.Split(':')[4].Split('#')[0];
                            string file                 = Path.Combine(_cacheDirPath, fileName);
                            instance3DType.MeshGeometry = await Read3DrepAsync(file);
                        });
                        tasks.Add(task);
                    });
                    await Task.WhenAll(tasks);


                    //referenceRepType是ProductStructure中的<ReferenceRep>  (xsi:type="ReferenceRepType")
                    //如果ProductStructure中包含的是<ReferenceRep>,以下代码可以运行并将数据放入ReferenceRepList中
                    _model3Dxml.ProductStructure.ReferenceRepList.ForEach((referenceRepType) =>
                    {
                        var task = Task.Run(async() =>
                        {
                            //获得<ReferenceRep>中的associatedFile所指向的文件,该文件可能包括一个零件的几何数据信息
                            var model3DRepXmlFile         = Path.Combine(_cacheDirPath, referenceRepType.AssociatedFile.Split(':')[2]);
                            referenceRepType.MeshGeometry = await Read3DrepAsync(model3DRepXmlFile);
                        });
                        tasks.Add(task);
                    });
                    await Task.WhenAll(tasks);

                    DeleteDirectory(_cacheDirPath);
                    return(_model3Dxml);
                });

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }