sanyaade-g2g-repos / jsc3d

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

[PATCH INCLUDED] Binary STLs entitled 'solid ...' trigger ascii STL loader #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
1. get Build_plate.stl from http://www.thingiverse.com/thing:12890
2. feed to jsc3d

due to my naive test, jsc3d thinks this is an ascii STL when really it's a 
binary STL entitled 'solid Build Plate'

--- jsc3d.js    2011-10-28 14:39:03.277821883 +1100
+++ ../../webskein/jsc3d.js 2011-10-28 14:52:34.491680315 +1100
@@ -4170,8 +4170,8 @@
    mesh.vertexBuffer = [];
    mesh.indexBuffer = [];
    mesh.faceNormalBuffer = [];

-   if (data.substring(0, 5).toLowerCase() == 'solid') {
+   if (data.match(/^solid[\s\S]*facet\s*normal/i)) {
        /*
            we have an ASCII STL file.

perhaps it would be better to run the full face pattern against it rather than 
this small snippet? Otherwise we'll still have this bug with binary STLs 
entitled 'solid .... facet normal'.

Original issue reported on code.google.com by triffid....@gmail.com on 28 Oct 2011 at 4:02

GoogleCodeExporter commented 8 years ago
thanks Triffid! It seems that the exsting detection routine is not robust 
enough. I have rewritten the codes and adopt a new way to do this. the new 
method looks like this:

bool isBinary = false;
if(file size > the min file size of a binary stl file) {
  assume this is a binary file and take a snippet of bytes following the file header
  for(each byte) {
    if(the byte code > 127) {
      isBinary = true;
      break;
    }
  }
}

if(isBinary)
  read as a binary file
else
  read as an ascii file

this method is introduced by 3ds Max and also used in MeshLab and it works 
perfectly.
I have commited the new code into the repository. great!

Original comment by Humu2...@gmail.com on 10 Nov 2011 at 3:41

GoogleCodeExporter commented 8 years ago
uuups! forgiveme! i do a mistake with the right permissions on FTP. Very stupid 
from my own... i'm able to load up to 9M STL files.

Original comment by claudio....@gmail.com on 20 Feb 2014 at 3:19