void CalculatePositionCC(ClayMesh clayMeshA, ClayMesh clayMeshB) { List <float> init_dataA = clayMeshA.RowAvgRadiusList; List <float> init_dataB = clayMeshB.RowAvgRadiusList; GetCorrelation(init_dataA, init_dataB); }
void CalculateCurvatureCC(ClayMesh clayMeshA, ClayMesh clayMeshB) { List <float> init_dataA = clayMeshA.RowAvgRadiusList; List <float> init_dataB = clayMeshB.RowAvgRadiusList; var curA = GetCurvature(init_dataA); var curB = GetCurvature(init_dataB); GetCorrelation(curA, curB); }
public void UpdateMesh() { int heightDivision = radiusList.Count - 1; float angleDelta = Mathf.PI * 2f / axisDivision; float heightDelta = height / heightDivision; float angleTheta = 0f; float heightTheta = 0f; var newVertices = new List <Vector3>(); var newTriangles = new List <int>(); for (int i = 0; i < heightDivision + 1; ++i) { for (int j = 0; j < axisDivision; ++j) { float r = radiusList[i]; Vector3 p = new Vector3(r * Mathf.Cos(angleTheta), heightTheta, r * Mathf.Sin(angleTheta)); newVertices.Add(p); angleTheta += angleDelta; } heightTheta += heightDelta; } for (int j = 0; j < heightDivision; ++j) { for (int i = 0; i < axisDivision; ++i) { ClayMesh.CreateTriangle(newTriangles, i + axisDivision * j, (i + 1) % axisDivision + axisDivision * j, i + axisDivision * (j + 1), (i + 1) % axisDivision + axisDivision * (j + 1)); } } Mesh m = new Mesh(); m.vertices = newVertices.ToArray(); m.triangles = newTriangles.ToArray(); m_meshFilter.sharedMesh = m; }
public void CreateMesh() { // cleanup first for (int i = 0; i < m_clayRoot.childCount; ++i) { DestroyImmediate(m_clayRoot.GetChild(i).gameObject); } // create ClayMesh ClayMesh clayMesh = ClayMeshFactory(); // assign ClayMesh ClayMeshContext cmc = Instantiate <ClayMeshContext>(m_prefab, m_clayRoot); cmc.gameObject.name = "Clay Mesh " + System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"); cmc.clayMesh = clayMesh; // generate mesh based on ClayMesh clayMesh.GenerateMesh(); Vertices = clayMesh.Mesh.vertexCount; Triangles = clayMesh.Mesh.triangles.Length / 3; }
ClayMesh ClayMeshFactory() { float delta = 2f * Mathf.PI / (float)m_segment; float heightDelta = (float)m_height / (float)m_verticalSegment; float theta = 0f; float heightTheta = 0f; Perlin perlin = new Perlin(); List <float> radiusList = new List <float> (); float maxRadius = 0f; for (int j = 0; j < m_verticalSegment + 1; ++j) { theta = 0f; // model the shape as a ellipse, get radius based on height // x^2 / a^2 + y^2 / b^2 = 1 float ellipsoidRadius = Mathf.Sqrt(Mathf.Max(0f, m_height * m_height - heightTheta * heightTheta)) * m_radius / m_height; float baseRadius = m_topBaseRatio * m_radius + (1f - m_topBaseRatio) * ellipsoidRadius; // get noise center float noiseParameter = (float)j / (float)m_verticalSegment; // 1. direction // 1D float noise0 = perlin.Noise(noiseParameter * m_angleNoiseSpan); float offsetAngle = Mathf.Lerp(0f, 2 * Mathf.PI, noise0); Vector3 offsetDir = new Vector3(Mathf.Cos(offsetAngle), 0f, Mathf.Sin(offsetAngle)).normalized; // 2. length // 1D float noise1 = perlin.Noise(noiseParameter * m_centerNoiseSpan); float offsetLength = noise1 * m_centerNoiseScale * m_radius; // the noise center Vector3 noiseCenter = offsetDir * offsetLength; // get collective noise radius // 1D // 1. length float noise2 = perlin.Noise(noiseParameter * m_rowNoiseSpan); float rowNoiseRadius = noise2 * m_rowNoiseScale * m_radius; for (int i = 0; i < m_segment; ++i) { // get individual noise // 3D float noise3 = perlin.Noise( Mathf.Cos(theta) * m_radius * m_individualNoiseSpan, heightTheta, Mathf.Sin(theta) * m_radius * m_individualNoiseSpan); float individualNoiseRadius = noise3 * m_individualNoiseScale * m_radius; float finalRadius = baseRadius + rowNoiseRadius + individualNoiseRadius; var noisePos = noiseCenter + new Vector3(finalRadius * Mathf.Cos(theta), 0f, finalRadius * Mathf.Sin(theta)); float result = noisePos.magnitude; if (result > maxRadius) { maxRadius = result; } // fill noise radius matrix radiusList.Add(result); theta += delta; } heightTheta += heightDelta; } ClayMesh cMesh = new ClayMesh(m_verticalSegment + 1, m_segment, radiusList, m_height, m_thicknessRatio); return(cMesh); }