Skip to content

Commit

Permalink
Bug fixes and error message pop ups.
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDoleOwndU committed Oct 20, 2018
1 parent 2c03770 commit 53633bd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
17 changes: 9 additions & 8 deletions FMDL-Studio-v2/Assets/Fmdl Studio/FMDL Studio v2.unity
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ OcclusionCullingSettings:
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
Expand All @@ -39,6 +39,7 @@ RenderSettings:
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44824535, g: 0.49827206, b: 0.5755818, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand All @@ -54,11 +55,10 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
Expand Down Expand Up @@ -116,9 +116,9 @@ NavMeshSettings:
--- !u!1 &1722762242
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
serializedVersion: 6
m_Component:
- component: {fileID: 1722762244}
- component: {fileID: 1722762243}
Expand All @@ -132,7 +132,7 @@ GameObject:
--- !u!108 &1722762243
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1722762242}
m_Enabled: 1
Expand All @@ -159,6 +159,7 @@ Light:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
Expand All @@ -168,7 +169,7 @@ Light:
--- !u!4 &1722762244
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1722762242}
m_LocalRotation: {x: 0.92387956, y: 0, z: 0, w: 0.38268343}
Expand Down
39 changes: 38 additions & 1 deletion FMDL-Studio-v2/Assets/Fmdl Studio/Scripts/Classes/Fmdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public void Write(GameObject gameObject, string filePath)

private void GetFmdlData(GameObject gameObject)
{
FoxModel foxModel = gameObject.GetComponent<FoxModel>();
FoxModel foxModel = gameObject.GetComponent<FoxModel>();// ? gameObject.GetComponent<FoxModel>() : null;
Transform rootBone = gameObject.transform;
List<Transform> bones = new List<Transform>(0);
List<BoxCollider> boundingBoxes = new List<BoxCollider>(0);
Expand All @@ -1178,16 +1178,32 @@ private void GetFmdlData(GameObject gameObject)
List<Vector4> materialParameterVectors = new List<Vector4>(0);
List<string> strings = new List<string>(0);

if(foxModel == null)
{
EditorUtility.DisplayDialog("FoxModel not found!", "The model does not contain a FoxModel component!", "Ok");
throw new Exception("FoxModel not found!");
} //if

foreach (Transform t in gameObject.transform)
if (t.gameObject.name == "[Root]")
{
rootBone = t;

if(!t.gameObject.GetComponent<BoxCollider>())
{
EditorUtility.DisplayDialog("Bounding boxes not found!", "Bounding boxes are missing! Make sure they've been generated!", "Ok");
throw new Exception("Bounding boxes not found!");
} //if

boundingBoxes.Add(t.gameObject.GetComponent<BoxCollider>());
break;
} //if

if (rootBone == gameObject.transform)
{
EditorUtility.DisplayDialog("[Root] not found!", "The [Root] object was not found in the model!", "Ok");
throw new Exception("[Root] not found!");
} //if

GetBonesAndBoundingBoxes(rootBone, bones, boundingBoxes);
GetMeshesMaterialsTexturesAndVectors(gameObject, meshes, materials, textures, materialParameterVectors);
Expand Down Expand Up @@ -1249,6 +1265,13 @@ private void GetFmdlData(GameObject gameObject)

fmdlMeshGroup.nameIndex = (ushort)strings.Count;
strings.Add(foxMeshGroup.name);

if(i == 0 && foxMeshGroup.name != "MESH_ROOT")
{
EditorUtility.DisplayDialog("MESH_ROOT missing!", "MESH_ROOT is missing from the mesh groups or is not the first mesh group!", "Ok");
throw new Exception("MESH_ROOT missing!");
} //if

fmdlMeshGroup.invisibilityFlag = foxMeshGroup.visible ? (ushort)0 : (ushort)1;
fmdlMeshGroup.parentIndex = foxMeshGroup.parent;
fmdlMeshGroup.unknown0 = -1;
Expand Down Expand Up @@ -1414,7 +1437,10 @@ private void GetFmdlData(GameObject gameObject)
int meshBoneCount = meshes[i].bones.Length;

if (meshBoneCount > 32)
{
EditorUtility.DisplayDialog("Bone Group has more than 32 bones!", "A mesh cannot be weighted to more than 32 bones!", "Ok");
throw new Exception("A mesh cannot be weighted to more than 32 bones!");
} //if

fmdlBoneGroup.unknown0 = 4;
fmdlBoneGroup.boneIndexCount = (ushort)meshBoneCount;
Expand Down Expand Up @@ -2313,6 +2339,8 @@ private void GetBonesAndBoundingBoxes(Transform transform, List<Transform> bones

private void GetMeshesMaterialsTexturesAndVectors(GameObject gameObject, List<SkinnedMeshRenderer> meshes, List<Material> materials, List<Texture> textures, List<Vector4> vectors)
{
string errors = "";

foreach (Transform t in gameObject.transform)
{
if (t.gameObject.GetComponent<SkinnedMeshRenderer>())
Expand All @@ -2328,6 +2356,9 @@ private void GetMeshesMaterialsTexturesAndVectors(GameObject gameObject, List<Sk
Shader shader = material.shader;
int propertyCount = ShaderUtil.GetPropertyCount(shader);

if (!shader.name.Contains("FoxShaders"))
errors += $"{skinnedMeshRenderer.name}\n";

for (int i = 0; i < propertyCount; i++)
if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
{
Expand All @@ -2346,6 +2377,12 @@ private void GetMeshesMaterialsTexturesAndVectors(GameObject gameObject, List<Sk
} //if
} //if
} //foreach

if(!string.IsNullOrWhiteSpace(errors))
{
EditorUtility.DisplayDialog("Invalid Shader!", $"The following meshes are not using Fox shaders:\n{errors}", "Ok");
throw new Exception("Invalid Shader!");
} //if
} //GetMeshesMaterialsAndTextures

private void WriteFmdlData(string filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ private void Awake()
{
meshGroups[i] = new FoxMeshGroup();
meshGroups[i].name = meshGroupNames[i];
if (i == 0)
meshGroups[i].parent = -1;
else
meshGroups[i].parent = 0;
} //for

meshDefinitions = new FoxMeshDefinition[meshes.Count];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ private static void SetBoundingBoxByVertex(Transform bone, Vector3 vertex)
Vector3 max = collider.bounds.max;
Vector3 min = collider.bounds.min;

if (vertex.x > max.x || max.x == 9999f)
if (vertex.x > max.x || max.x == 9999f || float.IsNaN(max.x))
max.x = vertex.x;
if (vertex.y > max.y || max.y == 9999f)
if (vertex.y > max.y || max.y == 9999f || float.IsNaN(max.y))
max.y = vertex.y;
if (vertex.z > max.z || max.z == 9999f)
if (vertex.z > max.z || max.z == 9999f || float.IsNaN(max.z))
max.z = vertex.z;
if (vertex.x < min.x || min.x == -9999f)
if (vertex.x < min.x || min.x == -9999f || float.IsNaN(min.x))
min.x = vertex.x;
if (vertex.y < min.y || min.y == -9999f)
if (vertex.y < min.y || min.y == -9999f || float.IsNaN(min.y))
min.y = vertex.y;
if (vertex.z < min.z || min.z == -9999f)
if (vertex.z < min.z || min.z == -9999f || float.IsNaN(min.z))
min.z = vertex.z;

Bounds bounds = new Bounds();
Expand Down
2 changes: 1 addition & 1 deletion FMDL-Studio-v2/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2018.2.1f1
m_EditorVersion: 2018.2.6f1

0 comments on commit 53633bd

Please sign in to comment.