generated from Distance-Modding/Template.CSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efb9cbf
commit 7551f34
Showing
24 changed files
with
2,790 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
124
Distance.MeshExporter/Harmony/Assembly-CSharp/MeshExport/ExportObj.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.