├── .gitattributes ├── Decal.meta ├── Decal ├── Decal.cs ├── Decal.cs.meta ├── DecalEditor.cs ├── DecalEditor.cs.meta ├── Helpers.meta └── Helpers │ ├── DecalBuilder.cs │ ├── DecalBuilder.cs.meta │ ├── DecalUtils.cs │ ├── DecalUtils.cs.meta │ ├── GUIUtils.cs │ ├── GUIUtils.cs.meta │ ├── MeshBuilder.cs │ ├── MeshBuilder.cs.meta │ ├── MeshUtils.cs │ ├── MeshUtils.cs.meta │ ├── PolygonUtils.cs │ ├── PolygonUtils.cs.meta │ ├── TerrainUtils.cs │ └── TerrainUtils.cs.meta ├── Examples.meta ├── Examples ├── CameraFly.cs └── CameraFly.cs.meta ├── Extensions.cs ├── Extensions.cs.meta ├── Formats.meta ├── Formats ├── Source.meta └── Source │ ├── MDL.meta │ ├── MDL │ ├── MDLArmatureInfo.cs │ ├── MDLArmatureInfo.cs.meta │ ├── MDLFile.cs │ ├── MDLFile.cs.meta │ ├── StudioStruct.cs │ ├── StudioStruct.cs.meta │ ├── VTXFile.cs │ ├── VTXFile.cs.meta │ ├── VVDFile.cs │ └── VVDFile.cs.meta │ ├── VBSP.meta │ ├── VBSP │ ├── EntInfo.cs │ ├── EntInfo.cs.meta │ ├── Entities.meta │ ├── Entities │ │ ├── point_viewcontrol.cs │ │ └── point_viewcontrol.cs.meta │ ├── EntitySetup.cs │ ├── EntitySetup.cs.meta │ ├── ObjectInfo.cs │ ├── ObjectInfo.cs.meta │ ├── PhysModel.cs │ ├── PhysModel.cs.meta │ ├── VBSPFile.cs │ ├── VBSPFile.cs.meta │ ├── VBSPLump.cs │ ├── VBSPLump.cs.meta │ ├── VBSPStruct.cs │ └── VBSPStruct.cs.meta │ ├── VPK.meta │ ├── VPK │ ├── VPKEntry.cs │ ├── VPKEntry.cs.meta │ ├── VPKFile.cs │ ├── VPKFile.cs.meta │ ├── VPKFilePart.cs │ ├── VPKFilePart.cs.meta │ ├── VPKReaderBase.cs │ └── VPKReaderBase.cs.meta │ ├── VTF.meta │ └── VTF │ ├── AnimatedTexture.cs │ ├── AnimatedTexture.cs.meta │ ├── DXTDecompress.cs │ ├── DXTDecompress.cs.meta │ ├── DebugMaterial.cs │ ├── DebugMaterial.cs.meta │ ├── VMTFile.cs │ ├── VMTFile.cs.meta │ ├── VTFFile.cs │ ├── VTFFile.cs.meta │ ├── VTFHeader.cs │ ├── VTFHeader.cs.meta │ ├── VTFImage.cs │ ├── VTFImage.cs.meta │ ├── VTFImageFormatInfo.cs │ ├── VTFImageFormatInfo.cs.meta │ ├── VTFResource.cs │ └── VTFResource.cs.meta ├── KeyValueParse.cs ├── KeyValueParse.cs.meta ├── Loader.unity ├── Loader.unity.meta ├── MathLib.meta ├── MathLib ├── Compressed_Vector.cs ├── Compressed_Vector.cs.meta ├── MathLibrary.cs └── MathLibrary.cs.meta ├── Pic1.png ├── Plugins.meta ├── Plugins ├── Facepunch.Parse.dll ├── Facepunch.Parse.dll.meta ├── Facepunch.Parse.pdb ├── Facepunch.Parse.pdb.meta ├── Facepunch.Parse.xml ├── Facepunch.Parse.xml.meta ├── ICSharpCode.SharpZipLib.dll ├── ICSharpCode.SharpZipLib.dll.meta ├── ICSharpCode.SharpZipLib.pdb ├── ICSharpCode.SharpZipLib.pdb.meta ├── ICSharpCode.SharpZipLib.xml └── ICSharpCode.SharpZipLib.xml.meta ├── README.md ├── Resource.meta ├── Resource ├── Editor.meta ├── Editor │ ├── LightmapSource.giparams │ └── LightmapSource.giparams.meta ├── Glow.flare └── Glow.flare.meta ├── Shaders.meta ├── Shaders ├── AdditiveGeneric.shader ├── AdditiveGeneric.shader.meta ├── CutoutGeneric.shader ├── CutoutGeneric.shader.meta ├── DecalModulate.shader ├── DecalModulate.shader.meta ├── DetailGeneric.shader ├── DetailGeneric.shader.meta ├── IllumGeneric.shader ├── IllumGeneric.shader.meta ├── Lightmapped.meta ├── Lightmapped │ ├── Generic.shader │ ├── Generic.shader.meta │ ├── SourceCG.cginc │ ├── SourceCG.cginc.meta │ ├── WorldTwoTextureBlend.shader │ ├── WorldTwoTextureBlend.shader.meta │ ├── WorldVertexTransition.shader │ └── WorldVertexTransition.shader.meta ├── TranslucentGeneric.shader ├── TranslucentGeneric.shader.meta ├── UnlitGeneric.shader └── UnlitGeneric.shader.meta ├── Vector3Int.cs ├── Vector3Int.cs.meta ├── uLoader.cs ├── uLoader.cs.meta ├── uReader.cs ├── uReader.cs.meta ├── uResourceManager.cs ├── uResourceManager.cs.meta ├── uSource.asmdef └── uSource.asmdef.meta /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Decal.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7fc660a7b801be6499bbb0e3aba4871b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Decal/Decal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | using UnityEngine; 8 | using UnityEngine.Serialization; 9 | 10 | namespace uSource.Decals 11 | { 12 | [RequireComponent(typeof(MeshFilter))] 13 | [RequireComponent(typeof(MeshRenderer))] 14 | [ExecuteInEditMode] 15 | public class Decal : MonoBehaviour 16 | { 17 | 18 | [FormerlySerializedAs("material")] public Material Material; 19 | [FormerlySerializedAs("sprite")] public Sprite Sprite; 20 | 21 | [FormerlySerializedAs("affectedLayers"), FormerlySerializedAs("AffectedLayers")] public LayerMask LayerMask = -1; 22 | [FormerlySerializedAs("maxAngle")] public float MaxAngle = 90.0f; 23 | [FormerlySerializedAs("pushDistance"), FormerlySerializedAs("PushDistance")] public float Offset = 0.009f; 24 | 25 | public MeshFilter MeshFilter 26 | { 27 | get 28 | { 29 | return gameObject.GetComponent() ?? gameObject.AddComponent(); 30 | } 31 | } 32 | public MeshRenderer MeshRenderer 33 | { 34 | get 35 | { 36 | return gameObject.GetComponent() ?? gameObject.AddComponent(); 37 | } 38 | } 39 | 40 | #if UNITY_EDITOR 41 | [MenuItem("GameObject/Decal")] 42 | internal static void Create() 43 | { 44 | new GameObject("Decal", typeof(Decal), typeof(MeshFilter), typeof(MeshRenderer)).isStatic = true; 45 | } 46 | #endif 47 | 48 | public void SetDirection() 49 | { 50 | float dist = (16 * uLoader.UnitScale) + 0.01f; 51 | List hits = new List(); 52 | 53 | if (Physics.Raycast(transform.position - new Vector3(0, 0, 0.01f), Vector3.forward, dist)) 54 | hits.Add(Vector3.forward); 55 | 56 | if (Physics.Raycast(transform.position - new Vector3(0, 0, -0.01f), Vector3.back, dist)) 57 | hits.Add(Vector3.back); 58 | 59 | if (Physics.Raycast(transform.position - new Vector3(0, 0.01f, 0), Vector3.up, dist)) 60 | hits.Add(Vector3.up); 61 | 62 | if (Physics.Raycast(transform.position - new Vector3(0, -0.01f, 0), Vector3.down, dist)) 63 | hits.Add(Vector3.down); 64 | 65 | if (Physics.Raycast(transform.position - new Vector3(0.01f, 0, 0), Vector3.right, dist)) 66 | hits.Add(Vector3.right); 67 | 68 | if (Physics.Raycast(transform.position - new Vector3(-0.01f, 0, 0), Vector3.left, dist)) 69 | hits.Add(Vector3.left); 70 | 71 | //Find median point 72 | if (hits.Count > 0) 73 | { 74 | Vector3 minPoint = hits[0]; 75 | Vector3 maxPoint = hits[0]; 76 | 77 | for (int i = 1; i < hits.Count; i++) 78 | { 79 | Vector3 pos = hits[i]; 80 | if (pos.x < minPoint.x) 81 | minPoint.x = pos.x; 82 | if (pos.x > maxPoint.x) 83 | maxPoint.x = pos.x; 84 | if (pos.y < minPoint.y) 85 | minPoint.y = pos.y; 86 | if (pos.y > maxPoint.y) 87 | maxPoint.y = pos.y; 88 | if (pos.z < minPoint.z) 89 | minPoint.z = pos.z; 90 | if (pos.z > maxPoint.z) 91 | maxPoint.z = pos.z; 92 | } 93 | 94 | transform.forward = minPoint + 0.5f * (maxPoint - minPoint); 95 | } 96 | 97 | float yDefault = 180; 98 | if (transform.eulerAngles.x < 0) 99 | yDefault = -270; 100 | if (transform.eulerAngles.x > 0) 101 | yDefault = 270; 102 | 103 | transform.rotation *= Quaternion.Euler(0, 0, yDefault); 104 | } 105 | 106 | public void OnValidate() 107 | { 108 | if (!Material) Sprite = null; 109 | if (Sprite && Material.mainTexture != Sprite.texture) Sprite = null; 110 | 111 | MaxAngle = Mathf.Clamp(MaxAngle, 1, 180); 112 | Offset = Mathf.Clamp(Offset, 0.005f, 0.05f); 113 | } 114 | 115 | void Awake() 116 | { 117 | var mesh = MeshFilter.sharedMesh; 118 | var meshes = GameObject.FindObjectsOfType().Select(i => i.MeshFilter.sharedMesh); 119 | if (meshes.Contains(mesh)) MeshFilter.sharedMesh = null; // if mesh was copied 120 | } 121 | 122 | void OnEnable() 123 | { 124 | //if (Application.isPlaying) 125 | // enabled = false; 126 | } 127 | 128 | void Update() 129 | { 130 | if (transform.hasChanged) 131 | { 132 | transform.hasChanged = false; 133 | BuildAndSetDirty(); 134 | } 135 | } 136 | 137 | void OnDrawGizmosSelected() 138 | { 139 | Gizmos.matrix = transform.localToWorldMatrix; 140 | Gizmos.color = Color.green; 141 | Gizmos.DrawWireCube(Vector3.zero, Vector3.one); 142 | 143 | var bounds = DecalUtils.GetBounds(this); 144 | Gizmos.matrix = Matrix4x4.identity; 145 | Gizmos.color = Color.white; 146 | Gizmos.DrawWireCube(bounds.center, bounds.size + Vector3.one * 0.01f); 147 | } 148 | 149 | 150 | public void BuildAndSetDirty() 151 | { 152 | DecalBuilder.Build(this); 153 | DecalUtils.SetDirty(this); 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /Decal/Decal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc94ce5ba77fa1d45ba7c6a0df113ba5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/DecalEditor.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | namespace uSource.Decals 8 | { 9 | [CustomEditor(typeof(Decal))] 10 | public class DecalEditor : Editor 11 | { 12 | private Decal Target 13 | { 14 | get { return (Decal)target; } 15 | } 16 | 17 | public override void OnInspectorGUI() 18 | { 19 | Target.Material = (Material)EditorGUILayout.ObjectField(Target.Material, typeof(Material), true); 20 | 21 | if (Target.Material && Target.Material.mainTexture) 22 | { 23 | Target.Sprite = (Sprite)EditorGUILayout.ObjectField(Target.Sprite, typeof(Sprite), true); 24 | } 25 | 26 | 27 | EditorGUILayout.Separator(); 28 | Target.LayerMask = GUIUtils.LayerMaskField("Layer Mask", Target.LayerMask); 29 | Target.MaxAngle = EditorGUILayout.Slider("Max Angle", Target.MaxAngle, 0, 180); 30 | Target.Offset = EditorGUILayout.Slider("Offset", Target.Offset, 0.001f, 0.05f); 31 | 32 | EditorGUILayout.Separator(); 33 | if (GUILayout.Button("Build")) 34 | Target.BuildAndSetDirty(); 35 | 36 | if (GUI.changed) 37 | { 38 | Target.OnValidate(); 39 | Target.BuildAndSetDirty(); 40 | GUI.changed = false; 41 | } 42 | } 43 | } 44 | } 45 | #endif -------------------------------------------------------------------------------- /Decal/DecalEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c76fefbf8256a41738d6cc566ab6c1cc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b12f9491f4315543b47beb9e9029874 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Decal/Helpers/DecalBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace uSource.Decals 7 | { 8 | static class DecalBuilder 9 | { 10 | private static readonly MeshBuilder Builder = new MeshBuilder(); 11 | 12 | public static void Build(Decal decal) 13 | { 14 | Build(Builder, decal); 15 | } 16 | 17 | private static void Build(MeshBuilder builder, Decal decal) 18 | { 19 | var filter = decal.MeshFilter; 20 | var renderer = decal.MeshRenderer; 21 | 22 | if (decal.Material && decal.Sprite) 23 | { 24 | builder.Clear(); 25 | Build_(builder, decal); 26 | filter.sharedMesh = builder.ToMesh(filter.sharedMesh, GetUVRect(decal.Sprite), decal.Offset); 27 | renderer.sharedMaterial = decal.Material; 28 | } 29 | else 30 | { 31 | Object.DestroyImmediate(filter.sharedMesh); 32 | filter.sharedMesh = null; 33 | renderer.sharedMaterial = null; 34 | } 35 | } 36 | 37 | private static void Build_(MeshBuilder builder, Decal decal) 38 | { 39 | var objects = DecalUtils.GetAffectedObjects(decal); 40 | var terrains = DecalUtils.GetAffectedTerrains(decal); 41 | var bounds = DecalUtils.GetBounds(decal); 42 | var worldToDecalMatrix = decal.transform.worldToLocalMatrix; 43 | 44 | var triangles1 = MeshUtils.GetTriangles(objects, worldToDecalMatrix).Where(i => Filter(i, decal)); 45 | var triangles2 = TerrainUtils.GetTriangles(terrains, bounds, worldToDecalMatrix).Where(i => Filter(i, decal)); 46 | 47 | AddTriangles(builder, triangles1); 48 | AddTriangles(builder, triangles2); 49 | } 50 | 51 | // Add 52 | private static void AddTriangles(MeshBuilder builder, IEnumerable triangles) 53 | { 54 | foreach (var triangle in triangles) 55 | { 56 | AddTriangle(builder, triangle); 57 | } 58 | } 59 | 60 | private static void AddTriangle(MeshBuilder builder, Triangle triangle) 61 | { 62 | var poly = PolygonUtils.Clip(triangle.V1, triangle.V2, triangle.V3); 63 | if (poly.Length > 0) builder.AddPolygon(poly); 64 | } 65 | 66 | // Helpers 67 | private static bool Filter(Triangle triangle, Decal decal) 68 | { 69 | var normal = GetNormal(triangle); 70 | return Vector3.Angle(Vector3.back, normal) <= decal.MaxAngle; 71 | } 72 | 73 | private static Vector3 GetNormal(Triangle triangle) 74 | { 75 | return Vector3.Cross(triangle.V2 - triangle.V1, triangle.V3 - triangle.V1).normalized; 76 | } 77 | 78 | private static Rect GetUVRect(Sprite sprite) 79 | { 80 | return ToRect01(sprite.rect, sprite.texture); 81 | } 82 | 83 | private static Rect ToRect01(Rect rect, Texture2D texture) 84 | { 85 | //rect.x /= texture.width; 86 | //rect.y /= texture.height; 87 | rect.width /= texture.width; 88 | rect.height /= texture.height; 89 | return rect; 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /Decal/Helpers/DecalBuilder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01844b7579060ef499f9f6ae42adbc47 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/DecalUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | using UnityEditor.SceneManagement; 7 | #endif 8 | using UnityEngine; 9 | 10 | namespace uSource.Decals 11 | { 12 | 13 | static class DecalUtils 14 | { 15 | public static MeshFilter[] GetAffectedObjects(Decal decal) 16 | { 17 | var bounds = GetBounds(decal); 18 | //var isOnlyStatic = decal.gameObject.isStatic; 19 | 20 | return GameObject.FindObjectsOfType() 21 | .Where(i => i.GetComponent() == null) // ignore another decals 22 | .Where(i => i.gameObject.isStatic == true)//!isOnlyStatic) 23 | .Where(i => HasLayer(decal.LayerMask, i.gameObject.layer)) 24 | .Where(i => bounds.Intersects(i.bounds)) 25 | 26 | .Select(i => i.GetComponent()) 27 | .Where(i => i) 28 | .Where(i => i.sharedMesh) 29 | .ToArray(); 30 | } 31 | 32 | public static Terrain[] GetAffectedTerrains(Decal decal) 33 | { 34 | var bounds = GetBounds(decal); 35 | var isOnlyStatic = decal.gameObject.isStatic; 36 | 37 | return Terrain.activeTerrains 38 | .Where(i => i.gameObject.isStatic || !isOnlyStatic) 39 | .Where(i => HasLayer(decal.LayerMask, i.gameObject.layer)) 40 | .Where(i => bounds.Intersects(i.GetBounds())) 41 | .ToArray(); 42 | } 43 | 44 | 45 | public static Bounds GetBounds(Decal decal) 46 | { 47 | var transform = decal.transform; 48 | var size = transform.lossyScale; 49 | var min = -size / 2f; 50 | var max = size / 2f; 51 | 52 | var vts = new Vector3[] { 53 | new Vector3( min.x, min.y, min.z ), 54 | new Vector3( max.x, min.y, min.z ), 55 | new Vector3( min.x, max.y, min.z ), 56 | new Vector3( max.x, max.y, min.z ), 57 | 58 | new Vector3( min.x, min.y, max.z ), 59 | new Vector3( max.x, min.y, max.z ), 60 | new Vector3( min.x, max.y, max.z ), 61 | new Vector3( max.x, max.y, max.z ), 62 | }; 63 | 64 | vts = vts.Select(transform.TransformDirection).ToArray(); 65 | min = vts.Aggregate(Vector3.Min); 66 | max = vts.Aggregate(Vector3.Max); 67 | 68 | return new Bounds(transform.position, max - min); 69 | } 70 | 71 | private static Bounds GetBounds(this Terrain terrain) 72 | { 73 | var bounds = terrain.terrainData.bounds; 74 | bounds.center += terrain.transform.position; 75 | return bounds; 76 | } 77 | 78 | 79 | public static void SetDirty(Decal decal) 80 | { 81 | #if UNITY_EDITOR 82 | if (decal.gameObject.scene.IsValid()) 83 | { 84 | if (!EditorApplication.isPlaying) EditorSceneManager.MarkSceneDirty(decal.gameObject.scene); 85 | } 86 | else 87 | { 88 | EditorUtility.SetDirty(decal.gameObject); 89 | } 90 | #endif 91 | } 92 | 93 | 94 | public static void FixRatio(Decal decal, ref Vector3 oldScale) 95 | { 96 | var transform = decal.transform; 97 | var rect = decal.Sprite.rect; 98 | var ratio = (rect.width / rect.height); 99 | 100 | var scale = transform.localScale; 101 | FixRatio(ref scale, ref oldScale, ratio); 102 | 103 | var hasChanged = transform.hasChanged; 104 | transform.localScale = scale; 105 | transform.hasChanged = hasChanged; 106 | } 107 | 108 | public static void FixRatio(ref Vector3 scale, ref Vector3 oldScale, float ratio) 109 | { 110 | if (!Mathf.Approximately(oldScale.x, scale.x)) 111 | scale.y = scale.x / ratio; // if scale.x was changed then fix scale.y 112 | else if (!Mathf.Approximately(oldScale.y, scale.y)) 113 | scale.x = scale.y * ratio; 114 | else if (!Mathf.Approximately(scale.x / scale.y, ratio)) 115 | scale.x = scale.y * ratio; 116 | 117 | oldScale = scale; 118 | } 119 | 120 | 121 | // Helpers 122 | private static bool HasLayer(LayerMask mask, int layer) 123 | { 124 | return (mask.value & 1 << layer) != 0; 125 | } 126 | 127 | 128 | } 129 | } -------------------------------------------------------------------------------- /Decal/Helpers/DecalUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ec7696f981f1b84a8571c22aa394f09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/GUIUtils.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using UnityEditor; 6 | using UnityEngine; 7 | 8 | namespace uSource.Decals 9 | { 10 | static class GUIUtils 11 | { 12 | public static LayerMask LayerMaskField(string label, LayerMask mask) 13 | { 14 | var names = Enumerable.Range(0, 32).Select(i => LayerMask.LayerToName(i))/*.Where( i => !string.IsNullOrEmpty( i ) )*/.ToArray(); // TODO: fix bug 15 | return EditorGUILayout.MaskField(label, mask.value, names); 16 | } 17 | } 18 | } 19 | #endif -------------------------------------------------------------------------------- /Decal/Helpers/GUIUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 100a84593b56bfa479736f98a0744b6f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/MeshBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace uSource.Decals 7 | { 8 | class MeshBuilder 9 | { 10 | 11 | private readonly List vertices = new List(); 12 | private readonly List indices = new List(); 13 | 14 | public void AddPolygon(Vector3[] poly) 15 | { 16 | var ind1 = AddVertex_(poly[0]); 17 | 18 | for (var i = 1; i < poly.Length - 1; i++) 19 | { 20 | var ind2 = AddVertex_(poly[i]); 21 | var ind3 = AddVertex_(poly[i + 1]); 22 | 23 | indices.Add(ind1); 24 | indices.Add(ind2); 25 | indices.Add(ind3); 26 | } 27 | } 28 | 29 | public Mesh ToMesh(Mesh mesh, Rect uvRect, float offset) 30 | { 31 | if (mesh == null) 32 | { 33 | mesh = new Mesh(); 34 | mesh.name = "Decal"; 35 | } 36 | 37 | ToMesh_(mesh, uvRect, offset); 38 | return mesh; 39 | } 40 | 41 | private void ToMesh_(Mesh mesh, Rect uvRect, float offset) 42 | { 43 | mesh.Clear(true); 44 | if (indices.Count == 0) return; 45 | 46 | var vertices_ = vertices.ToArray(); 47 | var indices_ = indices.ToArray(); 48 | var normals = GetNormals(vertices_, indices_); 49 | var uvs = GetUVs(vertices_, uvRect); 50 | Push(vertices_, normals, offset); 51 | 52 | mesh.vertices = vertices_; 53 | mesh.normals = normals; 54 | mesh.uv = uvs; 55 | mesh.triangles = indices_; 56 | } 57 | 58 | public void Clear() 59 | { 60 | vertices.Clear(); 61 | indices.Clear(); 62 | } 63 | 64 | // Helpers 65 | private int AddVertex_(Vector3 vertex) 66 | { 67 | var index = FindVertex(vertex); 68 | if (index == -1) 69 | { 70 | vertices.Add(vertex); 71 | return vertices.Count - 1; 72 | } 73 | else 74 | { 75 | return index; 76 | } 77 | } 78 | 79 | private int FindVertex(Vector3 vertex) 80 | { 81 | const float Epsilon = 0.01f; 82 | return vertices.FindIndex(i => Vector3.Distance(i, vertex) < Epsilon); 83 | } 84 | 85 | private static Vector3[] GetNormals(Vector3[] vertices, int[] indices) 86 | { 87 | var normals = new Vector3[vertices.Length]; 88 | 89 | for (var i = 0; i < indices.Length; i += 3) 90 | { 91 | var ind1 = indices[i]; 92 | var ind2 = indices[i + 1]; 93 | var ind3 = indices[i + 2]; 94 | 95 | var v1 = vertices[ind1]; 96 | var v2 = vertices[ind2]; 97 | var v3 = vertices[ind3]; 98 | 99 | var n = GetNormal(v1, v2, v3); 100 | 101 | normals[ind1] += n; 102 | normals[ind2] += n; 103 | normals[ind3] += n; 104 | } 105 | 106 | for (var i = 0; i < normals.Length; i++) 107 | { 108 | normals[i].Normalize(); 109 | } 110 | 111 | return normals; 112 | } 113 | 114 | private static Vector3 GetNormal(Vector3 v1, Vector3 v2, Vector3 v3) 115 | { 116 | return Vector3.Cross(v2 - v1, v3 - v1).normalized; 117 | } 118 | 119 | private static Vector2[] GetUVs(Vector3[] vertices, Rect uvRect) 120 | { 121 | return vertices.Select(i => GetUVs(i, uvRect)).ToArray(); 122 | } 123 | 124 | private static Vector2 GetUVs(Vector3 vertex, Rect uvRect) 125 | { 126 | var u = Mathf.Lerp(uvRect.xMin, uvRect.xMax, vertex.x + 0.5f); 127 | var v = Mathf.Lerp(uvRect.yMin, uvRect.yMax, vertex.y + 0.5f); 128 | return new Vector2(u, v); 129 | } 130 | 131 | private static void Push(Vector3[] vertices, Vector3[] normals, float offset) 132 | { 133 | for (var i = 0; i < vertices.Length; i++) 134 | { 135 | vertices[i] += normals[i] * offset; 136 | } 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /Decal/Helpers/MeshBuilder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 698435c2098001841b9ec6d0ae8afe7c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/MeshUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace uSource.Decals 7 | { 8 | public struct Triangle 9 | { 10 | public readonly Vector3 V1, V2, V3; 11 | public Triangle(Vector3 v1, Vector3 v2, Vector3 v3) 12 | { 13 | V1 = v1; 14 | V2 = v2; 15 | V3 = v3; 16 | } 17 | } 18 | 19 | public static class MeshUtils 20 | { 21 | 22 | public static IEnumerable GetTriangles(MeshFilter[] objects, Matrix4x4 worldToDecalMatrix) 23 | { 24 | return objects.SelectMany(i => GetTriangles(i, worldToDecalMatrix)); 25 | } 26 | private static IEnumerable GetTriangles(MeshFilter obj, Matrix4x4 worldToDecalMatrix) 27 | { 28 | var objToDecalMatrix = worldToDecalMatrix * obj.transform.localToWorldMatrix; 29 | return GetTriangles(obj.sharedMesh).Select(i => Transform(objToDecalMatrix, i)); 30 | } 31 | private static IEnumerable GetTriangles(Mesh mesh) 32 | { 33 | var vertices = mesh.vertices; 34 | var triangles = mesh.triangles; 35 | 36 | for (var i = 0; i < triangles.Length; i += 3) 37 | { 38 | var i1 = triangles[i]; 39 | var i2 = triangles[i + 1]; 40 | var i3 = triangles[i + 2]; 41 | 42 | var v1 = vertices[i1]; 43 | var v2 = vertices[i2]; 44 | var v3 = vertices[i3]; 45 | 46 | yield return new Triangle(v1, v2, v3); 47 | } 48 | } 49 | 50 | // Helpers 51 | internal static Triangle Transform(Matrix4x4 matrix, Triangle triangle) 52 | { 53 | var v1 = matrix.MultiplyPoint(triangle.V1); 54 | var v2 = matrix.MultiplyPoint(triangle.V2); 55 | var v3 = matrix.MultiplyPoint(triangle.V3); 56 | return new Triangle(v1, v2, v3); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Decal/Helpers/MeshUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 346a632b4f18ebf40b32e8baf7a0cc91 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/PolygonUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using UnityEngine; 4 | 5 | namespace uSource.Decals 6 | { 7 | static class PolygonUtils 8 | { 9 | private static readonly Plane Right = new Plane(Vector3.right, 0.5f); 10 | private static readonly Plane Left = new Plane(Vector3.left, 0.5f); 11 | 12 | private static readonly Plane Top = new Plane(Vector3.up, 0.5f); 13 | private static readonly Plane Bottom = new Plane(Vector3.down, 0.5f); 14 | 15 | private static readonly Plane Front = new Plane(Vector3.forward, 0.5f); 16 | private static readonly Plane Back = new Plane(Vector3.back, 0.5f); 17 | 18 | public static Vector3[] Clip(params Vector3[] poly) 19 | { 20 | poly = Clip(poly, Right).ToArray(); 21 | poly = Clip(poly, Left).ToArray(); 22 | poly = Clip(poly, Top).ToArray(); 23 | poly = Clip(poly, Bottom).ToArray(); 24 | poly = Clip(poly, Front).ToArray(); 25 | poly = Clip(poly, Back).ToArray(); 26 | return poly; 27 | } 28 | 29 | private static IEnumerable Clip(Vector3[] poly, Plane plane) 30 | { 31 | for (var i = 0; i < poly.Length; i++) 32 | { 33 | var next = (i + 1) % poly.Length; 34 | var v1 = poly[i]; 35 | var v2 = poly[next]; 36 | 37 | if (plane.GetSide(v1)) 38 | { 39 | yield return v1; 40 | } 41 | 42 | if (plane.GetSide(v1) != plane.GetSide(v2)) 43 | { 44 | yield return PlaneLineCast(plane, v1, v2); 45 | } 46 | } 47 | } 48 | 49 | // Helpers 50 | private static Vector3 PlaneLineCast(Plane plane, Vector3 a, Vector3 b) 51 | { 52 | float dis; 53 | var ray = new Ray(a, b - a); 54 | plane.Raycast(ray, out dis); 55 | return ray.GetPoint(dis); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Decal/Helpers/PolygonUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21ece542f320c324e85f10909da068e7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Decal/Helpers/TerrainUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace uSource.Decals 7 | { 8 | public static class TerrainUtils 9 | { 10 | public static IEnumerable GetTriangles(Terrain[] terrains, Bounds bounds, Matrix4x4 worldToDecalMatrix) 11 | { 12 | return terrains.SelectMany(i => GetTriangles(i, bounds, worldToDecalMatrix)); 13 | } 14 | 15 | private static IEnumerable GetTriangles(Terrain terrain, Bounds bounds, Matrix4x4 worldToDecalMatrix) 16 | { 17 | var terrainToWorldMatrix = GetLocalToWorldMatrix(terrain); 18 | var terrainToDecalMatrix = worldToDecalMatrix * terrainToWorldMatrix; 19 | 20 | bounds = Transform(terrainToWorldMatrix.inverse, bounds); // world to terrain 21 | Vector3Int min, max; 22 | GetMinMax(bounds, terrain.terrainData, out min, out max); 23 | 24 | return GetTriangles(terrain.terrainData, min, max).Select(i => MeshUtils.Transform(terrainToDecalMatrix, i)); 25 | } 26 | 27 | private static IEnumerable GetTriangles(TerrainData terrain, Vector3Int min, Vector3Int max) 28 | { 29 | for (var z = min.z; z <= max.z; z++) 30 | { 31 | for (var x = min.x; x <= max.x; x++) 32 | { 33 | // 1 2 34 | // 3 4 35 | var v1 = terrain.GetVertex(x + 0, z + 0); 36 | var v2 = terrain.GetVertex(x + 1, z + 0); 37 | var v3 = terrain.GetVertex(x + 0, z + 1); 38 | var v4 = terrain.GetVertex(x + 1, z + 1); 39 | 40 | yield return new Triangle(v1, v3, v4); 41 | yield return new Triangle(v1, v4, v2); 42 | } 43 | } 44 | } 45 | 46 | // Helpers 47 | private static Vector3 GetVertex(this TerrainData terrain, int x, int z) 48 | { 49 | var y = terrain.GetHeight(x, z); 50 | return new Vector3(x, y, z); 51 | } 52 | 53 | private static Matrix4x4 GetLocalToWorldMatrix(Terrain terrain) 54 | { 55 | var width = terrain.terrainData.heightmapWidth - 1; 56 | var height = terrain.terrainData.heightmapHeight - 1; 57 | var scale = new Vector3(terrain.terrainData.size.x / width, 1, terrain.terrainData.size.z / height); 58 | return Matrix4x4.TRS(terrain.transform.position, Quaternion.identity, scale); 59 | } 60 | 61 | private static Bounds Transform(Matrix4x4 matrix, Bounds bounds) 62 | { 63 | bounds.min = matrix.MultiplyPoint(bounds.min); 64 | bounds.max = matrix.MultiplyPoint(bounds.max); 65 | return bounds; 66 | } 67 | 68 | private static Triangle Transform(Matrix4x4 matrix, Triangle triangle) 69 | { 70 | return MeshUtils.Transform(matrix, triangle); 71 | } 72 | 73 | private static void GetMinMax(Bounds bounds, TerrainData terrain, out Vector3Int min, out Vector3Int max) 74 | { 75 | min = Vector3Int.FloorToInt(bounds.min); 76 | max = Vector3Int.CeilToInt(bounds.max); 77 | min.x = Mathf.Max(min.x, 0); 78 | min.z = Mathf.Max(min.z, 0); 79 | max.x = Mathf.Min(max.x, terrain.heightmapWidth - 1); 80 | max.z = Mathf.Min(max.z, terrain.heightmapHeight - 1); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Decal/Helpers/TerrainUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfdb69ae7369c83419aeed65084d1fd4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b39dbe84762bc5b49ac850a21379f4c7 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Examples/CameraFly.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace uSource.Example 6 | { 7 | public class CameraFly : MonoBehaviour 8 | { 9 | //3DSkybox 10 | public Vector3 offset3DSky; 11 | public float skyScale; 12 | public Transform skyCamera; 13 | public bool use3dSky = false; 14 | //3DSkybox 15 | 16 | public float cameraSensitivity = 90; 17 | public float climbSpeed = 4; 18 | public float normalMoveSpeed = 10; 19 | public float slowMoveFactor = 0.25f; 20 | public float fastMoveFactor = 3; 21 | 22 | private float rotationX = 0.0f; 23 | private float rotationY = 0.0f; 24 | 25 | void Start() 26 | { 27 | Cursor.lockState = CursorLockMode.Locked; 28 | Cursor.visible = true; 29 | use3dSky = uLoader.Use3DSkybox; 30 | } 31 | 32 | void Update() 33 | { 34 | rotationX += Input.GetAxis("Mouse X") * cameraSensitivity * Time.deltaTime; 35 | rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime; 36 | rotationY = Mathf.Clamp(rotationY, -90, 90); 37 | 38 | transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up); 39 | transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left); 40 | 41 | if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) 42 | { 43 | transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime; 44 | transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime; 45 | } 46 | else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) 47 | { 48 | transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Vertical") * Time.deltaTime; 49 | transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Horizontal") * Time.deltaTime; 50 | } 51 | else 52 | { 53 | transform.position += transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime; 54 | transform.position += transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime; 55 | } 56 | 57 | 58 | if (Input.GetKey(KeyCode.Q)) { transform.position += transform.up * climbSpeed * Time.deltaTime; } 59 | if (Input.GetKey(KeyCode.E)) { transform.position -= transform.up * climbSpeed * Time.deltaTime; } 60 | 61 | if (Input.GetKeyDown(KeyCode.End)) 62 | { 63 | Cursor.visible = (Cursor.visible == false) ? true : false; 64 | } 65 | } 66 | 67 | void LateUpdate() 68 | { 69 | if (use3dSky) 70 | { 71 | //3DSkybox 72 | skyCamera.transform.position = (transform.position / skyScale) + offset3DSky; 73 | skyCamera.transform.rotation = transform.rotation; 74 | //3DSkybox 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Examples/CameraFly.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c398d830f67a124485a3192e9c4c8bc 3 | timeCreated: 1503337597 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Extensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e5ca1fe7ab97e14c89a146345a3b592 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24ae70a8fd1c92e4186d4f0f70e5a04d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0ce99f370b820dc429bfdc23d78f4ddd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source/MDL.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e67f776c3a1fab449bb7548e011c45ec 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source/MDL/MDLArmatureInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | using uSource.Formats.Source.MDL; 8 | 9 | namespace uSource 10 | { 11 | public class MDLArmatureInfo : MonoBehaviour 12 | { 13 | //public MdlSpec.AniInfo[] aniDescs; 14 | public StudioStruct.SeqInfo[] seqDescs; 15 | public GameObject ModelObject; 16 | public Transform rootNode; 17 | public Transform[] boneNodes; 18 | public Transform[] attachmentNodes; 19 | //float size = 0.1f; 20 | //private TextGizmo TG; 21 | #if UNITY_EDITOR 22 | public void OnDrawGizmosSelected() 23 | { 24 | for (int i = 0; i < boneNodes.Length; i++) 25 | { 26 | Gizmos.color = Color.white; 27 | Gizmos.DrawWireCube(boneNodes[i].position, Vector3.one * 0.025f); 28 | 29 | if (boneNodes[i].parent != null) 30 | { 31 | Gizmos.color = Color.yellow; 32 | //Handles.Label(boneNodes[i].position, boneNodes[i].name); 33 | Gizmos.DrawLine(boneNodes[i].position, boneNodes[i].parent.position); 34 | } 35 | 36 | /*Handles.color = Color.blue; 37 | Handles.DrawWireArc(targetObject.transform.position, Vector3.up, Vector3.forward, 360, targetObject.range); 38 | Handles.DrawWireArc(targetObject.transform.position, Vector3.forward, Vector3.up, 360, targetObject.range); 39 | Handles.DrawWireArc(targetObject.transform.position, Vector3.left, Vector3.up, 360, targetObject.range); 40 | 41 | 42 | Handles.color = Color.yellow; 43 | Handles.DrawWireArc(targetObject.transform.position, Vector3.up, Vector3.forward, 360, targetObject.m_MaxSize); 44 | Handles.DrawWireArc(targetObject.transform.position, Vector3.forward, Vector3.up, 360, targetObject.m_MaxSize); 45 | Handles.DrawWireArc(targetObject.transform.position, Vector3.left, Vector3.up, 360, targetObject.m_MaxSize);*/ 46 | } 47 | 48 | /*for (int i = 0; i < attachmentNodes.Length; i++) 49 | { 50 | Handles.Label(attachmentNodes[i].position, attachmentNodes[i].name); 51 | 52 | Handles.color = Handles.xAxisColor; 53 | Handles.ArrowHandleCap(0, attachmentNodes[i].position, attachmentNodes[i].rotation * Quaternion.Euler(0, 90, 0), size, EventType.Repaint); 54 | 55 | Handles.color = Handles.yAxisColor; 56 | Handles.ArrowHandleCap(0, attachmentNodes[i].position, attachmentNodes[i].rotation * Quaternion.Euler(-90, 0, 0), size, EventType.Repaint); 57 | 58 | Handles.color = Handles.zAxisColor; 59 | Handles.ArrowHandleCap(0, attachmentNodes[i].position, attachmentNodes[i].rotation, size, EventType.Repaint); 60 | 61 | Handles.color = new Color32(255, 0, 0, 50); 62 | Handles.CubeHandleCap(0, attachmentNodes[i].position, attachmentNodes[i].rotation, size, EventType.Repaint); 63 | //Gizmos.DrawWireCube(attachmentNodes[i].position, Vector3.one * 0.05f); 64 | }*/ 65 | } 66 | #endif 67 | } 68 | } -------------------------------------------------------------------------------- /Formats/Source/MDL/MDLArmatureInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf2f8695c25a1b6439f82749e4664430 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/MDL/MDLFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74e842c2d0d38b34aa99aebca91e8674 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/MDL/StudioStruct.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88d8f0e9b4ab5ab44b8f716905940fc7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/MDL/VTXFile.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System; 4 | using System.IO; 5 | using UnityEngine; 6 | 7 | namespace uSource.Formats.Source.MDL 8 | { 9 | public class VTXFile : StudioStruct 10 | { 11 | public FileHeader_t VTX_Header; 12 | 13 | public VTXFile(Stream FileInput, MDLFile StudioMDL, VVDFile StudioVVD) 14 | { 15 | using (uReader FileStream = new uReader(FileInput)) 16 | { 17 | studiohdr_t MDL_Header = StudioMDL.MDL_Header; 18 | FileStream.ReadTypeFixed(ref VTX_Header, 36); 19 | 20 | if (VTX_Header.checkSum != MDL_Header.checksum) 21 | throw new FileLoadException(String.Format("{0}: Does not match the checksum in the .mdl", MDL_Header.Name)); 22 | 23 | #region BodyParts 24 | Int32[] VertexLODOffsets = new Int32[8]; 25 | for (Int32 BodypartID = 0; BodypartID < MDL_Header.bodypart_count; BodypartID++) 26 | { 27 | BodyPartHeader_t BodyPart = new BodyPartHeader_t(); 28 | Int64 BodyPartOffset = VTX_Header.bodyPartOffset + (8 * BodypartID); 29 | FileStream.ReadTypeFixed(ref BodyPart, 8, BodyPartOffset); 30 | 31 | StudioBodyPart StudioBodyPart = StudioMDL.MDL_Bodyparts[BodypartID]; 32 | 33 | #region Models 34 | for (Int32 ModelID = 0; ModelID < BodyPart.numModels; ModelID++) 35 | { 36 | StudioModel StudioModel = StudioBodyPart.Models[ModelID]; 37 | 38 | if (StudioModel.isBlank) 39 | { 40 | Debug.Log(String.Format("Model ID - {0} in bodypart \"{1}\" is blank, skip", ModelID, StudioBodyPart.Name)); 41 | continue; 42 | } 43 | 44 | ModelHeader_t Model = new ModelHeader_t(); 45 | Int64 ModelOffset = BodyPartOffset + (8 * ModelID) + BodyPart.modelOffset; 46 | FileStream.ReadTypeFixed(ref Model, 8, ModelOffset); 47 | 48 | StudioBodyPart.Models[ModelID].NumLODs = Model.numLODs; 49 | StudioBodyPart.Models[ModelID].LODData = new ModelLODHeader_t[Model.numLODs]; 50 | 51 | #region LOD's 52 | //TODO: Strip unused vertexes on lower lod's ("first" lod is fine) 53 | for (Int32 LODID = 0; LODID < Model.numLODs; LODID++) 54 | { 55 | ModelLODHeader_t LOD = new ModelLODHeader_t(); 56 | Int64 LODOffset = ModelOffset + (12 * LODID) + Model.lodOffset; 57 | FileStream.ReadTypeFixed(ref LOD, 12, LODOffset); 58 | 59 | StudioBodyPart.Models[ModelID].LODData[LODID] = LOD; 60 | 61 | #region Mesh LOD 62 | //Temp remember verts count per lod model 63 | Int32 VertexOffset = 0; 64 | //List VertexesPerLod = new List(); 65 | for (Int32 MeshID = 0; MeshID < StudioModel.Model.nummeshes; MeshID++) 66 | { 67 | mstudiomesh_t StudioMesh = StudioBodyPart.Models[ModelID].Meshes[MeshID]; 68 | 69 | //TODO: StudioModel.Meshes[MeshID].VertexData.numlodvertices[LODID]; - we no longer need this?? 70 | VertexOffset += StudioMesh.numvertices; 71 | List IndicesPerMesh = new List(); 72 | 73 | MeshHeader_t Mesh = new MeshHeader_t(); 74 | Int64 MeshOffset = LODOffset + (9 * MeshID) + LOD.meshOffset; 75 | FileStream.ReadTypeFixed(ref Mesh, 9, MeshOffset); 76 | 77 | #region StripGroups 78 | for (Int32 StripGroupID = 0; StripGroupID < Mesh.numStripGroups; StripGroupID++) 79 | { 80 | StripGroupHeader_t StripGroup = new StripGroupHeader_t(); 81 | Int64 StripGroupOffset = MeshOffset + (25 * StripGroupID) + Mesh.stripGroupHeaderOffset; 82 | FileStream.ReadTypeFixed(ref StripGroup, 25, StripGroupOffset); 83 | 84 | Vertex_t[] Vertexes = new Vertex_t[StripGroup.numVerts]; 85 | FileStream.BaseStream.Position = StripGroupOffset + StripGroup.vertOffset; 86 | FileStream.ReadArrayFixed(ref Vertexes, 9); 87 | 88 | FileStream.BaseStream.Position = StripGroupOffset + StripGroup.indexOffset; 89 | Int16[] Indices = FileStream.ReadShortArray(StripGroup.numIndices); 90 | 91 | #region Strips 92 | for (Int32 StripID = 0; StripID < StripGroup.numStrips; StripID++) 93 | { 94 | StripHeader_t VTXStrip = new StripHeader_t(); 95 | Int64 VTXStripOffset = StripGroupOffset + (27 * StripID) + StripGroup.stripOffset; 96 | FileStream.ReadTypeFixed(ref VTXStrip, 27, VTXStripOffset); 97 | 98 | //TODO: 99 | //Strip / "Split" vertexes 100 | //Pseudo code: 101 | /*for (Int32 VertID = 0; VertID < maxVertsPerLod; VertID++) 102 | { 103 | Int32 Index = MeshID * VTXStrip.numVerts + VertID; 104 | 105 | if (Index < numStripVerts) 106 | { 107 | splitVerts.Add(verts[Index]); 108 | splitIndices.Add(j); 109 | } 110 | }*/ 111 | 112 | //Hmmmmm... Well, it's looks what we want.... but still doesn't perfect (for lod's mesh) 113 | /*Int32 NumVerts = VTXStrip.indexOffset + VTXStrip.numVerts; 114 | for (Int32 VertID = VTXStrip.indexOffset; VertID < NumVerts; VertID++) 115 | { 116 | Int32 Index0 = VertID + StudioMesh.vertexoffset + VertexLODOffsets[LODID]; 117 | VertexesPerLod.Add(StudioVVD.tempVerts[Index0]); 118 | }*/ 119 | 120 | if ((VTXStrip.flags & VTXStripGroupTriStripFlag) > 0) 121 | { 122 | for (Int32 TempIdx = VTXStrip.indexOffset; TempIdx < VTXStrip.indexOffset + VTXStrip.numIndices - 2; TempIdx++) 123 | { 124 | Int32[] add = TempIdx % 2 == 1 ? 125 | new[] { TempIdx + 1, TempIdx, TempIdx + 2 } : 126 | new[] { TempIdx, TempIdx + 1, TempIdx + 2 }; 127 | 128 | foreach (Int32 Index in add) 129 | { 130 | IndicesPerMesh.Add(Vertexes[Indices[Index]].origMeshVertId + StudioMesh.vertexoffset); 131 | } 132 | } 133 | } 134 | else 135 | { 136 | for (Int32 Index = VTXStrip.indexOffset; Index < VTXStrip.indexOffset + VTXStrip.numIndices; Index++) 137 | { 138 | IndicesPerMesh.Add(Vertexes[Indices[Index]].origMeshVertId + StudioMesh.vertexoffset); 139 | } 140 | } 141 | } 142 | #endregion 143 | } 144 | #endregion 145 | 146 | StudioMDL.SetIndices(BodypartID, ModelID, LODID, MeshID, IndicesPerMesh); 147 | } 148 | #endregion 149 | 150 | //StudioMDL.MDL_Bodyparts[BodypartID].Models[ModelID].VerticesPerLod[LODID] = VertexesPerLod.ToArray(); 151 | ///TODO: Strip unused vertexes in per lod 152 | StudioMDL.SetVertices(BodypartID, ModelID, LODID, VertexOffset, VertexLODOffsets[LODID], StudioVVD.VVD_Vertexes[0]); 153 | 154 | VertexLODOffsets[LODID] += VertexOffset; 155 | } 156 | #endregion 157 | } 158 | #endregion 159 | } 160 | #endregion 161 | } 162 | } 163 | } 164 | } -------------------------------------------------------------------------------- /Formats/Source/MDL/VTXFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3fad78d120ae1f04da65bda795d64083 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/MDL/VVDFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using UnityEngine; 7 | 8 | namespace uSource.Formats.Source.MDL 9 | { 10 | public class VVDFile : StudioStruct 11 | { 12 | public vertexFileHeader_t VVD_Header; 13 | public mstudiovertex_t[][] VVD_Vertexes; 14 | public vertexFileFixup_t[] VVD_Fixups; 15 | //TODO 16 | //public Boolean HasTangents; 17 | 18 | //TODO: 19 | //Fix missed vertexes on some meshes. (on lod's & sometimes the main model) 20 | public VVDFile(Stream FileInput, MDLFile mdl) 21 | { 22 | using (uReader FileStream = new uReader(FileInput)) 23 | { 24 | FileStream.ReadTypeFixed(ref VVD_Header, 64); 25 | 26 | if (VVD_Header.checksum != mdl.MDL_Header.checksum) 27 | throw new FileLoadException(String.Format("{0}: Does not match the checksum in the .mdl", mdl.MDL_Header.Name)); 28 | 29 | if (VVD_Header.numFixups > 0) 30 | { 31 | VVD_Fixups = new vertexFileFixup_t[VVD_Header.numFixups]; 32 | FileStream.ReadArrayFixed(ref VVD_Fixups, 12, VVD_Header.fixupTableStart); 33 | } 34 | 35 | //TODO 36 | //HasTangents = VVD_Header.tangentDataStart != 0; 37 | 38 | //"HasTagents" used to avoid non-zero length 39 | //Int64 TotalVerts = (HasTangents ? VVD_Header.tangentDataStart - VVD_Header.vertexDataStart : FileStream.InputStream.Length - VVD_Header.vertexDataStart) / 48; 40 | mstudiovertex_t[] tempVerts = new mstudiovertex_t[VVD_Header.numLODVertexes[0]]; 41 | FileStream.ReadArrayFixed(ref tempVerts, 48, VVD_Header.vertexDataStart); 42 | 43 | VVD_Vertexes = new mstudiovertex_t[VVD_Header.numLODs][]; 44 | List TempVerts = new List(); 45 | 46 | for (Int32 LODID = 0; LODID < VVD_Header.numLODs; ++LODID) 47 | { 48 | if (VVD_Header.numFixups == 0) 49 | { 50 | VVD_Vertexes[LODID] = tempVerts.Take(VVD_Header.numLODVertexes[LODID]).ToArray(); 51 | continue; 52 | } 53 | 54 | TempVerts.Clear(); 55 | 56 | for (Int32 FixupID = 0; FixupID < VVD_Fixups.Length; FixupID++) 57 | { 58 | if (VVD_Fixups[FixupID].lod >= LODID) 59 | { 60 | TempVerts.AddRange(tempVerts.Skip(VVD_Fixups[FixupID].sourceVertexID).Take(VVD_Fixups[FixupID].numVertexes)); 61 | } 62 | } 63 | 64 | VVD_Vertexes[LODID] = TempVerts.ToArray(); 65 | } 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Formats/Source/MDL/VVDFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43c93c8db91fea542afa7ff630ada9a0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5c1a9116734c954dbcb187b119e2c70 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/EntInfo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Globalization; 5 | using System; 6 | 7 | namespace uSource.Formats.Source.VBSP 8 | { 9 | public class EntInfo : MonoBehaviour 10 | { 11 | public List Data; 12 | 13 | void OnDrawGizmos() 14 | { 15 | Gizmos.DrawCube(transform.position, Vector3.one / 5f); 16 | } 17 | 18 | void OnDrawGizmosSelected() 19 | { 20 | Gizmos.color = Color.red; 21 | Gizmos.DrawCube(transform.position, Vector3.one / 5f); 22 | } 23 | 24 | public void Configure(List Data) 25 | { 26 | this.Data = Data; 27 | transform.Configure(this.Data); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Formats/Source/VBSP/EntInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d2cef40884f7c046a4a82ea325d7eb8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/Entities.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 36d57ccffa3b36a4c9be7ae619066481 3 | folderAsset: yes 4 | timeCreated: 1503172416 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/Entities/point_viewcontrol.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class point_viewcontrol : MonoBehaviour 4 | { 5 | public Transform info_target; 6 | 7 | public void Start() 8 | { 9 | gameObject.AddComponent(); 10 | 11 | Vector3 relativePos = info_target.position - transform.position; 12 | transform.rotation = Quaternion.LookRotation(relativePos); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/Entities/point_viewcontrol.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1443193d3e94d214989c035abe496cc1 3 | timeCreated: 1503172416 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/EntitySetup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using uSource.Decals; 6 | using uSource.Formats.Source.VTF; 7 | using uSource.MathLib; 8 | using uSource.Example; 9 | 10 | namespace uSource.Formats.Source.VBSP 11 | { 12 | //TODO: 13 | //Rework this & make universal 14 | public static class EntitySetup 15 | { 16 | public static void Configure(this Transform transform, List Data) 17 | { 18 | //return; 19 | String Classname = Data[Data.FindIndex(n => n == "classname") + 1], Targetname = Data[Data.FindIndex(n => n == "targetname") + 1]; 20 | transform.name = Classname; 21 | 22 | //ResourceManager.LoadModel("editor/axis_helper").SetParent(transform, false); 23 | 24 | Int32 OriginIndex = Data.FindIndex(n => n == "origin"); 25 | if (OriginIndex != -1) 26 | { 27 | //Old but gold 28 | String[] origin = Data[OriginIndex + 1].Split(' '); 29 | 30 | while (origin.Length != 3) 31 | { 32 | Int32 TempIndex = OriginIndex + 1; 33 | origin = Data[Data.FindIndex(TempIndex, n => n == "origin") + 1].Split(' '); 34 | } 35 | //Old but gold 36 | 37 | transform.position = new Vector3(-origin[1].ToSingle(), origin[2].ToSingle(), origin[0].ToSingle()) * uLoader.UnitScale; 38 | } 39 | 40 | Int32 AnglesIndex = Data.FindIndex(n => n == "angles"); 41 | if (AnglesIndex != -1) 42 | { 43 | Vector3 EulerAngles = Data[AnglesIndex + 1].ToVector3(); 44 | 45 | EulerAngles = new Vector3(EulerAngles.x, -EulerAngles.y, -EulerAngles.z); 46 | 47 | if (Classname.StartsWith("light", StringComparison.Ordinal)) 48 | EulerAngles.x = -EulerAngles.x; 49 | 50 | Int32 PitchIndex = Data.FindIndex(n => n == "pitch"); 51 | //Lights 52 | if (PitchIndex != -1) 53 | EulerAngles.x = -Data[PitchIndex + 1].ToSingle(); 54 | 55 | transform.eulerAngles = EulerAngles; 56 | } 57 | 58 | if (Classname.Contains("trigger")) 59 | { 60 | for (Int32 i = 0; i < transform.childCount; i++) 61 | { 62 | GameObject Child = transform.GetChild(i).gameObject; 63 | Child.SetActive(false); 64 | Child.AddComponent().isTrigger = true; 65 | } 66 | } 67 | 68 | #if UNITY_EDITOR 69 | if (Classname.Equals("env_sprite")) 70 | { 71 | //TODO: fix scale 72 | LensFlare lensFlare = transform.gameObject.AddComponent(); 73 | 74 | if (VBSPFile.GlowFlare == null) 75 | { 76 | String path = UnityEditor.AssetDatabase.GUIDToAssetPath(UnityEditor.AssetDatabase.FindAssets("Glow t:Flare")[0]); 77 | VBSPFile.GlowFlare = UnityEditor.AssetDatabase.LoadAssetAtPath(path); 78 | } 79 | 80 | lensFlare.flare = VBSPFile.GlowFlare; 81 | lensFlare.brightness = Data[Data.FindIndex(n => n == "scale") + 1].ToSingle(); 82 | lensFlare.fadeSpeed = Data[Data.FindIndex(n => n == "GlowProxySize") + 1].ToSingle(); 83 | lensFlare.color = Data[Data.FindIndex(n => n == "rendercolor") + 1].ToColor32(); 84 | 85 | return; 86 | } 87 | #endif 88 | 89 | /*if (Classname.Equals("point_viewcontrol")) 90 | { 91 | transform.gameObject.AddComponent().Start(); 92 | }*/ 93 | 94 | //3D Skybox 95 | if (uLoader.Use3DSkybox && Classname.Equals("sky_camera")) 96 | { 97 | //Setup 3DSkybox 98 | Camera playerCamera = new GameObject("CameraPlayer").AddComponent(); 99 | Camera skyCamera = transform.gameObject.AddComponent(); 100 | 101 | CameraFly camFly = playerCamera.gameObject.AddComponent(); 102 | camFly.skyScale = Data[Data.FindIndex(n => n == "scale") + 1].ToSingle(); 103 | camFly.offset3DSky = transform.position; 104 | camFly.skyCamera = skyCamera.transform; 105 | 106 | playerCamera.depth = -1; 107 | playerCamera.clearFlags = CameraClearFlags.Depth; 108 | 109 | skyCamera.depth = -2; 110 | skyCamera.clearFlags = CameraClearFlags.Skybox; 111 | //Setup 3DSkybox 112 | return; 113 | } 114 | //3D Skybox 115 | 116 | #region Counter-Strike entities test 117 | /*if (Classname.Equals("info_player_terrorist")) 118 | { 119 | //Placeholder model (can be removed if needed) 120 | ResourceManager.LoadModel("player/t_phoenix").SetParent(transform, false); 121 | } 122 | 123 | //Counter-Strike CT spawn point 124 | if (Classname.Equals("info_player_counterterrorist")) 125 | { 126 | //Placeholder model (can be removed if needed) 127 | ResourceManager.LoadModel("player/ct_urban").SetParent(transform, false); 128 | } 129 | 130 | //Default spawn point 131 | if (Classname.Equals("info_player_start")) 132 | { 133 | //Placeholder model (can be removed if needed) 134 | ResourceManager.LoadModel("editor/playerstart").SetParent(transform, false); 135 | } 136 | 137 | //weapon spawn point 138 | if (Classname.Contains("weapon_")) 139 | { 140 | //Placeholder model (can be removed if needed) 141 | ResourceManager.LoadModel("weapons/w_rif_ak47").SetParent(transform, false); 142 | } 143 | 144 | //hostage spawn point 145 | if (Classname.Equals("hostage_entity")) 146 | { 147 | String[] hostages = 148 | { 149 | "characters/hostage_01", 150 | "characters/hostage_02", 151 | "characters/hostage_03", 152 | "characters/hostage_04" 153 | }; 154 | 155 | ResourceManager.LoadModel(hostages[UnityEngine.Random.Range(0, hostages.Length)]).SetParent(transform, false); 156 | }*/ 157 | #endregion 158 | 159 | Int32 RenderModeIndex = Data.FindIndex(n => n == "rendermode"); 160 | if (RenderModeIndex != -1) 161 | { 162 | if (Data[RenderModeIndex + 1] == "10") 163 | { 164 | for (Int32 i = 0; i < transform.childCount; i++) 165 | { 166 | GameObject Child = transform.GetChild(i).gameObject; 167 | Child.GetComponent().enabled = false; 168 | } 169 | } 170 | } 171 | 172 | if (Classname.Contains("prop_") || Classname.Contains("npc_"))// || Classname.Equals("asw_door")) 173 | { 174 | string ModelName = Data[Data.FindIndex(n => n == "model") + 1]; 175 | 176 | if (!string.IsNullOrEmpty(ModelName)) 177 | { 178 | uResourceManager.LoadModel(ModelName, uLoader.LoadAnims, uLoader.UseHitboxesOnModel).SetParent(transform, false); 179 | return; 180 | } 181 | 182 | return; 183 | } 184 | 185 | if (uLoader.ParseDecals && Classname.Equals("infodecal")) 186 | { 187 | String DecalName = Data[Data.FindIndex(n => n == "texture") + 1]; 188 | VMTFile DecalMaterial = uResourceManager.LoadMaterial(DecalName); 189 | 190 | Single DecalScale = DecalMaterial.GetSingle("$decalscale"); 191 | 192 | if (DecalScale <= 0) 193 | DecalScale = 1f; 194 | 195 | Int32 DecalWidth = DecalMaterial.Material.mainTexture.width; //X 196 | Int32 DecalHeight = DecalMaterial.Material.mainTexture.height; //Y 197 | Sprite DecalTexture = Sprite.Create((Texture2D)DecalMaterial.Material.mainTexture, new Rect(0, 0, DecalWidth, DecalHeight), Vector2.zero); 198 | 199 | Decal DecalBuilder = transform.gameObject.AddComponent(); 200 | 201 | #if UNITY_EDITOR 202 | if (uLoader.DebugMaterials) 203 | transform.gameObject.AddComponent().Init(DecalMaterial); 204 | #endif 205 | 206 | DecalBuilder.SetDirection(); 207 | DecalBuilder.MaxAngle = 87.5f; 208 | DecalBuilder.Offset = 0.001f; 209 | DecalBuilder.Sprite = DecalTexture; 210 | DecalBuilder.Material = DecalMaterial.Material; 211 | DecalBuilder.Material.SetTextureScale("_MainTex", new Vector2(-1, 1)); 212 | 213 | Single ScaleX = (DecalWidth * DecalScale) * uLoader.UnitScale; 214 | Single ScaleY = (DecalHeight * DecalScale) * uLoader.UnitScale; 215 | 216 | Single DepthSize = ScaleX; 217 | if (ScaleY < DepthSize) 218 | DepthSize = ScaleY; 219 | 220 | transform.localScale = new Vector3(ScaleX, ScaleY, DepthSize); 221 | transform.position += new Vector3(0, 0, 0.001f); 222 | 223 | #if !UNITY_EDITOR 224 | DecalBuilder.BuildAndSetDirty(); 225 | #endif 226 | } 227 | } 228 | } 229 | } -------------------------------------------------------------------------------- /Formats/Source/VBSP/EntitySetup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20cf4fb145f13c9489387c9fb64ff448 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/ObjectInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | public class ObjectInfo : MonoBehaviour 9 | { 10 | //public System.Text.StringBuilder info; 11 | [TextArea(0, 50)] 12 | public string infoOutput; 13 | public int size = 8; 14 | 15 | #if UNITY_EDITOR 16 | public void OnDrawGizmosSelected() 17 | { 18 | var style = new GUIStyle { fontSize = size, fontStyle = FontStyle.Bold }; 19 | style.normal.textColor = Handles.yAxisColor; 20 | Handles.Label(transform.position + Vector3.up * 2, infoOutput.ToString(), style); 21 | } 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/ObjectInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e87fa93a1e732cd48ab2b05cc82acc4d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/PhysModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using UnityEngine; 6 | 7 | namespace uSource.Formats.Source.VBSP 8 | { 9 | public class PhysModel 10 | { 11 | public PhysModel(Int32 modelIndex, Int32 solidCount, Byte[] collisionData, Byte[] keyData) 12 | { 13 | ModelIndex = modelIndex; 14 | KeyData = System.Text.Encoding.ASCII.GetString(keyData); 15 | 16 | using (var ms = new MemoryStream(collisionData)) 17 | { 18 | using (var br = new uReader(ms)) 19 | { 20 | for (Int32 i = 0; i < solidCount; i++) 21 | { 22 | var solid = new PhysModelSolid(); 23 | Solids.Add(solid); 24 | 25 | var size = br.ReadInt32(); 26 | var maxPos = br.BaseStream.Position + size; 27 | solid.vphysicsID = br.ReadInt16(); // ?? 28 | solid.version = br.ReadInt16(); 29 | br.ReadInt16(); 30 | solid.modelType = br.ReadInt16(); 31 | 32 | if (solid.modelType != 0x0) 33 | { 34 | br.BaseStream.Seek(maxPos - br.BaseStream.Position, SeekOrigin.Current); 35 | continue; 36 | } 37 | 38 | // ??? 39 | br.BaseStream.Seek(68, SeekOrigin.Current); 40 | 41 | while (true) 42 | { 43 | var cc = new PhysModelConvex(); 44 | solid.Convexes.Add(cc); 45 | 46 | var pos = br.BaseStream.Position; 47 | var vertexOffset = (Int32)(pos + br.ReadUInt32()); 48 | 49 | cc.BrushIndex = br.ReadInt32(); 50 | cc.idk2 = br.ReadByte(); 51 | cc.idk3 = br.ReadByte(); 52 | cc.idk4 = br.ReadUInt16(); 53 | 54 | var triCount = br.ReadInt16(); 55 | cc.idk5 = br.ReadUInt16(); 56 | 57 | for (Int32 j = 0; j < triCount; j++) 58 | { 59 | br.BaseStream.Seek(4, SeekOrigin.Current); 60 | 61 | var index1 = br.ReadInt16(); 62 | br.ReadInt16(); 63 | var index2 = br.ReadInt16(); 64 | br.ReadInt16(); 65 | var index3 = br.ReadInt16(); 66 | br.ReadInt16(); 67 | 68 | try 69 | { 70 | Vector3 v1 = collisionData.ReadAtPosition(vertexOffset + index1 * 16); 71 | Vector3 v2 = collisionData.ReadAtPosition(vertexOffset + index2 * 16); 72 | Vector3 v3 = collisionData.ReadAtPosition(vertexOffset + index3 * 16); 73 | 74 | cc.Triangles.Add(cc.Verts.Count); 75 | cc.Triangles.Add(cc.Verts.Count + 1); 76 | cc.Triangles.Add(cc.Verts.Count + 2); 77 | cc.Verts.Add(v1); 78 | cc.Verts.Add(v2); 79 | cc.Verts.Add(v3); 80 | } 81 | catch (System.Exception e) 82 | { 83 | Debug.Log("Error on solid type: " + solid.modelType); 84 | Debug.LogError(e); 85 | } 86 | } 87 | 88 | if (br.BaseStream.Position >= vertexOffset) 89 | { 90 | break; 91 | } 92 | } 93 | 94 | Int64 remainder = maxPos - br.BaseStream.Position; 95 | if (remainder > 0) 96 | { 97 | br.BaseStream.Seek(remainder, SeekOrigin.Current); 98 | } 99 | } 100 | } 101 | } 102 | 103 | KeyValues = KeyValues.Parse(KeyData); 104 | } 105 | 106 | public readonly Int32 ModelIndex; 107 | public String KeyData; 108 | public List Solids = new List(); 109 | public KeyValues KeyValues; 110 | 111 | } 112 | 113 | public class PhysModelConvex 114 | { 115 | public List Triangles = new List(); 116 | public List Verts = new List(); 117 | public Int32 BrushIndex; 118 | public Byte idk2; 119 | public Byte idk3; 120 | public UInt16 idk4; 121 | public UInt16 idk5; 122 | 123 | // todo : needs research. this presumably detects the convex that wraps an entity with multiple solids, which we won't want to actually generate 124 | public Boolean Skip => idk2 == 5; 125 | 126 | public override string ToString() 127 | { 128 | return $"#{BrushIndex} - {idk2} - {idk3} - {idk4} - {idk5}"; 129 | } 130 | } 131 | 132 | public class PhysModelSolid 133 | { 134 | public Int32 vphysicsID; 135 | public Int16 version; 136 | public Int16 modelType; 137 | public Boolean Fluid; 138 | public List Convexes = new List(); 139 | public GameObject ConvexContainer; 140 | } 141 | } -------------------------------------------------------------------------------- /Formats/Source/VBSP/PhysModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9e7f73a963898644b630eaf7704a6c7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/VBSPFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c43f466d819b5514994ad772ad0ebb64 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/VBSPLump.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using UnityEngine; 4 | 5 | namespace uSource.Formats.Source.VBSP 6 | { 7 | public class VBSPLump 8 | { 9 | [Flags] 10 | public enum STATICPROP_FLAGS 11 | { 12 | /// automatically computed 13 | STATIC_PROP_FLAG_FADES = 0x1, 14 | /// automatically computed 15 | STATIC_PROP_USE_LIGHTING_ORIGIN = 0x2, 16 | /// automatically computed; computed at run time based on dx level 17 | STATIC_PROP_NO_DRAW = 0x4, 18 | 19 | /// set in WC 20 | STATIC_PROP_IGNORE_NORMALS = 0x8, 21 | /// set in WC 22 | STATIC_PROP_NO_SHADOW = 0x10, 23 | /// set in WC 24 | STATIC_PROP_UNUSED = 0x20, 25 | 26 | /// in vrad, compute lighting at lighting origin, not for each vertex 27 | STATIC_PROP_NO_PER_VERTEX_LIGHTING = 0x40, 28 | 29 | /// disable self shadowing in vrad 30 | STATIC_PROP_NO_SELF_SHADOWING = 0x80 31 | } 32 | 33 | /// Game lump: Static prop. V4. Size: 56 bytes 34 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 35 | public struct StaticPropLumpV4_t 36 | { 37 | public Vector3 m_Origin; 38 | public Vector3 m_Angles; 39 | public ushort m_PropType; 40 | public ushort m_FirstLeaf; 41 | public ushort m_LeafCount; 42 | public byte m_Solid; 43 | public STATICPROP_FLAGS m_Flags; 44 | public int m_Skin; 45 | public float m_FadeMinDist; 46 | public float m_FadeMaxDist; 47 | public Vector3 m_LightingOrigin; 48 | } 49 | 50 | /// Game lump: Static prop. V5. Size: 60 bytes 51 | public struct StaticPropLumpV5_t 52 | { 53 | public Vector3 m_Origin; 54 | public Vector3 m_Angles; 55 | public ushort m_PropType; 56 | public ushort m_FirstLeaf; 57 | public ushort m_LeafCount; 58 | public byte m_Solid; 59 | public STATICPROP_FLAGS m_Flags; 60 | public int m_Skin; 61 | public float m_FadeMinDist; 62 | public float m_FadeMaxDist; 63 | public Vector3 m_LightingOrigin; 64 | public float m_flForcedFadeScale; 65 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 66 | } 67 | 68 | /// Game lump: Static prop. V6. Size: 64 bytes 69 | public struct StaticPropLumpV6_t 70 | { 71 | public Vector3 m_Origin; 72 | public Vector3 m_Angles; 73 | public ushort m_PropType; 74 | public ushort m_FirstLeaf; 75 | public ushort m_LeafCount; 76 | public byte m_Solid; 77 | public STATICPROP_FLAGS m_Flags; 78 | public int m_Skin; 79 | public float m_FadeMinDist; 80 | public float m_FadeMaxDist; 81 | public Vector3 m_LightingOrigin; 82 | public float m_flForcedFadeScale; 83 | public ushort m_nMinDXLevel; 84 | public ushort m_nMaxDXLevel; 85 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 86 | } 87 | 88 | /// Game lump: Static prop. V7. Size: 68 bytes 89 | public struct StaticPropLumpV7_t 90 | { 91 | public Vector3 m_Origin; 92 | public Vector3 m_Angles; 93 | public ushort m_PropType; 94 | public ushort m_FirstLeaf; 95 | public ushort m_LeafCount; 96 | public byte m_Solid; 97 | public STATICPROP_FLAGS m_Flags; 98 | public int m_Skin; 99 | public float m_FadeMinDist; 100 | public float m_FadeMaxDist; 101 | public Vector3 m_LightingOrigin; 102 | public float m_flForcedFadeScale; 103 | public ushort m_nMinDXLevel; 104 | public ushort m_nMaxDXLevel; 105 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 106 | public Color32 m_DiffuseModulation; // per instance color and alpha modulation 107 | } 108 | 109 | /// Game lump: Static prop. V8. Size: 68 bytes 110 | public struct StaticPropLumpV8_t 111 | { 112 | public Vector3 m_Origin; 113 | public Vector3 m_Angles; 114 | public ushort m_PropType; 115 | public ushort m_FirstLeaf; 116 | public ushort m_LeafCount; 117 | public byte m_Solid; 118 | public STATICPROP_FLAGS m_Flags; 119 | public int m_Skin; 120 | public float m_FadeMinDist; 121 | public float m_FadeMaxDist; 122 | public Vector3 m_LightingOrigin; 123 | public float m_flForcedFadeScale; 124 | public byte m_nMinCPULevel; 125 | public byte m_nMaxCPULevel; 126 | public byte m_nMinGPULevel; 127 | public byte m_nMaxGPULevel; 128 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 129 | public Color32 m_DiffuseModulation; // per instance color and alpha modulation 130 | } 131 | 132 | /// Game lump: Static prop. V9. Size: 72 bytes 133 | public struct StaticPropLumpV9_t 134 | { 135 | public Vector3 m_Origin; 136 | public Vector3 m_Angles; 137 | public ushort m_PropType; 138 | public ushort m_FirstLeaf; 139 | public ushort m_LeafCount; 140 | public byte m_Solid; 141 | public STATICPROP_FLAGS m_Flags; 142 | public int m_Skin; 143 | public float m_FadeMinDist; 144 | public float m_FadeMaxDist; 145 | public Vector3 m_LightingOrigin; 146 | public float m_flForcedFadeScale; 147 | public byte m_nMinCPULevel; 148 | public byte m_nMaxCPULevel; 149 | public byte m_nMinGPULevel; 150 | public byte m_nMaxGPULevel; 151 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 152 | public Color32 m_DiffuseModulation; // per instance color and alpha modulation 153 | public bool m_bDisableX360; // if true, don't show on XBox 360 (4-bytes long) 154 | } 155 | 156 | /// Game lump: Static prop. V10. Size: 76 bytes 157 | public struct StaticPropLumpV10_t 158 | { 159 | public Vector3 m_Origin; 160 | public Vector3 m_Angles; 161 | public ushort m_PropType; 162 | public ushort m_FirstLeaf; 163 | public ushort m_LeafCount; 164 | public byte m_Solid; 165 | public STATICPROP_FLAGS m_Flags; 166 | public int m_Skin; 167 | public float m_FadeMinDist; 168 | public float m_FadeMaxDist; 169 | public Vector3 m_LightingOrigin; 170 | public float m_flForcedFadeScale; 171 | public byte m_nMinCPULevel; 172 | public byte m_nMaxCPULevel; 173 | public byte m_nMinGPULevel; 174 | public byte m_nMaxGPULevel; 175 | // int m_Lighting; // index into the GAMELUMP_STATIC_PROP_LIGHTING lump 176 | public Color32 m_DiffuseModulation; // per instance color and alpha modulation 177 | public bool m_bDisableX360; // if true, don't show on XBox 360 (4-bytes long) 178 | public uint m_FlagsEx; // Further bitflags. 179 | } 180 | 181 | /// Game lump: Static prop. V11. Size: 80 bytes 182 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 183 | public struct StaticPropLumpV11_t 184 | { 185 | public Vector3 m_Origin; 186 | public Vector3 m_Angles; 187 | public ushort m_PropType; 188 | public ushort m_FirstLeaf; 189 | public ushort m_LeafCount; 190 | public byte m_Solid; 191 | public byte m_Flags; 192 | public int m_Skin; 193 | public float m_FadeMinDist; 194 | public float m_FadeMaxDist; 195 | public Vector3 m_LightingOrigin; 196 | public float m_ForcedFadeScale; 197 | public byte m_MinCPULevel; 198 | public byte m_MaxCPULevel; 199 | public byte m_MinGPULevel; 200 | public byte m_MaxGPULevel; 201 | public Color32 m_DiffuseModulation; // per instance color and alpha modulation 202 | public bool m_DisableX360; // if true, don't show on XBox 360 (4-bytes long) 203 | public uint m_FlagsEx; // Further bitflags. 204 | public float m_UniformScale; // Prop scale 205 | } 206 | } 207 | } -------------------------------------------------------------------------------- /Formats/Source/VBSP/VBSPLump.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bac7398707b5024282aa81fe77b3f68 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VBSP/VBSPStruct.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67b07711c8cce064d8504a2ec63d13d5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VPK.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 745a235b7221c9641ac0728ad04a0696 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKEntry.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace uSource.Formats.Source.VPK 4 | { 5 | public class VPKEntry 6 | { 7 | public bool HasPreloadData { get; set; } 8 | public uint Length => EntryLength; 9 | 10 | internal uint CRC; 11 | internal ushort PreloadBytes; 12 | internal uint PreloadDataOffset; 13 | internal ushort ArchiveIndex; 14 | internal uint EntryOffset; 15 | internal uint EntryLength; 16 | internal VPKFile ParentArchive; 17 | 18 | internal VPKEntry(VPKFile parentArchive, uint crc, ushort preloadBytes, uint preloadDataOffset, ushort archiveIndex, uint entryOffset, uint entryLength) 19 | { 20 | ParentArchive = parentArchive; 21 | CRC = crc; 22 | PreloadBytes = preloadBytes; 23 | PreloadDataOffset = preloadDataOffset; 24 | ArchiveIndex = archiveIndex; 25 | EntryOffset = entryOffset; 26 | EntryLength = entryLength; 27 | HasPreloadData = preloadBytes > 0; 28 | } 29 | 30 | public Stream ReadPreloadDataStream() 31 | { 32 | MemoryStream memStream = new MemoryStream(); 33 | CopyPreloadDataStreamTo(memStream); 34 | memStream.Seek(0, SeekOrigin.Begin); 35 | return memStream; 36 | } 37 | 38 | public bool CopyPreloadDataStreamTo(Stream outputStream) 39 | { 40 | if (HasPreloadData) 41 | { 42 | var fs = ParentArchive.MainPart.PartStream; 43 | fs.Seek(PreloadDataOffset, SeekOrigin.Begin); 44 | fs.CopyToLimited(outputStream, PreloadBytes); 45 | return true; 46 | } 47 | return false; 48 | } 49 | 50 | public Stream ReadDataStream() 51 | { 52 | MemoryStream memStream = new MemoryStream(); 53 | CopyDataStreamTo(memStream); 54 | memStream.Seek(0, SeekOrigin.Begin); 55 | return memStream; 56 | } 57 | 58 | public bool CopyDataStreamTo(Stream outputStream) 59 | { 60 | var partFile = ParentArchive.Parts[ArchiveIndex]; 61 | if (partFile != null && !HasPreloadData) 62 | { 63 | var fs = partFile.PartStream; 64 | fs.Seek(EntryOffset, SeekOrigin.Begin); 65 | fs.CopyToLimited(outputStream, (int)EntryLength); 66 | return true; 67 | } 68 | 69 | return false; 70 | } 71 | 72 | public Stream ReadAnyDataStream() 73 | { 74 | if (HasPreloadData) 75 | { 76 | return ReadPreloadDataStream(); 77 | } 78 | else 79 | { 80 | return ReadDataStream(); 81 | } 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKEntry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fe8caaada7fbb344af9fca37e5bed2a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | 5 | namespace uSource.Formats.Source.VPK 6 | { 7 | internal class ArchiveParsingException : Exception 8 | { 9 | public ArchiveParsingException() 10 | { 11 | } 12 | 13 | public ArchiveParsingException(String message) 14 | : base(message) 15 | { 16 | } 17 | 18 | public ArchiveParsingException(String message, Exception innerException) 19 | : base(message, innerException) 20 | { 21 | } 22 | } 23 | 24 | public sealed class VPKFile : IDisposable 25 | { 26 | public Boolean Loaded { get; private set; } 27 | public Boolean IsMultiPart 28 | { 29 | get 30 | { 31 | return Parts.Count > 1; 32 | } 33 | } 34 | 35 | private VPKReaderBase Reader { get; set; } 36 | private Boolean Disposed { get; set; } // To detect redundant calls 37 | 38 | public Dictionary Entries = new Dictionary(); 39 | internal Dictionary Parts { get; } = new Dictionary(); 40 | internal VPKFilePart MainPart 41 | { 42 | get 43 | { 44 | return Parts[MainPartIndex]; 45 | } 46 | } 47 | 48 | internal const Int32 MainPartIndex = -1; 49 | 50 | /// 51 | /// Loads the specified vpk archive by filename, if it's a _dir.vpk file it'll load related numbered vpks automatically 52 | /// 53 | /// A vpk archive ending in _dir.vpk 54 | public VPKFile(String FileName) 55 | { 56 | Load(new FileStream(FileName, FileMode.Open, FileAccess.Read), FileName); 57 | } 58 | 59 | /// 60 | /// Loads the specified vpk archive by filename, if it's a _dir.vpk file it'll load related numbered vpks automatically 61 | /// 62 | /// A vpk archive ending in _dir.vpk 63 | public void Load(String FileName) 64 | { 65 | Load(new FileStream(FileName, FileMode.Open, FileAccess.Read), FileName); 66 | } 67 | 68 | /// 69 | /// The main Load function, the related parts need to be numbered correctly as "archivename_01.vpk" and so forth 70 | /// 71 | /// 72 | /// 73 | public void Load(Stream Stream, String FileName = "") 74 | { 75 | if (Loaded) 76 | throw new NotSupportedException("Tried to call Load on a VpkArchive that is already loaded, dispose and create a new one instead"); 77 | 78 | if (String.IsNullOrEmpty(FileName)) 79 | throw new FileLoadException("File name is empty!!!"); 80 | 81 | Reader = new VPKReaderBase(Stream); 82 | 83 | UInt32 Signature = Reader.ReadUInt32(); 84 | UInt32 Version = Reader.ReadUInt32(); 85 | 86 | if (Signature != 0x55aa1234 && (Version > 2 || Version < 1)) 87 | { 88 | Dispose(); 89 | throw new ArchiveParsingException("Invalid archive header"); 90 | } 91 | 92 | // skip unneeded bytes 93 | if (Version == 1 || Version == 2) 94 | { 95 | Reader.ReadUInt32(); // - TreeSize; 96 | if (Version == 2) 97 | Reader.ReadBytes(16); 98 | } 99 | 100 | AddMainPart(FileName, Stream); 101 | 102 | //TODO: 103 | //OPTIMIZE PARSING 104 | String Folder = Path.GetDirectoryName(FileName) ?? ""; 105 | String NameWithoutExtension = Path.GetFileNameWithoutExtension(FileName) ?? ""; 106 | //String Extension = Path.GetExtension(FileName); 107 | 108 | String BaseName = NameWithoutExtension.Substring(0, NameWithoutExtension.Length - 4); 109 | 110 | String[] MatchingFiles = Directory.GetFiles(Folder, BaseName + "_???.vpk"); 111 | foreach (String MatchedFile in MatchingFiles) 112 | { 113 | var fileName = Path.GetFileNameWithoutExtension(MatchedFile); 114 | UInt16 Index; 115 | if (UInt16.TryParse(fileName.Substring(fileName.Length - 3), out Index)) 116 | { 117 | AddPart(MatchedFile, new FileStream(MatchedFile, FileMode.Open, FileAccess.Read), Index); 118 | } 119 | } 120 | 121 | Reader.ReadDirectories(this); 122 | 123 | Loaded = true; 124 | } 125 | 126 | private void AddMainPart(String filename, Stream stream = null) 127 | { 128 | if (stream == null) 129 | { 130 | stream = new FileStream(filename, FileMode.Open, FileAccess.Read); 131 | } 132 | AddPart(filename, stream, MainPartIndex); 133 | } 134 | 135 | private void AddPart(String filename, Stream stream, Int32 index) 136 | { 137 | Parts.Add(index, new VPKFilePart(index, filename, stream)); 138 | } 139 | 140 | #region IDisposable Support 141 | 142 | private void Dispose(Boolean disposing) 143 | { 144 | if (!Disposed) 145 | { 146 | if (disposing) 147 | { 148 | foreach (var partkv in Parts) 149 | { 150 | partkv.Value.PartStream?.Dispose(); 151 | } 152 | Parts.Clear(); 153 | Entries.Clear(); 154 | } 155 | Reader.Dispose(); 156 | Reader.Close(); 157 | // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. 158 | // TODO: set large fields to null. 159 | 160 | Disposed = true; 161 | } 162 | } 163 | 164 | // This code added to correctly implement the disposable pattern. 165 | public void Dispose() 166 | { 167 | // Do not change this code. Put cleanup code in Dispose(Boolean disposing) above. 168 | Dispose(true); 169 | GC.Collect(); 170 | } 171 | #endregion 172 | } 173 | } -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c44686af37a0cab4ba8395b06e02f64b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKFilePart.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace uSource.Formats.Source.VPK 4 | { 5 | internal class VPKFilePart 6 | { 7 | public uint Size { get; set; } 8 | public int Index { get; set; } 9 | public string Filename { get; set; } 10 | public Stream PartStream { get; set; } 11 | 12 | public VPKFilePart(uint size, int index, string filename, Stream filestream) 13 | { 14 | Size = size; 15 | Index = index; 16 | Filename = filename; 17 | PartStream = filestream; 18 | } 19 | 20 | public VPKFilePart(int index, string filename, Stream filestream) 21 | { 22 | Index = index; 23 | Filename = filename; 24 | PartStream = filestream; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKFilePart.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5ea07203b9e1ae44825d25249631be8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKReaderBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace uSource.Formats.Source.VPK 5 | { 6 | internal class VPKReaderBase : uReader 7 | { 8 | public VPKReaderBase(Stream InputStream) 9 | : base(InputStream) 10 | { 11 | this.InputStream = InputStream; 12 | 13 | if (!InputStream.CanRead) 14 | throw new FileLoadException("Can't read unreadable archive!"); 15 | } 16 | 17 | public void ReadDirectories(VPKFile RootArchive) 18 | { 19 | while (true) 20 | { 21 | String Extension = ReadNullTerminatedString(); 22 | if (String.IsNullOrEmpty(Extension)) 23 | break; 24 | 25 | while (true) 26 | { 27 | String Path = ReadNullTerminatedString(); 28 | if (String.IsNullOrEmpty(Path)) 29 | break; 30 | 31 | ReadEntries(RootArchive, Extension, Path); 32 | } 33 | } 34 | } 35 | 36 | public void ReadEntries(VPKFile RootArchive, String Extension, String Path) 37 | { 38 | while (true) 39 | { 40 | String FileName = ReadNullTerminatedString(); 41 | if (String.IsNullOrEmpty(FileName)) 42 | break; 43 | 44 | UInt32 CRC = ReadUInt32(); 45 | UInt16 PreloadBytes = ReadUInt16(); 46 | UInt16 ArchiveIndex = ReadUInt16(); 47 | UInt32 EntryOffset = ReadUInt32(); 48 | UInt32 EntryLength = ReadUInt32(); 49 | // skip terminator 50 | ReadUInt16(); 51 | UInt32 preloadDataOffset = (UInt32)BaseStream.Position; 52 | if (PreloadBytes > 0) 53 | { 54 | BaseStream.Position += PreloadBytes; 55 | } 56 | 57 | ArchiveIndex = ArchiveIndex == 32767 ? (UInt16)0 : ArchiveIndex; 58 | 59 | Path = Path.ToLower(); 60 | FileName = FileName.ToLower(); 61 | Extension = Extension.ToLower(); 62 | 63 | RootArchive.Entries.Add(String.Format("{0}/{1}.{2}", Path, FileName, Extension), new VPKEntry(RootArchive, CRC, PreloadBytes, preloadDataOffset, ArchiveIndex, EntryOffset, EntryLength)); 64 | } 65 | } 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /Formats/Source/VPK/VPKReaderBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 894aae224068b7440bc51f826d7f4a2a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a774fb7871b5a142a97e8e925c0b0db 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Formats/Source/VTF/AnimatedTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | namespace uSource.Formats.Source.VTF 5 | { 6 | public class AnimatedTexture : MonoBehaviour 7 | { 8 | public float AnimatedTextureFramerate; 9 | public Texture2D[] Frames; 10 | public MeshRenderer Renderer; 11 | int CFrame = 0; 12 | 13 | void Start() 14 | { 15 | if (Renderer == null) 16 | Renderer = GetComponent(); 17 | 18 | AnimatedTextureFramerate = 1f / AnimatedTextureFramerate; 19 | 20 | StartCoroutine(Play()); 21 | } 22 | 23 | IEnumerator Play() 24 | { 25 | while (true) 26 | { 27 | if (CFrame == Frames.Length) 28 | CFrame = 0; 29 | 30 | Renderer.sharedMaterial.mainTexture = Frames[CFrame]; 31 | CFrame++; 32 | 33 | yield return new WaitForSeconds(AnimatedTextureFramerate); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Formats/Source/VTF/AnimatedTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 959ce157349a1ab47814ca23763472d8 3 | timeCreated: 1503172945 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Formats/Source/VTF/DXTDecompress.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace uSource.Formats.Source.VTF 4 | { 5 | public static class DXTDecompress 6 | { 7 | public static void DecompressDXT1(Byte[] Buffer, Byte[] Data, Int32 Width, Int32 Height) 8 | { 9 | Int32 Position = 0; 10 | Byte[] c = new Byte[16]; 11 | for (Int32 y = 0; y < Height; y += 4) 12 | { 13 | for (Int32 x = 0; x < Width; x += 4) 14 | { 15 | Int32 c0 = Data[Position++]; 16 | c0 |= Data[Position++] << 8; 17 | 18 | Int32 c1 = Data[Position++]; 19 | c1 |= Data[Position++] << 8; 20 | 21 | c[0] = (Byte)((c0 & 0xF800) >> 8); 22 | c[1] = (Byte)((c0 & 0x07E0) >> 3); 23 | c[2] = (Byte)((c0 & 0x001F) << 3); 24 | c[3] = 255; 25 | 26 | c[4] = (Byte)((c1 & 0xF800) >> 8); 27 | c[5] = (Byte)((c1 & 0x07E0) >> 3); 28 | c[6] = (Byte)((c1 & 0x001F) << 3); 29 | c[7] = 255; 30 | 31 | if (c0 > c1) 32 | { 33 | // No Alpha channel 34 | 35 | c[8] = (Byte)((2 * c[0] + c[4]) / 3); 36 | c[9] = (Byte)((2 * c[1] + c[5]) / 3); 37 | c[10] = (Byte)((2 * c[2] + c[6]) / 3); 38 | c[11] = 255; 39 | 40 | c[12] = (Byte)((c[0] + 2 * c[4]) / 3); 41 | c[13] = (Byte)((c[1] + 2 * c[5]) / 3); 42 | c[14] = (Byte)((c[2] + 2 * c[6]) / 3); 43 | c[15] = 255; 44 | } 45 | else 46 | { 47 | // 1-bit Alpha channel 48 | 49 | c[8] = (Byte)((c[0] + c[4]) / 2); 50 | c[9] = (Byte)((c[1] + c[5]) / 2); 51 | c[10] = (Byte)((c[2] + c[6]) / 2); 52 | c[11] = 255; 53 | c[12] = 0; 54 | c[13] = 0; 55 | c[14] = 0; 56 | c[15] = 0; 57 | } 58 | 59 | Int32 Bytes = Data[Position++]; 60 | Bytes |= Data[Position++] << 8; 61 | Bytes |= Data[Position++] << 16; 62 | Bytes |= Data[Position++] << 24; 63 | 64 | for (Int32 yy = 0; yy < 4; yy++) 65 | { 66 | for (Int32 xx = 0; xx < 4; xx++) 67 | { 68 | Int32 xPosition = x + xx; 69 | Int32 yPosition = y + yy; 70 | if (xPosition < Width && yPosition < Height) 71 | { 72 | Int32 Index = Bytes & 0x0003; 73 | Index *= 4; 74 | Int32 Pointer = yPosition * Width * 4 + xPosition * 4; 75 | Buffer[Pointer + 0] = c[Index + 2]; // b 76 | Buffer[Pointer + 1] = c[Index + 1]; // g 77 | Buffer[Pointer + 2] = c[Index + 0]; // r 78 | Buffer[Pointer + 3] = c[Index + 3]; // a 79 | } 80 | Bytes >>= 2; 81 | } 82 | } 83 | } 84 | } 85 | } 86 | 87 | public static void DecompressDXT3(Byte[] Buffer, Byte[] Data, Int32 Width, Int32 Height) 88 | { 89 | Int32 Position = 0; 90 | Byte[] c = new Byte[16]; 91 | Byte[] a = new Byte[8]; 92 | for (Int32 y = 0; y < Height; y += 4) 93 | { 94 | for (Int32 x = 0; x < Width; x += 4) 95 | { 96 | for (Int32 i = 0; i < 8; i++) 97 | a[i] = Data[Position++]; 98 | 99 | Int32 c0 = Data[Position++]; 100 | c0 |= Data[Position++] << 8; 101 | 102 | Int32 c1 = Data[Position++]; 103 | c1 |= Data[Position++] << 8; 104 | 105 | c[0] = (Byte)((c0 & 0xF800) >> 8); 106 | c[1] = (Byte)((c0 & 0x07E0) >> 3); 107 | c[2] = (Byte)((c0 & 0x001F) << 3); 108 | c[3] = 255; 109 | 110 | c[4] = (Byte)((c1 & 0xF800) >> 8); 111 | c[5] = (Byte)((c1 & 0x07E0) >> 3); 112 | c[6] = (Byte)((c1 & 0x001F) << 3); 113 | c[7] = 255; 114 | 115 | c[8] = (Byte)((2 * c[0] + c[4]) / 3); 116 | c[9] = (Byte)((2 * c[1] + c[5]) / 3); 117 | c[10] = (Byte)((2 * c[2] + c[6]) / 3); 118 | c[11] = 255; 119 | 120 | c[12] = (Byte)((c[0] + 2 * c[4]) / 3); 121 | c[13] = (Byte)((c[1] + 2 * c[5]) / 3); 122 | c[14] = (Byte)((c[2] + 2 * c[6]) / 3); 123 | c[15] = 255; 124 | 125 | Int32 Bytes = Data[Position++]; 126 | Bytes |= Data[Position++] << 8; 127 | Bytes |= Data[Position++] << 16; 128 | Bytes |= Data[Position++] << 24; 129 | 130 | for (Int32 yy = 0; yy < 4; yy++) 131 | { 132 | for (Int32 xx = 0; xx < 4; xx++) 133 | { 134 | Int32 xPosition = x + xx; 135 | Int32 yPosition = y + yy; 136 | Int32 aIndex = yy * 4 + xx; 137 | if (xPosition < Width && yPosition < Height) 138 | { 139 | Int32 Index = Bytes & 0x0003; 140 | Index *= 4; 141 | Byte Alpha = (Byte)((a[aIndex >> 1] >> (aIndex << 2 & 0x07)) & 0x0f); 142 | Alpha = (Byte)((Alpha << 4) | Alpha); 143 | Int32 Pointer = yPosition * Width * 4 + xPosition * 4; 144 | Buffer[Pointer + 0] = c[Index + 2]; // b 145 | Buffer[Pointer + 1] = c[Index + 1]; // g 146 | Buffer[Pointer + 2] = c[Index + 0]; // r 147 | Buffer[Pointer + 3] = Alpha; // a 148 | } 149 | Bytes >>= 2; 150 | } 151 | } 152 | } 153 | } 154 | } 155 | 156 | public static void DecompressDXT5(Byte[] Buffer, Byte[] Data, Int32 Width, Int32 Height) 157 | { 158 | Int32 Position = 0; 159 | Byte[] c = new Byte[16]; 160 | Int32[] a = new Int32[8]; 161 | for (Int32 y = 0; y < Height; y += 4) 162 | { 163 | for (Int32 x = 0; x < Width; x += 4) 164 | { 165 | Byte a0 = Data[Position++]; 166 | Byte a1 = Data[Position++]; 167 | 168 | a[0] = a0; 169 | a[1] = a1; 170 | 171 | if (a0 > a1) 172 | { 173 | a[2] = (6 * a[0] + 1 * a[1] + 3) / 7; 174 | a[3] = (5 * a[0] + 2 * a[1] + 3) / 7; 175 | a[4] = (4 * a[0] + 3 * a[1] + 3) / 7; 176 | a[5] = (3 * a[0] + 4 * a[1] + 3) / 7; 177 | a[6] = (2 * a[0] + 5 * a[1] + 3) / 7; 178 | a[7] = (1 * a[0] + 6 * a[1] + 3) / 7; 179 | } 180 | else 181 | { 182 | a[2] = (4 * a[0] + 1 * a[1] + 2) / 5; 183 | a[3] = (3 * a[0] + 2 * a[1] + 2) / 5; 184 | a[4] = (2 * a[0] + 3 * a[1] + 2) / 5; 185 | a[5] = (1 * a[0] + 4 * a[1] + 2) / 5; 186 | a[6] = 0x00; 187 | a[7] = 0xFF; 188 | } 189 | 190 | Int64 aIndex = 0L; 191 | for (Int32 i = 0; i < 6; i++) 192 | aIndex |= ((Int64)Data[Position++]) << (8 * i); 193 | 194 | Int32 c0 = Data[Position++]; 195 | c0 |= Data[Position++] << 8; 196 | 197 | Int32 c1 = Data[Position++]; 198 | c1 |= Data[Position++] << 8; 199 | 200 | c[0] = (Byte)((c0 & 0xF800) >> 8); 201 | c[1] = (Byte)((c0 & 0x07E0) >> 3); 202 | c[2] = (Byte)((c0 & 0x001F) << 3); 203 | c[3] = 255; 204 | 205 | c[4] = (Byte)((c1 & 0xF800) >> 8); 206 | c[5] = (Byte)((c1 & 0x07E0) >> 3); 207 | c[6] = (Byte)((c1 & 0x001F) << 3); 208 | c[7] = 255; 209 | 210 | c[8] = (Byte)((2 * c[0] + c[4]) / 3); 211 | c[9] = (Byte)((2 * c[1] + c[5]) / 3); 212 | c[10] = (Byte)((2 * c[2] + c[6]) / 3); 213 | c[11] = 255; 214 | 215 | c[12] = (Byte)((c[0] + 2 * c[4]) / 3); 216 | c[13] = (Byte)((c[1] + 2 * c[5]) / 3); 217 | c[14] = (Byte)((c[2] + 2 * c[6]) / 3); 218 | c[15] = 255; 219 | 220 | Int32 Bytes = Data[Position++]; 221 | Bytes |= Data[Position++] << 8; 222 | Bytes |= Data[Position++] << 16; 223 | Bytes |= Data[Position++] << 24; 224 | 225 | for (Int32 yy = 0; yy < 4; yy++) 226 | { 227 | for (Int32 xx = 0; xx < 4; xx++) 228 | { 229 | Int32 xPosition = x + xx; 230 | Int32 yPosition = y + yy; 231 | if (xPosition < Width && yPosition < Height) 232 | { 233 | Int32 Index = Bytes & 0x0003; 234 | Index *= 4; 235 | Byte Alpha = (Byte)a[aIndex & 0x07]; 236 | Int32 Pointer = yPosition * Width * 4 + xPosition * 4; 237 | Buffer[Pointer + 0] = c[Index + 2]; // b 238 | Buffer[Pointer + 1] = c[Index + 1]; // g 239 | Buffer[Pointer + 2] = c[Index + 0]; // r 240 | Buffer[Pointer + 3] = Alpha; // a 241 | } 242 | Bytes >>= 2; 243 | aIndex >>= 3; 244 | } 245 | } 246 | } 247 | } 248 | } 249 | } 250 | } -------------------------------------------------------------------------------- /Formats/Source/VTF/DXTDecompress.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf9933ddc5da8a3489552947a36ee203 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/DebugMaterial.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEditor; 6 | using System.Text; 7 | 8 | namespace uSource.Formats.Source.VTF 9 | { 10 | public class DebugMaterial : MonoBehaviour 11 | { 12 | [TextArea(0, 20)] 13 | public string Data; 14 | 15 | StringBuilder builder; 16 | public void Init(VMTFile VMT) 17 | { 18 | if (VMT != null && VMT.KeyValues != null) 19 | { 20 | if (builder == null) 21 | builder = new StringBuilder(); 22 | 23 | foreach (var a in (VMT.Include != null ? VMT.Include : VMT).KeyValues) 24 | { 25 | builder.AppendLine(VMT.FileName); 26 | builder.AppendLine(a.Key); 27 | builder.AppendLine("{"); 28 | 29 | foreach (var b in a.Value) 30 | { 31 | builder.AppendLine($" \"{b.Key}\" \"{b.Value}\""); 32 | } 33 | 34 | builder.AppendLine("}"); 35 | } 36 | 37 | Data += builder.ToString(); 38 | } 39 | } 40 | } 41 | } 42 | #endif -------------------------------------------------------------------------------- /Formats/Source/VTF/DebugMaterial.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ece4fd9332c7d854199857c73fc4d2c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VMTFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5a52c2458eeb8244b00ee176e65d64d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using UnityEngine; 8 | 9 | namespace uSource.Formats.Source.VTF 10 | { 11 | public class VTFFile 12 | { 13 | private const String VTFHeader = "VTF"; 14 | public VTFHeader Header { get; set; } 15 | 16 | public VTFResource[] Resources { get; set; } 17 | 18 | public VTFImage LowResImage { get; set; } 19 | 20 | public Texture2D[,] Frames { get; set; } 21 | 22 | public UInt16 Width; 23 | public UInt16 Height; 24 | 25 | //http://wiki.xentax.com/index.php/Source_VTF 26 | /// 27 | /// Parser VTF format 28 | ///
Supported versions: 7.1 - 7.5 (maybe 7.0)
29 | ///
30 | /// Stream of input file 31 | /// Name of input file (optional) 32 | public VTFFile(Stream stream, String FileName = "") 33 | { 34 | using (uReader FileStream = new uReader(stream)) 35 | { 36 | String TempHeader = FileStream.ReadFixedLengthString(Encoding.ASCII, 4); 37 | if (TempHeader != VTFHeader) 38 | throw new Exception("Invalid VTF header. Expected '" + VTFHeader + "', got '" + TempHeader + "'."); 39 | 40 | Header = new VTFHeader(); 41 | 42 | UInt32 VersionMajor = FileStream.ReadUInt32(); 43 | UInt32 VersionMinor = FileStream.ReadUInt32(); 44 | Decimal Version = VersionMajor + (VersionMinor / 10m); // e.g. 7.3 45 | Header.Version = Version; 46 | 47 | UInt32 headerSize = FileStream.ReadUInt32(); 48 | Width = FileStream.ReadUInt16(); 49 | Height = FileStream.ReadUInt16(); 50 | 51 | Header.Flags = (VTFImageFlag)FileStream.ReadUInt32(); 52 | 53 | UInt16 NumFrames = FileStream.ReadUInt16(); 54 | UInt16 FirstFrame = FileStream.ReadUInt16(); 55 | 56 | FileStream.ReadBytes(4); // padding 57 | 58 | Header.Reflectivity = FileStream.ReadVector3D(false); 59 | 60 | FileStream.ReadBytes(4); // padding 61 | 62 | Header.BumpmapScale = FileStream.ReadSingle(); 63 | 64 | VTFImageFormat HighResImageFormat = (VTFImageFormat)FileStream.ReadUInt32(); 65 | Byte MipmapCount = FileStream.ReadByte(); 66 | VTFImageFormat LowResImageFormat = (VTFImageFormat)FileStream.ReadUInt32(); 67 | Byte LowResWidth = FileStream.ReadByte(); 68 | Byte LowResHeight = FileStream.ReadByte(); 69 | 70 | UInt16 Depth = 1; 71 | UInt32 NumResources = 0; 72 | 73 | if (Version >= 7.2m) 74 | { 75 | Depth = FileStream.ReadUInt16(); 76 | } 77 | if (Version >= 7.3m) 78 | { 79 | FileStream.ReadBytes(3); 80 | NumResources = FileStream.ReadUInt32(); 81 | FileStream.ReadBytes(8); 82 | } 83 | 84 | Int32 NumFaces = 1; 85 | if (Header.Flags.HasFlag(VTFImageFlag.TEXTUREFLAGS_ENVMAP)) 86 | { 87 | NumFaces = Version < 7.5m && FirstFrame != 0xFFFF ? 7 : 6; 88 | } 89 | 90 | VTFImageFormatInfo HighResFormatInfo = VTFImageFormatInfo.FromFormat(HighResImageFormat); 91 | VTFImageFormatInfo LowResFormatInfo = VTFImageFormatInfo.FromFormat(LowResImageFormat); 92 | 93 | Int32 ThumbnailSize = LowResImageFormat == VTFImageFormat.IMAGE_FORMAT_NONE ? 0 : LowResFormatInfo.GetSize(LowResWidth, LowResHeight); 94 | 95 | UInt32 ThumbnailOffset = headerSize; 96 | Int64 DataOffset = headerSize + ThumbnailSize; 97 | 98 | Resources = new VTFResource[NumResources]; 99 | for (Int32 i = 0; i < NumResources; i++) 100 | { 101 | VTFResourceType type = (VTFResourceType)FileStream.ReadUInt32(); 102 | UInt32 DataSize = FileStream.ReadUInt32(); 103 | switch (type) 104 | { 105 | case VTFResourceType.LowResImage: 106 | // Low res image 107 | ThumbnailOffset = DataSize; 108 | break; 109 | case VTFResourceType.Image: 110 | // Regular image 111 | DataOffset = DataSize; 112 | break; 113 | case VTFResourceType.Sheet: 114 | case VTFResourceType.CRC: 115 | case VTFResourceType.TextureLodSettings: 116 | case VTFResourceType.TextureSettingsEx: 117 | case VTFResourceType.KeyValueData: 118 | // todo 119 | Resources[i] = new VTFResource 120 | { 121 | Type = type, 122 | Data = DataSize 123 | }; 124 | break; 125 | default: 126 | throw new ArgumentOutOfRangeException(nameof(type), (uint)type, "Unknown resource type"); 127 | } 128 | } 129 | 130 | if (LowResImageFormat != VTFImageFormat.IMAGE_FORMAT_NONE) 131 | { 132 | FileStream.BaseStream.Position = ThumbnailOffset; 133 | Int32 thumbSize = LowResFormatInfo.GetSize(LowResWidth, LowResHeight); 134 | LowResImage = new VTFImage 135 | { 136 | Format = LowResImageFormat, 137 | Width = LowResWidth, 138 | Height = LowResHeight, 139 | Data = FileStream.ReadBytes(thumbSize) 140 | }; 141 | } 142 | 143 | Boolean ConvertToBGRA32 = true; 144 | Boolean hasAlpha = true; 145 | switch (HighResImageFormat) 146 | { 147 | //Unity support this formats natively 148 | case VTFImageFormat.IMAGE_FORMAT_A8: 149 | case VTFImageFormat.IMAGE_FORMAT_ABGR8888: 150 | case VTFImageFormat.IMAGE_FORMAT_ARGB8888: 151 | case VTFImageFormat.IMAGE_FORMAT_BGRA4444: 152 | case VTFImageFormat.IMAGE_FORMAT_DXT1_ONEBITALPHA: 153 | case VTFImageFormat.IMAGE_FORMAT_DXT3: 154 | case VTFImageFormat.IMAGE_FORMAT_DXT5: 155 | case VTFImageFormat.IMAGE_FORMAT_RGBA8888: 156 | case VTFImageFormat.IMAGE_FORMAT_BGRA8888: 157 | case VTFImageFormat.IMAGE_FORMAT_BGRX8888: 158 | case VTFImageFormat.IMAGE_FORMAT_RGBA16161616F: 159 | case VTFImageFormat.IMAGE_FORMAT_RGBA16161616: 160 | ConvertToBGRA32 = false; 161 | break; 162 | case VTFImageFormat.IMAGE_FORMAT_BGR565: 163 | case VTFImageFormat.IMAGE_FORMAT_RGB565: 164 | case VTFImageFormat.IMAGE_FORMAT_DXT1: 165 | case VTFImageFormat.IMAGE_FORMAT_RGB888: 166 | hasAlpha = false; 167 | ConvertToBGRA32 = false; 168 | break; 169 | } 170 | 171 | FileStream.BaseStream.Position = DataOffset; 172 | Frames = new Texture2D[NumFrames, NumFaces]; 173 | List[] FramesData = new List[NumFrames]; 174 | for (Int32 MipLevel = MipmapCount - 1; MipLevel >= 0; MipLevel--) 175 | { 176 | for (Int32 FrameID = 0; FrameID < NumFrames; FrameID++) 177 | { 178 | if (FramesData[FrameID] == null) 179 | FramesData[FrameID] = new List(); 180 | 181 | for (Int32 FaceID = 0; FaceID < NumFaces; FaceID++) 182 | { 183 | for (Int32 SliceID = 0; SliceID < Depth; SliceID++) 184 | { 185 | Int32 Wid = GetMipSize(Width, MipLevel); 186 | Int32 Hei = GetMipSize(Height, MipLevel); 187 | Int32 DataSize = HighResFormatInfo.GetSize(Wid, Hei); 188 | 189 | if(ConvertToBGRA32) 190 | FramesData[FrameID].InsertRange(0, VTFImageFormatInfo.FromFormat(HighResImageFormat).ConvertToBgra32(FileStream.ReadBytes(DataSize), Wid, Hei)); 191 | else 192 | FramesData[FrameID].InsertRange(0, FileStream.ReadBytes(DataSize)); 193 | } 194 | } 195 | } 196 | } 197 | 198 | TextureFormat InternalFormat = TextureFormat.BGRA32; 199 | Boolean needCompress = false; 200 | switch (HighResImageFormat) 201 | { 202 | case VTFImageFormat.IMAGE_FORMAT_A8: 203 | InternalFormat = TextureFormat.Alpha8; 204 | break; 205 | 206 | case VTFImageFormat.IMAGE_FORMAT_ABGR8888: 207 | case VTFImageFormat.IMAGE_FORMAT_ARGB8888: 208 | InternalFormat = TextureFormat.ARGB32; 209 | break; 210 | 211 | case VTFImageFormat.IMAGE_FORMAT_BGR565: 212 | case VTFImageFormat.IMAGE_FORMAT_RGB565: 213 | InternalFormat = TextureFormat.RGB565; 214 | break; 215 | 216 | case VTFImageFormat.IMAGE_FORMAT_BGRA4444: 217 | InternalFormat = TextureFormat.RGBA4444; 218 | break; 219 | 220 | case VTFImageFormat.IMAGE_FORMAT_DXT1: 221 | case VTFImageFormat.IMAGE_FORMAT_DXT1_ONEBITALPHA: 222 | InternalFormat = TextureFormat.DXT1; 223 | break; 224 | 225 | case VTFImageFormat.IMAGE_FORMAT_DXT3: 226 | case VTFImageFormat.IMAGE_FORMAT_DXT5: 227 | InternalFormat = TextureFormat.DXT5; 228 | break; 229 | 230 | case VTFImageFormat.IMAGE_FORMAT_RGB888: 231 | InternalFormat = TextureFormat.RGB24; 232 | break; 233 | 234 | case VTFImageFormat.IMAGE_FORMAT_RGBA8888: 235 | InternalFormat = TextureFormat.RGBA32; 236 | break; 237 | 238 | case VTFImageFormat.IMAGE_FORMAT_RGBA16161616F: 239 | case VTFImageFormat.IMAGE_FORMAT_RGBA16161616: 240 | InternalFormat = TextureFormat.RGBAHalf; 241 | break; 242 | 243 | default: 244 | //needCompress = true; 245 | break; 246 | } 247 | 248 | Boolean mipmaps = MipmapCount > 1; 249 | for (Int32 FrameID = 0; FrameID < NumFrames; FrameID++) 250 | { 251 | for (Int32 FaceID = 0; FaceID < NumFaces; FaceID++) 252 | { 253 | Frames[FrameID, FaceID] = new Texture2D(Width, Height, InternalFormat, mipmaps); 254 | Frames[FrameID, FaceID].name = FileName; 255 | //Temp fix before big update 256 | #if UNITY_EDITOR 257 | Frames[FrameID, FaceID].alphaIsTransparency = hasAlpha; 258 | #endif 259 | Frames[FrameID, FaceID].LoadRawTextureData(FramesData[FrameID].ToArray()); 260 | Frames[FrameID, FaceID].Apply(); 261 | 262 | if (needCompress) 263 | { 264 | Frames[FrameID, FaceID].Compress(false); 265 | Debug.LogWarning(FileName + " compressed!"); 266 | } 267 | } 268 | } 269 | } 270 | } 271 | 272 | private static Int32 GetMipSize(Int32 input, Int32 level) 273 | { 274 | Int32 res = input >> level; 275 | if (res < 1) res = 1; 276 | return res; 277 | } 278 | } 279 | } -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99ad3ded6cef84045a79c4d34f66effc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFHeader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace uSource.Formats.Source.VTF 5 | { 6 | [Flags] 7 | public enum VTFImageFlag : UInt32 8 | { 9 | TEXTUREFLAGS_POINTSAMPLE = 0x00000001, 10 | TEXTUREFLAGS_TRILINEAR = 0x00000002, 11 | TEXTUREFLAGS_CLAMPS = 0x00000004, 12 | TEXTUREFLAGS_CLAMPT = 0x00000008, 13 | TEXTUREFLAGS_ANISOTROPIC = 0x00000010, 14 | TEXTUREFLAGS_HINT_DXT5 = 0x00000020, 15 | TEXTUREFLAGS_SRGB = 0x00000040, 16 | TEXTUREFLAGS_DEPRECATEDNOCONPRESS = 0x00000040, 17 | TEXTUREFLAGS_NORMAL = 0x00000080, 18 | TEXTUREFLAGS_NOMIP = 0x00000100, 19 | TEXTUREFLAGS_NOLOD = 0x00000200, 20 | TEXTUREFLAGS_ALL_MIPS = 0x00000400, 21 | TEXTUREFLAGS_PROCEDURAL = 0x00000800, 22 | TEXTUREFLAGS_ONEBITALPHA = 0x00001000, 23 | TEXTUREFLAGS_EIGHTBITALPHA = 0x00002000, 24 | TEXTUREFLAGS_ENVMAP = 0x00004000, 25 | TEXTUREFLAGS_RENDERTARGET = 0x00008000, 26 | TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000, 27 | TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000, 28 | TEXTUREFLAGS_SINGLECOPY = 0x00040000, 29 | TEXTUREFLAGS_UNUSED0 = 0x00080000, 30 | TEXTUREFLAGS_DEPRECATEDONEOVERMIPLEVELINALPHA = 0x00080000, 31 | TEXTUREFLAGS_UNUSED1 = 0x00100000, 32 | TEXTUREFLAGS_DEPRECATEDPREMULTCOLORBYONEOVERMIPLEVEL = 0x00100000, 33 | TEXTUREFLAGS_UNUSED2 = 0x00200000, 34 | TEXTUREFLAGS_DEPRECATEDNORMALTODUDV = 0x00200000, 35 | TEXTUREFLAGS_UNUSED3 = 0x00400000, 36 | TEXTUREFLAGS_DEPRECATEDALPHATESTMIPGENERATION = 0x00400000, 37 | TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000, 38 | TEXTUREFLAGS_UNUSED4 = 0x01000000, 39 | TEXTUREFLAGS_DEPRECATEDNICEFILTERED = 0x01000000, 40 | TEXTUREFLAGS_CLAMPU = 0x02000000, 41 | TEXTUREFLAGS_VERTEXTEXTURE = 0x04000000, 42 | TEXTUREFLAGS_SSBUMP = 0x08000000, 43 | TEXTUREFLAGS_UNUSED5 = 0x10000000, 44 | TEXTUREFLAGS_DEPRECATEDUNFILTERABLEOK = 0x10000000, 45 | TEXTUREFLAGS_BORDER = 0x20000000, 46 | TEXTUREFLAGS_DEPRECATEDSPECVARRED = 0x40000000, 47 | TEXTUREFLAGS_DEPRECATEDSPECVARALPHA = 0x80000000, 48 | TEXTUREFLAGS_LAST = 0x20000000 49 | } 50 | 51 | public class VTFHeader 52 | { 53 | public Decimal Version { get; set; } 54 | public VTFImageFlag Flags { get; set; } 55 | public Vector3 Reflectivity { get; set; } 56 | public Single BumpmapScale { get; set; } 57 | } 58 | } -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFHeader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad09b0b48b3ec9e439bf1a912402c376 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFImage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace uSource.Formats.Source.VTF 4 | { 5 | /// 6 | /// A VTF image containing binary pixel data in some format. 7 | /// 8 | public class VTFImage 9 | { 10 | /// 11 | /// The format of this image. 12 | /// 13 | public VTFImageFormat Format { get; set; } 14 | 15 | /// 16 | /// The width of the image, in pixels 17 | /// 18 | public Int32 Width { get; set; } 19 | 20 | /// 21 | /// The height of the image, in pixels 22 | /// 23 | public Int32 Height { get; set; } 24 | 25 | /// 26 | /// The mipmap number of this image. Lower numbers = larger size. 27 | /// 28 | public Int32 Mipmap { get; set; } 29 | 30 | /// 31 | /// The frame number of this image. 32 | /// 33 | public Int32 Frame { get; set; } 34 | 35 | /// 36 | /// The face number of this image. 37 | /// 38 | public Int32 Face { get; set; } 39 | 40 | /// 41 | /// The slice (depth) number of this image. 42 | /// 43 | public Int32 Slice { get; set; } 44 | 45 | /// 46 | /// The image data, in native image format 47 | /// 48 | public Byte[] Data { get; set; } 49 | 50 | /// 51 | /// Convert the native format data to a standard 32-bit bgra8888 format. 52 | /// 53 | /// The data in bgra8888 format. 54 | public Byte[] GetBgra32Data() 55 | { 56 | return VTFImageFormatInfo.FromFormat(Format).ConvertToBgra32(Data, Width, Height); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFImage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8dc54b9e7cb1fa842aa99b319a5f152a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFImageFormatInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0fed660c78ae18488619ab75e6b32db 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFResource.cs: -------------------------------------------------------------------------------- 1 | namespace uSource.Formats.Source.VTF 2 | { 3 | public enum VTFResourceType : uint 4 | { 5 | LowResImage = 0x01, 6 | Image = 0x30, 7 | Sheet = 0x10, 8 | CRC = 'C' | ('R' << 8) | ('C' << 16) | (0x02 << 24), 9 | TextureLodSettings = 'L' | ('O' << 8) | ('D' << 16) | (0x02 << 24), 10 | TextureSettingsEx = 'T' | ('S' << 8) | ('O' << 16) | (0x02 << 24), 11 | KeyValueData = 'K' | ('V' << 8) | ('D' << 16), 12 | } 13 | 14 | public class VTFResource 15 | { 16 | public VTFResourceType Type { get; set; } 17 | public uint Data { get; set; } 18 | //public byte[] Data { get; set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Formats/Source/VTF/VTFResource.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fed222afbf866774b9ee54e68a97e535 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /KeyValueParse.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7f1c4ad92d5fc9469ec75c3929ef6a9 3 | timeCreated: 1454430159 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Loader.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 8 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 3 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | --- !u!157 &3 43 | LightmapSettings: 44 | m_ObjectHideFlags: 0 45 | serializedVersion: 11 46 | m_GIWorkflowMode: 1 47 | m_GISettings: 48 | serializedVersion: 2 49 | m_BounceScale: 1 50 | m_IndirectOutputScale: 1 51 | m_AlbedoBoost: 1 52 | m_TemporalCoherenceThreshold: 1 53 | m_EnvironmentLightingMode: 1 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 9 58 | m_Resolution: 1 59 | m_BakeResolution: 10 60 | m_TextureWidth: 1024 61 | m_TextureHeight: 1024 62 | m_AO: 0 63 | m_AOMaxDistance: 1 64 | m_CompAOExponent: 1 65 | m_CompAOExponentDirect: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 0 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 0 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVRFilterTypeDirect: 0 81 | m_PVRFilterTypeIndirect: 0 82 | m_PVRFilterTypeAO: 0 83 | m_PVRFilteringMode: 1 84 | m_PVRCulling: 1 85 | m_PVRFilteringGaussRadiusDirect: 1 86 | m_PVRFilteringGaussRadiusIndirect: 5 87 | m_PVRFilteringGaussRadiusAO: 2 88 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 89 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 90 | m_PVRFilteringAtrousPositionSigmaAO: 1 91 | m_ShowResolutionOverlay: 1 92 | m_LightingDataAsset: {fileID: 0} 93 | m_UseShadowmask: 1 94 | --- !u!196 &4 95 | NavMeshSettings: 96 | serializedVersion: 2 97 | m_ObjectHideFlags: 0 98 | m_BuildSettings: 99 | serializedVersion: 2 100 | agentTypeID: 0 101 | agentRadius: 0.5 102 | agentHeight: 2 103 | agentSlope: 45 104 | agentClimb: 0.4 105 | ledgeDropHeight: 0 106 | maxJumpAcrossDistance: 0 107 | minRegionArea: 2 108 | manualCellSize: 0 109 | cellSize: 0.16666667 110 | manualTileSize: 0 111 | tileSize: 256 112 | accuratePlacement: 0 113 | debug: 114 | m_Flags: 0 115 | m_NavMeshData: {fileID: 0} 116 | --- !u!1 &97944333 117 | GameObject: 118 | m_ObjectHideFlags: 0 119 | m_PrefabParentObject: {fileID: 0} 120 | m_PrefabInternal: {fileID: 0} 121 | serializedVersion: 5 122 | m_Component: 123 | - component: {fileID: 97944337} 124 | - component: {fileID: 97944336} 125 | - component: {fileID: 97944335} 126 | - component: {fileID: 97944334} 127 | - component: {fileID: 97944338} 128 | m_Layer: 0 129 | m_Name: Camera 130 | m_TagString: Untagged 131 | m_Icon: {fileID: 0} 132 | m_NavMeshLayer: 0 133 | m_StaticEditorFlags: 0 134 | m_IsActive: 1 135 | --- !u!81 &97944334 136 | AudioListener: 137 | m_ObjectHideFlags: 0 138 | m_PrefabParentObject: {fileID: 0} 139 | m_PrefabInternal: {fileID: 0} 140 | m_GameObject: {fileID: 97944333} 141 | m_Enabled: 1 142 | --- !u!124 &97944335 143 | Behaviour: 144 | m_ObjectHideFlags: 0 145 | m_PrefabParentObject: {fileID: 0} 146 | m_PrefabInternal: {fileID: 0} 147 | m_GameObject: {fileID: 97944333} 148 | m_Enabled: 1 149 | --- !u!20 &97944336 150 | Camera: 151 | m_ObjectHideFlags: 0 152 | m_PrefabParentObject: {fileID: 0} 153 | m_PrefabInternal: {fileID: 0} 154 | m_GameObject: {fileID: 97944333} 155 | m_Enabled: 1 156 | serializedVersion: 2 157 | m_ClearFlags: 1 158 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 159 | m_NormalizedViewPortRect: 160 | serializedVersion: 2 161 | x: 0 162 | y: 0 163 | width: 1 164 | height: 1 165 | near clip plane: 0.01 166 | far clip plane: 1000 167 | field of view: 54 168 | orthographic: 0 169 | orthographic size: 5 170 | m_Depth: 0 171 | m_CullingMask: 172 | serializedVersion: 2 173 | m_Bits: 4294967295 174 | m_RenderingPath: -1 175 | m_TargetTexture: {fileID: 0} 176 | m_TargetDisplay: 0 177 | m_TargetEye: 3 178 | m_HDR: 1 179 | m_AllowMSAA: 1 180 | m_AllowDynamicResolution: 0 181 | m_ForceIntoRT: 0 182 | m_OcclusionCulling: 1 183 | m_StereoConvergence: 10 184 | m_StereoSeparation: 0.022 185 | --- !u!4 &97944337 186 | Transform: 187 | m_ObjectHideFlags: 0 188 | m_PrefabParentObject: {fileID: 0} 189 | m_PrefabInternal: {fileID: 0} 190 | m_GameObject: {fileID: 97944333} 191 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 192 | m_LocalPosition: {x: 0, y: 0, z: 0} 193 | m_LocalScale: {x: 1, y: 1, z: 1} 194 | m_Children: [] 195 | m_Father: {fileID: 0} 196 | m_RootOrder: 1 197 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 198 | --- !u!114 &97944338 199 | MonoBehaviour: 200 | m_ObjectHideFlags: 0 201 | m_PrefabParentObject: {fileID: 0} 202 | m_PrefabInternal: {fileID: 0} 203 | m_GameObject: {fileID: 97944333} 204 | m_Enabled: 1 205 | m_EditorHideFlags: 0 206 | m_Script: {fileID: 11500000, guid: 4c398d830f67a124485a3192e9c4c8bc, type: 3} 207 | m_Name: 208 | m_EditorClassIdentifier: 209 | offset3DSky: {x: 0, y: 0, z: 0} 210 | skyScale: 0 211 | skyCamera: {fileID: 0} 212 | use3dSky: 0 213 | cameraSensitivity: 90 214 | climbSpeed: 4 215 | normalMoveSpeed: 10 216 | slowMoveFactor: 0.25 217 | fastMoveFactor: 3 218 | --- !u!1 &1340958609 219 | GameObject: 220 | m_ObjectHideFlags: 0 221 | m_PrefabParentObject: {fileID: 0} 222 | m_PrefabInternal: {fileID: 0} 223 | serializedVersion: 5 224 | m_Component: 225 | - component: {fileID: 1340958611} 226 | - component: {fileID: 1340958610} 227 | m_Layer: 0 228 | m_Name: Importer 229 | m_TagString: Untagged 230 | m_Icon: {fileID: 0} 231 | m_NavMeshLayer: 0 232 | m_StaticEditorFlags: 0 233 | m_IsActive: 1 234 | --- !u!114 &1340958610 235 | MonoBehaviour: 236 | m_ObjectHideFlags: 0 237 | m_PrefabParentObject: {fileID: 0} 238 | m_PrefabInternal: {fileID: 0} 239 | m_GameObject: {fileID: 1340958609} 240 | m_Enabled: 1 241 | m_EditorHideFlags: 0 242 | m_Script: {fileID: 11500000, guid: 3f75f342238cdbc4581afc3924148dbf, type: 3} 243 | m_Name: 244 | m_EditorClassIdentifier: 245 | --- !u!4 &1340958611 246 | Transform: 247 | m_ObjectHideFlags: 0 248 | m_PrefabParentObject: {fileID: 0} 249 | m_PrefabInternal: {fileID: 0} 250 | m_GameObject: {fileID: 1340958609} 251 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 252 | m_LocalPosition: {x: 0, y: 0, z: 0} 253 | m_LocalScale: {x: 1, y: 1, z: 1} 254 | m_Children: [] 255 | m_Father: {fileID: 0} 256 | m_RootOrder: 0 257 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 258 | -------------------------------------------------------------------------------- /Loader.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5417287e7ad27314088c5b5f59980792 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /MathLib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee91d4b030bc5094f8765f1f14953bc9 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /MathLib/Compressed_Vector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using UnityEngine; 4 | 5 | namespace uSource.MathLib 6 | { 7 | [StructLayout(LayoutKind.Explicit)] 8 | public struct IntegerAndSingleUnion 9 | { 10 | [FieldOffset(0)] 11 | public Int32 i; 12 | [FieldOffset(0)] 13 | public Single s; 14 | } 15 | 16 | [Serializable] 17 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 18 | public struct Float16 19 | { 20 | public Single GetFloat 21 | { 22 | get 23 | { 24 | Int32 sign = GetSign(bits); 25 | Int32 floatSign; 26 | if (sign == 1) 27 | { 28 | floatSign = -1; 29 | } 30 | else 31 | { 32 | floatSign = 1; 33 | } 34 | 35 | if (IsInfinity(bits)) 36 | { 37 | return maxfloat16bits * floatSign; 38 | } 39 | 40 | if (IsNaN(bits)) 41 | { 42 | return 0; 43 | } 44 | Int32 mantissa = GetMantissa(bits); 45 | Int32 biased_exponent = GetBiasedExponent(bits); 46 | Single result; 47 | if (biased_exponent == 0 && mantissa != 0) 48 | { 49 | Single floatMantissa = mantissa / 1024.0F; 50 | result = floatSign * floatMantissa * half_denorm; 51 | } 52 | else 53 | { 54 | result = GetSingle(); 55 | } 56 | return result; 57 | } 58 | } 59 | 60 | private Int32 GetMantissa(UInt16 value) 61 | { 62 | return (value & 0x3FF); 63 | } 64 | 65 | private Int32 GetBiasedExponent(UInt16 value) 66 | { 67 | return (value & 0x7C00) >> 10; 68 | } 69 | 70 | private Int32 GetSign(UInt16 value) 71 | { 72 | return (value & 0x8000) >> 15; 73 | } 74 | 75 | private Single GetSingle() 76 | { 77 | IntegerAndSingleUnion bitsResult = new IntegerAndSingleUnion(); 78 | bitsResult.i = 0; 79 | 80 | Int32 mantissa = GetMantissa(bits); 81 | Int32 biased_exponent = GetBiasedExponent(bits); 82 | Int32 sign = GetSign(bits); 83 | 84 | Int32 resultMantissa = mantissa << 23 - 10; 85 | Int32 resultBiasedExponent; 86 | if (biased_exponent == 0) 87 | { 88 | resultBiasedExponent = 0; 89 | } 90 | else 91 | { 92 | resultBiasedExponent = (biased_exponent - float16bias + float32bias) << 23; 93 | } 94 | Int32 resultSign = sign << 31; 95 | 96 | bitsResult.i = resultSign | resultBiasedExponent | resultMantissa; 97 | 98 | return bitsResult.s; 99 | } 100 | 101 | private bool IsInfinity(ushort value) 102 | { 103 | Int32 mantissa = GetMantissa(value); 104 | Int32 biased_exponent = GetBiasedExponent(value); 105 | return ((biased_exponent == 31) && (mantissa == 0)); 106 | } 107 | 108 | private bool IsNaN(ushort value) 109 | { 110 | Int32 mantissa = GetMantissa(value); 111 | Int32 biased_exponent = GetBiasedExponent(value); 112 | return ((biased_exponent == 31) && (mantissa != 0)); 113 | } 114 | 115 | private const Int32 float32bias = 127; 116 | private const Int32 float16bias = 15; 117 | private const Single maxfloat16bits = 65504.0F; 118 | private const Single half_denorm = (1.0F / 16384.0F); 119 | 120 | public UInt16 bits; 121 | } 122 | 123 | /// 124 | /// sizeof = 6 125 | /// 126 | [Serializable] 127 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 128 | public struct Vector48 129 | { 130 | public Float16 x; 131 | public Float16 y; 132 | public Float16 z; 133 | 134 | public Vector3 ToVector3() 135 | { 136 | Vector3 result; 137 | result.x = x.GetFloat; 138 | result.y = y.GetFloat; 139 | result.z = z.GetFloat; 140 | 141 | return result; 142 | } 143 | 144 | public static explicit operator Vector3(Vector48 obj) 145 | { 146 | return obj.ToVector3(); 147 | } 148 | } 149 | 150 | /// 151 | /// sizeof = 6 152 | /// 153 | [Serializable] 154 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 155 | public struct Quaternion48 156 | { 157 | public UInt16 theXInput; 158 | public UInt16 theYInput; 159 | public UInt16 theZWInput; 160 | 161 | public Single x 162 | { 163 | get 164 | { 165 | Single result = (Convert.ToInt32(theXInput) - 32768) * (1 / 32768.0f); 166 | return result; 167 | } 168 | } 169 | 170 | public Single y 171 | { 172 | get 173 | { 174 | Single result = (Convert.ToInt32(theYInput) - 32768) * (1 / 32768.0f); 175 | return result; 176 | } 177 | } 178 | 179 | public Single z 180 | { 181 | get 182 | { 183 | Int32 zInput = theZWInput & 0x7FFF; 184 | Single result = (zInput - 16384) * (1 / 16384.0f); 185 | return result; 186 | } 187 | } 188 | 189 | public Single w 190 | { 191 | get 192 | { 193 | return Mathf.Sqrt(1 - x * x - y * y - z * z) * wneg; 194 | } 195 | } 196 | 197 | public Single wneg 198 | { 199 | get 200 | { 201 | if ((theZWInput & 0x8000) > 0) 202 | { 203 | return -1; 204 | } 205 | else 206 | { 207 | return 1; 208 | } 209 | } 210 | } 211 | 212 | public Quaternion quaternion 213 | { 214 | get 215 | { 216 | Quaternion aQuaternion; 217 | aQuaternion.x = x; 218 | aQuaternion.y = y; 219 | aQuaternion.z = z; 220 | aQuaternion.w = w; 221 | return aQuaternion; 222 | } 223 | } 224 | } 225 | 226 | /// 227 | /// sizeof = 8 228 | /// 229 | [Serializable] 230 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 231 | public struct Quaternion64 232 | { 233 | [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 8)] 234 | public Byte[] theBytes; 235 | 236 | public Single x 237 | { 238 | get 239 | { 240 | IntegerAndSingleUnion bitsResult = new IntegerAndSingleUnion(); 241 | Int32 byte0 = Convert.ToInt32(theBytes[0]) & 0xFF; 242 | Int32 byte1 = (Convert.ToInt32(theBytes[1]) & 0xFF) << 8; 243 | Int32 byte2 = (Convert.ToInt32(theBytes[2]) & 0x1F) << 16; 244 | 245 | bitsResult.i = byte2 | byte1 | byte0; 246 | Single result = (bitsResult.i - 1048576) * (1 / 1048576.5f); 247 | 248 | if (Single.IsNaN(result)) 249 | result = 0.0f; 250 | 251 | return result; 252 | } 253 | } 254 | 255 | public Single y 256 | { 257 | get 258 | { 259 | IntegerAndSingleUnion bitsResult = new IntegerAndSingleUnion(); 260 | Int32 byte2 = (Convert.ToInt32(theBytes[2]) & 0xE0) >> 5; 261 | Int32 byte3 = (Convert.ToInt32(theBytes[3]) & 0xFF) << 3; 262 | Int32 byte4 = (Convert.ToInt32(theBytes[4]) & 0xFF) << 11; 263 | Int32 byte5 = (Convert.ToInt32(theBytes[5]) & 0x3) << 19; 264 | 265 | bitsResult.i = byte5 | byte4 | byte3 | byte2; 266 | Single result = (bitsResult.i - 1048576) * (1 / 1048576.5f); 267 | 268 | if (Single.IsNaN(result)) 269 | result = 0.0f; 270 | 271 | return result; 272 | } 273 | } 274 | 275 | public Single z 276 | { 277 | get 278 | { 279 | IntegerAndSingleUnion bitsResult = new IntegerAndSingleUnion(); 280 | Int32 byte5 = (Convert.ToInt32(theBytes[5]) & 0xFC) >> 2; 281 | Int32 byte6 = (Convert.ToInt32(theBytes[6]) & 0xFF) << 6; 282 | Int32 byte7 = (Convert.ToInt32(theBytes[7]) & 0x7F) << 14; 283 | 284 | bitsResult.i = byte7 | byte6 | byte5; 285 | Single result = (bitsResult.i - 1048576) * (1 / 1048576.5f); 286 | 287 | if (Single.IsNaN(result)) 288 | result = 0.0f; 289 | 290 | return result; 291 | } 292 | } 293 | 294 | public Single w 295 | { 296 | get 297 | { 298 | //result = Me.wneg 299 | Single result = Mathf.Sqrt(1 - x * x - y * y - z * z) * wneg; 300 | 301 | if (Single.IsNaN(result)) 302 | result = 0.0f; 303 | 304 | return result; 305 | } 306 | } 307 | 308 | public Single wneg 309 | { 310 | get 311 | { 312 | if ((theBytes[7] & 0x80) > 0) 313 | { 314 | return -1; 315 | } 316 | else 317 | { 318 | return 1; 319 | } 320 | } 321 | } 322 | 323 | public Quaternion quaternion 324 | { 325 | get 326 | { 327 | Quaternion aQuaternion; 328 | aQuaternion.x = x; 329 | aQuaternion.y = y; 330 | aQuaternion.z = z; 331 | aQuaternion.w = w; 332 | return aQuaternion; 333 | } 334 | } 335 | } 336 | } -------------------------------------------------------------------------------- /MathLib/Compressed_Vector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6795649af4c53bc4dbe7451ec0deca72 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /MathLib/MathLibrary.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace uSource.MathLib 5 | { 6 | public class MathLibrary 7 | { 8 | //TODO: FIX ROTATION ON ATTACHMENTS 9 | public static void ConvertRotationMatrixToDegrees(float m0, float m1, float m2, float m3, float m4, float m5, float m8, ref Vector3 angles) 10 | { 11 | double c; 12 | double translateX; 13 | double translateY; 14 | 15 | // NOTE: For Math.Asin, return value is NaN if d < -1 or d > 1 or d equals NaN. 16 | // Therefore, change value outside of domain to edge of domain. 17 | if (m2 < -1) 18 | { 19 | m2 = -1; 20 | } 21 | else if (m2 > 1f) 22 | { 23 | m2 = 1f; 24 | } 25 | 26 | angles.y = (float)-Math.Asin(Math.Round(m2, 6)); 27 | c = Math.Cos(angles.y); 28 | angles.y = angles.y * Mathf.Rad2Deg; 29 | if (Math.Abs(c) > 0.005d) 30 | { 31 | translateX = Math.Round(m8, 6) / c; 32 | translateY = Math.Round(-m5, 6) / c; 33 | angles.x = (float)Math.Atan2(translateY, translateX) * Mathf.Rad2Deg; 34 | translateX = Math.Round(m0, 6) / c; 35 | translateY = Math.Round(-m1, 6) / c; 36 | angles.z = (float)Math.Atan2(translateY, translateX) * Mathf.Rad2Deg; 37 | } 38 | else 39 | { 40 | angles.x = (float)0d; 41 | translateX = Math.Round(m4, 6); 42 | translateY = Math.Round(m3, 6); 43 | angles.z = (float)Math.Atan2(translateY, translateX) * Mathf.Rad2Deg; 44 | } 45 | } 46 | 47 | public static Vector3 SwapZY(Vector3 Inp) 48 | { 49 | Inp.x = -Inp.x; 50 | float temp = Inp.y; 51 | Inp.y = Inp.z; 52 | Inp.z = -temp; 53 | 54 | return Inp; 55 | //return new Vector3(-Inp.x, Inp.z, -Inp.y); 56 | } 57 | 58 | public static Vector3 NegateX(Vector3 Inp) 59 | { 60 | Inp.x = -Inp.x; 61 | return Inp; 62 | } 63 | 64 | public static Quaternion AngleQuaternion(Vector3 eulerAngles) 65 | { 66 | Quaternion qx = Quaternion.AngleAxis(eulerAngles.x, Vector3.right); 67 | Quaternion qy = Quaternion.AngleAxis(-eulerAngles.y, Vector3.up); 68 | Quaternion qz = Quaternion.AngleAxis(-eulerAngles.z, Vector3.forward); 69 | 70 | return qz * qy * qx; 71 | } 72 | 73 | public static Vector3 SwapY(Vector3 Inp) 74 | { 75 | //X Y Z 76 | return new Vector3(-Inp.y, Inp.z, Inp.x); 77 | } 78 | 79 | public static Vector3 SwapZYX(Vector3 Inp) 80 | { 81 | return new Vector3(-Inp.z, -Inp.y, Inp.x); 82 | } 83 | 84 | public static Vector3 UnSwapZY(Vector3 Inp) 85 | { 86 | /*Vector3 temp = Inp; 87 | Inp.x = temp.z; 88 | Inp.y = -temp.x; 89 | Inp.z = temp.y; 90 | 91 | return Inp;*/ 92 | return new Vector3(Inp.z, -Inp.x, Inp.y); 93 | } 94 | 95 | //SOURCEMATH 96 | 97 | /// 98 | /// (V_swap) 99 | /// 100 | /// Input X Component 101 | /// Input Y Component 102 | public static void SwapComponent(ref T x, ref T y ) 103 | { 104 | T temp = x; 105 | x = y; 106 | y = temp; 107 | } 108 | 109 | // solves for "a, b, c" where "a x^2 + b x + c = y", return true if solution exists 110 | public static bool SolveInverseQuadratic(float x1, float y1, float x2, float y2, float x3, float y3, ref float a, ref float b, ref float c ) 111 | { 112 | float det = (x1 - x2) * (x1 - x3) * (x2 - x3); 113 | 114 | // FIXME: check with some sort of epsilon 115 | if (det == 0.0f) 116 | return false; 117 | 118 | a = (x3 * (-y1 + y2) + x2 * (y1 - y3) + x1 * (-y2 + y3)) / det; 119 | 120 | b = (x3 * x3 * (y1 - y2) + x1 * x1 * (y2 - y3) + x2 * x2 * (-y1 + y3)) / det; 121 | 122 | c = (x1 * x3 * (-x1 + x3) * y2 + x2 * x2 * (x3 * y1 - x1 * y3) + x2 * (-(x3 * x3 * y1) + x1 * x1 * y3)) / det; 123 | 124 | return true; 125 | } 126 | 127 | public static bool SolveInverseQuadraticMonotonic(Single x1, Single y1, Single x2, Single y2, Single x3, Single y3, ref Single a, ref Single b, ref Single c ) 128 | { 129 | // use SolveInverseQuadratic, but if the sigm of the derivative at the start point is the wrong 130 | // sign, displace the mid point 131 | 132 | // first, sort parameters 133 | if (x1 > x2) 134 | { 135 | SwapComponent(ref x1, ref x2); 136 | SwapComponent(ref y1, ref y2); 137 | } 138 | if (x2 > x3) 139 | { 140 | SwapComponent(ref x2, ref x3); 141 | SwapComponent(ref y2, ref y3); 142 | } 143 | if (x1 > x2) 144 | { 145 | SwapComponent(ref x1, ref x2); 146 | SwapComponent(ref y1, ref y2); 147 | } 148 | // this code is not fast. what it does is when the curve would be non-monotonic, slowly shifts 149 | // the center point closer to the linear line between the endpoints. Should anyone need htis 150 | // function to be actually fast, it would be fairly easy to change it to be so. 151 | for (float blend_to_linear_factor = 0.0f; blend_to_linear_factor <= 1.0; blend_to_linear_factor += 0.05f) 152 | { 153 | float tempy2 = (1 - blend_to_linear_factor) * y2 + blend_to_linear_factor * FLerp(y1, y3, x1, x3, x2); 154 | if (!SolveInverseQuadratic(x1, y1, x2, tempy2, x3, y3, ref a, ref b, ref c)) 155 | return false; 156 | float derivative = 2.0f * a + b; 157 | if ((y1 < y2) && (y2 < y3)) // monotonically increasing 158 | { 159 | if (derivative >= 0.0f) 160 | return true; 161 | } 162 | else 163 | { 164 | if ((y1 > y2) && (y2 > y3)) // monotonically decreasing 165 | { 166 | if (derivative <= 0.0f) 167 | return true; 168 | } 169 | else 170 | return true; 171 | } 172 | } 173 | return true; 174 | } 175 | 176 | // 5-argument floating point linear interpolation. 177 | // FLerp(f1,f2,i1,i2,x)= 178 | // f1 at x=i1 179 | // f2 at x=i2 180 | // smooth lerp between f1 and f2 at x>i1 and xi2 182 | // 183 | // If you know a function f(x)'s value (f1) at position i1, and its value (f2) at position i2, 184 | // the function can be linearly interpolated with FLerp(f1,f2,i1,i2,x) 185 | // i2=i1 will cause a divide by zero. 186 | public static Single FLerp(Single f1, Single f2, Single i1, Single i2, Single x) 187 | { 188 | return f1 + (f2 - f1) * (x - i1) / (i2 - i1); 189 | } 190 | 191 | private enum EulerParity 192 | { 193 | Even, 194 | Odd 195 | } 196 | 197 | private enum EulerRepeat 198 | { 199 | No, 200 | Yes 201 | } 202 | 203 | private enum EulerFrame 204 | { 205 | S, 206 | R 207 | } 208 | 209 | public static Vector3 ToEulerAngles(Quaternion q) 210 | { 211 | return Eul_FromQuat(q, 0, 1, 2, 0, EulerParity.Even, EulerRepeat.No, EulerFrame.S); 212 | } 213 | 214 | private static Vector3 Eul_FromHMatrix(float[,] M, int i, int j, int k, int h, EulerParity parity, EulerRepeat repeat, EulerFrame frame) 215 | { 216 | Vector3 ea = new Vector3(); 217 | 218 | if (repeat == EulerRepeat.Yes) 219 | { 220 | float sy = Mathf.Sqrt(M[i, j] * M[i, j] + M[i, k] * M[i, k]); 221 | if (sy > 16 * Mathf.Epsilon) 222 | { 223 | ea.x = Mathf.Atan2(M[i, j], M[i, k]); 224 | ea.y = Mathf.Atan2(sy, M[i, i]); 225 | ea.z = Mathf.Atan2(M[j, i], -M[k, i]); 226 | } 227 | else 228 | { 229 | ea.x = Mathf.Atan2(-M[j, k], M[j, j]); 230 | ea.y = Mathf.Atan2(sy, M[i, i]); 231 | ea.z = 0; 232 | } 233 | } 234 | else 235 | { 236 | float cy = Mathf.Sqrt(M[i, i] * M[i, i] + M[j, i] * M[j, i]); 237 | if (cy > 16 * Mathf.Epsilon) 238 | { 239 | ea.x = Mathf.Atan2(M[k, j], M[k, k]); 240 | ea.y = Mathf.Atan2(-M[k, i], cy); 241 | ea.z = Mathf.Atan2(M[j, i], M[i, i]); 242 | } 243 | else 244 | { 245 | ea.x = Mathf.Atan2(-M[j, k], M[j, j]); 246 | ea.y = Mathf.Atan2(-M[k, i], cy); 247 | ea.z = 0; 248 | } 249 | } 250 | 251 | if (parity == EulerParity.Odd) 252 | { 253 | ea.x = -ea.x; 254 | ea.y = -ea.y; 255 | ea.z = -ea.z; 256 | } 257 | 258 | if (frame == EulerFrame.R) 259 | { 260 | float t = ea.x; 261 | ea.x = ea.z; 262 | ea.z = t; 263 | } 264 | 265 | //ea.w = order 266 | return ea; 267 | } 268 | 269 | private static Vector3 Eul_FromQuat(Quaternion q, int i, int j, int k, int h, EulerParity parity, EulerRepeat repeat, EulerFrame frame) 270 | { 271 | float[,] M = 272 | { 273 | {0, 0, 0, 0}, 274 | {0, 0, 0, 0}, 275 | {0, 0, 0, 0}, 276 | {0, 0, 0, 0} 277 | }; 278 | float Nq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w; 279 | float s; 280 | if (Nq > 0) 281 | { 282 | s = 2.0f / Nq; 283 | } 284 | else 285 | { 286 | s = 0; 287 | } 288 | float xs = q.x * s; 289 | float ys = q.y * s; 290 | float zs = q.z * s; 291 | 292 | float wx = q.w * xs; 293 | float wy = q.w * ys; 294 | float wz = q.w * zs; 295 | float xx = q.x * xs; 296 | float xy = q.x * ys; 297 | float xz = q.x * zs; 298 | float yy = q.y * ys; 299 | float yz = q.y * zs; 300 | float zz = q.z * zs; 301 | M[0, 0] = 1.0f - (yy + zz); 302 | M[0, 1] = xy - wz; 303 | M[0, 2] = xz + wy; 304 | M[1, 0] = xy + wz; 305 | M[1, 1] = 1.0f - (xx + zz); 306 | M[1, 2] = yz - wx; 307 | M[2, 0] = xz - wy; 308 | M[2, 1] = yz + wx; 309 | M[2, 2] = 1.0f - (xx + yy); 310 | M[3, 3] = 1.0f; 311 | 312 | return Eul_FromHMatrix(M, i, j, k, h, parity, repeat, frame); 313 | } 314 | 315 | //SOURCEMATH 316 | } 317 | } -------------------------------------------------------------------------------- /MathLib/MathLibrary.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 738ca8d21e76c2d49b50f19f98028667 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Pic1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeadZoneLuna/uSource/01ab6a2f080ce7341b87f2d867bfae079c0fa06e/Pic1.png -------------------------------------------------------------------------------- /Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a867a6ece0cb3d43a81bebc3bcbbce5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeadZoneLuna/uSource/01ab6a2f080ce7341b87f2d867bfae079c0fa06e/Plugins/Facepunch.Parse.dll -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02183ee3386e8404c80ce7522241d371 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | isPreloaded: 0 9 | isOverridable: 0 10 | platformData: 11 | - first: 12 | Any: 13 | second: 14 | enabled: 1 15 | settings: {} 16 | - first: 17 | Editor: Editor 18 | second: 19 | enabled: 0 20 | settings: 21 | DefaultValueInitialized: true 22 | - first: 23 | Windows Store Apps: WindowsStoreApps 24 | second: 25 | enabled: 0 26 | settings: 27 | CPU: AnyCPU 28 | userData: 29 | assetBundleName: 30 | assetBundleVariant: 31 | -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeadZoneLuna/uSource/01ab6a2f080ce7341b87f2d867bfae079c0fa06e/Plugins/Facepunch.Parse.pdb -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 053e796156853ec49ac3c6ebba21574c 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Facepunch.Parse 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Plugins/Facepunch.Parse.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b3e832babcda40488bd522f9bf7bf0c 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Plugins/ICSharpCode.SharpZipLib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeadZoneLuna/uSource/01ab6a2f080ce7341b87f2d867bfae079c0fa06e/Plugins/ICSharpCode.SharpZipLib.dll -------------------------------------------------------------------------------- /Plugins/ICSharpCode.SharpZipLib.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 430a7e13a00737849aa901a50acc0cc5 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | isPreloaded: 0 9 | isOverridable: 0 10 | platformData: 11 | - first: 12 | Any: 13 | second: 14 | enabled: 1 15 | settings: {} 16 | - first: 17 | Editor: Editor 18 | second: 19 | enabled: 0 20 | settings: 21 | DefaultValueInitialized: true 22 | - first: 23 | Windows Store Apps: WindowsStoreApps 24 | second: 25 | enabled: 0 26 | settings: 27 | CPU: AnyCPU 28 | userData: 29 | assetBundleName: 30 | assetBundleVariant: 31 | -------------------------------------------------------------------------------- /Plugins/ICSharpCode.SharpZipLib.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DeadZoneLuna/uSource/01ab6a2f080ce7341b87f2d867bfae079c0fa06e/Plugins/ICSharpCode.SharpZipLib.pdb -------------------------------------------------------------------------------- /Plugins/ICSharpCode.SharpZipLib.pdb.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a3c951b492b56048b738a523f74c51a 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Plugins/ICSharpCode.SharpZipLib.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 186243b83f0ee014dba1cb36a0cc9fa1 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # uSource 2 | uSource is a plugin for importing MDL / BSP / VMT / VTF and etc... resources to Unity! 3 | 4 | ![Screenshot](Pic1.png) 5 | 6 | # Supported formats (1.1 Beta): 7 | 8 | ## Source 9 | | Format | Type of content | Import | Export to Unity | 10 | | ------ | ------ | ------ | ------ | 11 | | .MDL | Studio Models | :heavy_check_mark: | :x: | 12 | | .VCD | Choreography Scenes (scenes.image) | In the future | :x: | 13 | | .BSP | Map Files (Compiled) | :heavy_check_mark: | :x: | 14 | | .VMF | Map Files (Hammer format) | In the future | :x: | 15 | | .VPK | Valve Packages | :heavy_check_mark: | :x: | 16 | | .GCF | Grid Cache Files | In the future | :x: | 17 | | .NCF | No Cache Files | In the future | :x: | 18 | | .DMX | Datamodels | :x: | :x: | 19 | | .PCF | Particles | :x: | :x: | 20 | | .DMX | SFM Sessions | :x: | :x: | 21 | | .VTF | Textures | :heavy_check_mark: | :heavy_check_mark: | 22 | | .VMT | Materials | :heavy_check_mark: | :heavy_check_mark: | 23 | 24 | ## GoldSource 25 | | Format | Type of content | Import | Export to Unity | 26 | | ------ | ------ | ------ | ------ | 27 | | NOT SUPPORTED YET | NOT SUPPORTED YET | NOT SUPPORTED YET | NOT SUPPORTED YET | 28 | 29 | ## Source 2 30 | | Format | Type of content | Import | Export to Unity | 31 | | ------ | ------ | ------ | ------ | 32 | | NOT SUPPORTED YET | NOT SUPPORTED YET | NOT SUPPORTED YET | NOT SUPPORTED YET | 33 | 34 | # Supported features (1.1 Beta): 35 | 36 | ## Studio Models (MDL / VVD / VTX / PHY / ANI / VHV) 37 | | Feature | Supported | 38 | | ------ | ------ | 39 | | Versions | 44 - 49 (Some older versions can load too, but possible errors!) | 40 | | Bones | :heavy_check_mark: | 41 | | Hitboxes | :heavy_check_mark: | 42 | | Animations / Sequences | (Partial) | 43 | | Procedural Bones | :x: | 44 | | Materials | :heavy_check_mark: | 45 | | Skinfamilies | :x: | 46 | | Attachments | :x: | 47 | | Flexes / Vertex Animations | :x: | 48 | | Meshes (With skinning) | :heavy_check_mark: (Some mdl version 49 may not have meshes!) | 49 | | Physics Model | :x: | 50 | | Vertex Lighting (Static props) | :x: | 51 | 52 | ## BSP / Map Files 53 | | Feature | Supported | 54 | | ------ | ------ | 55 | | Versions | 19 (possible errors!), 20, 21 | 56 | | PAK | :heavy_check_mark: | 57 | | LZMA Lumps | :x: (TF2 Updated maps) | 58 | | Models | :heavy_check_mark: | 59 | | Physics | (Not a stable implementation, the code is "disabled") | 60 | | Displacements | (Partial, neighbor disps not supported yet) | 61 | | Visibility | :x: | 62 | | Occlusion | :x: | 63 | | Entities | :heavy_check_mark: | 64 | | Static / Dynamic Props | :heavy_check_mark: | 65 | | WorldLights | :heavy_check_mark: | 66 | | Decals | (Partial, overlays still not supported) | 67 | | Cubemaps | :x: | 68 | | Lightmaps | (Partial, light style not supported yet) | 69 | | Ambient cubes | :x: | 70 | 71 | ## Textures 72 | | Feature | Supported | 73 | | ------ | ------ | 74 | | Versions | 7.1 - 7.5 (Maybe 7.0?) | 75 | | Envmaps (Cubemaps) | :heavy_check_mark: | 76 | | Convert to BGRA32 | :heavy_check_mark: | 77 | 78 | | Texture Formats | Supported | 79 | | ------ | ------ | 80 | | RGBA8888 | :heavy_check_mark: | 81 | | ABGR8888 | :heavy_check_mark: | 82 | | RGB888 | :heavy_check_mark: | 83 | | BGR888 | :heavy_check_mark: | 84 | | RGB565 | :heavy_check_mark: | 85 | | I8 | :heavy_check_mark: | 86 | | IA88 | :heavy_check_mark: | 87 | | P8 | :heavy_check_mark: | 88 | | A8 | :heavy_check_mark: | 89 | | RGB888_BLUESCREEN | :heavy_check_mark: | 90 | | BGR888_BLUESCREEN | :heavy_check_mark: | 91 | | DXT1 | :heavy_check_mark: | 92 | | DXT3 | :heavy_check_mark: | 93 | | DXT5 | :heavy_check_mark: | 94 | | BGR565 | :heavy_check_mark: | 95 | | BGRX5551 | :heavy_check_mark: | 96 | | BGRA4444 | :heavy_check_mark: | 97 | | DXT1_ONEBITALPHA | :heavy_check_mark: | 98 | | UV88 | :heavy_check_mark: | 99 | | UVWQ8888 | :heavy_check_mark: | 100 | | RGBA16161616F | :heavy_check_mark: | 101 | | RGBA16161616 | :heavy_check_mark: | 102 | | R32F | :heavy_check_mark: | 103 | | RGB323232F | :heavy_check_mark: | 104 | | RGBA32323232F | :heavy_check_mark: | 105 | | NV_DST16 | (Not Tested) | 106 | | NV_DST24 | (Not Tested) | 107 | | NV_INTZ | (Not Tested) | 108 | | NV_RAWZ | (Not Tested) | 109 | | ATI_DST16 | (Not Tested) | 110 | | ATI_DST24 | (Not Tested) | 111 | | NV_NULL | (Not Tested) | 112 | | ATI_2N | (Not Tested) | 113 | | ATI_1N | (Not Tested) | 114 | 115 | ## Materials (In Progress rework!) 116 | | Shaders | Supported | 117 | | ------ | ------ | 118 | | LightmappedGeneric | (Use Default / Generic) | 119 | | LightmappedReflective | (Use Default / Generic) | 120 | | LightmappedTwoTexture | (Use Default / Generic) | 121 | | Lightmapped_4WayBlend | (Use Default / Generic) | 122 | | Multiblend | (Use Default / Generic) | 123 | | WorldTwoTextureBlend | :heavy_check_mark: | 124 | | WorldVertexTransition | (Partial) | 125 | | WindowImposter | (Use Default) | 126 | | Water | (Use Default) | 127 | | UnlitGeneric | (Partial) | 128 | | UnlitTwoTexture | (Use Default / Generic) | 129 | | WorldGGX | (Use Default / Generic) | 130 | | ParallaxTest | (Use Default / Generic) | 131 | | Sky | :heavy_check_mark: | 132 | | Core | (Use Default) | 133 | | SpriteCard | (Use Default) | 134 | | Cable | (Use Default) | 135 | | SplineRope | (Use Default) | 136 | | Refract | (Use Default) | 137 | | MonitorScreen | (Use Default) | 138 | | Modulate | (Use Default) | 139 | | VertexLitGeneric | (Use Default / Generic) | 140 | | Eyes | (Use Default) | 141 | | EyeRefract | (Use Default) | 142 | | VortWarp | (Use Default) | 143 | | Aftershock | (Use Default) | 144 | | Teeth | (Use Default) | 145 | | SurfaceGGX | (Use Default) | 146 | | Character | (Use Default / Generic) | 147 | | SolidEnergy | (Use Default) | 148 | | VolumeCloud | (Use Default) | 149 | | DecalModulate | (Use Default) | 150 | | Shadow | (Use Default) | 151 | | Subrect | (Use Default) | 152 | 153 | ## VPK 154 | | Feature | Supported | 155 | | ------ | ------ | 156 | | Version 1 | :heavy_check_mark: | 157 | | Version 2 | :heavy_check_mark: | 158 | 159 | ## Datamodels (DMX) 160 | | Feature | Supported | 161 | | ------ | ------ | 162 | | NOT SUPPORTED YET | NOT SUPPORTED YET | 163 | 164 | ## Particles (PCF) 165 | | Feature | Supported | 166 | | ------ | ------ | 167 | | NOT SUPPORTED YET | NOT SUPPORTED YET | 168 | 169 | ## SFM Sessions (DMX) 170 | | Feature | Supported | 171 | | ------ | ------ | 172 | | NOT SUPPORTED YET | NOT SUPPORTED YET | 173 | -------------------------------------------------------------------------------- /Resource.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b2f902c024ff14b41816698fb6b67d4b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Resource/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f89a9dfbf702b854eab4883196f579f8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Resource/Editor/LightmapSource.giparams: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1113 &111300000 4 | LightmapParameters: 5 | m_ObjectHideFlags: 0 6 | m_PrefabParentObject: {fileID: 0} 7 | m_PrefabInternal: {fileID: 0} 8 | m_Name: LightmapSource 9 | serializedVersion: 3 10 | resolution: 1 11 | clusterResolution: 1 12 | irradianceBudget: 128 13 | irradianceQuality: 8192 14 | backFaceTolerance: 0.9 15 | isTransparent: 0 16 | modellingTolerance: 0 17 | systemTag: -1 18 | edgeStitching: 1 19 | blurRadius: 2 20 | directLightQuality: 64 21 | antiAliasingSamples: 8 22 | bakedLightmapTag: -1 23 | pushoff: 0.0001 24 | AOQuality: 256 25 | AOAntiAliasingSamples: 16 26 | -------------------------------------------------------------------------------- /Resource/Editor/LightmapSource.giparams.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa19c78e3b6c28e4d8e9f37fad9018ab 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 111300000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Resource/Glow.flare: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!121 &12100000 4 | Flare: 5 | m_ObjectHideFlags: 0 6 | m_PrefabParentObject: {fileID: 0} 7 | m_PrefabInternal: {fileID: 0} 8 | m_Name: Glow 9 | m_FlareTexture: {fileID: 10300, guid: 0000000000000000f000000000000000, type: 0} 10 | m_TextureLayout: 2 11 | m_Elements: 12 | - m_ImageIndex: 0 13 | m_Position: 0 14 | m_Size: 16 15 | m_Color: {r: 0.21568628, g: 0.21568628, b: 0.21568628, a: 0} 16 | m_UseLightColor: 1 17 | m_Rotate: 1 18 | m_Zoom: 0 19 | m_Fade: 1 20 | m_UseFog: 1 21 | -------------------------------------------------------------------------------- /Resource/Glow.flare.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 424198359e98e594faf745316fbbbdfd 3 | NativeFormatImporter: 4 | externalObjects: {} 5 | mainObjectFileID: 12100000 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a74c3167f32076e4ea24157f0c2d4a0e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/AdditiveGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/AdditiveGeneric" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB)", 2D) = "white" {} 7 | _Cull("Cull State", Int) = 2 8 | } 9 | 10 | SubShader 11 | { 12 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } 13 | 14 | Blend SrcAlpha One 15 | Cull[_Cull] 16 | Lighting Off 17 | ZWrite Off 18 | Fog { Color(0,0,0,0) } 19 | 20 | CGPROGRAM 21 | #pragma surface surf Lambert 22 | 23 | sampler2D _MainTex; 24 | fixed4 _Color; 25 | 26 | struct Input 27 | { 28 | float2 uv_MainTex; 29 | }; 30 | 31 | void surf (Input IN, inout SurfaceOutput o) 32 | { 33 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); 34 | o.Albedo = baseColor.rgb * 0.15; 35 | o.Alpha = baseColor.rgb; 36 | } 37 | ENDCG 38 | } 39 | FallBack "Legacy Shaders/VertexLit" 40 | } -------------------------------------------------------------------------------- /Shaders/AdditiveGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6766b3442bfb6b479ad104cbcd46eff 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/CutoutGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/CutoutGeneric" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} 7 | _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 8 | _Cull("Cull State", Int) = 2 9 | } 10 | 11 | SubShader 12 | { 13 | Tags { "Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout" } 14 | LOD 200 15 | 16 | Cull [_Cull] 17 | 18 | CGPROGRAM 19 | #pragma surface surf Lambert alphatest:_Cutoff 20 | 21 | sampler2D _MainTex; 22 | fixed4 _Color; 23 | 24 | struct Input { 25 | float2 uv_MainTex; 26 | }; 27 | 28 | void surf (Input IN, inout SurfaceOutput o) { 29 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 30 | o.Albedo = c.rgb; 31 | o.Alpha = c.a; 32 | } 33 | ENDCG 34 | } 35 | 36 | Fallback "Legacy Shaders/Transparent/Cutout/VertexLit" 37 | } 38 | -------------------------------------------------------------------------------- /Shaders/CutoutGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad01f649111fd1747a027f4c8f429679 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/DecalModulate.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/DecalModulate" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB)", 2D) = "white" {} 7 | } 8 | 9 | SubShader 10 | { 11 | Tags { "RenderType" = "Transparent" } 12 | LOD 200 13 | 14 | //ZTest Greater 15 | Blend DstColor SrcColor 16 | 17 | CGPROGRAM 18 | #pragma surface surf Lambert alpha 19 | 20 | sampler2D _MainTex; 21 | fixed4 _Color; 22 | 23 | struct Input 24 | { 25 | float2 uv_MainTex; 26 | }; 27 | 28 | void surf (Input IN, inout SurfaceOutput o) 29 | { 30 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex) * _Color; 31 | o.Albedo = baseColor.rgb; 32 | o.Alpha = baseColor.a; 33 | } 34 | ENDCG 35 | } 36 | 37 | Fallback "Legacy Shaders/VertexLit" 38 | } -------------------------------------------------------------------------------- /Shaders/DecalModulate.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 498b41a49a9bc3f4eaf288fa97aeb84c 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/DetailGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/DetailGeneric" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB)", 2D) = "white" {} 7 | _Cull("Cull State", Int) = 2 8 | _Detail("Detail (RGB)", 2D) = "white" {} 9 | _DetailFactor("Detail Blend Factor", Range(0,1)) = 0 10 | _DetailBlendMode("Detail Blend Mode", Int) = 0 11 | } 12 | 13 | SubShader 14 | { 15 | Tags { "RenderType"="Opaque" } 16 | LOD 200 17 | 18 | Cull[_Cull] 19 | 20 | CGPROGRAM 21 | #pragma surface surf Lambert 22 | #include "Lightmapped/SourceCG.cginc" 23 | 24 | sampler2D _MainTex; 25 | sampler2D _Detail; 26 | fixed4 _Color; 27 | half _DetailFactor; 28 | float _DetailBlendMode; 29 | 30 | struct Input 31 | { 32 | float2 uv_MainTex; 33 | float2 uv_Detail; 34 | }; 35 | 36 | void surf (Input IN, inout SurfaceOutput o) 37 | { 38 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); 39 | fixed4 secondColor = tex2D(_Detail, IN.uv_Detail); 40 | o.Albedo = TextureCombine(baseColor, secondColor, _DetailBlendMode, _DetailFactor) * _Color; 41 | //o.Alpha = baseColor.a; 42 | } 43 | ENDCG 44 | } 45 | 46 | Fallback "Legacy Shaders/VertexLit" 47 | } -------------------------------------------------------------------------------- /Shaders/DetailGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 699ac386e10cafa42a822ed7f34816c8 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/IllumGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/IllumGeneric" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB)", 2D) = "white" {} 7 | _AlphaMask("Use Mask", Int) = 0 8 | _MaskTex("Mask (A)", 2D) = "white" {} 9 | } 10 | 11 | SubShader 12 | { 13 | Tags { "RenderType"="Opaque" } 14 | LOD 200 15 | 16 | CGPROGRAM 17 | #pragma surface surf Lambert 18 | 19 | sampler2D _MainTex; 20 | float _AlphaMask; 21 | sampler2D _MaskTex; 22 | fixed4 _Color; 23 | 24 | struct Input 25 | { 26 | float2 uv_MainTex; 27 | float2 uv_MaskTex; 28 | }; 29 | 30 | void surf (Input IN, inout SurfaceOutput o) 31 | { 32 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); 33 | fixed4 maskColor = tex2D(_MaskTex, IN.uv_MaskTex); 34 | fixed4 c = baseColor * _Color; 35 | o.Albedo = c.rgb; 36 | 37 | if(_AlphaMask == 1) 38 | o.Emission = c.rgb * (c.a * maskColor.rgb); 39 | else 40 | o.Emission = c.rgb * c.a; 41 | //o.Alpha = c.a; 42 | } 43 | ENDCG 44 | } 45 | FallBack "Legacy Shaders/VertexLit" 46 | } -------------------------------------------------------------------------------- /Shaders/IllumGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0a09fe0c033b7348a35930313185910 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/Lightmapped.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 53c23f143e4f09a448e428c629ec210b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/Lightmapped/Generic.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/Lightmapped/Generic" 2 | { 3 | //Support future: 4 | //Basic 5 | //$basetexture - Yes 6 | //$surfaceprop - Maybe? 7 | //$detail - 56% (4 / 7) 8 | // -$detailtexturetransform Maybe? 9 | // -$detailscale TODO 10 | // -$detailtint TODO (It's supported but didn't use at the moment) 11 | // -$detailframe TODO 12 | // -$detail_alpha_mask_base_texture TODO 13 | //$model - Maybe? 14 | //Adjust 15 | //$basetexturetransform - Nope 16 | //$color - Yes 17 | //$seamless_scale - Nope 18 | //Transparency 19 | //$alpha - Nope 20 | //$alphatest - Yes 21 | //$distancealpha - Maybe? 22 | //$nocull - Yes 23 | //Lighting 24 | //$bumpmap - Nope 25 | //$ssbump - Nope 26 | //$selfillum - Nope 27 | //$lightwarptexture - Nope 28 | //Reflection 29 | //$reflectivity - Nope 30 | //$envmap - Nope 31 | Properties 32 | { 33 | _Color ("Main Color (RGBA)", Color) = (1,1,1,1) 34 | _MainTex ("Base (RGB)", 2D) = "white" {} 35 | _IsTranslucent("Is Translucent", Int) = 0 36 | _Cull("Cull State", Int) = 2 37 | _ZState("Z-Buffer State", Int) = 1 38 | _AlphaTest("Is AlphaTest", Int) = 0 39 | _DetailColor ("Detail Tint (RGBA)", Color) = (1,1,1,1) 40 | _Detail ("Base Detail (RGB)", 2D) = "white" {} 41 | _DetailFactor ("Factor of detail", Range(0,1)) = 0 42 | _DetailBlendMode ("Blend mode of detail", Int) = 0 43 | } 44 | 45 | //TODO: 46 | //Optimize shader passes! 47 | SubShader 48 | { 49 | Tags 50 | { 51 | "Queue" = "Geometry" 52 | //"IgnoreProjector" = "True" 53 | "RenderType" = "Transparent" 54 | } 55 | 56 | //Lighting off 57 | 58 | ZWrite [_ZState] 59 | // in order not to occlude other objects 60 | Blend SrcAlpha OneMinusSrcAlpha 61 | 62 | Pass 63 | { 64 | Tags { "LightMode" = "ForwardBase" } 65 | 66 | ZTest Less 67 | Cull [_Cull] 68 | 69 | CGPROGRAM 70 | // Must be a vert/frag shader, not a surface shader: the necessary variables 71 | // won't be defined yet for surface shaders. 72 | #pragma vertex vert 73 | #pragma fragment frag 74 | //#pragma multi_compile_fwdbase 75 | 76 | #include "UnityCG.cginc" 77 | //#include "Lighting.cginc" 78 | #include "SourceCG.cginc" 79 | 80 | // shadow helper functions and macros 81 | //#include "AutoLight.cginc" 82 | 83 | struct v2f 84 | { 85 | float4 pos : SV_POSITION; 86 | float2 uv0 : TEXCOORD0; 87 | float2 uv1 : TEXCOORD1; 88 | float2 uv2 : TEXCOORD2; 89 | }; 90 | 91 | struct appdata_lightmap 92 | { 93 | float4 vertex : POSITION; 94 | float3 normal : NORMAL; 95 | float2 texcoord : TEXCOORD0; 96 | float2 texcoord1 : TEXCOORD1; 97 | UNITY_VERTEX_INPUT_INSTANCE_ID 98 | }; 99 | 100 | sampler2D _MainTex; 101 | sampler2D _Detail; 102 | float4 _Detail_ST; 103 | fixed4 _Color; 104 | fixed4 _DetailColor; 105 | float4 _MainTex_ST; 106 | half _DetailFactor; 107 | float _DetailBlendMode; 108 | float _IsTranslucent; 109 | float _AlphaTest; 110 | 111 | v2f vert(appdata_lightmap i) 112 | { 113 | v2f o; 114 | o.pos = UnityObjectToClipPos(i.vertex); 115 | o.uv0 = TRANSFORM_TEX(i.texcoord, _MainTex); 116 | o.uv1 = i.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw; 117 | o.uv2 = TRANSFORM_TEX(i.texcoord, _Detail); 118 | 119 | return o; 120 | } 121 | 122 | fixed4 frag(v2f i) : COLOR 123 | { 124 | fixed4 baseColor = tex2D(_MainTex, i.uv0) * _Color; 125 | fixed4 detailColor = tex2D(_Detail, i.uv2) * _DetailColor; 126 | 127 | baseColor = TextureCombine(baseColor, detailColor, _DetailBlendMode, _DetailFactor); 128 | baseColor.rgb *= SourceDecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv1)); 129 | 130 | if (_IsTranslucent != 1 && _AlphaTest != 1) 131 | baseColor.a = _Color.a; 132 | 133 | if (_AlphaTest == 1 && _IsTranslucent != 1) 134 | clip(baseColor.a - 0.5); 135 | 136 | //if(_IsTranslucent == 1 && _AlphaTest != 1) 137 | // clip(baseColor.a); 138 | 139 | return baseColor; 140 | } 141 | 142 | ENDCG 143 | } 144 | } 145 | 146 | Fallback "VertexLit" 147 | } -------------------------------------------------------------------------------- /Shaders/Lightmapped/Generic.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86690233744c63d4090318ef75dac5a6 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/Lightmapped/SourceCG.cginc: -------------------------------------------------------------------------------- 1 | // Decodes lightmaps: 2 | // doubleLDR encoded on GLES 3 | inline fixed3 SourceDecodeLightmap(fixed4 color) 4 | { 5 | #if defined(UNITY_COLORSPACE_GAMMA) 6 | #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE) 7 | return (1.75 * color.rgb; 8 | #else 9 | return (1.75 * color.a) * color.rgb; 10 | #endif 11 | #else 12 | #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE) 13 | return 3.75 * color.rgb; 14 | #else 15 | return (3.75 * color.a) * color.rgb; 16 | #endif 17 | #endif 18 | } 19 | 20 | // Needs to match NormalDecodeMode_t enum in imaterialsystem.h 21 | #define NORM_DECODE_NONE 0 22 | #define NORM_DECODE_ATI2N 1 23 | #define NORM_DECODE_ATI2N_ALPHA 2 24 | 25 | float4 DecompressNormal(sampler NormalSampler, float2 tc, int nDecompressionMode, sampler AlphaSampler) 26 | { 27 | float4 normalTexel = tex2D(NormalSampler, tc); 28 | float4 result; 29 | 30 | if (nDecompressionMode == NORM_DECODE_NONE) 31 | { 32 | result = float4(normalTexel.xyz * 2.0f - 1.0f, normalTexel.a); 33 | } 34 | else if (nDecompressionMode == NORM_DECODE_ATI2N) 35 | { 36 | result.xy = normalTexel.xy * 2.0f - 1.0f; 37 | result.z = sqrt(1.0f - dot(result.xy, result.xy)); 38 | result.a = 1.0f; 39 | } 40 | else // ATI2N plus ATI1N for alpha 41 | { 42 | result.xy = normalTexel.xy * 2.0f - 1.0f; 43 | result.z = sqrt(1.0f - dot(result.xy, result.xy)); 44 | result.a = tex2D(AlphaSampler, tc).x; // Note that this comes in on the X channel 45 | } 46 | 47 | return result; 48 | } 49 | 50 | float4 DecompressNormal(sampler NormalSampler, float2 tc, int nDecompressionMode) 51 | { 52 | return DecompressNormal(NormalSampler, tc, nDecompressionMode, NormalSampler); 53 | } 54 | 55 | // texture combining modes for combining base and detail/basetexture2 56 | #define TCOMBINE_RGB_EQUALS_BASE_x_DETAILx2 0 // original mode 57 | #define TCOMBINE_RGB_ADDITIVE 1 // base.rgb+detail.rgb*fblend 58 | #define TCOMBINE_DETAIL_OVER_BASE 2 59 | #define TCOMBINE_FADE 3 // straight fade between base and detail. 60 | #define TCOMBINE_BASE_OVER_DETAIL 4 // use base alpha for blend over detail 61 | #define TCOMBINE_RGB_ADDITIVE_SELFILLUM 5 // add detail color post lighting 62 | #define TCOMBINE_RGB_ADDITIVE_SELFILLUM_THRESHOLD_FADE 6 63 | #define TCOMBINE_MOD2X_SELECT_TWO_PATTERNS 7 // use alpha channel of base to select between mod2x channels in r+a of detail 64 | #define TCOMBINE_MULTIPLY 8 65 | #define TCOMBINE_MASK_BASE_BY_DETAIL_ALPHA 9 // use alpha channel of detail to mask base 66 | #define TCOMBINE_SSBUMP_BUMP 10 // use detail to modulate lighting as an ssbump 67 | #define TCOMBINE_SSBUMP_NOBUMP 11 // detail is an ssbump but use it as an albedo. shader does the magic here - no user needs to specify mode 11 68 | 69 | inline float4 TextureCombine(float4 baseColor, float4 detailColor, int combine_mode, float fBlendFactor) 70 | { 71 | if (combine_mode == TCOMBINE_MOD2X_SELECT_TWO_PATTERNS) 72 | { 73 | float3 dc = lerp(detailColor.r, detailColor.a, baseColor.a); 74 | baseColor.rgb *= lerp(float3(1, 1, 1), 2.0 * dc, fBlendFactor); 75 | } 76 | if (combine_mode == TCOMBINE_RGB_EQUALS_BASE_x_DETAILx2) 77 | baseColor.rgb *= lerp(float3(1, 1, 1), 2.0 * detailColor.rgb, fBlendFactor); 78 | if (combine_mode == TCOMBINE_RGB_ADDITIVE) 79 | baseColor.rgb += fBlendFactor * detailColor.rgb; 80 | if (combine_mode == TCOMBINE_DETAIL_OVER_BASE) 81 | { 82 | float fblend = fBlendFactor * detailColor.a; 83 | baseColor.rgb = lerp(baseColor.rgb, detailColor.rgb, fblend); 84 | } 85 | if (combine_mode == TCOMBINE_FADE) 86 | { 87 | baseColor = lerp(baseColor, detailColor, fBlendFactor); 88 | } 89 | if (combine_mode == TCOMBINE_BASE_OVER_DETAIL) 90 | { 91 | float fblend = fBlendFactor * (1 - baseColor.a); 92 | baseColor.rgb = lerp(baseColor.rgb, detailColor.rgb, fblend); 93 | baseColor.a = detailColor.a; 94 | } 95 | if (combine_mode == TCOMBINE_MULTIPLY) 96 | { 97 | baseColor = lerp(baseColor, baseColor * detailColor, fBlendFactor); 98 | } 99 | 100 | if (combine_mode == TCOMBINE_MASK_BASE_BY_DETAIL_ALPHA) 101 | { 102 | baseColor.a = lerp(baseColor.a, baseColor.a * detailColor.a, fBlendFactor); 103 | } 104 | if (combine_mode == TCOMBINE_SSBUMP_NOBUMP) 105 | { 106 | baseColor.rgb = baseColor.rgb * dot(detailColor.rgb, 2.0 / 3.0); 107 | } 108 | return baseColor; 109 | } -------------------------------------------------------------------------------- /Shaders/Lightmapped/SourceCG.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ec0012b293061034d8b61694ac51cf17 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/Lightmapped/WorldTwoTextureBlend.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/Lightmapped/WorldTwoTextureBlend" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGBA)", 2D) = "white" {} 7 | _Detail("Detail (RGBA)", 2D) = "white" {} 8 | } 9 | 10 | SubShader 11 | { 12 | Tags { "RenderType"="Opaque" } 13 | LOD 200 14 | 15 | CGPROGRAM 16 | #pragma surface surf Lambert 17 | 18 | fixed4 _Color; 19 | sampler2D _MainTex; 20 | sampler2D _Detail; 21 | 22 | struct Input 23 | { 24 | float2 uv_MainTex; 25 | float2 uv_Detail; 26 | }; 27 | 28 | void surf (Input IN, inout SurfaceOutput o) 29 | { 30 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex) * _Color; 31 | fixed4 detailColor = tex2D(_Detail, IN.uv_Detail); 32 | 33 | o.Albedo = lerp(detailColor.rgb, baseColor.rgb * detailColor.rgb, detailColor.a); 34 | o.Alpha = baseColor.a; 35 | } 36 | ENDCG 37 | } 38 | 39 | Fallback "Legacy Shaders/VertexLit" 40 | } -------------------------------------------------------------------------------- /Shaders/Lightmapped/WorldTwoTextureBlend.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4aaf17c4ba48fc94190a47ebf489737f 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/Lightmapped/WorldVertexTransition.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/Lightmapped/WorldVertexTransition" 2 | { 3 | Properties 4 | { 5 | _Color ("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Base (RGB)", 2D) = "white" {} 7 | _SecondTex("Second Base (RGB)", 2D) = "white" {} 8 | } 9 | 10 | SubShader 11 | { 12 | Tags { "RenderType"="Opaque" } 13 | LOD 200 14 | 15 | CGPROGRAM 16 | #pragma surface surf Lambert 17 | 18 | sampler2D _MainTex; 19 | sampler2D _SecondTex; 20 | fixed4 _Color; 21 | 22 | struct Input 23 | { 24 | float2 uv_MainTex; 25 | float2 uv_SecondTex; 26 | float4 color : COLOR; 27 | }; 28 | 29 | void surf (Input IN, inout SurfaceOutput o) 30 | { 31 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex); 32 | fixed4 secondColor = tex2D(_SecondTex, IN.uv_SecondTex); 33 | o.Albedo = lerp(baseColor.rgb, secondColor.rgb, IN.color.a) * _Color; 34 | //o.Alpha = baseColor.a; 35 | } 36 | ENDCG 37 | } 38 | 39 | Fallback "Legacy Shaders/VertexLit" 40 | } 41 | -------------------------------------------------------------------------------- /Shaders/Lightmapped/WorldVertexTransition.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c418bd34b0092d44b3dd9c3668a8d07 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/TranslucentGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/TranslucentGeneric" 2 | { 3 | Properties 4 | { 5 | _Color("Main Color", Color) = (1,1,1,1) 6 | _MainTex("Base (RGB) Trans (A)", 2D) = "white" {} 7 | _Cull("Cull State", Int) = 2 8 | _Detail("Base Detail (RGB)", 2D) = "white" {} 9 | _DetailFactor("Factor of detail", Range(0,1)) = 0 10 | _DetailBlendMode("Blend mode of detail", Int) = 0 11 | } 12 | 13 | SubShader 14 | { 15 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } 16 | LOD 200 17 | 18 | Cull[_Cull] 19 | 20 | CGPROGRAM 21 | #pragma surface surf Lambert alpha:fade 22 | #include "Lightmapped/SourceCG.cginc" 23 | 24 | fixed4 _Color; 25 | sampler2D _MainTex; 26 | sampler2D _Detail; 27 | half _DetailFactor; 28 | float _DetailBlendMode; 29 | 30 | struct Input 31 | { 32 | float2 uv_MainTex; 33 | float2 uv_Detail; 34 | }; 35 | 36 | void surf(Input IN, inout SurfaceOutput o) 37 | { 38 | fixed4 baseColor = tex2D(_MainTex, IN.uv_MainTex) * _Color; 39 | fixed4 detailColor = tex2D(_Detail, IN.uv_Detail); 40 | o.Albedo = TextureCombine(baseColor, detailColor, _DetailBlendMode, _DetailFactor); 41 | o.Alpha = baseColor.a; 42 | } 43 | ENDCG 44 | } 45 | 46 | Fallback "Legacy Shaders/Transparent/VertexLit" 47 | } 48 | -------------------------------------------------------------------------------- /Shaders/TranslucentGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2bb7144fc2739d144a443feec9e70c6d 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Shaders/UnlitGeneric.shader: -------------------------------------------------------------------------------- 1 | Shader "USource/UnlitGeneric" 2 | { 3 | Properties 4 | { 5 | _Color("Main Color", Color) = (1,1,1,1) 6 | _MainTex ("Texture", 2D) = "white" {} 7 | _Detail("Base Detail (RGB)", 2D) = "white" {} 8 | _DetailFactor("Factor of detail", Range(0,1)) = 0 9 | _DetailBlendMode("Blend mode of detail", Int) = 0 10 | } 11 | SubShader 12 | { 13 | Tags { "RenderType"="Opaque" } 14 | LOD 100 15 | 16 | Pass 17 | { 18 | CGPROGRAM 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | // make fog work 22 | #pragma multi_compile_fog 23 | 24 | #include "UnityCG.cginc" 25 | #include "Lightmapped/SourceCG.cginc" 26 | 27 | struct appdata 28 | { 29 | float4 vertex : POSITION; 30 | float2 uv : TEXCOORD0; 31 | }; 32 | 33 | struct v2f 34 | { 35 | float2 uv : TEXCOORD0; 36 | UNITY_FOG_COORDS(1) 37 | float4 vertex : SV_POSITION; 38 | }; 39 | 40 | float4 _Color; 41 | sampler2D _MainTex; 42 | sampler2D _Detail; 43 | float4 _MainTex_ST; 44 | float4 _Detail_ST; 45 | half _DetailFactor; 46 | float _DetailBlendMode; 47 | 48 | v2f vert (appdata v) 49 | { 50 | v2f o; 51 | o.vertex = UnityObjectToClipPos(v.vertex); 52 | o.uv = TRANSFORM_TEX(v.uv, _MainTex); 53 | UNITY_TRANSFER_FOG(o,o.vertex); 54 | return o; 55 | } 56 | 57 | fixed4 frag (v2f i) : SV_Target 58 | { 59 | // sample the texture 60 | fixed4 baseColor = tex2D(_MainTex, i.uv) * _Color; 61 | fixed4 detailColor = tex2D(_Detail, i.uv); 62 | // apply fog 63 | UNITY_APPLY_FOG(i.fogCoord, baseColor); 64 | 65 | baseColor.rgb *= lerp(float3(1, 1, 1), 2.0 * detailColor.rgb, _DetailFactor); 66 | 67 | return baseColor; 68 | } 69 | ENDCG 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Shaders/UnlitGeneric.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 42b5db7144e702142bb04389fa29cfd2 3 | ShaderImporter: 4 | externalObjects: {} 5 | defaultTextures: [] 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Vector3Int.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_5 || UNITY_2017_1 2 | // Unity C# reference source 3 | // Copyright (c) Unity Technologies. For terms of use, see 4 | // https://unity3d.com/legal/licenses/Unity_Reference_Only_License 5 | 6 | using System; 7 | using System.Runtime.InteropServices; 8 | using UnityEngine; 9 | 10 | public struct Vector3Int 11 | { 12 | public int x { get { return m_X; } set { m_X = value; } } 13 | public int y { get { return m_Y; } set { m_Y = value; } } 14 | public int z { get { return m_Z; } set { m_Z = value; } } 15 | 16 | private int m_X; 17 | private int m_Y; 18 | private int m_Z; 19 | 20 | public Vector3Int(int x, int y, int z) 21 | { 22 | m_X = x; 23 | m_Y = y; 24 | m_Z = z; 25 | } 26 | 27 | // Set x, y and z components of an existing Vector. 28 | public void Set(int x, int y, int z) 29 | { 30 | m_X = x; 31 | m_Y = y; 32 | m_Z = z; 33 | } 34 | 35 | // Access the /x/, /y/ or /z/ component using [0], [1] or [2] respectively. 36 | public int this[int index] 37 | { 38 | get 39 | { 40 | switch (index) 41 | { 42 | case 0: return x; 43 | case 1: return y; 44 | case 2: return z; 45 | default: 46 | throw new IndexOutOfRangeException(string.Format("Invalid Vector3Int index addressed: {0}!", index)); 47 | } 48 | } 49 | 50 | set 51 | { 52 | switch (index) 53 | { 54 | case 0: x = value; break; 55 | case 1: y = value; break; 56 | case 2: z = value; break; 57 | default: 58 | throw new IndexOutOfRangeException(string.Format("Invalid Vector3Int index addressed: {0}!", index)); 59 | } 60 | } 61 | } 62 | 63 | // Returns the length of this vector (RO). 64 | public float magnitude { get { return Mathf.Sqrt((float)(x * x + y * y + z * z)); } } 65 | 66 | // Returns the squared length of this vector (RO). 67 | public int sqrMagnitude { get { return x * x + y * y + z * z; } } 68 | 69 | // Returns the distance between /a/ and /b/. 70 | public static float Distance(Vector3Int a, Vector3Int b) { return (a - b).magnitude; } 71 | 72 | // Returns a vector that is made from the smallest components of two vectors. 73 | public static Vector3Int Min(Vector3Int lhs, Vector3Int rhs) { return new Vector3Int(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y), Mathf.Min(lhs.z, rhs.z)); } 74 | 75 | // Returns a vector that is made from the largest components of two vectors. 76 | public static Vector3Int Max(Vector3Int lhs, Vector3Int rhs) { return new Vector3Int(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y), Mathf.Max(lhs.z, rhs.z)); } 77 | 78 | // Multiplies two vectors component-wise. 79 | public static Vector3Int Scale(Vector3Int a, Vector3Int b) { return new Vector3Int(a.x * b.x, a.y * b.y, a.z * b.z); } 80 | 81 | // Multiplies every component of this vector by the same component of /scale/. 82 | public void Scale(Vector3Int scale) { x *= scale.x; y *= scale.y; z *= scale.z; } 83 | 84 | public void Clamp(Vector3Int min, Vector3Int max) 85 | { 86 | x = Math.Max(min.x, x); 87 | x = Math.Min(max.x, x); 88 | y = Math.Max(min.y, y); 89 | y = Math.Min(max.y, y); 90 | z = Math.Max(min.z, z); 91 | z = Math.Min(max.z, z); 92 | } 93 | 94 | // Converts a Vector3Int to a [[Vector3]]. 95 | public static implicit operator Vector3(Vector3Int v) 96 | { 97 | return new Vector3(v.x, v.y, v.z); 98 | } 99 | 100 | public static Vector3Int FloorToInt(Vector3 v) 101 | { 102 | return new Vector3Int( 103 | Mathf.FloorToInt(v.x), 104 | Mathf.FloorToInt(v.y), 105 | Mathf.FloorToInt(v.z) 106 | ); 107 | } 108 | 109 | public static Vector3Int CeilToInt(Vector3 v) 110 | { 111 | return new Vector3Int( 112 | Mathf.CeilToInt(v.x), 113 | Mathf.CeilToInt(v.y), 114 | Mathf.CeilToInt(v.z) 115 | ); 116 | } 117 | 118 | public static Vector3Int RoundToInt(Vector3 v) 119 | { 120 | return new Vector3Int( 121 | Mathf.RoundToInt(v.x), 122 | Mathf.RoundToInt(v.y), 123 | Mathf.RoundToInt(v.z) 124 | ); 125 | } 126 | 127 | public static Vector3Int operator +(Vector3Int a, Vector3Int b) 128 | { 129 | return new Vector3Int(a.x + b.x, a.y + b.y, a.z + b.z); 130 | } 131 | 132 | public static Vector3Int operator -(Vector3Int a, Vector3Int b) 133 | { 134 | return new Vector3Int(a.x - b.x, a.y - b.y, a.z - b.z); 135 | } 136 | 137 | public static Vector3Int operator *(Vector3Int a, Vector3Int b) 138 | { 139 | return new Vector3Int(a.x * b.x, a.y * b.y, a.z * b.z); 140 | } 141 | 142 | public static Vector3Int operator *(Vector3Int a, int b) 143 | { 144 | return new Vector3Int(a.x * b, a.y * b, a.z * b); 145 | } 146 | 147 | public static bool operator ==(Vector3Int lhs, Vector3Int rhs) 148 | { 149 | return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; 150 | } 151 | 152 | public static bool operator !=(Vector3Int lhs, Vector3Int rhs) 153 | { 154 | return !(lhs == rhs); 155 | } 156 | 157 | public override bool Equals(object other) 158 | { 159 | if (!(other is Vector3Int)) return false; 160 | 161 | Vector3Int rhs = (Vector3Int)other; 162 | return this == rhs; 163 | } 164 | 165 | public override int GetHashCode() 166 | { 167 | return x.GetHashCode() ^ (y.GetHashCode() << 2) ^ (z.GetHashCode() >> 2); 168 | } 169 | 170 | public override string ToString() 171 | { 172 | return string.Format("({0}, {1}, {2})", x, y, z); 173 | } 174 | 175 | public string ToString(string format) 176 | { 177 | return string.Format("({0}, {1}, {2})", x.ToString(format), y.ToString(format), z.ToString(format)); 178 | } 179 | 180 | public static Vector3Int zero { get { return s_Zero; } } 181 | public static Vector3Int one { get { return s_One; } } 182 | public static Vector3Int up { get { return s_Up; } } 183 | public static Vector3Int down { get { return s_Down; } } 184 | public static Vector3Int left { get { return s_Left; } } 185 | public static Vector3Int right { get { return s_Right; } } 186 | 187 | private static readonly Vector3Int s_Zero = new Vector3Int(0, 0, 0); 188 | private static readonly Vector3Int s_One = new Vector3Int(1, 1, 1); 189 | private static readonly Vector3Int s_Up = new Vector3Int(0, 1, 0); 190 | private static readonly Vector3Int s_Down = new Vector3Int(0, -1, 0); 191 | private static readonly Vector3Int s_Left = new Vector3Int(-1, 0, 0); 192 | private static readonly Vector3Int s_Right = new Vector3Int(1, 0, 0); 193 | } 194 | #endif -------------------------------------------------------------------------------- /Vector3Int.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb873723789b77d4fbb3e8502efe76be 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /uLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f75f342238cdbc4581afc3924148dbf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /uReader.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Runtime.InteropServices; 3 | using System.IO; 4 | using System; 5 | using System.Text; 6 | 7 | namespace uSource 8 | { 9 | public class uReader : BinaryReader 10 | { 11 | public Stream InputStream; 12 | 13 | public uReader(Stream InputStream) 14 | : base(InputStream) 15 | { 16 | this.InputStream = InputStream; 17 | 18 | if (!InputStream.CanRead) 19 | throw new InvalidDataException("Stream unreadable!"); 20 | } 21 | 22 | public byte[] GetBytes(int Count, long Offset) 23 | { 24 | if (!Offset.Equals(0) && !Offset.Equals(InputStream.Position)) 25 | InputStream.Seek(Offset, SeekOrigin.Begin); 26 | 27 | byte[] Buffer = new byte[Count]; 28 | InputStream.Read(Buffer, 0, Buffer.Length); 29 | 30 | return Buffer; 31 | } 32 | 33 | public void ReadType(ref T Variable, long? Offset = null) 34 | { 35 | if (Offset.HasValue) 36 | InputStream.Seek(Offset.Value, SeekOrigin.Begin); 37 | 38 | Byte[] Buffer = new byte[Marshal.SizeOf(typeof(T))]; 39 | InputStream.Read(Buffer, 0, Buffer.Length); 40 | 41 | GCHandle Handle = GCHandle.Alloc(Buffer, GCHandleType.Pinned); 42 | try 43 | { 44 | Variable = (T)Marshal.PtrToStructure(Handle.AddrOfPinnedObject(), typeof(T)); 45 | } 46 | finally 47 | { 48 | Handle.Free(); 49 | } 50 | } 51 | 52 | public void ReadArray(ref T[] Array, long? Offset = null) 53 | { 54 | if (Offset.HasValue) 55 | InputStream.Seek(Offset.Value, SeekOrigin.Begin); 56 | 57 | for (Int32 i = 0; i < Array.Length; i++) 58 | ReadType(ref Array[i]); 59 | } 60 | 61 | public void ReadTypeFixed(ref T Variable, Int32 TypeSizeOf, long? Offset = null) 62 | { 63 | if (Offset.HasValue) 64 | InputStream.Seek(Offset.Value, SeekOrigin.Begin); 65 | 66 | Byte[] Buffer = new byte[TypeSizeOf]; 67 | InputStream.Read(Buffer, 0, Buffer.Length); 68 | 69 | GCHandle Handle = GCHandle.Alloc(Buffer, GCHandleType.Pinned); 70 | try 71 | { 72 | Variable = (T)Marshal.PtrToStructure(Handle.AddrOfPinnedObject(), typeof(T)); 73 | } 74 | finally 75 | { 76 | Handle.Free(); 77 | } 78 | } 79 | 80 | public void ReadArrayFixed(ref T[] Array, Int32 TypeSizeOf, long? Offset = null) 81 | { 82 | if (Offset.HasValue) 83 | InputStream.Seek(Offset.Value, SeekOrigin.Begin); 84 | 85 | for (Int32 i = 0; i < Array.Length; i++) 86 | ReadTypeFixed(ref Array[i], TypeSizeOf); 87 | } 88 | 89 | [ThreadStatic] 90 | private static StringBuilder _sBuilder; 91 | public String ReadNullTerminatedString(long? Offset = null) 92 | { 93 | if (Offset.HasValue && !Offset.Value.Equals(InputStream.Position)) 94 | InputStream.Seek(Offset.Value, SeekOrigin.Begin); 95 | 96 | if (_sBuilder == null) 97 | _sBuilder = new StringBuilder(); 98 | else 99 | _sBuilder.Remove(0, _sBuilder.Length); 100 | 101 | while (true) 102 | { 103 | Char c = (char)InputStream.ReadByte(); 104 | if (c == 0) 105 | return _sBuilder.ToString(); 106 | 107 | _sBuilder.Append(c); 108 | } 109 | } 110 | 111 | public Vector3 ReadVector2D() 112 | { 113 | Vector2 Vector2D;// = new Vector2(ReadSingle(), ReadSingle()); 114 | Vector2D.x = ReadSingle(); 115 | Vector2D.y = ReadSingle(); 116 | 117 | return Vector2D; 118 | } 119 | 120 | public Vector3 ReadVector3D(bool SwapZY = true) 121 | { 122 | Vector3 Vector3D;// = new Vector3(ReadSingle(), ReadSingle(), ReadSingle()); 123 | Vector3D.x = ReadSingle(); 124 | Vector3D.y = ReadSingle(); 125 | Vector3D.z = ReadSingle(); 126 | 127 | if (SwapZY) 128 | { 129 | //float x = Vector3D.x; 130 | //float y = Vector3D.y; 131 | //float z = Vector3D.z; 132 | 133 | Single tempX = Vector3D.x; 134 | 135 | Vector3D.x = -Vector3D.y; 136 | Vector3D.y = Vector3D.z; 137 | Vector3D.z = tempX; 138 | } 139 | 140 | return Vector3D; 141 | } 142 | 143 | public Vector3 ReadVector4D() 144 | { 145 | Vector4 Vector4D; 146 | Vector4D.x = ReadSingle(); 147 | Vector4D.y = ReadSingle(); 148 | Vector4D.z = ReadSingle(); 149 | Vector4D.w = ReadSingle(); 150 | 151 | return Vector4D; 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /uReader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efddea8c476268d48baa89412004aa22 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /uResourceManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a65dc6db86980604d9a462106fad877b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /uSource.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "uSource", 3 | "references": [], 4 | "includePlatforms": [], 5 | "excludePlatforms": [] 6 | } -------------------------------------------------------------------------------- /uSource.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0645629861f21c3479d3caf820b5d17a 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------