public static Quaternion GetRotationFromString(string rot) { Matrix4x4 matrix = Util.GenerateMatrix4x4String(rot); Quaternion newQuat = MatrixHelper.QuatFromMatrix(matrix); return(newQuat); }
public static Quaternion GetRotation(Inst inst) { Matrix4x4 matrix = Util.GenerateMatrix4x4(inst); Quaternion newQuat = MatrixHelper.QuatFromMatrix(matrix); return(newQuat); }
// Horrible! //public IEnumerator GenerateItem(Inst inst) { void GenerateItem(Inst inst) { Vector3 pos = Util.GetPosition(inst); Quaternion rot = Util.GetRotation(inst); string name = "Unknown"; string mesh = inst.type + " | " + inst.guid; List <Partition> partitions = new List <Partition>(); string shaderName = ""; string shaderPath = ""; string refMeshClean = ""; //This part is just trying to get the actual model name. It goes through different partitions and blueprints in order to get an accurate model name. //Normally, it's fine to just do name + _lod0_data, but sometimes we have objects that reference non-existant objects, such as container_large_blue. //While container_large exists, _blue is just referencing an other instance, and thus an other material for said container. //It's mostly not an issue. if (inst.type == "Entity.ReferenceObjectData" && Util.GetField("ReferencedObject", inst) != null && (Util.GetField("ReferencedObject", inst).reference != null && Util.GetField("ReferencedObject", inst).reference != "null")) { name = Util.GetField("ReferencedObject", inst).reference; string cleanName = Util.ClearGUIDString(name); string refGuid = Util.GetGuid(name); Partition refPartition = Util.LoadPartition(cleanName); partitions.Add(refPartition); if (refPartition != null && name != "null") { Inst bluePrint = Util.GetInst(refGuid, refPartition); string refObject = ""; if (bluePrint != null) { refObject = Util.GetField("Object", bluePrint).reference; } if (Util.GetInst(refObject, refPartition) != null) { Inst staticModelEntityData = Util.GetInst(refObject, refPartition); if (staticModelEntityData != null) { if (Util.GetField("Mesh", staticModelEntityData) != null) { string refMesh = Util.GetField("Mesh", staticModelEntityData).reference; refMeshClean = Util.ClearGUIDString(refMesh); string refMeshGuid = Util.GetGuid(refMesh); Partition meshPartition = Util.LoadPartition(refMeshClean); if (meshPartition != null) { List <Inst> shaderInstances = Util.GetTypes("Render.MeshShaderSetAsset", meshPartition); foreach (Inst shaderInstance in shaderInstances) { foreach (Complex complex in Util.GetArray("SurfaceShaders", shaderInstance).complex) { List <string> textureNames = new List <string>(); foreach (Field field in complex.field) { if (field.name == "Name") { shaderName = Util.ClearGUIDString(field.value); } if (field.name == "Shader") { shaderPath = Util.ClearGUIDString(field.reference); } } materialManager.RegisterShader(refMeshClean, shaderPath, shaderName); } } Inst rigidMeshAsset = Util.GetInst(refMeshGuid, meshPartition); if (rigidMeshAsset != null) { string refMeshMesh = Util.GetField("Name", rigidMeshAsset).value; mesh = refMeshMesh + "_lod0_data"; } } } } } } } string meshpath = "Resources/" + mesh + ".meshdata"; GameObject go = null; List <Mesh> subsetMesh = new List <Mesh> (); List <string> subsetNames = new List <string> (); if (Util.FileExist(meshpath)) { BC2Mesh bc2mesh = null; go = Instantiate(empty, Vector3.zero, Quaternion.identity) as GameObject; if (!(instantiatedMeshDictionary.TryGetValue(mesh, out bc2mesh))) { bc2mesh = MeshDataImporter.LoadMesh(meshpath); foreach (string s in subsetNames) { Debug.Log(s); } instantiatedMeshDictionary.Add(mesh, bc2mesh); } int subsetInt = 0; subsetMesh = bc2mesh.subMesh; subsetNames = bc2mesh.subMeshNames; foreach (Mesh sub in subsetMesh) { GameObject subGO = (GameObject)Instantiate(empty, Vector3.zero, Quaternion.identity); MeshRenderer mr = subGO.AddComponent <MeshRenderer>(); MeshFilter mf = subGO.AddComponent <MeshFilter>(); MeshCollider mc = subGO.AddComponent <MeshCollider> (); mr.material = materialManager.GetMaterial(refMeshClean, shaderPath, subsetNames[subsetInt]); mf.mesh = sub; mf.mesh.RecalculateNormals(); subGO.name = subsetNames[subsetInt]; subGO.transform.parent = go.transform; mc.sharedMesh = mf.mesh; subsetInt++; } if (bc2mesh.inverted) { Vector3 localScale = go.transform.localScale; localScale.x *= -1; go.transform.localScale = localScale; } } else { go = Instantiate(placeholder.gameObject, pos, rot) as GameObject; } go.name = Util.ClearGUID(inst); //go.AddComponent<MeshRenderer>().material.color = new Color (UnityEngine.Random.Range (0.1f, 1.0f), UnityEngine.Random.Range (0.1f, 1.0f), UnityEngine.Random.Range (0.1f, 1.0f)); GameObject parent = transform.GetComponent <MapItems>().SelectParent(inst.type); go.transform.parent = parent.transform; Matrix4x4 matrix = Util.GenerateMatrix4x4(inst); Quaternion newQuat = MatrixHelper.QuatFromMatrix(matrix); //Quaternion newQuat = go.transform.localRotation; //newQuat.x *= -1; //newQuat.z *= -1f; go.transform.localRotation = newQuat; go.transform.position = pos; if (inst.type == "Entity.ReferenceObjectData") { Vector3 scale = go.transform.localScale; scale.x *= -1; // the meshimporter is inverted. This is a workaround. go.transform.localScale = scale; if (Regex.IsMatch(go.name.ToLower(), "invisiblewall")) { go.GetComponentInChildren <MeshRenderer>().material = new Material(materialInvisibleWall); } } BC2Instance instance = go.AddComponent <BC2Instance>(); instance.instance = inst; instance.id = i; instance.mapLoad = this; instance.partitions = partitions; instantiatedGameObjects.Add(go.gameObject); instantiatedDictionary.Add(inst.guid.ToUpper(), go.gameObject); i++; // yield return null; }
public void GenerateHavokItem(Inst inst) { string coordinatestring = ""; if (inst.array != null) { foreach (BC2Array array in inst.array) { if (array.name == "Transforms") { coordinatestring = array.value; GeneratePosRot(coordinatestring); } if (array.name == "Assets") { int i = 0; foreach (Item item in array.item) { Vector3 pos = positions [i]; Quaternion rot = MatrixHelper.QuatFromMatrix(matrix[i]); string name = CleanName(item.reference); string modelName = name; string actualModelName = name + "_lod0_data.meshdata"; string actualModelName2 = name + "_mesh_lod0_data.meshdata"; if (Util.FileExist("Resources/" + actualModelName)) { modelName = actualModelName; } else if (Util.FileExist("Resources/" + actualModelName2)) { modelName = actualModelName2; } else { modelName = "Havok_unknown"; } if (modelName != "Havok_unknown") { // if (instantiatedDictionary.ContainsKey (name)) { // instantiatedDictionary.TryGetValue (name, out go); // Util.Log ("Saving time on caching yo"); // } else { GameObject go = loadMesh("Resources/" + modelName, name); // instantiatedDictionary.Add (name, go.gameObject); // } // go.transform.position = pos; go.transform.rotation = rot; go.transform.localScale = Vector3.one; Vector3 scale = go.transform.localScale; scale.x *= -1; go.transform.localScale = scale; go.name = name; go.transform.parent = transform; HavokItem hi = go.AddComponent <HavokItem> (); hi.ID = i; hi.pos = pos; hi.rot = rot; gameObjects.Add(go); } i++; } } } } }