public Mesh ExtrudeAlong(BezierSpline spline, Vector3 down) { MeshBuilder meshBuilder = new MeshBuilder(); meshBuilder.BeforeNext(Matrix4x4.identity, new Vector3()); Vector3 lastTangent = spline.GetFirstDerivative(0, spline.pts[0]); Quaternion quat = Quaternion.LookRotation(lastTangent, -down); Vector3 up = down; Vertex[] lastVerts = null; for(int i = 0; i < spline.pts.Length; i ++) { BezierSpline.BezierPoint pt = spline.pts[i]; if (Vector3.Distance(pt.startPos, pt.endPos) > 0.001f) { int subdivisions = pt.numSubdivisions; for (int div = 0; div <= subdivisions; div++) { float t = div / (float)pt.numSubdivisions; Vector3 ptT = spline.GetPoint(t, pt); Vector3 tangent = spline.GetFirstDerivative(t, pt).normalized; quat = Quaternion.FromToRotation(lastTangent, tangent) * quat; lastVerts = BuildNextSection(meshBuilder, ptT, tangent, quat, lastVerts); lastTangent = tangent; } } } AddCap(meshBuilder, new Vector3[] { lastVerts[0].position, lastVerts[2].position, lastVerts[4].position, lastVerts[6].position }, true); return meshBuilder.DoneCreateMesh(); }
public void Build(Vector3 pos, AdjacencyMatrix adjacencyMatrix, MeshBlock block, MeshBuilder meshBuilder, BlockBounds clipBounds) { Quaternion rot = block.RotationQuat; Matrix4x4 transform = Matrix4x4.TRS(pos + new Vector3(0.5f, 0.5f, 0.5f), rot, new Vector3(1, 1, 1)); BlockBounds localClipBounds = new BlockBounds (clipBounds.Position - block.OriginalBounds.Position - pos, clipBounds.Size); localClipBounds.SetToRotationFrom (Quaternion.Inverse(block.RotationQuat), new Vector3(0.5f, 0.5f, 0.5f)); meshBuilder.BeforeNext (transform, new Vector3(-0.5f, -0.5f, -0.5f), localClipBounds); foreach (Part part in _blockParts) { if ((part.Direction == null) || (!adjacencyMatrix.RPt(part.Direction[0], part.Direction[1], part.Direction[2]).Occluded)) { IProcMeshGenerator meshGenerator; if(!_meshGenerators.TryGetValue(part.MeshGenerator, out meshGenerator)){ _meshGenerators[part.MeshGenerator] = (meshGenerator = (IProcMeshGenerator)Activator.CreateInstance(part.MeshGenerator)); } meshGenerator.BuildMesh(part.PartType, adjacencyMatrix, meshBuilder, localClipBounds); } } }