Skip to content

Commit

Permalink
Add mod and everything to template.
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatoryBalloon committed Jan 1, 2022
1 parent efb9cbf commit 7551f34
Show file tree
Hide file tree
Showing 24 changed files with 2,790 additions and 205 deletions.
8 changes: 5 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SOLUTION=Mod.Template.sln
ARTIFACTS=Build/Distance Mod Template.zip
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info.
SOLUTION=Distance.MeshExporter.sln
ARTIFACTS=Build/Distance MeshExporter.zip
RELEASE_BODY=This release was automatically generated as part of a GitHub workflow. Please read the repository README for more info.


Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>4e7d37c7-8afe-4f79-baf6-4ce82d05e091</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Mod.Template.Content</Import_RootNamespace>
<Import_RootNamespace>Distance.MeshExporter.Content</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)Mod\mod.json">
Expand All @@ -16,4 +16,6 @@
<ItemGroup>
<Folder Include="$(MSBuildThisFileDirectory)Mod\" />
</ItemGroup>
</Project>
</Project>


Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Mod.Template.Content.projitems" Label="Shared" />
<Import Project="Distance.MeshExporter.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
</Project>


12 changes: 12 additions & 0 deletions Distance.MeshExporter.Content/Mod/mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"FriendlyName": "MeshExporter",
"Author": "PB",
"Contact": "( .-.)",
"ModuleFileName": "Distance.MeshExporter.dll",
"Dependencies": [],
"SkipLoad": false,
"Priority": 10,
"RequiredGSLs": [
"com.github.reherc/Centrifuge.Distance"
]
}
11 changes: 7 additions & 4 deletions Mod.Template.sln → Distance.MeshExporter.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Mod.Template.Content", "Mod.Template.Content\Mod.Template.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.MeshExporter.Content", "Distance.MeshExporter.Content\Distance.MeshExporter.Content.shproj", "{4E7D37C7-8AFE-4F79-BAF6-4CE82D05E091}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mod.Template", "Mod.Template\Mod.Template.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Distance.MeshExporter", "Distance.MeshExporter\Distance.MeshExporter.csproj", "{7BCB2908-B003-45D9-BE68-50CBA5217603}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{08A1C9FA-7DC2-4A60-B9A6-AC0EB7132893}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Mod.Template.Content\Mod.Template.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
Distance.MeshExporter.Content\Distance.MeshExporter.Content.projitems*{4e7d37c7-8afe-4f79-baf6-4ce82d05e091}*SharedItemsImports = 13
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,3 +36,6 @@ Global
SolutionGuid = {E6970D48-CD23-4427-951B-448B144F30DA}
EndGlobalSection
EndGlobal



49 changes: 49 additions & 0 deletions Distance.MeshExporter/ConfigurationLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Reactor.API.Configuration;
using System;
using UnityEngine;

