lucasfanning / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 0 forks source link

Support for colored binary STL #137

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Export a binary STL with "keep color" option (i did it with Autodesk 
Inventor 2014)
2. load your STL with JSC3D

What is the expected output? What do you see instead?
i expected JSC3D to have an option to render objects using theyr original RGB 
color

What version of the product are you using? On what operating system?
1.6.5

Please provide any additional information below.
if you open a binary STL file u will notice that the STL RGB color code is 
stored in bytes 1E-20.
These bytes are preceded by "COLOR="

Original issue reported on code.google.com by e.fanz...@gmail.com on 16 Dec 2014 at 3:35

GoogleCodeExporter commented 9 years ago
I see. This is a non-standard extension on binary STL file format. It is 
documented in this article: 
http://en.wikipedia.org/wiki/STL_(file_format)#Color_in_binary_STL.  Current 
implementation does not support per-triangle color. Can you convert the STL to 
a wavefront obj file, which provide good support for per-face color?

Original comment by Humu2...@gmail.com on 17 Dec 2014 at 12:58

GoogleCodeExporter commented 9 years ago
converting my STLs to OBJs will be very uncomfortable.
The STLs are automatically generated by our PDM every time me or one of my 
colleagues modifies a part.

i'm looking to code a little hack to read the color directly from the file and 
set it.

file = '../stl/mymodel.stl'
viewer.setParameter('SceneUrl', file);
viewer.setParameter('ModelColor', STLRGBcolor(file));

it will surely impact performance, let's see how much.

Original comment by e.fanz...@gmail.com on 17 Dec 2014 at 2:46

GoogleCodeExporter commented 9 years ago
It requires modification of the JSC3D.Mesh structure, adding additional buffers 
to store per face colors. The rasterization routines must also be modified to 
take the color info into account.

Original comment by Humu2...@gmail.com on 18 Dec 2014 at 1:43

GoogleCodeExporter commented 9 years ago
Are you planning to implement this, even if it's not a standard extension of 
binary STL file format?

Original comment by e.fanz...@gmail.com on 18 Dec 2014 at 2:03

GoogleCodeExporter commented 9 years ago
Not yet. It is not difficult to modify the STL parser to read in extra 
information correctly. But it requires a lot of coding work to rewrite the 
rasterization pipelines to support per face colors, without messing up the 
existing implementation.

Original comment by Humu2...@gmail.com on 20 Dec 2014 at 3:06

GoogleCodeExporter commented 9 years ago
If you are using Jsc3d for an educational or a public project, I can write a 
customized branch edition of the library with this very feature especially for 
your project.

Original comment by Humu2...@gmail.com on 20 Dec 2014 at 11:47

GoogleCodeExporter commented 9 years ago
I'm testing jsc3d for business purposes.

I already wrote some code that can read color from the STL file and set it.
It sort of works.
I still need to find a way to properly read HEX data and give modelColor the 
proper value (i'm very bad at JS)

here's some code
notes: i'm using JQuery

$("CANVAS.3dviewer").each(function() {

    var fileUrl = this.innerHTML;
    var modelColor = '#888888'; //default color

    //keeps the canvas from stretcing my model
    this.width  = this.clientWidth * 2;
    this.height = this.clientHeight * 2;

    var viewer = new JSC3D.Viewer(this);

    viewer.setParameter('SceneUrl', fileUrl);

    $.ajax({
        url: fileUrl,
        async: false,
        success: function(data) {
            var search = "COLOR=";
            var pos = data.indexOf(search);
            if (pos >= 0) {
                pos += search.length;
                //modelColor = data[pos] + data[pos + 1] + data[pos + 2]                
            }
        }
    });

    viewer.setParameter('ModelColor', modelColor);

    viewer.init();  
    viewer.update();

});

i'll appreciate any suggestion/correction

Original comment by e.fanz...@gmail.com on 20 Dec 2014 at 12:49

GoogleCodeExporter commented 9 years ago
The solution looks good except it need to load an STL file twice.

I think I misunderstood what you meant. I had thought we were talking about the 
non-standard per-face color extension on binary STL format. In fact, it seems 
you actually meant the definition of the overall color for the entire model 
leading by 'COLOR='.  The latter is not that difficult to support based on the 
current implementation.

I'm just considering to support this feature in Jsc3d's STL loader. Could you 
send me some sample STL files with color defined for testing perpose? I guess 
it can be done within 1 or 2 days if all goes well.

Original comment by Humu2...@gmail.com on 21 Dec 2014 at 2:08

GoogleCodeExporter commented 9 years ago
I did some testing and the browser (Chrome, at least) caches the STL between 
the 2 requests.

Per-face color sounds pretty hard to me.
The STL file format defines one single color for the entire model.

And... that's one of my biggest concern.
The viewer i'm coding must display single parts and assemblies.
When the assembly contains parts of 2 different materials (for instance a piece 
of plastic with a steel insert) i can't differentiate between the two.
That's not a JSC3D fault, it's an STL file format limitation.

Original comment by e.fanz...@gmail.com on 21 Dec 2014 at 1:22

GoogleCodeExporter commented 9 years ago
That's it. The STL file format was designed mainly for rapid prototyping and 
CAM. The surface colors or materials are of less importance for this aim.

Original comment by Humu2...@gmail.com on 22 Dec 2014 at 1:42