/// <summary> /// Generates a ring of vertices using circular UV mapping, where the center of the ring is the center of the UV area. /// This would be used to generate a partial ring, such as the procedural decoupler /// Input radius is the radius of the actual ring, uvRadius is the radius to be used for maximal UV bounds /// (e.g. they will only be different on an inner-ring; where radius=ring radius, and uvRadius = outerRingRadius) /// </summary> /// <param name="offset"></param> /// <param name="faces"></param> /// <param name="radius"></param> /// <param name="height"></param> /// <param name="startAngle"></param> /// <param name="endAngle"></param> /// <param name="area">The UV area to map the UV vertex to.</param> /// <param name="uvRadius">The radius to be used for the UV area, in case it differs from the radius in use (basically scales the UV area)</param> /// <param name="yCos">Determines the x/z normal component</param> /// <param name="ySin">Used directly as the y normal component</param> /// <returns></returns> public List <Vertex> generateRadialVerticesCylinderUVs(Vector3 offset, int faces, float radius, float height, float startAngle, float endAngle, UVArea area, float uvRadius, float yCos, float ySin) { List <Vertex> verts = new List <Vertex>(); float startRad = startAngle * Mathf.Deg2Rad; float endRad = endAngle * Mathf.Deg2Rad; float totalRad = endRad - startRad; float radPerFace = (2f * Mathf.PI) / faces; //int numOfFaces = (int)(totalRad / radPerFace); int numOfFaces = (int)Math.Round(totalRad / radPerFace, 0); float rads, xCos, zSin, nx, nz, x, y, z; Vector2 min = new Vector2(-uvRadius, -uvRadius); Vector2 max = new Vector2(uvRadius, uvRadius); Vector2 pos; Vector2 uv; //unchanging vars y = height + offset.y; for (int i = 0; i < numOfFaces + 1; i++) { rads = startRad + (radPerFace * i); xCos = Mathf.Cos(rads); zSin = Mathf.Sin(rads); x = xCos * radius + offset.x; z = zSin * radius + offset.z; nx = xCos * yCos; nz = zSin * yCos; pos = new Vector2(xCos * radius, zSin * radius); uv = area.getUV(min, max, pos); verts.Add(addVertex(new Vector3(x, y, z), new Vector3(nx, ySin, nz), uv)); } return(verts); }
public void generateCylinderCap(Vector3 offset, int faces, float outerRadius, float innerRadius, float height, float startAngle, float endAngle, UVArea area, bool bottomCap) { float ySin = bottomCap ? -1 : 1; List <Vertex> outerVerts = generateRadialVerticesCylinderUVs(offset, faces, outerRadius, height, startAngle, endAngle, area, outerRadius, 0, ySin); if (innerRadius > 0)//partial cap { List <Vertex> innerVerts = generateRadialVerticesCylinderUVs(offset, faces, innerRadius, height, startAngle, endAngle, area, outerRadius, 0, ySin); generateQuads(outerVerts, innerVerts, bottomCap); } else { Vector2 min = new Vector2(-outerRadius, -outerRadius); Vector2 max = new Vector2(outerRadius, outerRadius); Vector2 centerUV = area.getUV(min, max, new Vector2(0, 0)); Vertex center = addVertex(offset + new Vector3(0, height, 0), bottomCap ? Vector3.down : Vector3.up, centerUV); generateTriangleFan(outerVerts, center, bottomCap); } }