public Texture2D ToUnity(Utils.Progress progress = null) { if (unityTexture == null) { if (data != null) { unityTexture = new Texture2D(width, height, format, false); unityTexture.LoadRawTextureData(data); unityTexture.name = filename; unityTexture.Apply(); } else { unityTexture = new Texture2D(1, 1); unityTexture.name = "ERROR"; unityTexture.Apply(); } if (progress != null) { progress.Update(1); } } return(unityTexture); }
public UnityEngine.Material ToUnity(Scene scene, Utils.Progress progress = null) { if (unityMaterial == null) { // Get the material shader Shader unity_shader = GetUnityShader(shader); if (unity_shader != null) { // Create a new material with the selected shader unityMaterial = new UnityEngine.Material(unity_shader); // Set material options unityMaterial.name = name; unityMaterial.renderQueue = renderQueue; unityMaterial.hideFlags = hideFlags; unityMaterial.globalIlluminationFlags = globalIlluminationFlags; unityMaterial.shaderKeywords = keywords; // Activate required shader passes if (passes != null) { for (int i = 0; i < passes.Length; i++) { #if UNITY_5_6_OR_NEWER unityMaterial.SetShaderPassEnabled(unityMaterial.GetPassName(i), passes[i]); #endif } } // Set material properties ToUnityMaterialProperties <int, int>(unityMaterial, ints, (m, p, v) => m.SetInt(p, v)); ToUnityMaterialProperties <float, float>(unityMaterial, floats, (m, p, v) => m.SetFloat(p, v)); ToUnityMaterialProperties <Vector3, Vector3>(unityMaterial, vectors, (m, p, v) => m.SetVector(p, v)); ToUnityMaterialProperties <Color, Color>(unityMaterial, colors, (m, p, v) => m.SetColor(p, v)); ToUnityMaterialProperties <TextureParams, UnityEngine.Texture>(unityMaterial, textures, (m, p, v) => { m.SetTexture(p, scene.textures[v.index].ToUnity(progress)); m.SetTextureOffset(p, v.offset); m.SetTextureScale(p, v.scale); }); // Set materials missing properties / keywords if material is imported from assimp if ((keywords == null || keywords.Length <= 0) && shader == Constants.defaultAssimpShader) { CLARTE.Shaders.Standard.Utility.MaterialChanged(unityMaterial); } } if (progress != null) { progress.Update(1); } } return(unityMaterial); }
private string GenerateSequenceImplementation(int numbers, ref Utils.Progress progressForm) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < numbers; ++i) { sb.Append(NextBit() & 1); progressForm.PerformStep(); } progressForm.CloseFormSafe(); Utils.MultiThreadHelper.SetTextBoxSafe(sb.ToString(), ref TextBox); return(sb.ToString()); }
public string Decrypt(string encryptedText) { string[] textNumb = encryptedText.Split('\n'); List <BigInteger> message = new List <BigInteger>(); for (int i = 0; i < textNumb.Length; ++i) { if (textNumb[i] != "" && textNumb[i] != "\r") { message.Add(BigInteger.Parse(textNumb[i])); } } if (_form != null) { _progress = new Utils.Progress(0, message.Count, 1, "Дешифрование"); _progress.Show(); } BigInteger h = BigInteger.ModPow(_p, _key, _q); byte[] decryptedMessage = new byte[message.Count]; for (int i = 0; i < message.Count; ++i) { decryptedMessage[i] = (byte)(message[i] / h); if (_form != null) { _progress.PerformStep(); } } if (_form != null) { _progress.CloseFormSafe(); string curExt = WordPad.Helpers.ReadHelper.GetExtention(_form.Text); if (WordPad.Form1.TxtExts.Any(str => str == curExt)) { return(Encoding.Default.GetString(decryptedMessage)); } else { StringBuilder sb = new StringBuilder(); foreach (var b in decryptedMessage) { sb.Append($"{b} "); } return(sb.ToString()); } } return(Encoding.Default.GetString(decryptedMessage)); }
public string Encrypt(string inputStr, bool isText) { if (_form != null) { _progress = new Utils.Progress(0, inputStr.Length, 1, "Шифрование"); _progress.Show(); } List <byte> bytes = new List <byte>(); if (isText) { bytes = Encoding.Default.GetBytes(inputStr).ToList(); } else { string[] bytesInStrings = inputStr.Split(' '); foreach (var ch in bytesInStrings) { if (ch == "" || ch == " ") { continue; } bytes.Add(Byte.Parse(ch)); } } BigInteger k = KeyGen(); BigInteger s = BigInteger.ModPow(_h, k, _q); _p = BigInteger.ModPow(_g, k, _q); List <BigInteger> encryptedMessage = new List <BigInteger>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.Count; ++i) { encryptedMessage.Add(s * bytes[i]); sb.Append(encryptedMessage[i].ToString() + '\n'); if (_form != null) { _progress.PerformStep(); } } if (_form != null) { _progress.CloseFormSafe(); } return(sb.ToString()); }
public void GenerateSequence(object sender, EventArgs e) { string result = Interaction.InputBox("Введите длину генерируемой последовательности (10000)"); int seqLength = 10000; try { int tLen = Int32.Parse(result); seqLength = tLen; } catch (FormatException e2) { MessageBox.Show("Неверное число"); } catch (OverflowException e3) { MessageBox.Show("Переполнение"); } Utils.Progress progressForm = new Utils.Progress(0, seqLength, 1, "Gen progress"); progressForm.Show(); Thread genThread = new Thread(() => { GenerateSequenceAbstract(seqLength, ref progressForm); }); genThread.Start(); }
private string GenerateSequenceImplementation(int numbers, ref Utils.Progress progressForm) { StringBuilder sb = new StringBuilder(); return(sb.ToString()); }
public UnityEngine.Mesh ToUnity(Utils.Progress progress = null) { if (unityMesh == null) { unityMesh = new UnityEngine.Mesh(); if (name != null) { unityMesh.name = name; } if (vertices != null) { unityMesh.vertices = vertices; } if (normals != null) { unityMesh.normals = normals; } if (tangents != null) { unityMesh.tangents = tangents; } if (uv1 != null) { unityMesh.uv = uv1; } if (uv2 != null) { unityMesh.uv2 = uv2; } if (colors != null) { unityMesh.colors = colors; } if (submeshes != null) { int nb_submeshes = submeshes.Length; unityMesh.subMeshCount = nb_submeshes; for (int i = 0; i < nb_submeshes; i++) { SubMesh submesh = submeshes[i]; unityMesh.SetIndices(submesh.triangles, submesh.topology, i); } } unityMesh.RecalculateBounds(); #if !UNITY_5_5_OR_NEWER unityMesh.Optimize(); #endif if (progress != null) { progress.Update(1); } } return(unityMesh); }
public IEnumerator ToUnity(Module.ProgressCallback progress_callback = null) { unityRoot = null; if (root_node != null) { GameObject node_template = new GameObject("Node"); GameObject mesh_template = new GameObject("Mesh"); mesh_template.AddComponent <MeshFilter>(); mesh_template.AddComponent <MeshRenderer>(); unityMapping = new Mapping(); unityReferences = new HashSet <UnityReference>(); uint nb_steps = CountNodes(root_node); nb_steps += (uint)(meshes != null ? meshes.Length : 0); nb_steps += (uint)(materials != null ? materials.Length : 0); nb_steps += (uint)(textures != null ? textures.Length : 0); Utils.Progress progress = new Utils.Progress(); progress.Init(nb_steps, progress_callback); IEnumerator it = root_node.ToUnity(this, null, node_template, mesh_template, progress); while (it.MoveNext()) { progress.Display(); yield return(it.Current); } // Destroy templates if (Application.isPlaying) { UnityEngine.Object.Destroy(node_template); UnityEngine.Object.Destroy(mesh_template); } else { UnityEngine.Object.DestroyImmediate(node_template); UnityEngine.Object.DestroyImmediate(mesh_template); } if (root_node.UnityNodes != null && root_node.UnityNodes.Length > 0) { GameObject[] nodes = root_node.UnityNodes; // This can happen if we have a single original mesh splitted into multiple unity meshes if (nodes.Length > 1) { unityRoot = new GameObject(nodes[0].name); // Regiter an ID for this object unityMapping.Add(unityRoot, unityMapping.GetNewId()); unityRoot.SetActive(false); unityRoot.transform.position = nodes[0].transform.position; unityRoot.transform.rotation = nodes[0].transform.rotation; unityRoot.transform.localScale = nodes[0].transform.localScale; foreach (GameObject go in nodes) { go.transform.parent = unityRoot.transform; go.SetActive(root_node.Active); } } else { unityRoot = nodes[0]; } } // Resolve references foreach (UnityReference reference in unityReferences) { reference.ToUnity(this); } if (unityRoot != null) { unityRoot.SetActive(root_node.Active); } // Clean up unityReferences = null; } }
public static IEnumerator FromUnity(GameObject root, Action <Scene> callback, Module.ProgressCallback progress_callback = null) { if (root != null && callback != null) { Scene scene = new Scene(); scene.unityMapping = new Mapping(); scene.unityMeshes = new Dictionary <UnityEngine.Mesh, int>(); scene.unityMaterials = new Dictionary <UnityEngine.Material, int>(); scene.unityTextures = new Dictionary <Texture2D, int>(); scene.unityComponents = new Dictionary <Component, UnityComponent>(); scene.unityReferences = new HashSet <UnityReference>(); uint nb_nodes = CountNodes(root.transform); Utils.Progress progress = new Utils.Progress(); progress.Init(nb_nodes, progress_callback); // Parse the node hierarchy IEnumerator it = Node.FromUnity(scene, root.transform, n => scene.root_node = n, progress); while (it.MoveNext()) { progress.Display(); yield return(it.Current); } int meshes_count = scene.unityMeshes.Count; int materials_count = scene.unityMaterials.Count; int textures_count = scene.unityTextures.Count; progress.Init((uint)(nb_nodes + meshes_count + materials_count + textures_count), progress_callback); progress.Update(nb_nodes); // Convert the quick lookup meshes dictionary to the final destination array if (meshes_count > 0) { Mesh[] meshes = new Mesh[meshes_count]; foreach (KeyValuePair <UnityEngine.Mesh, int> mesh_pair in scene.unityMeshes) { meshes[mesh_pair.Value] = Mesh.FromUnity(mesh_pair.Key); progress.Update(1); progress.Display(); yield return(null); } scene.meshes = meshes; } // Convert the quick lookup materials dictionary to the final destination array if (materials_count > 0) { Material[] materials = new Material[materials_count]; foreach (KeyValuePair <UnityEngine.Material, int> mat_pair in scene.unityMaterials) { materials[mat_pair.Value] = Material.FromUnity(scene, mat_pair.Key); progress.Update(1); progress.Display(); yield return(null); } scene.materials = materials; } // Convert the quick lookup materials dictionary to the final destination array if (textures_count > 0) { Texture[] textures = new Texture[textures_count]; foreach (KeyValuePair <Texture2D, int> tex_pair in scene.unityTextures) { textures[tex_pair.Value] = Texture.FromUnity(tex_pair.Key); progress.Update(1); progress.Display(); yield return(null); } scene.textures = textures; } // Resolve references foreach (UnityReference reference in scene.unityReferences) { reference.ResolveReference(scene.unityMapping, scene.unityMeshes, scene.unityMaterials, scene.unityTextures); } // Clean up scene.unityMapping = null; scene.unityMeshes = null; scene.unityMaterials = null; scene.unityTextures = null; scene.unityComponents = null; scene.unityReferences = null; // Return the result callback(scene); } }