summaryrefslogtreecommitdiff
path: root/make_map_model.rb
blob: fa0061999b0fea8c3b0983ad757054d5893262c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/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"]

# 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
end

final_data = BrresWriter.write_file(brres)
System::IO::File.write_all_bytes("#{path}/MMFullWorld_mod.brres", final_data)