crysislinux / vscode-openjscad

An extension to integrate OpenJscad(v2) with Vscode
7 stars 6 forks source link

Support loading relative files #4

Open danmarshall opened 3 years ago

danmarshall commented 3 years ago

Hello, thanks so much for creating this extension! I can load a single Jscad file and see it, but not if it requires another file:

//cube.js
var jscadModeling = require("@jscad/modeling");
var primitives = jscadModeling.primitives;
var cube = primitives.cube;
function main() {
    return cube({ size: 10 });
}
module.exports = { main: main };
//cube2.js
var jscadModeling = require("@jscad/modeling");
var cube1 = require("./cube");
var booleans = jscadModeling.booleans, primitives = jscadModeling.primitives;
var cube = primitives.cube;
function main() {
    return booleans.union(
        cube({ size: 20, center: [20, 0, 0] }),
        cube1.main()
    );
}
module.exports = { main: main };
crysislinux commented 3 years ago

If you want to load multiple files, you need to use a "Project", which is basically a directory with an index.js file.

So here you can have a cube folder, then put an index.js file and export the main function from it. You can require other .js files in index.js. It's similar to a commonjs node modue.

Then instead of previewing a file, previewing the cube folder.

danmarshall commented 3 years ago

Thanks! I'll modify my local project.