Skip to content

Commit

Permalink
uvj: Add support for transition layers
Browse files Browse the repository at this point in the history
Summary:
- Fixes #114
  • Loading branch information
ezrec committed Oct 20, 2020
1 parent b156883 commit 5caffa9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ The command line tool is designed to be used in a 'pipeline' style, for example:

Options for '.sl1':

-f, --bottom-fade Fade bottom layers exposure time
-m, --material-name string config.init entry 'materialName' (default "3DM-ABS @")

Options for '.uvj':
Expand Down
2 changes: 1 addition & 1 deletion ctb/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ctbSlicer struct {
ChiTuBoxVersion [4]byte // 30: major, minor, patch, release
Unknown34 uint32
Unknown38 uint32
Unknown3C float32
Unknown3C float32 // 3c: TransitionLayerCount (?)
Unknown40 uint32
Unknown44 uint32
Unknown48 float32
Expand Down
17 changes: 12 additions & 5 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (exp *Exposure) Duration() (total time.Duration) {
}

// Interpolate scales settings between this and another Exposure
// scale of 0.0 = this exposure, 1.0 = target exposure
func (exp *Exposure) Interpolate(target Exposure, scale float32) (result Exposure) {
result.LightOnTime = exp.LightOnTime + float32(float64(target.LightOnTime-exp.LightOnTime)*float64(scale))
result.LightOffTime = exp.LightOffTime + float32(float64(target.LightOffTime-exp.LightOffTime)*float64(scale))
Expand All @@ -68,8 +69,9 @@ func (exp *Exposure) Interpolate(target Exposure, scale float32) (result Exposur

// Bottom layer exposure
type Bottom struct {
Exposure // Exposure
Count int // Number of bottom layers
Exposure // Exposure
Count int // Number of bottom layers
Transition int // Number of transition layers above the bottom layer
}

type PreviewType uint
Expand Down Expand Up @@ -117,10 +119,15 @@ func (prop *Properties) Bounds() image.Rectangle {

// Exposure gets the default exposure by layer index
func (prop *Properties) LayerExposure(index int) (exposure Exposure) {
if index >= prop.Bottom.Count {
exposure = prop.Exposure
} else {
switch {
case index < prop.Bottom.Count:
exposure = prop.Bottom.Exposure
case index < prop.Bottom.Count+prop.Bottom.Transition:
// Scaling is a bit odd, but we don't want to include 0.0 (same as bottom) or 1.0 (same as top) in our range
scale := float32(index-prop.Bottom.Count+1) / float32(prop.Bottom.Transition+1)
exposure = prop.Bottom.Exposure.Interpolate(prop.Exposure, scale)
default:
exposure = prop.Exposure
}

// Validate LightPWM
Expand Down
23 changes: 6 additions & 17 deletions sl1/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ type Format struct {
*pflag.FlagSet

MaterialName string
BottomFade bool
}

func NewFormatter(suffix string) (sf *Format) {
Expand All @@ -150,7 +149,6 @@ func NewFormatter(suffix string) (sf *Format) {
}

sf.StringVarP(&sf.MaterialName, "material-name", "m", "3DM-ABS @", "config.init entry 'materialName'")
sf.BoolVarP(&sf.BottomFade, "bottom-fade", "f", false, "Fade bottom layers exposure time")
sf.SetInterspersed(false)

return
Expand All @@ -170,21 +168,15 @@ func (sf *Format) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err er
size := printable.Size()
exp := printable.Exposure()
bot := printable.Bottom().Exposure
bot_count := printable.Bottom().Count
bot_slow := printable.Bottom().Count
bot_fade := printable.Bottom().Transition

layerHeight := fmt.Sprintf("%.3g", size.LayerHeight)
materialName := sf.MaterialName
if strings.HasSuffix(materialName, " @") {
materialName += layerHeight
}

numFade := 0
numSlow := bot_count
if sf.BottomFade {
numFade = bot_count
numSlow = 0
}

config_ini := map[string]string{
"action": "print",
"jobDir": "uv3dp",
Expand All @@ -193,9 +185,9 @@ func (sf *Format) Encode(writer uv3dp.Writer, printable uv3dp.Printable) (err er
"fileCreationTimestamp": sl1Timestamp(),
"layerHeight": layerHeight,
"materialName": materialName,
"numFade": fmt.Sprintf("%v", numFade),
"numFade": fmt.Sprintf("%v", bot_fade),
"numFast": fmt.Sprintf("%v", size.Layers),
"numSlow": fmt.Sprintf("%v", numSlow),
"numSlow": fmt.Sprintf("%v", bot_slow),
"printProfile": layerHeight + " Normal",
"printTime": fmt.Sprintf("%.3f", float32(uv3dp.PrintDuration(printable))/float32(time.Second)),
"printerModel": "SL1",
Expand Down Expand Up @@ -369,11 +361,8 @@ func (sf *Format) Decode(reader uv3dp.Reader, filesize int64) (printable uv3dp.P
bot.Exposure = defaultBottomExposure
bot.Exposure.LightOnTime = config.expTimeFirst

if config.numFade > 0 {
bot.Count = int(config.numFade)
} else {
bot.Count = int(config.numSlow)
}
bot.Transition = int(config.numFade)
bot.Count = int(config.numSlow)

exp := &prop.Exposure
*exp = defaultExposure
Expand Down
8 changes: 4 additions & 4 deletions sl1/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ var (
RetractSpeed: 200.0,
},
Bottom: uv3dp.Bottom{
Count: 2,
Count: 2,
Transition: 1,
Exposure: uv3dp.Exposure{
LightOnTime: 16.500,
LightOffTime: 2.250,
Expand All @@ -80,9 +81,9 @@ fileCreationTimestamp = 1-01-01 at 00:00:00 UTC
jobDir = uv3dp
layerHeight = 0.05
materialName = 3DM-ABS @0.05
numFade = 2
numFade = 1
numFast = 4
numSlow = 0
numSlow = 2
printProfile = 0.05 Normal
printTime = 100.520
printerModel = SL1
Expand Down Expand Up @@ -111,7 +112,6 @@ func TestEncodeEmptySl1(t *testing.T) {
empty := uv3dp.NewEmptyPrintable(testProperties)

formatter := NewFormatter(".sl1")
formatter.BottomFade = true

buffWriter := &bytes.Buffer{}
formatter.Encode(buffWriter, empty)
Expand Down
22 changes: 12 additions & 10 deletions uvj/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
LayerHeight: 0.05,
},
Exposure: uv3dp.Exposure{
LightOnTime: 16.500,
LightOnTime: 16,
LightOffTime: 2.250,
LightPWM: 123,
LiftHeight: 5.5,
Expand All @@ -113,9 +113,10 @@ var (
RetractSpeed: 200.0,
},
Bottom: uv3dp.Bottom{
Count: 2,
Count: 1,
Transition: 1,
Exposure: uv3dp.Exposure{
LightOnTime: 30.500,
LightOnTime: 30,
LightOffTime: 2.250,
LightPWM: 255,
LiftHeight: 5.5,
Expand Down Expand Up @@ -145,7 +146,7 @@ const (
"LayerHeight": 0.05
},
"Exposure": {
"LightOnTime": 16.5,
"LightOnTime": 16,
"LightOffTime": 2.25,
"LightPWM": 123,
"LiftHeight": 5.5,
Expand All @@ -154,20 +155,21 @@ const (
"RetractSpeed": 200
},
"Bottom": {
"LightOnTime": 30.5,
"LightOnTime": 30,
"LightOffTime": 2.25,
"LiftHeight": 5.5,
"LiftSpeed": 120,
"RetractHeight": 3.3,
"RetractSpeed": 200,
"Count": 2
"Count": 1,
"Transition": 1
}
},
"Layers": [
{
"Z": 0.05,
"Exposure": {
"LightOnTime": 30.5,
"LightOnTime": 30,
"LightOffTime": 2.25,
"LiftHeight": 5.5,
"LiftSpeed": 120,
Expand All @@ -178,7 +180,7 @@ const (
{
"Z": 0.1,
"Exposure": {
"LightOnTime": 30.5,
"LightOnTime": 23,
"LightOffTime": 2.25,
"LiftHeight": 5.5,
"LiftSpeed": 120,
Expand All @@ -189,7 +191,7 @@ const (
{
"Z": 0.15,
"Exposure": {
"LightOnTime": 16.5,
"LightOnTime": 16,
"LightOffTime": 2.25,
"LightPWM": 123,
"LiftHeight": 5.5,
Expand All @@ -201,7 +203,7 @@ const (
{
"Z": 0.2,
"Exposure": {
"LightOnTime": 16.5,
"LightOnTime": 16,
"LightOffTime": 2.25,
"LightPWM": 123,
"LiftHeight": 5.5,
Expand Down

0 comments on commit 5caffa9

Please sign in to comment.