<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating SubDMesh in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6444619#M35330</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By looking at the code provided it seems that you have an issue when filling&amp;nbsp;"facearray". This is the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int[] ptr1 = new int[(pts.Count) * 2 + 1];
int[] ptr2 = new int[(pts.Count) * 2 + 1];
int[] ptr3 = new int[(pts.Count) * 2 + 1];

Int32Collection facearray = new Int32Collection();

for (int i = 0; i &amp;lt; ep; i++)
{

 facearray.Add(3);
 facearray.Add(ptr1[i]);
 facearray.Add(ptr2[i]);
 facearray.Add(ptr3[i]);

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ptr1,&amp;nbsp;&lt;SPAN&gt;ptr2 and&amp;nbsp;ptr3&amp;nbsp;have no information. What you have to provide here is, for each triangle each vertex. And the vertex are&amp;nbsp;indexes&amp;nbsp;of the array of points.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example. If you have a 3 points ( p1 = {0,0,0}, p2 = {1,0,0}, p3 = {0,1,0}&lt;BR /&gt;The facearray should be&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;meshPts.add(p1);
meshPts.add(p2);
meshPts.add(p3);

facearray.add(3); &amp;lt;- number of points
facearray.add(0); &amp;lt;- first point (p1)
facearray.add(1); &amp;lt;- second point (p2)
facearray.add(2); &amp;lt;- third point (p3)&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In your case you can try something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;for (int i = 0; i &amp;lt; pts.Count - 2; i++)
{

 facearray.Add(3);
 facearray.Add(0);
 facearray.Add(i+1);
 facearray.Add(i+2);

}&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Hope it helps&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jul 2016 11:35:19 GMT</pubDate>
    <dc:creator>cgcamilo</dc:creator>
    <dc:date>2016-07-18T11:35:19Z</dc:date>
    <item>
      <title>Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6436360#M35329</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got some code (c#) which allows the user to select a block, and then will explode the block into a collection of points (held&amp;nbsp;in a 3dpointcollection called 'pts'). It will then&amp;nbsp;transform the points such that they are positioned at each vertex of a polyline (denoted 'poly')&amp;nbsp;and also orientated to face along the next segment of the polyline (hopefully you are still with me, the screenshot below should explain a bit better).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG width="750" height="570" title="cad temp.JPG" alt="cad temp.JPG" src="https://forums.autodesk.com/t5/image/serverpage/image-id/255196i7DF1313A75470B06/image-size/original?v=v2&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the individual points are stored in a 3dpointcollection called 'MeshPts'. I now want to connect the points in a SubDMesh. I have had a look at Kean's demonstration and have come up with the following, however it doesn't display anything on screen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 			int ep = Convert.ToInt32(poly.EndParam);

                         int[] ptr1 = new int[(pts.Count) * 2 + 1];
                         int[] ptr2 = new int[(pts.Count) * 2 + 1];
                         int[] ptr3 = new int[(pts.Count) * 2 + 1];

                         Int32Collection facearray = new Int32Collection();

                         for (int i = 0; i &amp;lt; ntri; i++)
                         {

                             facearray.Add(3);
                             facearray.Add(ptr1[i]);
                             facearray.Add(ptr2[i]);
                             facearray.Add(ptr3[i]);

                         }


                         SubDMesh sdm = new SubDMesh();

                         sdm.SetDatabaseDefaults();

                         sdm.SetSubDMesh(meshPts, facearray, 0);

                         btr.AppendEntity(sdm);

                         tr.AddNewlyCreatedDBObject(sdm, true);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sort of running blind at the minute as I don't have any experience with meshes, only a very short time spent working with solid3d objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if anything needs clarifying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Full code so far is here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Point3dCollection polyPts = new Point3dCollection();
                            Polyline3d poly = tr.GetObject(psr1.ObjectId, OpenMode.ForRead) as Polyline3d;
                     
                            int ep = Convert.ToInt32(poly.EndParam);
                                                       
                            for (int q = 0; q &amp;lt;= ep; q++) //Open foreach to iterate through the 3D polyline
                            {
                                if(q != poly.EndParam)
                                {   Point3d pt1 = poly.GetPointAtParameter(q);
                                    int a = q + 1;
                                    Vector3d vec1 = pt1.GetVectorTo(poly.GetPointAtParameter(a));
                                    double angle = Vector3d.XAxis.GetAngleTo(vec1, Vector3d.ZAxis);
                                    
                                foreach (Point3d r in pts)
                                {
                                    Point3d t = new Point3d();
                                    Vector3d pt1Vec = pt1.GetAsVector();
                                    Vector3d insVec = ins.GetAsVector();
                                    Matrix3d rot = Matrix3d.Rotation(angle, zAz, pt1);
                                    t = r.Add(pt1Vec).Subtract(insVec);
                                    Point3d g = t.TransformBy(rot);
                                    meshPts.Add(g);

                                } //Close foreach
                                }
                               
                                                        
                            } //close for
                           


                         foreach (Point3d y in meshPts)
                    {
                        DBPoint b = new DBPoint(y);
                        btr.AppendEntity(b);
                        tr.AddNewlyCreatedDBObject(b, true);
                    
                         
                    }
                       
                         int[] ptr1 = new int[(pts.Count) * 2 + 1];
                         int[] ptr2 = new int[(pts.Count) * 2 + 1];
                         int[] ptr3 = new int[(pts.Count) * 2 + 1];

                         Int32Collection facearray = new Int32Collection();

                         for (int i = 0; i &amp;lt; ep; i++)
                         {

                             facearray.Add(3);
                             facearray.Add(ptr1[i]);
                             facearray.Add(ptr2[i]);
                             facearray.Add(ptr3[i]);

                         }


                         SubDMesh sdm = new SubDMesh();

                         sdm.SetDatabaseDefaults();

                         sdm.SetSubDMesh(meshPts, facearray, 0);

                         btr.AppendEntity(sdm);

                         tr.AddNewlyCreatedDBObject(sdm, true);






&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jul 2016 15:51:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6436360#M35329</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-14T15:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6444619#M35330</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By looking at the code provided it seems that you have an issue when filling&amp;nbsp;"facearray". This is the error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int[] ptr1 = new int[(pts.Count) * 2 + 1];
int[] ptr2 = new int[(pts.Count) * 2 + 1];
int[] ptr3 = new int[(pts.Count) * 2 + 1];

Int32Collection facearray = new Int32Collection();

for (int i = 0; i &amp;lt; ep; i++)
{

 facearray.Add(3);
 facearray.Add(ptr1[i]);
 facearray.Add(ptr2[i]);
 facearray.Add(ptr3[i]);

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ptr1,&amp;nbsp;&lt;SPAN&gt;ptr2 and&amp;nbsp;ptr3&amp;nbsp;have no information. What you have to provide here is, for each triangle each vertex. And the vertex are&amp;nbsp;indexes&amp;nbsp;of the array of points.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For example. If you have a 3 points ( p1 = {0,0,0}, p2 = {1,0,0}, p3 = {0,1,0}&lt;BR /&gt;The facearray should be&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;meshPts.add(p1);
meshPts.add(p2);
meshPts.add(p3);

facearray.add(3); &amp;lt;- number of points
facearray.add(0); &amp;lt;- first point (p1)
facearray.add(1); &amp;lt;- second point (p2)
facearray.add(2); &amp;lt;- third point (p3)&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In your case you can try something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;for (int i = 0; i &amp;lt; pts.Count - 2; i++)
{

 facearray.Add(3);
 facearray.Add(0);
 facearray.Add(i+1);
 facearray.Add(i+2);

}&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Hope it helps&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 11:35:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6444619#M35330</guid>
      <dc:creator>cgcamilo</dc:creator>
      <dc:date>2016-07-18T11:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6445554#M35331</link>
      <description>&lt;P&gt;Part of the trick with subd meshes is you have to first know the faces you want to make.&lt;/P&gt;
&lt;P&gt;Then extract the verticies and keep them in a list.&lt;/P&gt;
&lt;P&gt;Then you loop through the faces, and record what verticies occurred at each triangle vertex.&lt;/P&gt;
&lt;P&gt;Then you can add the points to the subdmesh, and add faces which are lists of (integer) indicies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have done this extensively and it works for lots of faces, but best to keep down to 20,000 faces for each subdmesh for speed!&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jul 2016 18:59:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6445554#M35331</guid>
      <dc:creator>JamesMaeding</dc:creator>
      <dc:date>2016-07-18T18:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6446586#M35332</link>
      <description>&lt;P&gt;Thanks very much, both, for your replies.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I now understand the concept behind the triangulation. Although I now need to devise&amp;nbsp;a way of creating the triangles, as I think one of the points in each triangle will have to be at the next node along the polyline as per the drawing below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In any case, I think I should be able to create something that works. If not, I'll have to go back to the drawing board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers guys.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 10:01:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6446586#M35332</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-19T10:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6447306#M35333</link>
      <description>&lt;P&gt;note that Ceometric.com sells .net libraries for efficient delunay triangulation of points.&lt;/P&gt;
&lt;P&gt;Its not as fast as Civil3d for millions of points, but you would not care about that.&lt;/P&gt;
&lt;P&gt;There are several non-optimized delunay triangulation sets of code hanging around that you could use for free.&lt;/P&gt;
&lt;P&gt;Your challenge is to split up the points into sets for each pline seg, let's call those "walls".&lt;/P&gt;
&lt;P&gt;You would take each wall, lay it down, and run the triangulation to get tris for that wall, then stand back up.&lt;/P&gt;
&lt;P&gt;Then do remaining walls....&lt;/P&gt;
&lt;P&gt;This is because the triangulation routines are not "3d", they are actually 2d, but keep the z values for the points.&lt;/P&gt;
&lt;P&gt;The tris look the same from the top...&lt;/P&gt;
&lt;P&gt;I have done this for a few things relating to 3d printing.&lt;/P&gt;
&lt;P&gt;thx&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 15:09:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6447306#M35333</guid>
      <dc:creator>JamesMaeding</dc:creator>
      <dc:date>2016-07-19T15:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6448749#M35334</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should have a look at &lt;A href="http://through-the-interface.typepad.com/through_the_interface/2009/07/triangulating-an-autocad-sub-division-mesh-from-a-set-of-points-using-net.html" target="_blank"&gt;this topic&lt;/A&gt; from Kean Walmsley blog.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 07:26:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6448749#M35334</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2016-07-20T07:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating SubDMesh</title>
      <link>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6451878#M35335</link>
      <description>&lt;P&gt;Thanks for the link. I've had a look through and tried to apply Kean's code but it produced&amp;nbsp;a random set of faces and so the mesh didn't make much sense. In any case, I think I have found a way to do it now (in theory) so I will have a go at that.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 10:28:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/creating-subdmesh/m-p/6451878#M35335</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-07-21T10:28:28Z</dc:date>
    </item>
  </channel>
</rss>

