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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
using System;
using System.IO;
using System.Collections.Generic;
using NW4RTools;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
namespace TestApp {
class MainClass {
public static void Main(string[] args) {
string mdlPath = "/home/me/Games/Newer/ModelRev/";
//skawo(); return;
//oldBehaviour(); return;
// Going to create a model!
//string filename = "crapmap", resmdlname = "CrapMap";
/*string filename = "SMGoldwood";
ResFile rf = new ResFile();
ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "GoldwoodBase.obj"), rf, "GoldwoodBase", ObjImporter.LightmapType.Map);
ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "BrownTree.obj"), rf, "BrownTree", ObjImporter.LightmapType.MapObj);
ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "RedTree.obj"), rf, "RedTree", ObjImporter.LightmapType.MapObj);
File.WriteAllBytes(mdlPath + "SMGoldwood.brres", BrresWriter.WriteFile(rf));*/
/*
for (int i = 0; i < 10; i++) {
string filename = "MMFullWorld";
string resmdlname = "WorldBase";
ResFile rf = new ResFile();
ObjImporter.ImportModel(mdlPath, File.OpenText(mdlPath + "fullworld-tree-fbx.obj"), rf, resmdlname, ObjImporter.LightmapType.Map);
var m = rf.GetModelGroup()["WorldBase"];
var bc = m.Bytecode["DrawOpa"];
var blah = bc.Instructions[2] as NW4RTools.Models.ByteCode.DrawShapeInstruction;
blah.MaterialID = (ushort)m.Materials.IndexOfKey("Material__76");
// trash most entries
var newList = new List<NW4RTools.Models.ByteCode.Instruction>();
for (int j = 0; j < i; j++) {
newList.Add(bc.Instructions[j]);
}
newList.Add(new NW4RTools.Models.ByteCode.DoneInstruction());
bc.Instructions = newList;
File.WriteAllBytes(mdlPath + "base" + i.ToString() + ".brres", BrresWriter.WriteFile(rf));
}
//*/
ResFile rf2 = BrresReader.LoadFile(File.ReadAllBytes(mdlPath + "base2.brres"));
using (var gw = new RenderWindow()) {
gw.Title = "whatever";
gw.SetModel(rf2, "WorldBase");
gw.Run(1, 1);
}
//*/
/*var texs = rf.GetGroup<Texture>("Textures(NW4R)");
// wtf C#?!
foreach (var kv in (IEnumerable<KeyValuePair<string,Texture>>)texs) {
kv.Value.BaseImage.Save(mdlPath + "images/" + kv.Key + ".png");
}
//var objFile = File.Open(mdlPath + mdlName + ".obj", FileMode.OpenOrCreate);
var objFile = File.Open(mdlPath + mdlName + ".dae", FileMode.OpenOrCreate);
//var sw = new StreamWriter(objFile);
//ObjWriter.WriteModel(sw, rf, mdlName);
ColladaWriter.WriteModel(objFile, rf, mdlName + whatever);
objFile.Close();*/
}
private static void skawo() {
string mdlPath = "/home/me/Games/Newer/ModelRev/";
string skawopath = "/home/me/Dropbox/NEWERsmbw/Nowy folder/obj/";
ResFile rf = new ResFile();
ObjImporter.ImportModel(skawopath, File.OpenText(skawopath + "edited.obj"), rf, "Skawo");
File.WriteAllBytes(skawopath + "skawo.brres", BrresWriter.WriteFile(rf));
ResFile rf2 = BrresReader.LoadFile(File.ReadAllBytes(skawopath + "skawo.brres"));
using (var gw = new RenderWindow()) {
gw.Title = "Skawo";
gw.SetModel(rf2, "Skawo");
gw.Run(1, 1);
}
}
private static void oldBehaviour() {
string mdlPath = "/home/me/Games/Newer/ModelRev/";
string mdlName = "cobKinokoRed";
//string mdlName = "lift_han_wood";
//string mdlName = "bgB_4502";
//string mdlName = "cobKoopaCastle";
//string mdlName = "waterPlate_W4boss";
//mdlName = "test_lift";
string whatever = (mdlName == "CS_W2" || mdlName == "CS_W3" || mdlName == "CS_W6") ? "a" : "";
byte[] file = File.ReadAllBytes(mdlPath + mdlName + ".brres");
ResFile rf = BrresReader.LoadFile(file);
using (var gw = new RenderWindow()) {
gw.Title = mdlName;
gw.SetModel(rf, mdlName);
gw.Run(1, 1);
}
//File.WriteAllBytes(mdlPath + mdlName + "_rewritten.brres", BrresWriter.WriteFile(rf));
var texs = rf.GetGroup<Texture>("Textures(NW4R)");
// wtf C#?!
foreach (var kv in (IEnumerable<KeyValuePair<string,Texture>>)texs) {
kv.Value.Images[0].Save(mdlPath + "images/" + kv.Key + ".png");
}
//var objFile = File.Open(mdlPath + "lift_han_wood_M.dae", FileMode.OpenOrCreate);
//ColladaExporter.WriteModel(objFile, rf, "lift_han_wood_M");
//objFile.Close();
}
}
}
|