Archive for the ‘File format’ Category

WPF STL decoder

Wednesday, September 26th, 2012

For my most recent enrichment, this is my first exercise using WPF.  I am implementing a STL binary decoder in C#.  The ASCII format decoder is ‘work-in-progress’.

Visual Studio 2008 DecoderExercise project on GitHub.

wpf

Might you advice on Rhino v4 ?

Tuesday, August 21st, 2012

Prerequisite to building a Rhino plugin, I need to validate my understanding of the sketchfab upload process. I begin with a python script from the API page, my new token and a sample lamp OBJ file.

pythonScript

type in ‘pythonw upload.py’ and a successful upload delivers a screen dump of the file transfer along with an id and validating success confirmation.

pythonUpload1My credential works and now I am ready to write my own uploader test in C#.  From the API and python script, I gather the four necessary steps; 1) load CAD file, 2) convert to base64, 3) build JSON, 4) upload/post JSON.

Rhino v4 supports plugin development with Visual Studio 2008, C#, VB and C++.  The simplest for me is a C# dialog application with default controls and OpenFileDialog module.

Using FileStream, CAD file is read in as a byte array.

Since some CAD files (STL, PLY) can be in binary or ASCII format, a base64 conversion is used.  Thanks to C#, the conversion is available in the System.Convert library.

Screen Shot 2012-08-21 at 7.38.57 AMFollowing Sketchfab API, I am creating a JSON string with  below function.  After conversion to a byte array, HttpWebRequest uploads my content to sketchfab server.

Screen Shot 2012-08-21 at 7.43.04 AMUpon a successful upload, I receive a confirmation id and ‘success : true’.

testApp3

It is exciting working on my first Rhino plugin with C#, Visual Studio 2008.  The body of code samples is massive (over 150+).  From McNeel’s dialog example, I am able to incorporate the test code user interface.

plugin2The challenge is getting access to the mesh data.  It seems that each example requires user to select data and I am at a loss how.  Might you share some wisdom ?  Here is my source code for ExporterTest and RhinoExporter (experiment).

plugin3

Happy to have found the most recent Rhino 5 API documentation online.

sketchfab – exporter test

Sunday, August 12th, 2012

Exciting opportunity to develop exporter(s) for sketchfab.  The offer is to implement exporter plugin(s) for popular CAD software in exchange for sketchfab account for a year.  There are already three such implementations: AutoDesk-3dMax, Blender and Google-SketchUp.  I am looking into Rhino and Meshlab.

Rhino v5 beta is available in Mac OSX and Windows.  Python scripting is a big feature I have been anticipating for sometime.  Sadly, I did not witness its functionality in OSX beta WIP.  Any suggestion(s) ?  Windows Rhino v5 is only available for licensed Rhino users.  So, I downloaded Rhino v4 evaluation which does not support python.  Pray to the Rhino deity that the documentation and SDK is excellent and writing a C# plugin will be a cinch !

Meshlab is an open source project with seemingly good documentation on wiki.  But apparently there is nothing under ‘plugin’ ?  I did find these plugin examples and this official documentation which includes instruction on C++ plugin development as well as the project location and compile.  Meshlab is compiled with QT.  Might QT Creator be the magical tool I seek ?

Before the actual implementation, I thought to make a prototype.  The API specification is available on sketchfab, token is provided upon sign up.  My prototype is in C#; got it working quickly (praise to a good language, tools and user community, thank you!)  So, here is the Visual Studio 2005 C# application for uploading your CAD file to sketchfab.  Feel free to use this GitHub source code for your next exporter implementation (if it is helpful).

Screen Shot 2012-08-12 at 4.56.25 PM

Loading local OBJ file, javascript

Friday, August 10th, 2012

Last year I implemented four decoders (wireframe-basic) for formats: STL, PLY, OFF and OBJ.  The decoders were based on Devon Govett’s bmp decoder.  The bmp decoder loaded binary data via AJAX and type cast as uint8Array.

Screen Shot 2012-08-22 at 8.09.29 AM

Unfortunately, IE9 and prior versions didn’t support uint8Array type (IE10 does, horay) !  So, for the ASCII only CAD formats (OBJ, OFF), I re-wrote their decoders to keep the returned data in ASCII.

Screen Shot 2012-08-22 at 8.12.29 AMI extracted the AJAX into its own common Loader class for re-usability across multiple decoders.  In addition, thanks to Eric Bidelman’s article on local file access, I am adding local file load capability to the Loader class in my OBJ decoder.

Screen Shot 2012-08-22 at 8.22.02 AM

A byproduct of handling ASCII data is the possibility of line parsing with Regular Expression as I have learned from Three.js’ very own Mr. Doob.  This is somewhat put into practice in my work-in-progress Three.js-OFF-decoder.

Source code is available on Github – OBJDecoder, Github – OFFDecoder.

