Skip to content

Commit 5201821

Browse files
author
theawesomecoder61
committed
Version 1.5.1
1 parent 3e2ec78 commit 5201821

34 files changed

+4508
-215
lines changed

Blacksmith/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<setting name="pointSize" serializeAs="String">
3838
<value>5</value>
3939
</setting>
40+
<setting name="hidePopups" serializeAs="String">
41+
<value>3</value>
42+
</setting>
4043
</Blacksmith.Properties.Settings>
4144
</userSettings>
4245
<runtime>

Blacksmith/Blacksmith.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<ApplicationIcon>Resources\noun_Blacksmith_1124400.ico</ApplicationIcon>
8181
</PropertyGroup>
8282
<ItemGroup>
83+
<Reference Include="INIFileParser, Version=2.5.2.0, Culture=neutral, PublicKeyToken=79af7b307b65cf3c, processorArchitecture=MSIL">
84+
<HintPath>..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll</HintPath>
85+
</Reference>
8386
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
8487
<HintPath>..\packages\NLog.4.5.10\lib\net45\NLog.dll</HintPath>
8588
</Reference>
@@ -118,12 +121,14 @@
118121
</Reference>
119122
</ItemGroup>
120123
<ItemGroup>
124+
<Compile Include="Enums\NormalExportMode.cs" />
121125
<Compile Include="Forms\ConvertDialog.cs">
122126
<SubType>Form</SubType>
123127
</Compile>
124128
<Compile Include="Forms\ConvertDialog.Designer.cs">
125129
<DependentUpon>ConvertDialog.cs</DependentUpon>
126130
</Compile>
131+
<Compile Include="Message.cs" />
127132
<Compile Include="Three\Cube.cs" />
128133
<Compile Include="Enums\EntryTreeNodeType.cs" />
129134
<Compile Include="Enums\FindType.cs" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Blacksmith.Enums
2+
{
3+
public enum NormalExportMode
4+
{
5+
EXTRACTED = 0,
6+
CALCULATED = 1,
7+
NONE = 2
8+
}
9+
}

