public GameObject[] generateColliders() { GameObject[] colliders = new GameObject[faces]; float anglePerFace = 360f / (float)faces; float start = 0; float end = start + anglePerFace; float thickness = topRadius - topInnerRadius; Mesh mesh; MeshFilter mf; MeshCollider mc; ROTMeshBuilder builder = new ROTMeshBuilder(); GameObject collider; for (int i = 0; i < faces; i++) { collider = new GameObject("ProceduralCylinderCollider-" + i); colliders[i] = collider; start = (float)i * anglePerFace; end = start + anglePerFace; builder.generatePanelCollider(offset, start, end, 0, height, bottomRadius, topRadius, thickness); mesh = builder.buildMesh(); mf = collider.AddComponent <MeshFilter>(); mf.mesh = mesh; mc = collider.AddComponent <MeshCollider>(); mc.sharedMesh = mesh; mc.convex = true; builder.clear(); } return(colliders); }
public Mesh generateMesh() { ROTMeshBuilder builder = new ROTMeshBuilder(); Arc bottomOuterArc = new Arc(bottomRadius, 0, 0, 360, faces); Arc topOuterArc = new Arc(topRadius, height, 0, 360, faces); List <Vertex> verts1 = bottomOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v1, 1, 0); List <Vertex> verts2 = topOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v2, 1, 0); builder.generateQuads(verts1, verts2, false); if (bottomInnerRadius != 0 || topInnerRadius != 0) { Arc bottomInnerArc = new Arc(bottomInnerRadius, 0, 0, 360, faces); Arc topInnerArc = new Arc(topInnerRadius, height, 0, 360, faces); float heightDiff = topInnerArc.height - bottomInnerArc.height; float radiusDiff = bottomInnerArc.radius - topInnerArc.radius; float sideRadians = Mathf.Atan2(heightDiff, radiusDiff) - 90 * Mathf.Deg2Rad; float yCos = Mathf.Cos(sideRadians); float ySin = Mathf.Sin(sideRadians); verts1 = bottomInnerArc.generateVertices(builder, offset, insideUV, insideUV.v1, -yCos, ySin); verts2 = topInnerArc.generateVertices(builder, offset, insideUV, insideUV.v2, -yCos, ySin); builder.generateQuads(verts1, verts2, true); } builder.generateCylinderCap(offset, faces, bottomRadius, bottomInnerRadius, 0, 0, 360, bottomUV, true); builder.generateCylinderCap(offset, faces, topRadius, topInnerRadius, height, 0, 360, topUV, false); Mesh mesh = builder.buildMesh(); mesh.name = "ProceduralCylinderMesh"; return(mesh); }
public GameObject[] generateColliders(Vector3 center, int facesPerCollider) { float totalAngle = endAngle - startAngle; float anglePerFace = 360f / (float)faces; int localFaces = (int)Math.Round(totalAngle / anglePerFace); localFaces /= facesPerCollider; GameObject[] colliders = new GameObject[localFaces * (innerArcs.Count - 1)]; float localStart, localEnd, startY, height, topRadius, bottomRadius, thickness; Mesh colliderMesh; MeshFilter mf; //MeshRenderer mr; MeshCollider mc; thickness = outerArcs[0].radius - innerArcs[0].radius; ROTMeshBuilder builder = new ROTMeshBuilder(); int colliderIndex = 0; for (int i = 0; i < localFaces; i++) { localStart = startAngle + (float)i * anglePerFace; localEnd = localStart + (anglePerFace * facesPerCollider); for (int k = 0; k < innerArcs.Count - 1; k++, colliderIndex++) { startY = innerArcs[k].height; height = innerArcs[k + 1].height - startY; bottomRadius = outerArcs[k].radius; topRadius = outerArcs[k + 1].radius; builder.generatePanelCollider(center, localStart, localEnd, startY, height, bottomRadius, topRadius, thickness); colliderMesh = builder.buildMesh(); builder.clear(); colliders[colliderIndex] = new GameObject("PanelCollider" + i + "-" + k); mf = colliders[colliderIndex].AddComponent <MeshFilter>(); //mr = colliders[i].AddComponent<MeshRenderer>(); mc = colliders[colliderIndex].AddComponent <MeshCollider>(); mf.mesh = colliderMesh; //mr.enabled = true; mc.sharedMesh = colliderMesh; mc.enabled = mc.convex = true; } } return(colliders); }
public Mesh generatePanels(Vector3 pos, UVArea outer, UVArea inner, UVArea caps) { int len = outerArcs.Count; ROTMeshBuilder builder = new ROTMeshBuilder(); for (int i = 0; i < len - 1; i++) { generatePanelSegment(builder, pos, outerArcs[i], outerArcs[i + 1], outer, false, true, false); //outside panels generatePanelSegment(builder, pos, innerArcs[i], innerArcs[i + 1], inner, true, false, true); //inside panels } generatePanelSegment(builder, pos, outerArcs[0], innerArcs[0], caps, true, false, false); //bottom cap generatePanelSegment(builder, pos, outerArcs[outerArcs.Count - 1], innerArcs[innerArcs.Count - 1], caps, false, false, false); //top cap if (shouldGenerateSidewalls) { generateSidewalls(builder, caps); } return(builder.buildMesh()); }