Initial MoonModel implementation
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class ThreeMFTest < Minitest::Test
|
||||
def test_bambu_part_names_and_slots_follow_palette_order
|
||||
palette = [
|
||||
{ "name" => "Bright & Structural", "hex" => "#EEEEEE" },
|
||||
{ "name" => "Dark", "hex" => "#222222" },
|
||||
{ "name" => "Mid gray", "hex" => "#888888" },
|
||||
{ "name" => "Blue gray", "hex" => "#667788" }
|
||||
]
|
||||
meshes = [mesh("moon_structure", palette[0], 0)] +
|
||||
palette.each_with_index.map { |color, index| mesh("moon_surface_#{index + 1}", color, index + 2) }
|
||||
|
||||
Dir.mktmpdir do |dir|
|
||||
path = File.join(dir, "moon.3mf")
|
||||
MoonModel::ThreeMF.write(path, meshes, metadata: { "Title" => "Four Color Moon" }, palette: palette)
|
||||
Zip::File.open(path) do |zip|
|
||||
model = zip.read("3D/3dmodel.model").force_encoding(Encoding::UTF_8)
|
||||
settings = zip.read("Metadata/model_settings.config").force_encoding(Encoding::UTF_8)
|
||||
|
||||
assert_operator model.index('name="Bright & Structural"'), :<, model.index('name="Dark"')
|
||||
assert_includes model, 'name="Four Color Moon" type="model"><components>'
|
||||
assert_includes settings, 'value="Structure — Bright & Structural (#EEEEEE) — Filament 1"'
|
||||
assert_includes settings, 'value="Surface — Bright & Structural (#EEEEEE) — Filament 1"'
|
||||
assert_equal 2, settings.scan('key="extruder" value="1"').length
|
||||
assert_equal 1, settings.scan('key="extruder" value="2"').length
|
||||
assert_equal 1, settings.scan('key="extruder" value="3"').length
|
||||
assert_equal 1, settings.scan('key="extruder" value="4"').length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_unassigned_mesh_has_name_but_no_extruder
|
||||
mesh = mesh("three_leg_stand", nil, 0)
|
||||
|
||||
settings = MoonModel::ThreeMF.send(:build_bambu_model_settings, [mesh], { "Title" => "Stand" }, [])
|
||||
|
||||
assert_includes settings, "Three Leg Stand — material unassigned"
|
||||
refute_includes settings, 'key="extruder"'
|
||||
end
|
||||
|
||||
def test_unused_colors_do_not_renumber_later_palette_slots
|
||||
palette = [
|
||||
{ "name" => "First", "hex" => "#111111" },
|
||||
{ "name" => "Unused", "hex" => "#222222" },
|
||||
{ "name" => "Third", "hex" => "#333333" }
|
||||
]
|
||||
meshes = [mesh("moon_structure", palette[0], 0), mesh("moon_third", palette[2], 2)]
|
||||
|
||||
settings = MoonModel::ThreeMF.send(:build_bambu_model_settings, meshes, { "Title" => "Moon" }, palette)
|
||||
|
||||
assert_includes settings, "Surface — Third (#333333) — Filament 3"
|
||||
assert_includes settings, 'key="extruder" value="3"'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mesh(name, material, offset)
|
||||
MoonModel::Mesh.new(name: name, material: material).tap do |value|
|
||||
value.add_box([offset, 0, 0], [1, 1, 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user