Loading a stl

Discussion in 'ShapeJS' started by Mowi, Dec 8, 2013.

  1. Mowi
    Mowi Member
    I am trying to load a stl file into shape js. I found Grid load in the documentation but i cannot get it to work.
    Underneath is one of the things i tried. I used a file input box with it. What do i do wrong?

    function main(args)
    {
    //user defined parameters
    var stl = args[0];


    //Shapejs required parameters
    var modelsize = 0.1; // total size of the model
    var voxelSize = 0.1*MM; // size of grid voxel
    var a = modelsize*1.1; // make the grid size a little larger to have some clearance

    //modules

    var plate = Grid load(stl);

    // Shapejs required: render the endresult
    var endresult = plate;// choose the thing to be renndered
    var grid = createGrid(-a,a,-a,a,-a,a,voxelSize); // create the grid
    var maker = new GridMaker(); // create instance of grid maker
    maker.setSource(endresult); // gives GridMaker object to work on
    maker.makeGrid(grid); // GridMaker fills the grid with data
    return grid; // return the grid for final processing
    }
     
  2. AlanHudson
    AlanHudson Shapeways Employee Dev Team
    Here is the easiest example:

    function main(args) {
    var baseFile = args[0];
    var grid = load(baseFile,0.1*MM);

    return grid;
    }

    The load function returns a grid. So you can just return that as the result of the script.

    If you want to play with the file you might use DataSourceGrid to turn a grid into a Datasource. This example intersects a Gyroid with the loaded STL file.

    function main(args) {
    var baseFile = args[0];
    var grid = load(baseFile,0.06*MM);
    var intersect = new Intersection();
    intersect.add(new DataSourceGrid(grid, 255));
    intersect.add(new VolumePatterns.Gyroid(10*MM, 1*MM));
    var maker = new GridMaker();
    maker.setSource(intersect);
    var dest = createGrid(grid);
    maker.makeGrid(dest);
    return dest;
    }

     
  3. jpitkin
    jpitkin Member
    I can't get either of the examples above to work. Both produce an "empty scene" error.
     
  4. jpitkin
    jpitkin Member
    I fixed the problem by reducing the voxel size.