diff --git a/cws/format.go b/cws/format.go index 0bdab6c..62d9862 100644 --- a/cws/format.go +++ b/cws/format.go @@ -517,7 +517,7 @@ func (cws *CWS) Layer(index int) (layer uv3dp.Layer) { panic(err) } - layer.Z = float32(index) * cws.properties.Size.LayerHeight + layer.Z = cws.properties.LayerZ(index) layer.Image = pngImage.(*image.Gray) layer.Exposure = cws.properties.LayerExposure(index) diff --git a/empty.go b/empty.go index 4ddba58..57faa35 100644 --- a/empty.go +++ b/empty.go @@ -29,7 +29,7 @@ func (empty *EmptyPrintable) Properties() (prop Properties) { func (empty *EmptyPrintable) Layer(index int) (layer Layer) { prop := empty.Properties() - layer.Z = prop.Size.LayerHeight * float32(index) + layer.Z = prop.LayerZ(index) layer.Image = image.NewGray(prop.Bounds()) if index < prop.Bottom.Count { diff --git a/properties.go b/properties.go index ad681ab..c42f961 100644 --- a/properties.go +++ b/properties.go @@ -6,6 +6,7 @@ package uv3dp import ( "image" + "math" ) type SizeMillimeter struct { @@ -118,3 +119,8 @@ func (prop *Properties) LayerExposure(index int) (exposure Exposure) { return } + +// LayerZ get the default Z height at a layer index +func (prop *Properties) LayerZ(index int) (z float32) { + return float32(math.Round(float64(prop.Size.LayerHeight)*float64(index+1)*100) / 100.0) +} diff --git a/pws/format.go b/pws/format.go index 90a89ef..e966714 100644 --- a/pws/format.go +++ b/pws/format.go @@ -589,7 +589,7 @@ func (pws *Print) Layer(index int) (layer uv3dp.Layer) { panic(fmt.Sprintf("pws: layer %v/%v: %s", index+1, prop.Size.Layers, err)) } - layer.Z = float32(index) * prop.Size.LayerHeight + layer.Z = prop.LayerZ(index) layer.Image = slice return } diff --git a/sl1/format.go b/sl1/format.go index 3ae305c..648a56f 100644 --- a/sl1/format.go +++ b/sl1/format.go @@ -409,7 +409,7 @@ func (sl1 *Sl1) Layer(index int) (layer uv3dp.Layer) { panic(err) } - layer.Z = float32(index) * sl1.properties.Size.LayerHeight + layer.Z = sl1.properties.LayerZ(index) layer.Image = pngImage.(*image.Gray) layer.Exposure = sl1.properties.LayerExposure(index) diff --git a/uvj/format.go b/uvj/format.go index 4402479..22662ce 100644 --- a/uvj/format.go +++ b/uvj/format.go @@ -287,7 +287,7 @@ func (uvj *UVJ) Layer(index int) (layer uv3dp.Layer) { if len(uvj.Config.Layers) == 0 { layer = uv3dp.Layer{ - Z: float32(index) * uvj.Config.Properties.Size.LayerHeight, + Z: uvj.Config.Properties.LayerZ(index), Exposure: uvj.Config.Properties.LayerExposure(index), } } else { diff --git a/uvj/format_test.go b/uvj/format_test.go index e9250e6..d08c3ae 100644 --- a/uvj/format_test.go +++ b/uvj/format_test.go @@ -108,7 +108,7 @@ const ( }, "Layers": [ { - "Z": 0, + "Z": 0.05, "Exposure": { "LightOnTime": 30.5, "LightOffTime": 2.25, @@ -119,7 +119,7 @@ const ( } }, { - "Z": 0.05, + "Z": 0.1, "Exposure": { "LightOnTime": 30.5, "LightOffTime": 2.25, @@ -130,7 +130,7 @@ const ( } }, { - "Z": 0.1, + "Z": 0.15, "Exposure": { "LightOnTime": 16.5, "LightOffTime": 2.25, @@ -142,7 +142,7 @@ const ( } }, { - "Z": 0.15, + "Z": 0.2, "Exposure": { "LightOnTime": 16.5, "LightOffTime": 2.25, diff --git a/zcodex/format.go b/zcodex/format.go index 2e1c6cb..ab7d3a7 100644 --- a/zcodex/format.go +++ b/zcodex/format.go @@ -418,7 +418,7 @@ func (zcodex *Zcodex) Layer(index int) (layer uv3dp.Layer) { grayImage = asGray(pngImage) } - layer.Z = float32(index) * zcodex.properties.Size.LayerHeight + layer.Z = zcodex.properties.LayerZ(index) layer.Image = grayImage layer.Exposure = zcodex.properties.LayerExposure(index)