void Update() { mcBlob.Update(); float time = Time.realtimeSinceStartup; Mesh newWireMesh = null; if (uiToggle.isOn) { newWireMesh = WireframeGenerator.Generate(mcBlob.finalMesh); } else { newWireMesh = WireframeGenerator.GenerateFast(mcBlob.finalMesh); } // uiText.text = "Wireframe generation speed: " + (Time.realtimeSinceStartup - time).ToString("f5") + " ms"; uiText.text += "\nVertexCount: " + newWireMesh.vertexCount; uiText.text += "\nTrinaglesCount: " + (newWireMesh.triangles.Length / 3); //Destroy previously generated wirefame mesh if (meshFilter.sharedMesh != null) { DestroyImmediate(meshFilter.sharedMesh); } //render new wireframe mesh meshFilter.sharedMesh = newWireMesh; }
// Use this for initialization void Start() { components = GetComponentsInChildren <MeshFilter>(); rend = GetComponentsInChildren <Renderer>(); if (gameObject.isStatic) { enabled = false; Debug.Log("Static mesh convertion is not possible"); return; } ; quadMesh = GetComponentsInChildren <MeshFilter>(); foreach (Renderer red in rend) { material = red.sharedMaterials; } if (quadMesh != null) { /* foreach (MeshFilter quad in quadMesh) * { * DestroyImmediate(quad.sharedMesh); * }*/ // DestroyImmediate(quadMesh[i]); //Generate new quad mesh based on 'Coef' parameters foreach (MeshFilter mf in components) { Mesh originalMesh = mf.sharedMesh; quadMesh[i].sharedMesh = WireframeGenerator.GenerateQuads(originalMesh, normalCoef, angleCoef, areaCoef); i++; } } i = 0; /* if (originalMesh == null) * { * Debug.LogWarning("No mesh data."); * * enabled = false; * }*/ /*else if(originalMesh.triangles.Length / 3 > 21000) * { * Debug.LogWarning("Can not convert mesh with more then 21000 triangles."); * * originalMesh = null; * enabled = false; * }*/ i = 0; this.gameObject.SetActive(false); }
// Update is called once per frame void Update() { if (originalMesh == null) { return; } //If any of the properties has changed, than generate new mesh if ((normalCoef_current != normalCoef) || (angleCoef_current != angleCoef) || (areaCoef_current != areaCoef)) { normalCoef_current = normalCoef; angleCoef_current = angleCoef; areaCoef_current = areaCoef; //Do not forget to delete previously generated quad mesh if (quadMesh != null) { DestroyImmediate(quadMesh); } //Generate new quad mesh based on 'Coef' parameters quadMesh = WireframeGenerator.GenerateQuads(originalMesh, normalCoef, angleCoef, areaCoef); //Assign new mesh if (quadMesh != null) { GetComponent <MeshFilter>().sharedMesh = quadMesh; //Just make wireframe visible material.SetColor("_V_WIRE_Color", new Color(1, 0.5f, 0f, 1)); } else { Debug.Log("houston we have a problem"); } } }