Blacksmith/Enums/ResourceType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Blacksmith.Enums
44
{
55
public enum ResourceType : uint
66
{
7-
// http://wiki.tbotr.net/index.php?title=Assassins_Creed:File_Formats
7+
// source: http://wiki.tbotr.net/index.php?title=Assassins_Creed:File_Formats
88
_NONE = 4291144048, // something I chose randomly
99
ANIMATION = 262342271,
1010
BUILD_TABLE = 585940579,

Blacksmith/FileTypes/OBJ.cs

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Blacksmith.Three;
1+
using Blacksmith.Enums;
2+
using Blacksmith.Three;
23
using OpenTK;
34
using System;
45
using System.Collections.Generic;
@@ -193,8 +194,6 @@ public static Model LoadFromString(string obj)
193194
texs.Add(new Vector2());
194195
normals.Add(new Vector3());
195196

196-
//int currentindice = 0;
197-
198197
// Read file line by line
199198
foreach (string line in lines)
200199
{
@@ -304,8 +303,6 @@ public static Model LoadFromString(string obj)
304303
success |= int.TryParse(faceparts[1].Split('/')[0], out v2);
305304
success |= int.TryParse(faceparts[2].Split('/')[0], out v3);
306305

307-
faceIndices.Add(new Tuple<int, int, int>(v1, v2, v3));
308-
309306
if (faceparts[0].Count((char c) => c == '/') >= 2)
310307
{
311308
success |= int.TryParse(faceparts[0].Split('/')[1], out t1);
@@ -351,6 +348,8 @@ public static Model LoadFromString(string obj)
351348
}
352349
else
353350
{
351+
faceIndices.Add(new Tuple<int, int, int>(v1, v2, v3));
352+
354353
TempVertex tv1 = new TempVertex(v1, n1, t1);
355354
TempVertex tv2 = new TempVertex(v2, n2, t2);
356355
TempVertex tv3 = new TempVertex(v3, n3, t3);
@@ -364,37 +363,33 @@ public static Model LoadFromString(string obj)
364363
}
365364
}
366365
}
367-
368-
Model mdl = new Model();
366+
369367
Mesh mesh = new Mesh();
370-
for (int i = 0; i < verts.Count; i += 3)
368+
for (int i = 0; i < faces.Count; i += 3)
371369
{
372370
var face = faces[i];
373-
FaceVertex v1 = new FaceVertex(verts[face.Item1.Vertex], normals[face.Item1.Normal], texs[face.Item1.Texcoord]);
374-
FaceVertex v2 = new FaceVertex(verts[face.Item2.Vertex], normals[face.Item2.Normal], texs[face.Item2.Texcoord]);
375-
FaceVertex v3 = new FaceVertex(verts[face.Item3.Vertex], normals[face.Item3.Normal], texs[face.Item3.Texcoord]);
376371

377372
Mesh.Vertex vert1 = new Mesh.Vertex
378373
{
379-
Position = v1.Position,
380-
Normal = v1.Normal,
381-
TextureCoordinate = v1.TextureCoord
374+
Position = verts[face.Item1.Vertex],
375+
Normal = normals[face.Item1.Normal],
376+
TextureCoordinate = texs[face.Item1.Texcoord]
382377
};
383378
mesh.Vertices.Add(vert1);
384379

385380
Mesh.Vertex vert2 = new Mesh.Vertex
386381
{
387-
Position = v2.Position,
388-
Normal = v2.Normal,
389-
TextureCoordinate = v2.TextureCoord
382+
Position = verts[face.Item2.Vertex],
383+
Normal = normals[face.Item2.Normal],
384+
TextureCoordinate = texs[face.Item2.Texcoord]
390385
};
391386
mesh.Vertices.Add(vert2);
392387

393388
Mesh.Vertex vert3 = new Mesh.Vertex
394389
{
395-
Position = v3.Position,
396-
Normal = v3.Normal,
397-
TextureCoordinate = v3.TextureCoord
390+
Position = verts[face.Item3.Vertex],
391+
Normal = normals[face.Item3.Normal],
392+
TextureCoordinate = texs[face.Item3.Texcoord]
398393
};
399394
mesh.Vertices.Add(vert3);
400395

@@ -416,30 +411,41 @@ public static Model LoadFromString(string obj)
416411
mesh.VertexCount = mesh.Vertices.Count;
417412
mesh.FaceCount = mesh.Faces.Count;
418413
mesh.IndexCount = mesh.Indices.Count;
419-
mdl.Meshes.Add(mesh);
420414

421-
return mdl;
415+
return Model.CreateFromMesh(mesh);
422416
}
423-
424-
public static string Export(Model model, bool calculateNormals = false, bool exportingIndividually = false)
417+
418+
public static string Export(Model model, NormalExportMode normalMode, bool exportingIndividually = false)
425419
{
426420
StringBuilder obj = new StringBuilder();
427421
for (int i = 0; i < model.Meshes.Count; i++)
428422
{
423+
for (int j = 0; j < model.Meshes[i].Vertices.Count; j++)
424+
{
425+
Mesh.Vertex v = model.Meshes[i].Vertices[j];
426+
obj.AppendLine($"v {v.Position.X} {v.Position.Y} {v.Position.Z}");
427+
}
428+
429429
for (int j = 0; j < model.Meshes[i].Vertices.Count; j++)
430430
{
431431
Mesh.Vertex v = model.Meshes[i].Vertices[j];
432432
Vector3 n = v.Normal;
433-
if (calculateNormals)
433+
434+
if (normalMode == NormalExportMode.CALCULATED)
434435
n = model.Meshes[i].CalculatedNormals[j];
435436

436-
obj.AppendLine($"v {v.Position.X} {v.Position.Y} {v.Position.Z}");
437-
obj.AppendLine($"vn {n.X} {n.Y} {n.Z}");
437+
if (normalMode != NormalExportMode.NONE)
438+
obj.AppendLine($"vn {n.X} {n.Y} {n.Z}");
439+
}
440+
441+
for (int j = 0; j < model.Meshes[i].Vertices.Count; j++)
442+
{
443+
Mesh.Vertex v = model.Meshes[i].Vertices[j];
438444
obj.AppendLine($"vt {v.TextureCoordinate.X} {v.TextureCoordinate.Y}");
439445
}
440446

441447
obj.AppendLine($"g mesh{i}");
442-
for (int j = 0; j < model.Meshes[i].FaceCount; j++)
448+
for (int j = 0; j < model.Meshes[i].Faces.Count; j++)
443449
{
444450
Mesh.Face f = model.Meshes[i].Faces[j];
445451
if (exportingIndividually)
@@ -448,9 +454,17 @@ public static string Export(Model model, bool calculateNormals = false, bool exp
448454
f.Y -= model.Meshes[i].NumOfVerticesBeforeMe;
449455
f.Z -= model.Meshes[i].NumOfVerticesBeforeMe;
450456
}
451-
string x = $"{f.X + 1}/{f.X + 1}/{f.X + 1}";
452-
string y = $"{f.Y + 1}/{f.Y + 1}/{f.Y + 1}";
453-
string z = $"{f.Z + 1}/{f.Z + 1}/{f.Z + 1}";
457+
458+
string x = $"{f.X + 1}/{f.X + 1}";
459+
string y = $"{f.Y + 1}/{f.Y + 1}";
460+
string z = $"{f.Z + 1}/{f.Z + 1}";
461+
if (normalMode != NormalExportMode.NONE)
462+
{
463+
x += f.X + 1;
464+
y += f.Y + 1;
465+
z += f.Z + 1;
466+
}
467+
454468
obj.AppendLine($"f {x} {y} {z}");
455469
}
456470
}

Blacksmith/FileTypes/STL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void ExportBinary(string fileName, Model model, bool exportingIndi
6767
}
6868
catch (Exception e)
6969
{
70-
MessageBox.Show(e.Message, "Failure");
70+
Message.Fail(e.Message + e.StackTrace);
7171
}
7272
}
7373
}

0 commit comments

Comments
 (0)