namespace Mod.MeshExporter
{
public class ConfigurationLogic : MonoBehaviour
{
#region Properties
#endregion

internal Settings Config;

public event Action<ConfigurationLogic> OnChanged;

private void Load()
{
Config = new Settings("Config");
}

public void Awake()
{
Load();

Save();
}

public T Get<T>(string key, T @default = default)
{
return Config.GetOrCreate(key, @default);
}

public void Set<T>(string key, T value)
{
Config[key] = value;
Save();
}

public void Save()
{
Config?.Save();
OnChanged?.Invoke(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{7BCB2908-B003-45D9-BE68-50CBA5217603}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Mod.Template</RootNamespace>
<AssemblyName>Mod.Template</AssemblyName>
<RootNamespace>Distance.MeshExporter</RootNamespace>
<AssemblyName>Distance.MeshExporter</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -86,11 +86,27 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mod.cs" />
<Compile Include="ConfigurationLogic.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Harmony\Assembly-CSharp\MeshExport\ExportObj.cs" />
<Compile Include="Harmony\Assembly-CSharp\MeshExport\MeshExporter.cs" />
<Compile Include="Harmony\UnityFBXExporter\Editor\ExporterMenu.cs" />
<Compile Include="Harmony\UnityFBXExporter\FBXExporter.cs" />
<Compile Include="Harmony\UnityFBXExporter\FBXUnityMaterialGetter.cs" />
<Compile Include="Harmony\UnityFBXExporter\FBXUnityMeshGetter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Mod.Template.targets" />
<None Include="Distance.MeshExporter.targets" />
<None Include="Harmony\UnityFBXExporter\Editor.meta" />
<None Include="Harmony\UnityFBXExporter\Editor\ExporterMenu.cs.meta" />
<None Include="Harmony\UnityFBXExporter\FBXExporter.cs.meta" />
<None Include="Harmony\UnityFBXExporter\FBXUnityMaterialGetter.cs.meta" />
<None Include="Harmony\UnityFBXExporter\FBXUnityMeshGetter.cs.meta" />
<None Include="Harmony\UnityFBXExporter\LICENSE" />
<None Include="Harmony\UnityFBXExporter\LICENSE.meta" />
<None Include="Harmony\UnityFBXExporter\readme.md" />
<None Include="Harmony\UnityFBXExporter\readme.md.meta" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
7 changes: 7 additions & 0 deletions Distance.MeshExporter/Distance.MeshExporter.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ModName>Distance MeshExporter</ModName>
</PropertyGroup>
</Project>


68 changes: 68 additions & 0 deletions Distance.MeshExporter/Entry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Centrifuge.Distance.Game;
using Centrifuge.Distance.GUI.Controls;
using Centrifuge.Distance.GUI.Data;
using Events.MainMenu;
using Events.QuitLevelEditor;
using Reactor.API.Attributes;
using Reactor.API.Interfaces.Systems;
using Reactor.API.Logging;
using Reactor.API.Runtime.Patching;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Reactor.API.Storage;

namespace Mod.MeshExporter
{
[ModEntryPoint("com.github.PredatoryBalloon/Distance.MeshExporter")]
public class Mod : MonoBehaviour
{
public static Mod Instance;

public IManager Manager { get; set; }

public static Log Logger { get; private set; }

public static ConfigurationLogic Config { get; private set; }

public static bool ModEnabled { get; set; }

public static FileSystem FileSystem_ { get; set; }


public void Initialize(IManager manager)
{
Instance = this;
Logger = LogManager.GetForCurrentAssembly();
Manager = manager;
Config = gameObject.AddComponent<ConfigurationLogic>();
FileSystem_ = new FileSystem();
//Events.MainMenu.Initialized.Subscribe(OnMainMenuInitialized);
//Events.QuitLevelEditor.Quit.Subscribe(OnMainMenuInitialized2);
//Events.MainMenu.Initialized.Unsubscribe(OnMainMenuInitialized);
//Events.MainMenu.Initialized.Broadcast(new Initialized.Data());
CreateSettingsMenu();
//GameObject lamp = new GameObject();
//Type lamptrans = System.Type.GetType("Transform");
//lamp.AddComponent(lamptrans);
RuntimePatcher.AutoPatch();
}

public void CreateSettingsMenu()
{

}

private void OnMainMenuInitialized(Initialized.Data data)
{
Resource.CreateLevelEditorPrefabDirInfo();
}

private void OnMainMenuInitialized2(Quit.Data data)
{
Resource.CreateResourceList();
}
}
}
124 changes: 124 additions & 0 deletions Distance.MeshExporter/Harmony/Assembly-CSharp/MeshExport/ExportObj.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text;
using System.IO;
namespace Mod.MeshExporter.Harmony
{
public class ExportObj
{

private string pathUrl = "Assets/";
private MeshFilter mf;

void Start(GameObject mfmwe)
{
mf = mfmwe.gameObject.GetComponent<MeshFilter>();
//CreateFile();
}

private static string MeshToString(MeshFilter mf, Vector3 scale)
{
Mesh mesh = mf.mesh;
Material[] sharedMaterials = mf.GetComponent<Renderer>().sharedMaterials;
Vector2 textureOffset = mf.GetComponent<Renderer>().material.GetTextureOffset("_MainTex");
Vector2 textureScale = mf.GetComponent<Renderer>().material.GetTextureScale("_MainTex");

StringBuilder stringBuilder = new StringBuilder().Append("mtllib design.mtl")
.Append("\n")
.Append("g ")
.Append(mf.name)
.Append("\n");

Vector3[] vertices = mesh.vertices;
for (int i = 0; i < vertices.Length; i++)
{
Vector3 vector = vertices[i];
stringBuilder.Append(string.Format("v {0} {1} {2}\n", vector.x * scale.x, vector.y * scale.y, vector.z * scale.z));
}

stringBuilder.Append("\n");

Dictionary<int, int> dictionary = new Dictionary<int, int>();

if (mesh.subMeshCount > 1)
{
int[] triangles = mesh.GetTriangles(1);

for (int j = 0; j < triangles.Length; j += 3)
{
if (!dictionary.ContainsKey(triangles[j]))
{
dictionary.Add(triangles[j], 1);
}

if (!dictionary.ContainsKey(triangles[j + 1]))
{
dictionary.Add(triangles[j + 1], 1);
}

if (!dictionary.ContainsKey(triangles[j + 2]))
{
dictionary.Add(triangles[j + 2], 1);
}
}
}

for (int num = 0; num != mesh.uv.Length; num++)
{
Vector2 vector2 = Vector2.Scale(mesh.uv[num], textureScale) + textureOffset;

if (dictionary.ContainsKey(num))
{
stringBuilder.Append(string.Format("vt {0} {1}\n", mesh.uv[num].x, mesh.uv[num].y));
}
else
{
stringBuilder.Append(string.Format("vt {0} {1}\n", vector2.x, vector2.y));
}
}

for (int k = 0; k < mesh.subMeshCount; k++)
{
stringBuilder.Append("\n");

if (k == 0)
{
stringBuilder.Append("usemtl ").Append("Material_design").Append("\n");
}

if (k == 1)
{
stringBuilder.Append("usemtl ").Append("Material_logo").Append("\n");
}

int[] triangles2 = mesh.GetTriangles(k);

for (int l = 0; l < triangles2.Length; l += 3)
{
stringBuilder.Append(string.Format("f {0}/{0} {1}/{1} {2}/{2}\n", triangles2[l] + 1, triangles2[l + 2] + 1, triangles2[l + 1] + 1));
}
}

return stringBuilder.ToString();
}

public static void CreateFile(GameObject gameob, string path)
{
using (StreamWriter streamWriter = new StreamWriter(string.Format("{0}{1}.obj", path, gameob.gameObject.name)))
{
streamWriter.Write(MeshToString(gameob.GetComponent<MeshFilter>(), new Vector3(-1f, 1f, 1f)));
streamWriter.Close();
Mod.Logger.Info("MeshExported: "+ gameob.gameObject.name);
}
// AssetDatabase.Refresh();
}

}
}
Loading

0 comments on commit 7551f34

Please sign in to comment.