diff options
Diffstat (limited to 'make_map_model_b.rb')
-rwxr-xr-x | make_map_model_b.rb | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/make_map_model_b.rb b/make_map_model_b.rb new file mode 100755 index 0000000..388c4ac --- /dev/null +++ b/make_map_model_b.rb @@ -0,0 +1,89 @@ +#!/usr/bin/mono /home/me/Packages/IronLanguages-main-ba2094c/bin/Release/ir.exe +## Requires IronRuby + +$: << "/home/me/Dev/NW4RTools/NW4RTools/bin/Release" +require 'NW4RTools' +require 'System.Drawing' + +include System +include NW4RTools +include NW4RTools::Models + +brres = ResFile.new +models = brres.create_model_group +path = '/home/me/Games/Newer/ModelRev' +reader = System::IO::StreamReader.new("#{path}/fullworld-Z20nvrc.obj") + +ObjImporter.ImportModel(path, reader, brres, "WorldBase", ObjImporter::LightmapType.Map) + +model = models["WorldBase"] + +alpha_tex = Texture.new +alpha_bitmap = System::Drawing::Bitmap.new("#{path}/images/alphaBlender.png") +alpha_tex.images = System::Array[System::Drawing::Bitmap].new([alpha_bitmap]) +alpha_tex.format = TextureFormat.RGB5A3 +brres.get_texture_group.add 'alphaBlender', alpha_tex + +# yay +#model.shapes["World2_PathsPlumbing__World2_PathsPlumbing"].clr_data[0].raw_data = System::Array[Byte].new([255, 255, 255, 128]) + +# move paths into DrawXlu +opa = model.bytecode["DrawOpa"] +if model.bytecode.contains_key("DrawXlu") + xlu = model.bytecode["DrawXlu"] +else + xlu = ByteCode.new + xlu.instructions = System::Collections::Generic::List[ByteCode::Instruction].new + xlu.instructions << ByteCode::DoneInstruction.new + model.bytecode["DrawXlu"] = xlu +end + +shape_array = model.shapes.to_a + +to_be_moved = opa.instructions.select do |insn| + insn.is_a?(ByteCode::DrawShapeInstruction) and + shape_array[insn.shape_i_d].key =~ /path/i +end + +to_be_moved.each do |insn| + opa.instructions.remove insn + xlu.instructions.insert 0, insn +end + +# how's this for hackiness? +model.materials.each do |kvp| + next unless kvp.key =~ /path/i + + mat = kvp.value + + pix = DisplayListWriter.new + pix.load_b_p_reg 0xF33F0000 + pix.load_b_p_reg 0x40000017 + pix.load_b_p_reg 0xFE00FFE3 + + # Blend Mode: logicmode: LO_SET, subtract: 0, srcfactor: SRCALPHA, dstfactor: INVSRCALPHA, + # alphaupdate: 0, colorupdate: 0, dither: 0, logicopenable: 0, blendenable: 1 + pix.load_b_p_reg 0x4100F4A1 + + pix.load_b_p_reg 0x42000000 + pix.end + mat.pix_d_l = pix.get_buffer + + tc = DisplayListWriter.new + [0xE2,0xE3,0xE4,0xE5,0xE6,0xE7].each_slice(2) do |first, second| + tc.load_b_p_reg first << 24 + 3.times { tc.load_b_p_reg second << 24 } + end + tc.add_padding 4 + (0xE0..0xE5).each {|bit| tc.load_b_p_reg (bit << 24) | 0x800000} + tc.load_b_p_reg 0xE688F000 + tc.load_b_p_reg 0xE7800000 + tc.pad_to_size 0x80 + tc.end + mat.tev_color_d_l = tc.get_buffer + +end + +final_data = BrresWriter.write_file(brres) +System::IO::File.write_all_bytes("#{path}/MMFullWorld_mod.brres", final_data) + |