I'm trying to write an Ascii STL file ysing a poly_shade command in IDL. basically it outputs vertices and polygons where the first numbe rin polygons is the number of vertices and the following numbers are the vertices that are connected.

I havn't been able to find any software or algorithms to do this data reformatting.

Is anyone familiar with this kind of algorithm?

I have only found ways to print out the vertices and polygons in seperate blocks, I'm thinking I might have to store all the vertices than start writing the file based on the polygon list.

Any ideas or questions, please let me know.

Dani AI

Generated

Good progress — a few focused checks usually fix the “only a couple triangles” / import-token problems when converting IDL poly data to STL.

STL supports triangles only. For each polygon entry (count, index1, index2, ...), build triangles before emitting facets. A simple and fast method for most meshes is fan triangulation (works if vertices are ordered and the polygon is planar and roughly convex):

for each polygon:
  read n, idx[0..n-1]
  if n == 3: emit triangle(idx[0], idx[1], idx[2])
  else:
    for k = 1 to n-2:
      emit triangle(idx[0], idx[k], idx[k+1])

Compute a per-triangle normal (cross product of two edges) and write it with the facet. Keep vertex ordering consistent (all triangles wound CCW when viewed from outside) so normals point a consistent way; many importers will recompute normals but some are strict.

Common causes of the errors you saw

  • Not triangulating polygons (importers silently skip or misread non-tri faces).
  • Wrong index base (off-by-one): confirm whether the polygon indices reference your stored vertex array correctly.
  • Malformed ASCII tokens/format: each facet must have the exact lines facet normal, outer loop, three vertex lines, endloop, endfacet; solid/endsolid wrap the file.
  • Binary STL pitfalls: header must be 80 bytes, then a 4-byte unsigned little-endian triangle count, then 50 bytes per triangle (12 floats + 2 byte attribute). Wrong endianness or wrong triangle count will make readers report far fewer elements.

Quick debug workflow: export a tiny test mesh (2–4 faces) and open it in a text editor/viewer to verify tokens and numbers; if binary, check triangle count and endianness. If polygons are concave or nonplanar, use an ear‑clipping triangulation instead of a fan.

I have the program written, ust tossed it out there over the weekend just in case.

however, when i try to import he mesh into gambit all i get are 2 polygons when there should be a few hundred more.

anyone know why io got this:


STL file to FIDAP7 file
Error at line 17: expected 'outer loop' token in ASCII format.

Trying binary instead.

Read 6 nodes, 2 elements, 0 groups.
Error in reading the file
2 tri elements

or where i can get help on this?

actually i can get it to gambit fine now, anyone know of some good gambit or fluent forums?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.