Paul Lasman wrote:
>
> Hi all,
>
> I have a customer that wants to convert an Stl file to a nastran triangle
> mesh file.
>
> 1. Where can I find the description of the Stl file ?
>
> 2. Has anyone else done anything like that ?
>
> Thanks in advance.
>
Paul,
In addition to the information on STL file formats at Dr. Wei Feng's Web
site, here are a few practical tips on implementing a binary format
converter in the form of snippets of C code ...
// Header - 80 bytes + 4-byte integer giving total number
// of facets in file.
struct {
char whatever[80];
int nfacets;
} header;
// Structure for triangle facet data. 48 bytes in length.
// Note: Many C compilers (such as SGI's) align structures on 4-byte
// boundaries, making it impossible to design a 50-byte record for
// the facet as required by the STL spec. The problem is solved by
// writing the 48-byte facet structure followed by 2-bytes of padding
// (see below).
struct Facet {
float nx, ny, nz; // surface normals
float v1x, v1y, v1z; // vertex 1
float v2x, v2y, v2z; // vertex 2
float v3x, v3y, v3z; // vertex 3
} facet;
// The "lswap" routine byte swaps a 4-byte value.
// You may or may not need to byte swap values, depending on hardware
// (issues of little endian vs, big endian). However, even on the same
// platform, some software expects the data to be swapped. For example,
// Stratasys' QuickSlice running on SGI.
void lswap(unsigned int *v) // Byte swaps a 4-byte val
{
unsigned int r;
r = *v;
*v = ((r & 0xff) << 24) | ((r & 0xff00) << 8)
| ((r & 0xff0000) >> 8) | ((r & 0xff000000) >> 24);
}
// Main body of converter ...
...
// "padding" is used to flesh out the facet's file record to
// 50 bytes
short padding = 0;
...
// Fill in header and write
header.nfacets = ...
// Byte swap if necessary
lswap((unsigned int *)&header.nfacets);
n = fwrite((void *)&header, 1, sizeof(header), fp);
...
// Compute values
...
facet.nx = ...
// Byte swap if necessary
lswap((unsigned int *)&facet.nx);
...
// Write the 48-byte facet structure
n = fwrite((void *)&facet, 1, sizeof(facet), fp);
// This next is to make each record 50 bytes in size according
// to STL specification.
n = fwrite((void *)&padding, 1, sizeof(short), fp);
...
-- Regards,Dr Charles Knox, Vice President Phone: +1 (612) 482-7938 Image3, LLC, Midwest Division FAX: +1 (612) 490-9717 1000 Ingerson Road E-mail: scivis@mndata.com Shoreview MN 55126-8146 Web: http://www.image3.com
"In America, anyone can become president. That's one of the risks you take." -- ADLAI STEVENSON
For more information about the rp-ml, see http://ltk.hut.fi/rp-ml/
This archive was generated by hypermail 2.1.2 : Tue Jun 05 2001 - 22:45:20 EEST