public static int QuadraticCurve(StructList <ShapeGenerator.PathPoint> output, Vector2 start, Vector2 ctrl, Vector2 end) { Vector2 ctrl2 = start + (2f / 3f) * (ctrl - start); Vector2 ctrl3 = end + (2f / 3f) * (ctrl - end); return(CubicCurve(output, start, ctrl2, ctrl3, end)); }
public VertigoContext(ShapeMode shapeMode = ShapeMode.SDF, IDrawCallBatcher batcher = null, MaterialPool materialPool = null) { if (batcher == null) { batcher = new DefaultDrawCallBatcher(); } if (materialPool == null) { materialPool = DefaultMaterialPool; } this.defaultShapeMode = shapeMode; this.renderTextures = new Stack <RenderTexture>(); this.renderCalls = new StructList <RenderCall>(); this.renderTexturesToRelease = new LightList <RenderTexture>(); this.batcher = batcher; this.materialPool = materialPool; this.stateStack = new Stack <VertigoState>(); this.position = Vector3.zero; this.rotation = Quaternion.identity; this.scale = Vector3.one; this.shapeGenerator = new ShapeGenerator(); this.geometryGenerator = new GeometryGenerator(); this.geometryCache = new GeometryCache(); }
public GeometryCache() { shapes = new StructList <GeometryShape>(); positions = new StructList <Vector3>(32); normals = new StructList <Vector3>(32); colors = new StructList <Color>(32); texCoord0 = new StructList <Vector4>(32); texCoord1 = new StructList <Vector4>(32); triangles = new StructList <int>(64); }
public void SetTexCoord1(int idx, StructList <Vector4> uvs) { if (idx < 0 || idx > shapes.size) { return; } GeometryShape shape = shapes[idx]; Array.Copy(uvs.array, 0, texCoord1.array, shape.vertexStart, shape.vertexCount); }
public void GetTextureCoord1(int idx, StructList <Vector4> retn) { if (idx < 0 || idx > shapes.size) { return; } GeometryShape shape = shapes[idx]; retn.EnsureCapacity(shape.vertexCount); Array.Copy(texCoord1.array, shape.vertexStart, retn.array, 0, shape.vertexCount); retn.size = shape.vertexCount; }
public VertigoContextOld() { instanceId = s_InstanceIdGenerator; s_InstanceIdGenerator += 100000; parameterTexture = new ParameterTexture(64, 64); shapeData = new StructList <Vector3>(128); shapes = new StructList <Shape>(64); pendingDrawCalls = new StructList <PendingDrawCall>(32); issuedDrawCalls = new StructList <IssuedDrawCall>(); shapeBatchPool = new ShapeBatch.ShapeBatchPool(); shapes.Add(new Shape(ShapeType.Unset)); }
// todo -- remove recursion, maybe jobify private static void RecursiveBezier(StructList <ShapeGenerator.PathPoint> points, int currentIteration, float distanceTolerance, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { while (true) { if (currentIteration++ >= MaxAdaptiveBezierIteration) { return; } float x12 = (x1 + x2) * 0.5f; float y12 = (y1 + y2) * 0.5f; float x23 = (x2 + x3) * 0.5f; float y23 = (y2 + y3) * 0.5f; float x34 = (x3 + x4) * 0.5f; float y34 = (y3 + y4) * 0.5f; float x123 = (x12 + x23) * 0.5f; float y123 = (y12 + y23) * 0.5f; float x234 = (x23 + x34) * 0.5f; float y234 = (y23 + y34) * 0.5f; float x1234 = (x123 + x234) * 0.5f; float y1234 = (y123 + y234) * 0.5f; float dx = x4 - x1; float dy = y4 - y1; float d2 = Mathf.Abs(((x2 - x4) * dy - (y2 - y4) * dx)); float d3 = Mathf.Abs(((x3 - x4) * dy - (y3 - y4) * dx)); if ((d2 + d3) * (d2 + d3) < distanceTolerance * (dx * dx + dy * dy)) { points.Add(new ShapeGenerator.PathPoint(x1234, y1234)); return; } RecursiveBezier(points, currentIteration, distanceTolerance, x1, y1, x12, y12, x123, y123, x1234, y1234); x1 = x1234; y1 = y1234; x2 = x234; y2 = y234; x3 = x34; y3 = y34; } }
public static int CubicCurve(StructList <ShapeGenerator.PathPoint> output, Vector2 start, Vector2 ctrl0, Vector2 ctrl1, Vector2 end, float distanceTolerance = 1f) { if (start == ctrl0 && ctrl0 == ctrl1 && ctrl1 == end) { return(0); } int originalPointCount = output.Count; if (output.Count == 0 || output[output.Count - 1].position != start) { output.Add(new ShapeGenerator.PathPoint(start.x, start.y)); } RecursiveBezier(output, 0, distanceTolerance * distanceTolerance, start.x, start.y, ctrl0.x, ctrl0.y, ctrl1.x, ctrl1.y, end.x, end.y); output.Add(new ShapeGenerator.PathPoint(end.x, end.y)); return(output.Count - originalPointCount); }
public ShapeGenerator(int capacity = 8) { this.shapes = new StructList <ShapeDef>(capacity); this.points = new StructList <PathPoint>(capacity * 8); this.holes = new StructList <PathPoint>(capacity * 2); }