public override void Exit() { ObjectObj.SetActive(false); BulletObj.SetActive(false); HitObj.SetActive(false); base.Exit(); }
/// <summary> /// Return one object from the obj file /// </summary> /// <param name="listKeysValues"></param> /// <param name="allVertices"></param> /// <param name="startIndex"></param> /// <param name="endIndex"></param> /// <returns></returns> private static ObjectObj ObjectData(List <Tuple <string, string> > listKeysValues, AllVerticesDataObj allVertices, int startIndex, int endIndex) { LocalIndexesObj indexesObj = new LocalIndexesObj(); ObjectObj objectObj = new ObjectObj(); int i = startIndex; while (i < endIndex) { Tuple <string, string> keyValue = listKeysValues[i]; if (keyValue != null) { string key = keyValue.Item1; string value = keyValue.Item2.TrimEnd('\0').Trim(); // Remove the null character and any blank space if (ObjUtils.IsVertData(key)) // f { VerticeData(value, objectObj, allVertices, indexesObj); } else // Other key (o, g, s, usemtl) { switch (key) { case "usemtl": objectObj.MaterialName = value; break; case "o": objectObj.ObjectName = value; break; case "g": objectObj.GroupName = value; break; case "s": if (value != "off") { if (Int32.TryParse(value, out int s)) { objectObj.Smooth = s; } } break; default: break; } } } i++; } return(objectObj); }
/// <summary> /// Rename every materials from the given list to make them unique /// </summary> /// <param name="objData"></param> /// <param name="groups"></param> /// <param name="indexMaterial"></param> private static void SetUniqueMaterialsName(ObjData objData, List <int> groups, IntWrapper indexMaterial) { foreach (int i in groups) { ObjectObj objectObj = objData.ObjectsList[i]; if (objectObj.ObjectName == null) { objectObj.ObjectName = objectObj.GroupName; } if (objectObj.MaterialName != null) { objectObj.MaterialName = GenericUtils.MergeIndexStr(indexMaterial.Value, objectObj.MaterialName); } } }
protected override void OnAtk() { base.OnAtk(); //TODO eff关闭后再推出 HitObj.transform.position = BulletObj.transform.position; if (IsHit == false) { Exit(); } IsHit = true; if (ObjectObj != null) { ObjectObj.transform.position = target.GetPoint; ObjectObj.SetActive(true); } }
/// <summary> /// Store the f, v, vt and vn lines into the object /// </summary> /// <param name="value"></param> /// <param name="objectObj"></param> /// <param name="allVertices"></param> /// <param name="indexesObj"></param> private static void VerticeData(string value, ObjectObj objectObj, AllVerticesDataObj allVertices, LocalIndexesObj indexesObj) { VertIndexesObj vertIndexes = new VertIndexesObj(); foreach (string indexes in ObjUtils.SplitVertData(value)) { VertIndexObj vertIndex = new VertIndexObj(); string[] indexList = ObjUtils.SplitIndexes(indexes); int length = indexList.Length; for (int i = 0; i < length; i++) { int index = 0; if (indexList[i] != "") // the vt line can be empty { if (Int32.TryParse(indexList[i], out int tmpIndex)) // Get the index { index = tmpIndex; } } if (i == 0) // v { if (index != 0) { vertIndex.V = indexesObj.vIndex; string vLine = allVertices.GetVIndex(index - 1); // Obj index start at 1 if (vLine != null) { objectObj.VerticesList.Add(new Point(vLine)); indexesObj.vIndex++; } } } else if (i == 1) // vt { if (index != 0) { vertIndex.Vt = indexesObj.vtIndex; string vtLine = allVertices.GetVtIndex(index - 1); // Obj index start at 1 if (vtLine != null) { objectObj.UVsList.Add(new UVCoordinates(vtLine)); indexesObj.vtIndex++; } } } else if (i == 2) // vn { if (index != 0) { vertIndex.Vn = indexesObj.vnIndex; string vnLine = allVertices.GetVnIndex(index - 1); // Obj index start at 1 if (vnLine != null) { objectObj.NormalsList.Add(new Vector(vnLine)); indexesObj.vnIndex++; } } } } vertIndexes.VertIndexList.Add(vertIndex); } objectObj.VertIndexesList.Add(vertIndexes); }
/// <summary> /// Delete all groups that use textures from a given list (compare the textures) /// </summary> /// <param name="objData">Data parsed from the obj file</param> /// <param name="mtlData">Data parsed from the mtl file</param> /// <param name="listFileName">List of textures that should be matched</param> public static bool DeleteMatchingGroups(ObjData objData, MtlData mtlData, List <string> listFileName) { if (mtlData == null) { return(false); } List <BitmapStoreData> imgList = BitmapStoreData.GetListBitmapStoreData(listFileName); var tupleTextureMaterials = MtlUtils.GetTupleDictTextureMaterials(mtlData); // Dictionary that associate every texture to a list of materials Dictionary <string, List <int> > dictTextureMaterials = tupleTextureMaterials.Item1; // List of materials without any texture List <int> untexturedMaterials = tupleTextureMaterials.Item2; // Dictionary that associate every material to a list of groups Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData); // Dictionary that associate every texture to a list of groups Dictionary <string, List <int> > dictTextureGroups = ObjUtils.GetDictTextureGroups(objData, mtlData, dictTextureMaterials, dictMaterialGroups); List <ObjectObj> newObjectsList = new List <ObjectObj>(); List <MaterialMtl> newMaterialsList = new List <MaterialMtl>(); string srcDir = System.IO.Path.GetDirectoryName(mtlData.FilePath); foreach (KeyValuePair <string, List <int> > keyValue in dictTextureGroups) { List <int> groups = keyValue.Value; if (groups != null) { if (groups.Count >= 1) // Should always be the case { string texturePath = keyValue.Key; if (!System.IO.Path.IsPathRooted(texturePath)) // Not an absolute path { texturePath = System.IO.Path.Combine(srcDir, texturePath); } System.Drawing.Bitmap img = ImageUtilsShared.CreateBitmap(texturePath); if (img != null) { BitmapStoreData bmpData = new BitmapStoreData(img); if (bmpData.BData != null) { if (!ImageUtilsShared.SamePictures(imgList, bmpData)) // Not the same image { // We can keep all these groups and materials foreach (int groupId in groups) { ObjectObj objectObj = objData.ObjectsList[groupId]; newObjectsList.Add(objectObj); // Insert the object in the list } if (dictTextureMaterials.TryGetValue(keyValue.Key, out List <int> materials)) { if (materials != null) { foreach (int materialId in materials) { MaterialMtl materialMtl = mtlData.MaterialsList[materialId]; newMaterialsList.Add(materialMtl); // Insert the material in the list } } } } bmpData.UnlockBits(); } } } } } foreach (int materialId in untexturedMaterials) // The untextured materials { MaterialMtl materialMtl = mtlData.MaterialsList[materialId]; newMaterialsList.Add(materialMtl); // Insert material in the list if (dictMaterialGroups.TryGetValue(materialMtl.NewMtl, out List <int> groups)) { if (groups != null) { foreach (int groupId in groups) { ObjectObj objectObj = objData.ObjectsList[groupId]; newObjectsList.Add(objectObj); // Insert the object in the list } } } } BitmapStoreData.BitmapDataUnlock(imgList); objData.ObjectsList = newObjectsList; mtlData.MaterialsList = newMaterialsList; return(true); }
/// <summary> /// Merge together every group in the array /// </summary> /// <param name="objData">Data parsed from the obj file</param> /// <param name="textureName">Path to the texture file</param> /// <param name="groups">List of groups index</param> /// <returns></returns> private static ObjectObj MergeObjects(ObjData objData, string textureName, List <int> groups) { int length = groups.Count; if (length >= 1) // Should always be the case { // If the texture name is a relative/absolute path to the file, we only keep the name string relativeTexture = System.IO.Path.GetFileName(textureName); ObjectObj objectObj = new ObjectObj(objData.ObjectsList[groups[0]]) { MaterialName = relativeTexture, // Materialname will be the same as the texture file GroupName = relativeTexture, ObjectName = relativeTexture, TextureName = textureName }; if (length == 1) // Only one group { return(objectObj); } else // More group to merge with the first one { LocalIndexesObj localIndexes = new LocalIndexesObj { vIndex = objectObj.VerticesList.Count, vtIndex = objectObj.UVsList.Count, vnIndex = objectObj.NormalsList.Count }; for (int i = 1; i < length; i++) { ObjectObj nextObjectObj = objData.ObjectsList[groups[i]]; foreach (Point p in nextObjectObj.VerticesList) { objectObj.VerticesList.Add(p); } foreach (UVCoordinates uv in nextObjectObj.UVsList) { objectObj.UVsList.Add(uv); } foreach (Vector v in nextObjectObj.NormalsList) { objectObj.NormalsList.Add(v); } foreach (VertIndexesObj vertIndexes in nextObjectObj.VertIndexesList) { foreach (VertIndexObj vertIndex in vertIndexes.VertIndexList) { if (vertIndex.V != null) { vertIndex.V += localIndexes.vIndex; } if (vertIndex.Vt != null) { vertIndex.Vt += localIndexes.vtIndex; } if (vertIndex.Vn != null) { vertIndex.Vn += localIndexes.vnIndex; } } objectObj.VertIndexesList.Add(vertIndexes); } localIndexes.vIndex += nextObjectObj.VerticesList.Count; localIndexes.vtIndex += nextObjectObj.UVsList.Count; localIndexes.vnIndex += nextObjectObj.NormalsList.Count; } return(objectObj); } } return(null); }
/// <summary> /// Merge together groups that share a texture /// </summary> /// <param name="objData">Data parsed from the obj file</param> /// <param name="mtlData">Data parsed from the mtl file</param> public static bool MergeGroups(ObjData objData, MtlData mtlData) { if (mtlData == null) { return(false); } var tupleTextureMaterials = MtlUtils.GetTupleDictTextureMaterials(mtlData); // Dictionary that associate every texture to a list of materials Dictionary <string, List <int> > dictTextureMaterials = tupleTextureMaterials.Item1; // List of materials without any texture List <int> untexturedMaterials = tupleTextureMaterials.Item2; // Dictionary that associate every material to a list of groups Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData); // Dictionary that associate every texture to a list of groups Dictionary <string, List <int> > dictTextureGroups = ObjUtils.GetDictTextureGroups(objData, mtlData, dictTextureMaterials, dictMaterialGroups); List <ObjectObj> newObjectsList = new List <ObjectObj>(); List <MaterialMtl> newMaterialsList = new List <MaterialMtl>(); foreach (KeyValuePair <string, List <int> > keyValue in dictTextureGroups) // Textured groups { // Merge the groups ObjectObj objectObj = MergeObjects(objData, keyValue.Key, keyValue.Value); newObjectsList.Add(objectObj); if (dictTextureMaterials.TryGetValue(keyValue.Key, out List <int> materials)) { if (materials != null) { // Merge the materials MaterialMtl materialMtl = MergeMaterials(mtlData, keyValue.Key, materials); newMaterialsList.Add(materialMtl); } } } foreach (int materialId in untexturedMaterials) // The untextured materials { MaterialMtl materialMtl = mtlData.MaterialsList[materialId]; newMaterialsList.Add(materialMtl); // Insert material in the list if (dictMaterialGroups.TryGetValue(materialMtl.NewMtl, out List <int> groups)) { if (groups != null) { foreach (int groupId in groups) { ObjectObj objectObj = objData.ObjectsList[groupId]; newObjectsList.Add(objectObj); // Insert the object in the list } } } } objData.ObjectsList = newObjectsList; mtlData.MaterialsList = newMaterialsList; return(true); }