unity and native osx bundles and frameworks build from the same project now
This commit is contained in:
9
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta
Normal file
9
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8700a9474fed74e75b15b31742f639e2
|
||||
folderAsset: yes
|
||||
timeCreated: 1465591252
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class OBJData
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public List<Vector3> m_Vertices = new List<Vector3>();
|
||||
public List<Vector3> m_Normals = new List<Vector3>();
|
||||
public List<Vector2> m_UVs = new List<Vector2>();
|
||||
public List<Vector2> m_UV2s = new List<Vector2>();
|
||||
public List<Color> m_Colors = new List<Color>();
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public List<OBJMaterial> m_Materials = new List<OBJMaterial>();
|
||||
public List<OBJGroup> m_Groups = new List<OBJGroup>();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c57f7fdab36a3f4d9d97f4785a884f6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
101
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs
Normal file
101
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using UnityExtension;
|
||||
|
||||
public class OBJFace
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private readonly List<OBJFaceVertex> m_Vertices = new List<OBJFaceVertex>();
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public void AddVertex(OBJFaceVertex lVertex)
|
||||
{
|
||||
m_Vertices.Add(lVertex);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public void ParseVertex(string lVertexString)
|
||||
{
|
||||
var fields = lVertexString.Split(new[] { '/' }, StringSplitOptions.None);
|
||||
|
||||
var lIndex = fields[0].ParseInvariantInt();
|
||||
var faceVertex = new OBJFaceVertex
|
||||
{
|
||||
m_VertexIndex = lIndex - 1
|
||||
};
|
||||
|
||||
if (fields.Length > 1)
|
||||
{
|
||||
lIndex = fields[1].Length == 0 ? 0 : fields[1].ParseInvariantInt();
|
||||
faceVertex.m_UVIndex = lIndex - 1;
|
||||
}
|
||||
|
||||
if (fields.Length > 2)
|
||||
{
|
||||
lIndex = fields[2].Length == 0 ? 0 : fields[2].ParseInvariantInt();
|
||||
faceVertex.m_NormalIndex = lIndex - 1;
|
||||
}
|
||||
|
||||
if (fields.Length > 3)
|
||||
{
|
||||
lIndex = fields[3].Length == 0 ? 0 : fields[3].ParseInvariantInt();
|
||||
faceVertex.m_UV2Index = lIndex - 1;
|
||||
}
|
||||
|
||||
if (fields.Length > 4)
|
||||
{
|
||||
lIndex = fields[4].Length == 0 ? 0 : fields[4].ParseInvariantInt();
|
||||
faceVertex.m_ColorIndex = lIndex - 1;
|
||||
}
|
||||
|
||||
AddVertex(faceVertex);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string ToString(int lIndex)
|
||||
{
|
||||
OBJFaceVertex lFaceVertex = m_Vertices[lIndex];
|
||||
|
||||
string lOutput = (lFaceVertex.m_VertexIndex + 1).ToString();
|
||||
|
||||
if (lFaceVertex.m_UVIndex > -1)
|
||||
{
|
||||
lOutput += string.Format("/{0}", (lFaceVertex.m_UVIndex + 1).ToString());
|
||||
}
|
||||
|
||||
if (lFaceVertex.m_NormalIndex > -1)
|
||||
{
|
||||
lOutput += string.Format("/{0}", (lFaceVertex.m_NormalIndex + 1).ToString());
|
||||
}
|
||||
|
||||
if (lFaceVertex.m_UV2Index > -1)
|
||||
{
|
||||
lOutput += string.Format("/{0}", (lFaceVertex.m_UV2Index + 1).ToString());
|
||||
}
|
||||
|
||||
if (lFaceVertex.m_ColorIndex > -1)
|
||||
{
|
||||
lOutput += string.Format("/{0}", (lFaceVertex.m_ColorIndex + 1).ToString());
|
||||
}
|
||||
|
||||
return lOutput;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public OBJFaceVertex this[int i]
|
||||
{
|
||||
get { return m_Vertices[i]; }
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public int Count
|
||||
{
|
||||
get { return m_Vertices.Count; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07402f6cbfe2d0e40ab4d7363cb0ed64
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
public class OBJFaceVertex
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public int m_VertexIndex = -1;
|
||||
public int m_UVIndex = -1;
|
||||
public int m_UV2Index = -1;
|
||||
public int m_NormalIndex = -1;
|
||||
public int m_ColorIndex = -1;
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_VertexIndex ^ m_UVIndex ^ m_UV2Index ^ m_NormalIndex ^ m_ColorIndex;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
OBJFaceVertex faceVertex = (OBJFaceVertex)obj;
|
||||
return m_VertexIndex == faceVertex.m_VertexIndex
|
||||
&& m_UVIndex == faceVertex.m_UVIndex
|
||||
&& m_UV2Index == faceVertex.m_UV2Index
|
||||
&& m_NormalIndex == faceVertex.m_NormalIndex
|
||||
&& m_ColorIndex == m_ColorIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5cff977d3365a4f9f33933bb603037
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OBJGroup
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private readonly List<OBJFace> m_Faces = new List<OBJFace>();
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public OBJGroup(string lName)
|
||||
{
|
||||
m_Name = lName;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_Name { get; private set; }
|
||||
public OBJMaterial m_Material { get; set; }
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public IList<OBJFace> Faces { get { return m_Faces; } }
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public void AddFace(OBJFace lFace)
|
||||
{
|
||||
m_Faces.Add(lFace);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8508b6de42212c84ebaec559aed6c7b6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
219
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs
Normal file
219
integrations/Unity3D/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs
Normal file
@@ -0,0 +1,219 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using UnityExtension;
|
||||
|
||||
/*
|
||||
* Currently only supports Triangluar Meshes
|
||||
*/
|
||||
|
||||
public class OBJLoader
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static OBJData m_OBJData = null;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static OBJMaterial m_CurrentMaterial = null;
|
||||
private static OBJGroup m_CurrentGroup = null;
|
||||
|
||||
#region PROCESSORS
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static readonly Dictionary<string, Action<string>> m_ParseOBJActionDictionary = new Dictionary<string, Action<string>>
|
||||
{
|
||||
{ "mtllib", (lEntry) => { /*Load MTL*/ } },
|
||||
{ "usemtl", (lEntry) => { PushOBJGroupIfNeeded(); m_CurrentGroup.m_Material = m_OBJData.m_Materials.SingleOrDefault((lX) => { return lX.m_Name.EqualsInvariantCultureIgnoreCase(lEntry); }); } },
|
||||
{ "v", (lEntry) => { m_OBJData.m_Vertices.Add(Utils.ParseVector3String(lEntry)); } },
|
||||
{ "vn", (lEntry) => { m_OBJData.m_Normals.Add(Utils.ParseVector3String(lEntry)); } },
|
||||
{ "vt", (lEntry) => { m_OBJData.m_UVs.Add(Utils.ParseVector2String(lEntry)); } },
|
||||
{ "vt2", (lEntry) => { m_OBJData.m_UV2s.Add(Utils.ParseVector2String(lEntry)); } },
|
||||
{ "vc", (lEntry) => { m_OBJData.m_Colors.Add(Utils.ParseVector4String(lEntry).ToColor()); } },
|
||||
{ "f", PushOBJFace },
|
||||
{ "g", PushOBJGroup },
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static readonly Dictionary<string, Action<string>> m_ParseMTLActionDictionary = new Dictionary<string, Action<string>>
|
||||
{
|
||||
{ "newmtl", PushOBJMaterial },
|
||||
{ "Ka", (lEntry) => { m_CurrentMaterial.m_AmbientColor = Utils.ParseVector3String(lEntry).ToColor(); } },
|
||||
{ "Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseColor = Utils.ParseVector3String(lEntry).ToColor(); } },
|
||||
{ "Ks", (lEntry) => { m_CurrentMaterial.m_SpecularColor = Utils.ParseVector3String(lEntry).ToColor(); } },
|
||||
{ "Ns", (lEntry) => { m_CurrentMaterial.m_SpecularCoefficient = lEntry.ParseInvariantFloat(); } },
|
||||
{ "d", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } },
|
||||
{ "Tr", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } },
|
||||
{ "illum", (lEntry) => { m_CurrentMaterial.m_IlluminationModel = lEntry.ParseInvariantInt(); } },
|
||||
{ "map_Ka", (lEntry) => { m_CurrentMaterial.m_AmbientTextureMap = lEntry; } },
|
||||
{ "map_Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseTextureMap = lEntry; } },
|
||||
{ "map_Ks", (lEntry) => { m_CurrentMaterial.m_SpecularTextureMap = lEntry; } },
|
||||
{ "map_Ns", (lEntry) => { m_CurrentMaterial.m_SpecularHighlightTextureMap = lEntry; } },
|
||||
{ "map_d", (lEntry) => { m_CurrentMaterial.m_AlphaTextureMap = lEntry; } },
|
||||
{ "map_bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } },
|
||||
{ "bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } },
|
||||
{ "disp", (lEntry) => { m_CurrentMaterial.m_DisplacementMap = lEntry; } },
|
||||
{ "decal",(lEntry) => { m_CurrentMaterial.m_StencilDecalMap = lEntry; } },
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region PUBLIC_INTERFACE
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public static OBJData LoadOBJ(Stream lStream)
|
||||
{
|
||||
m_OBJData = new OBJData();
|
||||
|
||||
m_CurrentMaterial = null;
|
||||
m_CurrentGroup = null;
|
||||
|
||||
StreamReader lLineStreamReader = new StreamReader(lStream);
|
||||
|
||||
Action<string> lAction = null;
|
||||
string lCurrentLine = null;
|
||||
string[] lFields = null;
|
||||
string lKeyword = null;
|
||||
string lData = null;
|
||||
|
||||
while (!lLineStreamReader.EndOfStream)
|
||||
{
|
||||
lCurrentLine = lLineStreamReader.ReadLine();
|
||||
|
||||
if (StringExt.IsNullOrWhiteSpace(lCurrentLine)
|
||||
|| lCurrentLine[0] == '#')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lFields = lCurrentLine.Trim().Split(null, 2);
|
||||
if (lFields.Length < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lKeyword = lFields[0].Trim();
|
||||
lData = lFields[1].Trim();
|
||||
|
||||
lAction = null;
|
||||
m_ParseOBJActionDictionary.TryGetValue(lKeyword.ToLowerInvariant(), out lAction);
|
||||
|
||||
if (lAction != null)
|
||||
{
|
||||
lAction(lData);
|
||||
}
|
||||
}
|
||||
|
||||
var lOBJData = m_OBJData;
|
||||
m_OBJData = null;
|
||||
|
||||
return lOBJData;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public static void ExportOBJ(OBJData lData, Stream lStream)
|
||||
{
|
||||
StreamWriter lLineStreamWriter = new StreamWriter(lStream);
|
||||
|
||||
lLineStreamWriter.WriteLine(string.Format("# File exported by Unity3D version {0}", Application.unityVersion));
|
||||
|
||||
for (int lCount = 0; lCount < lData.m_Vertices.Count; ++lCount)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("v {0} {1} {2}",
|
||||
lData.m_Vertices[lCount].x.ToString("n8"),
|
||||
lData.m_Vertices[lCount].y.ToString("n8"),
|
||||
lData.m_Vertices[lCount].z.ToString("n8")));
|
||||
}
|
||||
|
||||
for (int lCount = 0; lCount < lData.m_UVs.Count; ++lCount)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("vt {0} {1}",
|
||||
lData.m_UVs[lCount].x.ToString("n5"),
|
||||
lData.m_UVs[lCount].y.ToString("n5")));
|
||||
}
|
||||
|
||||
for (int lCount = 0; lCount < lData.m_UV2s.Count; ++lCount)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("vt2 {0} {1}",
|
||||
lData.m_UVs[lCount].x.ToString("n5"),
|
||||
lData.m_UVs[lCount].y.ToString("n5")));
|
||||
}
|
||||
|
||||
for (int lCount = 0; lCount < lData.m_Normals.Count; ++lCount)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("vn {0} {1} {2}",
|
||||
lData.m_Normals[lCount].x.ToString("n8"),
|
||||
lData.m_Normals[lCount].y.ToString("n8"),
|
||||
lData.m_Normals[lCount].z.ToString("n8")));
|
||||
}
|
||||
|
||||
for (int lCount = 0; lCount < lData.m_Colors.Count; ++lCount)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("vc {0} {1} {2} {3}",
|
||||
lData.m_Colors[lCount].r.ToString("n8"),
|
||||
lData.m_Colors[lCount].g.ToString("n8"),
|
||||
lData.m_Colors[lCount].b.ToString("n8"),
|
||||
lData.m_Colors[lCount].a.ToString("n8")));
|
||||
}
|
||||
|
||||
for (int lGroup = 0; lGroup < lData.m_Groups.Count; ++lGroup)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("g {0}", lData.m_Groups[lGroup].m_Name));
|
||||
|
||||
for (int lFace = 0; lFace < lData.m_Groups[lGroup].Faces.Count; ++lFace)
|
||||
{
|
||||
lLineStreamWriter.WriteLine(string.Format("f {0} {1} {2}",
|
||||
lData.m_Groups[lGroup].Faces[lFace].ToString(0),
|
||||
lData.m_Groups[lGroup].Faces[lFace].ToString(1),
|
||||
lData.m_Groups[lGroup].Faces[lFace].ToString(2)));
|
||||
}
|
||||
}
|
||||
|
||||
lLineStreamWriter.Flush();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static void PushOBJMaterial(string lMaterialName)
|
||||
{
|
||||
m_CurrentMaterial = new OBJMaterial(lMaterialName);
|
||||
m_OBJData.m_Materials.Add(m_CurrentMaterial);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static void PushOBJGroup(string lGroupName)
|
||||
{
|
||||
m_CurrentGroup = new OBJGroup(lGroupName);
|
||||
m_OBJData.m_Groups.Add(m_CurrentGroup);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static void PushOBJGroupIfNeeded()
|
||||
{
|
||||
if (m_CurrentGroup == null)
|
||||
{
|
||||
PushOBJGroup("default");
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
private static void PushOBJFace(string lFaceLine)
|
||||
{
|
||||
PushOBJGroupIfNeeded();
|
||||
|
||||
var vertices = lFaceLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var face = new OBJFace();
|
||||
|
||||
foreach (var vertexString in vertices)
|
||||
{
|
||||
face.ParseVertex(vertexString);
|
||||
}
|
||||
|
||||
m_CurrentGroup.AddFace(face);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bda02739f6fbaeb4c8c3da925164b8cf
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class OBJMaterial
|
||||
{
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public OBJMaterial(string lMaterialName)
|
||||
{
|
||||
m_Name = lMaterialName;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_Name;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public Color m_AmbientColor;
|
||||
public Color m_DiffuseColor;
|
||||
public Color m_SpecularColor;
|
||||
public float m_SpecularCoefficient;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public float m_Transparency;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public int m_IlluminationModel;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_AmbientTextureMap;
|
||||
public string m_DiffuseTextureMap;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_SpecularTextureMap;
|
||||
public string m_SpecularHighlightTextureMap;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_BumpMap;
|
||||
public string m_DisplacementMap;
|
||||
public string m_StencilDecalMap;
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
public string m_AlphaTextureMap;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ceb2526c78b78c04592f312a4e65ec95
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user