mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-08 12:24:39 +00:00
Update API
This commit is contained in:
@@ -20,4 +20,14 @@ typedef struct MeshTransformMeshVertex {
|
||||
MeshTransformPoint3D to;
|
||||
} MeshTransformMeshVertex;
|
||||
|
||||
@protocol MeshTransformClass <NSObject>
|
||||
|
||||
- (id)meshTransformWithVertexCount:(NSUInteger)vertexCount
|
||||
vertices:(MeshTransformMeshVertex *)vertices
|
||||
faceCount:(NSUInteger)faceCount
|
||||
faces:(MeshTransformMeshFace *)faces
|
||||
depthNormalization:(NSString *)depthNormalization;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
@@ -623,6 +623,5 @@ public func generateGlassMeshFromDisplacementMap(
|
||||
endAngle: .pi / 2
|
||||
)
|
||||
|
||||
transform.subdivisionSteps = 0
|
||||
return (mesh: transform, wireframe: wireframe)
|
||||
}
|
||||
|
||||
@@ -45,6 +45,27 @@ private func invokeTransformCreateMethod() -> NSObject? {
|
||||
}
|
||||
}
|
||||
|
||||
private var cachedTransformCreateCustomMethod: (@convention(c) (AnyObject, Selector, _ vertexCount: UInt, _ vertices: UnsafeMutablePointer<MeshTransformMeshVertex>, _ faceCount: UInt, _ faces: UnsafeMutablePointer<MeshTransformMeshFace>, _ depthNormalization: NSString) -> NSObject?, Selector)?
|
||||
private func invokeTransformCreateCustomMethod(vertexCount: UInt, vertices: UnsafeMutablePointer<MeshTransformMeshVertex>, faceCount: UInt, faces: UnsafeMutablePointer<MeshTransformMeshFace>, depthNormalization: String) -> NSObject? {
|
||||
guard let transformClass = transformClass else {
|
||||
return nil
|
||||
}
|
||||
if let cachedTransformCreateCustomMethod {
|
||||
return cachedTransformCreateCustomMethod.0(transformClass, cachedTransformCreateCustomMethod.1, vertexCount, vertices, faceCount, faces, depthNormalization as NSString)
|
||||
} else {
|
||||
let selectorName = ("meshTransf" as NSString).appending("ormWithVertexCount:vertices:faceCount:faces:depthNormalization:")
|
||||
|
||||
let method: (@convention(c) (AnyObject, Selector, _ vertexCount: UInt, _ vertices: UnsafeMutablePointer<MeshTransformMeshVertex>, _ faceCount: UInt, _ faces: UnsafeMutablePointer<MeshTransformMeshFace>, _ depthNormalization: NSString) -> NSObject?)? = getMethod(object: transformClass, selector: selectorName)
|
||||
if let method {
|
||||
let selector = NSSelectorFromString(selectorName)
|
||||
cachedTransformCreateCustomMethod = (method, selector)
|
||||
return method(transformClass, selector, vertexCount, vertices, faceCount, faces, depthNormalization as NSString)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var cachedTransformAddFaceMethod: (@convention(c) (AnyObject, Selector, MeshTransformMeshFace) -> Void, Selector)?
|
||||
private func invokeTransformAddFaceMethod(object: NSObject, face: MeshTransformMeshFace) {
|
||||
if let cachedTransformAddFaceMethod {
|
||||
@@ -97,44 +118,31 @@ public final class MeshTransform {
|
||||
private var vertices: ContiguousArray<Vertex> = []
|
||||
private var faces: ContiguousArray<Face> = []
|
||||
|
||||
public var subdivisionSteps: Int = -1 {
|
||||
didSet {
|
||||
/*if self.subdivisionSteps != oldValue, let value {
|
||||
invokeTransformSetSubdivisionStepsMethod(object: value, value: self.subdivisionSteps)
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func add(_ vertex: Vertex) {
|
||||
/*if let value = self.value {
|
||||
invokeTransformAddVertexMethod(object: value, vertex: vertex)
|
||||
}*/
|
||||
self.vertices.append(vertex)
|
||||
}
|
||||
|
||||
public func add(_ face: Face) {
|
||||
/*if let value = self.value {
|
||||
invokeTransformAddFaceMethod(object: value, face: face)
|
||||
}*/
|
||||
self.faces.append(face)
|
||||
}
|
||||
|
||||
public consuming func makeValue() -> Value? {
|
||||
guard let transformClass else {
|
||||
return nil
|
||||
}
|
||||
let value = unsafeBitCast(transformClass, to: MeshTransformClass.self)
|
||||
let result = self.vertices.withUnsafeMutableBufferPointer { vertices -> NSObject? in
|
||||
return self.faces.withUnsafeMutableBufferPointer { faces -> NSObject? in
|
||||
let result = value.meshTransform(withVertexCount: UInt(vertices.count), vertices: vertices.baseAddress!, faceCount: UInt(faces.count), faces: faces.baseAddress!, depthNormalization: "none")
|
||||
return result as? NSObject
|
||||
return invokeTransformCreateCustomMethod(
|
||||
vertexCount: UInt(vertices.count),
|
||||
vertices: vertices.baseAddress!,
|
||||
faceCount: UInt(faces.count),
|
||||
faces: faces.baseAddress!,
|
||||
depthNormalization: "none"
|
||||
)
|
||||
}
|
||||
}
|
||||
if let result {
|
||||
invokeTransformSetSubdivisionStepsMethod(object: result, value: self.subdivisionSteps)
|
||||
invokeTransformSetSubdivisionStepsMethod(object: result, value: 0)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user