Cloud-CNC / cura-wasm

Cura Engine powered by Web Assembly (WASM)
https://cloud-cnc.github.io
Other
61 stars 17 forks source link

Definition "fdmprinter" doesn't work #12

Closed benzend closed 3 years ago

benzend commented 3 years ago

I've tried using 'ultimaker2', 'ultimaker3', and other definitions but the one that I've found that doesn't work is 'fdmprinter'.

I've attempted to use it with overrides, without overrides, and even tested it with a command. It just doesn't seem to work correctly.

I've narrowed it down to the slicer.slice() function. And as an example so that you know that I'm using it correctly:

 const slicer = new CuraWASM({

    definition: resolveDefinition("fdmprinter"),
    overrides: [...myOverrides],

  });

  const res = await fetch(url);
  const stl = await res.arrayBuffer();

  const { gcode } = await slicer.slice(stl, "stl");

  const blob = new Blob([gcode], { type: "text/plain" }); // This isn't throwing the error, I've placed 
                                                                                        // a debugger right above this line and it never 
                                                                                        // caught it, and when I use a debugger above the slicer.slice()
                                                                                        // it throws an error
Wakeful-Cloud commented 3 years ago

@benzend Can you post the error message?

PS: sometimes debugging breakpoints don't work if you place them on empty lines.

benzend commented 3 years ago

@Wakeful-Cloud

I went through looking at how you create your resolvePrinter function which is used in your resolveDefinition function. I noticed that you do something special for "fdmprinter" and "fdmextruder".

resolvePrinter

I'm guessing if I simply don't add the definition specification it should default to "fdmprinter" and "fdmextruder"? Because it worked and I'm going to test the print.

benzend commented 3 years ago

Also here is the error that I normally get:

cura-wasm-error

Update:

My printer will just sit there and extrude, not moving anywhere. Here are some of the overrides that I'm using:

{ scope: "e0", key: "cool_fan_enabled", value: "False" },
{ scope: "e0", key: "cool_fan_full_at_height", value: "1" },
{ scope: "e0", key: "infill_before_walls", value: "False" },
{ scope: "e0", key: "infill_overlap", value: "40" },
{ scope: "e0", key: "infill_sparse_density", value: "20" },
{ scope: "e0", key: "layer_0_z_overlap", value: "0.15" },

Hopefully they're in the right format, as in TS, the values are only accepted as strings.

Lastly, I attempted adding the setting "verbose" to true in the slicer. I received this warning if that matters. extruder-count-warning

benzend commented 3 years ago

Also, I found something cool you can do, I'm not exactly what the possibilities are but I noticed you can only add one metadata key-val on the printer part.

something-cool-cura

Am I able to put more meta on there or is the limit rather than just TypeScript complaining?

Also, I know you were saying using debugger sometimes doesn't get caught, but I also attempted to comment out the code and leave just the slicer and array buffer and ended up getting the same results, and still, really only for the "fdmprinter" definition.

Wakeful-Cloud commented 3 years ago

I've tried using 'ultimaker2', 'ultimaker3', and other definitions but the one that I've found that doesn't work is 'fdmprinter'. I noticed that you do something special for "fdmprinter" and "fdmextruder".

Correct, because every printer definition relies on fdmprinter and/or fdmextruder, these are shipped with cura-wasm itself while other definitions are shipped in cura-wasm-definitions. You can see here that fdmprinter and fdmextruder (Primary definitions) are loaded into the virtual filesystem separately from each other and everything else (As opposed to resolved/secondary definitions which are combined into a single JSON document and loaded as a single file). If you examine how the CLI arguments are generated, you'll see that Cura WASM expects the secondary definition to be located at definitions/printer.def.json. So when you use either fdmprinter or fdmextruder (Which resolve to undefined as you saw), an empty file is created at definitions/printer.def.json (Instead of a secondary definition). This likely tricks Cura Engine into slicing the STL but yielding bad GCODE (Probably why your printer didn't move). Having the definition split between two repositories is going to change in V2, but in the meantime as long as you set the definition file (-j argument) to definitions/fdmprinter.def.json or definitions/fdmextruder.def.json (Via the command option), you should be fine.

Hopefully they're in the right format, as in TS, the values are only accepted as strings.

This is because all options are converted to CLI arguments (Which don't have data types).

Am I able to put more meta on there or is the limit rather than just TypeScript complaining?

You're able to define arbitrary data (Which will be stringified); only the fields necessary for Cura WASM internals are defined.

If you're still getting an error, please post more than just the promise rejection message (Even if heavily redacted), thanks!

benzend commented 3 years ago

Thank you for the elegant response! Very helpful!

Just so I'm getting this straight, if I'm using fdmprinter that means that I can only use the command option inside of the CuraWASM class?

So something like this should work:

 const slicer = new CuraWASM({
    command: "slice -j definitions/fdmprinter.def.json -o Model.gcode -s my_override -l Model.stl",
 });

Also thank you again! This piece of software is honestly really cool especially since it's in TypeScript. I'd love to run a PR but I honestly have no idea where to start.

Wakeful-Cloud commented 3 years ago

Yes, that command should work. Thanks for your interest in Cura WASM!