Custom Grain Import

From BurnSim Wiki
Jump to navigation Jump to search

Beyond the standard grain shapes, BurnSim 4's Custom grain type lets you build a cross-section that doesn't fit any of them - sketched directly in BurnSim, or imported from a drawing. Select grain type Custom in the Grain Editor to reveal four buttons:

  • Edit shape... - opens BurnSim's own shape editor, where you build the cross-section as a list of features (holes and/or slots cut into a circular or polygonal outer boundary) rather than by drawing points. See Sketching a Shape below.
  • Import DXF... - reads a cross-section from an AutoCAD DXF file
  • Import SVG... - reads a cross-section from an SVG (vector drawing) file
  • Import Image... - traces a cross-section from a raster image (PNG/JPEG/BMP) of a drawing, scan, or photo

Whichever way a shape is built, it's simulated through the same pixel-based eroder as every other grain type - a custom cross-section erodes and reports Kn exactly as faithfully as a BATES or star grain does.

Sketching a Shape

The shape editor builds a cross-section as an outer boundary (a circle or a regular polygon) with features cut into it - any number of hole arrays or slot arrays, each an evenly-spaced ring of copies around the axis. A live preview shows the actual bitmap the simulation would rasterize, and features can be dragged directly in the preview as well as edited numerically. The editor also reports diagnostics (thin ledges, features that nearly touch, etc.) a few hundred milliseconds after each edit, and can export the shape currently on screen straight to a DXF file - useful for taking a shape built in BurnSim out to a CAD program, or for round-tripping through it as a template for hand-editing.

Importing a Drawing

All three import formats answer the same two questions the same way, so the identical drawing produces the identical grain no matter which format it's expressed in:

  • Propellant vs. void is decided by nesting: the outermost loop is propellant, a loop inside it is a void (a hole or slot), a loop inside that is an island of propellant again, and so on. There's nothing to mark or label - it's exactly how a "profile with pockets" already reads in any CAD or drawing tool.
  • Where the axis is - every import is automatically centred on the smallest circle enclosing the whole drawing (not its bounding box, which can overstate a shape's true extent).

The suggested grain diameter is set to that enclosing circle's diameter, but only when the grain's current diameter is blank or too small to contain the import - a larger existing diameter is left alone, since an imported shape can legitimately sit smaller than the grain around it.

DXF

Reads an ASCII DXF (re-export as "ASCII DXF" or "R12 ASCII" if your CAD program saved a binary one). Supported entities: LINE, CIRCLE, ARC, LWPOLYLINE and POLYLINE (including bulged/arced segments) - a drawing's outline is very often many of these meeting at their endpoints, and BurnSim chains them into closed loops automatically, bridging gaps narrower than one simulation pixel. SPLINE and ELLIPSE aren't read directly; convert them to polylines or arcs in your CAD program first.

Units come from the file's own $INSUNITS header field (inches, feet, mm, cm, or m). A DXF with no declared units is read as inches, and one with an unrecognized unit is also read as inches - both cases surface a warning so a drawing that's actually in millimetres (and would otherwise come in about 25x too large) doesn't go unnoticed.

SVG

Reads standard vector shapes: <circle>, <ellipse>, <rect> (including rounded corners), <polygon>, <polyline>, and <path> (the full M/L/H/V/C/S/Q/T/A/Z path syntax, absolute and relative), including nested <g> groups and transform attributes (translate/scale/rotate/skew/matrix). <use>/<symbol> references, <text>, embedded raster <image> elements, and CSS-driven styling aren't read - convert those to plain paths in your drawing program first.

Units come from the SVG's viewBox and width attributes (inches, cm, mm, pt, pc, or px all recognized); with neither declared, the SVG/CSS default of 96 pixels per inch is assumed, with a warning.

Raster Image (PNG/JPEG/BMP)

The least precise of the three, for when there's no vector source at all - a hand sketch, a scan, a photo of a paper template. BurnSim thresholds the image to ink/background and traces the boundary (marching squares), then simplifies the result to remove the pixel-grid staircase. Unlike DXF/SVG, a bitmap carries no scale or meaning of its own, so two things have to be entered by hand in the options dialog that appears before the trace runs:

  • Width (inches) - the physical width the image spans in real life. Required; there's nothing in a bitmap to infer it from.
  • Threshold - how dark a pixel has to be (0-255) to count as "ink" to trace. 128 (the default) suits a clean black-line-on-white drawing; lower it for a noisy scan whose background isn't quite white, raise it for faint lines. Invert flips this for a light-line-on-dark-background image.

Troubleshooting

Each importer reports failures in terms of what to fix in the source drawing rather than a generic error:

  • "No usable geometry found" - the file has none of the supported element/entity types above; check for a drawing made entirely of the unsupported ones (SPLINE, `<use>`, etc.)
  • "...has geometry but no closed outline" (DXF) - the outline has loose ends; some segments don't quite meet. Join them into a single polyline in your CAD program, or check for gaps at corners.
  • "This is a binary DXF" - re-export as ASCII/R12 ASCII DXF.
  • "This does not look like an SVG file" - the file isn't well-formed XML, or has no `<svg>` root element.