Swiftgram/Tests/LottieMesh/Sources/ViewController.swift
2021-11-20 17:20:37 +04:00

37 lines
1.5 KiB
Swift

import Foundation
import UIKit
import LottieMeshSwift
import Postbox
public final class ViewController: UIViewController {
override public func viewDidLoad() {
super.viewDidLoad()
TempBox.initializeShared(basePath: NSTemporaryDirectory(), processType: "test", launchSpecificId: Int64.random(in: Int64.min ..< Int64.max))
self.view.backgroundColor = .black
let path = Bundle.main.path(forResource: "Fireworks", ofType: "json")!
//let path = Bundle.main.path(forResource: "Cat", ofType: "json")!
/*for _ in 0 ..< 100 {
let _ = generateMeshAnimation(data: try! Data(contentsOf: URL(fileURLWithPath: path)))!
}*/
if #available(iOS 13.0, *) {
let startTime = CFAbsoluteTimeGetCurrent()
let animationFile = generateMeshAnimation(data: try! Data(contentsOf: URL(fileURLWithPath: path)))!
print("Time: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0)")
let buffer = MeshReadBuffer(data: try! Data(contentsOf: URL(fileURLWithPath: animationFile.path)))
let animation = MeshAnimation.read(buffer: buffer)
let renderer = MeshRenderer(wireframe: true)!
renderer.frame = CGRect(origin: CGPoint(x: 0.0, y: 50.0), size: CGSize(width: 300.0, height: 300.0))
self.view.addSubview(renderer)
renderer.add(mesh: animation, offset: CGPoint(), loop: true)
}
}
}