mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Update LottieMesh
This commit is contained in:
parent
a76672896e
commit
66861def92
1
Tests/LottieMesh/Resources/SUPER Fire.json
Normal file
1
Tests/LottieMesh/Resources/SUPER Fire.json
Normal file
File diff suppressed because one or more lines are too long
@ -12,6 +12,7 @@ public final class ViewController: UIViewController {
|
|||||||
|
|
||||||
self.view.backgroundColor = .black
|
self.view.backgroundColor = .black
|
||||||
|
|
||||||
|
//let path = Bundle.main.path(forResource: "SUPER Fire", ofType: "json")!
|
||||||
let path = Bundle.main.path(forResource: "Fireworks", ofType: "json")!
|
let path = Bundle.main.path(forResource: "Fireworks", ofType: "json")!
|
||||||
//let path = Bundle.main.path(forResource: "Cat", ofType: "json")!
|
//let path = Bundle.main.path(forResource: "Cat", ofType: "json")!
|
||||||
/*for _ in 0 ..< 100 {
|
/*for _ in 0 ..< 100 {
|
||||||
@ -25,7 +26,7 @@ public final class ViewController: UIViewController {
|
|||||||
let buffer = MeshReadBuffer(data: try! Data(contentsOf: URL(fileURLWithPath: animationFile.path)))
|
let buffer = MeshReadBuffer(data: try! Data(contentsOf: URL(fileURLWithPath: animationFile.path)))
|
||||||
let animation = MeshAnimation.read(buffer: buffer)
|
let animation = MeshAnimation.read(buffer: buffer)
|
||||||
|
|
||||||
let renderer = MeshRenderer(wireframe: true)!
|
let renderer = MeshRenderer(wireframe: false)!
|
||||||
|
|
||||||
renderer.frame = CGRect(origin: CGPoint(x: 0.0, y: 50.0), size: CGSize(width: 300.0, height: 300.0))
|
renderer.frame = CGRect(origin: CGPoint(x: 0.0, y: 50.0), size: CGSize(width: 300.0, height: 300.0))
|
||||||
self.view.addSubview(renderer)
|
self.view.addSubview(renderer)
|
||||||
|
@ -56,13 +56,23 @@ std::unique_ptr<Mesh> generateMesh(std::vector<Path> const &paths, std::unique_p
|
|||||||
|
|
||||||
assert(mesh->triangles.size() % 3 == 0);
|
assert(mesh->triangles.size() % 3 == 0);
|
||||||
return mesh;
|
return mesh;
|
||||||
} else {
|
} else if (fill) {
|
||||||
TESStesselator *tessellator = tessNewTess(NULL);
|
TESStesselator *tessellator = tessNewTess(NULL);
|
||||||
tessSetOption(tessellator, TESS_CONSTRAINED_DELAUNAY_TRIANGULATION, 1);
|
tessSetOption(tessellator, TESS_CONSTRAINED_DELAUNAY_TRIANGULATION, 1);
|
||||||
for (const auto &path : paths) {
|
for (const auto &path : paths) {
|
||||||
tessAddContour(tessellator, 2, path.points.data(), sizeof(Point), (int)path.points.size());
|
tessAddContour(tessellator, 2, path.points.data(), sizeof(Point), (int)path.points.size());
|
||||||
}
|
}
|
||||||
tessTesselate(tessellator, TESS_WINDING_ODD, TESS_POLYGONS, 3, 2, NULL);
|
|
||||||
|
switch (fill->rule) {
|
||||||
|
case Fill::Rule::EvenOdd: {
|
||||||
|
tessTesselate(tessellator, TESS_WINDING_ODD, TESS_POLYGONS, 3, 2, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
tessTesselate(tessellator, TESS_WINDING_NONZERO, TESS_POLYGONS, 3, 2, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int vertexCount = tessGetVertexCount(tessellator);
|
int vertexCount = tessGetVertexCount(tessellator);
|
||||||
const TESSreal *vertices = tessGetVertices(tessellator);
|
const TESSreal *vertices = tessGetVertices(tessellator);
|
||||||
@ -77,6 +87,8 @@ std::unique_ptr<Mesh> generateMesh(std::vector<Path> const &paths, std::unique_p
|
|||||||
mesh->triangles.push_back(indices[i]);
|
mesh->triangles.push_back(indices[i]);
|
||||||
}
|
}
|
||||||
return mesh;
|
return mesh;
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ float approximateBezierQuadraticLength(MeshGenerator::Point const &p0, MeshGener
|
|||||||
}
|
}
|
||||||
|
|
||||||
void tesselateBezier(MeshGenerator::Path &path, MeshGenerator::Point const &p1, MeshGenerator::Point const &p2, MeshGenerator::Point const &p3, MeshGenerator::Point const &p4, int level) {
|
void tesselateBezier(MeshGenerator::Path &path, MeshGenerator::Point const &p1, MeshGenerator::Point const &p2, MeshGenerator::Point const &p3, MeshGenerator::Point const &p4, int level) {
|
||||||
const float tessTol = 0.25f / 0.5f;
|
const float tessTol = 0.25f / 0.1f;
|
||||||
|
|
||||||
float x1 = p1.x;
|
float x1 = p1.x;
|
||||||
float y1 = p1.y;
|
float y1 = p1.y;
|
||||||
|
@ -124,8 +124,10 @@ final class ShapeRenderLayer: ShapeContainerLayer {
|
|||||||
for i in stride(from: (renderer.numberOfColors * 4), to: renderer.colors.endIndex, by: 2) {
|
for i in stride(from: (renderer.numberOfColors * 4), to: renderer.colors.endIndex, by: 2) {
|
||||||
let alpha = renderer.colors[i + 1]
|
let alpha = renderer.colors[i + 1]
|
||||||
var currentAlpha: CGFloat = 1.0
|
var currentAlpha: CGFloat = 1.0
|
||||||
gradientColors[alphaIndex].getRed(nil, green: nil, blue: nil, alpha: ¤tAlpha)
|
if alphaIndex < gradientColors.count {
|
||||||
gradientColors[alphaIndex] = gradientColors[alphaIndex].withAlphaComponent(alpha * currentAlpha)
|
gradientColors[alphaIndex].getRed(nil, green: nil, blue: nil, alpha: ¤tAlpha)
|
||||||
|
gradientColors[alphaIndex] = gradientColors[alphaIndex].withAlphaComponent(alpha * currentAlpha)
|
||||||
|
}
|
||||||
alphaIndex += 1
|
alphaIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user