Main logic is ported from SuperSlicer Signed-off-by: SoftFever <103989404+SoftFever@users.noreply.github.com>