public void CreateMesh(NameValueMap nv)
        {
            var N  = 512;
            var T0 = DateTime.Now;

            if (null != mGraphicsDataSets)
            {
                mGraphicsDataSets.Delete();
                mGraphicsDataSets = null;

                mGraphicsNode.Delete();
                mGraphicsNode = null;

                mApp.ActiveView.Update();
                return;
            }

            var doc = mApp.ActiveDocument as PartDocument;

            if (null == mClientGraphics)
            {
                mClientGraphics = doc.ComponentDefinition.ClientGraphicsCollection.Add("MyTest");
            }

            mGraphicsDataSets = doc.GraphicsDataSetsCollection.Add("MyTest");

            var setupTimeSeconds = (DateTime.Now - T0).TotalSeconds;

            T0 = DateTime.Now;

            var msg = string.Format("N = {0}, {1} triangles\n", N, mNumTriangles)
                      + string.Format("Inventor setup time: {0} sec\n", setupTimeSeconds);

            T0 = DateTime.Now;

            try
            {
                var dataSetsTimeSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gcs = mGraphicsDataSets.CreateCoordinateSet(1) as GraphicsCoordinateSet;
                gcs.PutCoordinates(mVertices);

                var coordSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gis = mGraphicsDataSets.CreateIndexSet(2) as GraphicsIndexSet;
                gis.PutIndices(mIndices);

                var indexSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                var gns = mGraphicsDataSets.CreateNormalSet(3) as GraphicsNormalSet;
                gns.PutNormals(mNormals);

                var normalSetSeconds = (DateTime.Now - T0).TotalSeconds;
                T0 = DateTime.Now;

                mGraphicsNode = mClientGraphics.AddNode(1) as GraphicsNode;
                var triangles = mGraphicsNode.AddTriangleGraphics() as TriangleGraphics;

                triangles.CoordinateSet      = gcs;
                triangles.CoordinateIndexSet = gis;
                triangles.NormalSet          = gns;
                triangles.NormalBinding      = NormalBindingEnum.kPerItemNormals;
                triangles.NormalIndexSet     = gis;

                var trianglesSeconds = (DateTime.Now - T0).TotalSeconds;

                bool inActiveDocument;
                var  brassAsset = GetAsset("Brass - Satin", out inActiveDocument);
                if (null != brassAsset)
                {
                    if (!inActiveDocument)
                    {
                        brassAsset = brassAsset.CopyTo(doc);
                    }
                    mGraphicsNode.Appearance = brassAsset;
                }

                msg = msg + string.Format("GraphicsDataSetsCollection.Add time: {0} sec\n", dataSetsTimeSeconds)
                      + string.Format("Coordinate set creation time: {0} sec\n", coordSetSeconds)
                      + string.Format("Index set creation time: {0} sec\n", indexSetSeconds)
                      + string.Format("Normal set creation time: {0} sec\n", normalSetSeconds)
                      + string.Format("Triangle node creation time: {0} sec\n", trianglesSeconds);
            }
            catch (Exception e)
            {
                msg += string.Format("Exception: {0}", e.ToString());
            }

            mApp.ActiveView.Update();

            System.Windows.MessageBox.Show(msg);
        }
Ejemplo n.º 2
0
        public void Draw3D(Part Bauteil, string Name)
        {
            foreach (var mmface in Bauteil.Faces)
            {
                foreach (var point in mmface.VertexCoords)
                {
                    mVertices.Add((double)point.X);
                    mVertices.Add((double)point.Y);
                    mVertices.Add((double)point.Z);
                }

                var N = mmface.VertexIndices.Count; //  Nomber of Indices
                foreach (var indice in mmface.VertexIndices)
                {
                    var i0 = indice;
                    var i1 = i0 + N;

                    var t0 = i0;
                    var t1 = i1;

                    // NOTE: The extra +1 on each line is because Inventor expects 1 - based indices.

                    mIndices.Add(t1 + 1 + 1);
                    mIndices.Add(t0 + 1);



                    mIndices.Add(t0 + 1 + 1);
                    //  mIndices.Add(t1 + 1 + 1);
                    //  mIndices.Add(t0 + 1);

                    mIndices.Add(t1 + 1);
                }
                foreach (var Norm in mmface.Normals)
                {
                    mNormals.Add((double)Norm.X);
                    mNormals.Add((double)Norm.Y);
                    mNormals.Add((double)Norm.Z);
                }
            }



            if (null != mGraphicsDataSets)
            {
                mGraphicsDataSets.Delete();
                mGraphicsDataSets = null;

                mGraphicsNode.Delete();
                mGraphicsNode = null;

                Addin3DPdf.TrAddInServer.MApp.ActiveView.Update();
                return;
            }

            PartDocument
                doc = Addin3DPdf.TrAddInServer.MApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                  Addin3DPdf.TrAddInServer.MApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject),
                                                                  true) as PartDocument;

            //    PartDocument doc = Addin3DPdf.TransAddInServer.MApp.ActiveDocument as PartDocument;
            if (null == mClientGraphics)
            {
                mClientGraphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(Name);
            }

            mGraphicsDataSets = doc.GraphicsDataSetsCollection.Add(Name);



            double[] A_Verties = mVertices.ToArray();
            int[]    A_Indices = mIndices.ToArray();
            double[] A_Normals = mNormals.ToArray();
            try
            {
                var gcs = mGraphicsDataSets.CreateCoordinateSet(1) as GraphicsCoordinateSet;
                gcs.PutCoordinates(A_Verties);



                var gis = mGraphicsDataSets.CreateIndexSet(2) as GraphicsIndexSet;
                gis.PutIndices(A_Indices);



                var gns = mGraphicsDataSets.CreateNormalSet(3) as GraphicsNormalSet;
                gns.PutNormals(A_Normals);


                mGraphicsNode = mClientGraphics.AddNode(1) as GraphicsNode;
                var triangles = mGraphicsNode.AddTriangleGraphics() as TriangleGraphics;

                triangles.CoordinateSet      = gcs;
                triangles.CoordinateIndexSet = gis;
                triangles.NormalSet          = gns;
                triangles.NormalBinding      = NormalBindingEnum.kPerItemNormals;
                triangles.NormalIndexSet     = gis;



                bool inActiveDocument;
                var  brassAsset = GetAsset("Silver", out inActiveDocument);
                if (null != brassAsset)
                {
                    if (!inActiveDocument)
                    {
                        brassAsset = brassAsset.CopyTo(doc);
                    }
                    mGraphicsNode.Appearance = brassAsset;
                }
            }
            catch (Exception e)
            {
            }
            doc.SaveAs(Name, false);

            Addin3DPdf.TrAddInServer.MApp.ActiveView.Update();
        }