3D-Javascript-Geomview Object File Format (OFF) Decoder

Saturday, March 17th, 2012

For personal enrichment in 3D file format, this is my exercise on Geomview Object File Format, OFF.  OFF can be encoded in binary or ascii but this decoder handles only ascii at this point.  Like the previous decoders, this OFF demo has been tested on Firefox, Safari, Chrome and **Internet Explorer 10 preview**.

Documentation, C++ source code and sample OFF files maybe found at Holmes3D.NET.

I have implemented the ascii format and will continue to work on the binary decoder.  Here is the demo and source code in GitHub.

Attending Minnebar conference, I learned that STL, OBJ decoders have already been implemented with Three.js by Thingiview.js.

Screen Shot 2012-03-17 at 11.04.45 PM

3D – Javascript – PLY Decoder

Tuesday, January 31st, 2012

For personal enrichment in 3D file format, this is my exercise on Stanford ploygon file format (PLY).  PLY is a popular format for 3D scanner with project like “The Digital Michelangelo, David”.

PLY file data can be stored in ascii, binary-big-endian or binary-little-endian.  Regardless of the data type, the file header is ascii.  For binary mode, data maybe stored in any type, char, short, int, float, etc.  In addition to the PLY wiki page, Stanford provides excellent documentation, sample code as well as a toolkit.

As in other 3D decoder exercises, I am using Devon Govett’s bmp.js as reference and tested on browsers: Chrome, Safari, Firefox and **Internet Explorer 10 preview**.

I have implemented the ascii format and will continue to work on the binary decoder.  Here is the demo and source code in GitHub.

dolphins

3D – Javascript – OBJ Decoder

Sunday, January 22nd, 2012

For my enrichment in 3D file format, this is my exercise in Wavefront Technologies’ OBJ decoder.  OBJ file format is simply structured in ascii and contains only data describing geometry and material.  The data content is ordered in lists of vertexes (v), texture (vt), normal (vn) and faces (f).  Each face entry consist of indexes to above mentioned lists to form a polygon – triangle or quad.  One special quality of the file format is its support of free form curved surface object as those in NURB.

For the initial implementation  in javascript, I am decoding only vertexes and faces to render a wire-frame.  This obj decoder is tested for Firefox, Chrome, Safari and **Internet Explorer 10 preview**.  Source code and history is available in GitHub.

The new samples of shuttle and lamp post are found in open source project, MeshLab.

DecodeOBJ

3D – Javascript-STL Decoder

Friday, December 23rd, 2011

Standard Tessellation Language (STL) for stereolithography CAD is a popular file format for rapid prototyping.  The file format supports both ascii and binary and consists of an order list of vertexes in float to make up triangle polygons.

With permission and support from Jostens, I have been working on an STL-optimized encoder/decoder.  The ultimate goal is to produce an optimized STL format that is 1/3 of a regular STL binary file while achieving an identical load time.  The concept was originally proposed in May 2011 and partially implemented in Adobe Flex.

For personal enrichment, this is an exercise in decoding STL with javascript.  This implementation is base on an existing javascrip-windows-bitmap-decoder.bmp.js authored by Devon Govett.  I have to implement a byteArray to float conversion (see previous blog entry).

Just as Devon Govett’s bmp decoder, this STL decoder will render for Firefox, Safari, Chrome and **Internet explorer 10 preview**.

The STL models were samples from the Android STLViewer application download.

Here is the project in googleSVN and GitHub.

monkey

Truevision TARGA Encoder

Sunday, May 2nd, 2010

TruevisionAnother popular image format yet to be supported by Flash and Flex is Truevision TARGA (.tga) format (also see Encyclopedia of graphics format).   This format supports the popular 1, 8,16,  24, 32 bits per pixel for RGBA.  In addition, it also supports run length encoding (RLE) for compression.  I am still working on the decoding but encoding RGB24bpp and RGBA32bpp with no-compression is available here right now.  This feature has also been added to the ImageDEncoder project for demonstration purpose.

Adobe Tagged Image File Format (TIFF) decoder

Saturday, August 1st, 2009

Originally created by Aldus, TIFF has been in circulation for the last two decades.  This format is currently not supported by Flash/Flex.  However, Kevin Hoyt has developed an open source encoder.  In support of this effort, I have developed a TIFF 6.0 “baseline” decoder.  According to the TIFF 6.0 specification, baseline does not support any compression, nor color spaces outside of RGB.  What this decoder does support is RGB and grayscale in bit depth 1, 8, 24 bits per pixel.  It also support pixel order of interlaced and planar as well as byte order for Intel (little endian) and Motorolla (big endian).

My decoder has been tested successfully with Adobe CS4 photoshop.  However, it will not work with Windows Vista Paint utility “yet” (stay tune).  Paint utility currently encodes with LZW compression.

For source code, example of use and construct, try it out in ImageDencoder AIR project.