fix deprecation warnings for swift 5

This commit is contained in:
Volodymyr Boichentsov 2019-07-14 08:24:40 +03:00
parent 062712d951
commit 349582af8d
7 changed files with 30 additions and 116 deletions

View File

@ -127,37 +127,37 @@ extension GLTF {
var values = [Any]()
switch componentType {
case .BYTE:
values = data.int8Array
values = data.array() as [Int8]
break
case .UNSIGNED_BYTE:
values = data.uint8Array
values = data.array() as [UInt8]
break
case .SHORT:
values = data.int16Array
values = data.array() as [Int16]
break
case .UNSIGNED_SHORT:
values = data.uint16Array
values = data.array() as [UInt16]
break
case .UNSIGNED_INT:
values = data.uint32Array
values = data.array() as [UInt32]
break
case .FLOAT:
do {
switch type {
case .SCALAR:
values = data.floatArray
values = data.array() as [Float]
break
case .VEC2:
values = data.vec2Array
values = data.array() as [SCNVector2]
break
case .VEC3:
values = data.vec3Array
values = data.array() as [GLKVector3]
for i in 0..<values.count {
values[i] = SCNVector3FromGLKVector3(values[i] as! GLKVector3)
}
break
case .VEC4:
values = data.vec4Array
values = data.array() as [GLKVector4]
for i in 0..<values.count {
values[i] = SCNVector4FromGLKVector4(values[i] as! GLKVector4)
}
@ -167,7 +167,7 @@ extension GLTF {
case .MAT3:
break
case .MAT4:
values = data.mat4Array
values = data.array() as [GLKMatrix4]
for i in 0..<values.count {
values[i] = SCNMatrix4FromGLKMatrix4(values[i] as! GLKMatrix4)
}

View File

@ -124,11 +124,13 @@ extension GLTF {
for i in 0 ..< mipmapsCount {
let data = mipmaps[i]
let bPr = bppBlock(width, height)
data.withUnsafeBytes {
texture?.replace(region: MTLRegionMake2D(0, 0, width, height),
mipmapLevel: i,
withBytes: $0,
bytesPerRow: bPr)
data.withUnsafeBytes { (unsafeBufferPointer:UnsafeRawBufferPointer) in
if let unsafePointer = unsafeBufferPointer.bindMemory(to: UInt8.self).baseAddress {
texture?.replace(region: MTLRegionMake2D(0, 0, width, height),
mipmapLevel: i,
withBytes: unsafePointer,
bytesPerRow: bPr)
}
}
width = max(width >> 1, 1);

View File

@ -137,7 +137,7 @@ open class GLTFResourceLoaderDefault : GLTFResourceLoader {
throw "Can't find file at \(filepath)"
}
} else {
return (data == nil) ? nil : Data(bytes: [UInt8](data!))
return (data == nil) ? nil : Data([UInt8](data!))
}
return data
}

View File

@ -133,9 +133,7 @@ extension GLTF {
// Get dispatch group for current GLTF
let convertGroup = self.nodesDispatchGroup
convertGroup.enter()
// let geometryGroup = DispatchGroup()
if self.scenes != nil && self.scene != nil {
let sceneGlTF = self.scenes![(self.scene)!]
if let sceneName = sceneGlTF.name {

View File

@ -80,98 +80,9 @@ extension String {
}
extension Data {
var int8: Int8 {
return withUnsafeBytes { $0.pointee }
}
var uint8: UInt8 {
return withUnsafeBytes { $0.pointee }
}
var int16: Int16 {
return withUnsafeBytes { $0.pointee }
}
var uint16: UInt16 {
return withUnsafeBytes { $0.pointee }
}
var int32: Int32 {
return withUnsafeBytes { $0.pointee }
}
var uint32: UInt32 {
return withUnsafeBytes { $0.pointee }
}
var integer: Int {
return withUnsafeBytes { $0.pointee }
}
var uinteger: UInt {
return withUnsafeBytes { $0.pointee }
}
var float: Float {
return withUnsafeBytes { $0.pointee }
}
var double: Double {
return withUnsafeBytes { $0.pointee }
}
var vec2: SCNVector2 {
return withUnsafeBytes { $0.pointee }
}
var vec3: SCNVector3 {
return withUnsafeBytes { $0.pointee }
}
var vec4: SCNVector4 {
return withUnsafeBytes { $0.pointee }
}
var int8Array: [Int8] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<Int8>(start: $0, count: self.count/MemoryLayout<Int8>.size))
}
}
var uint8Array: [UInt8] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<UInt8>(start: $0, count: self.count/MemoryLayout<UInt8>.size))
}
}
var int16Array: [Int16] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<Int16>(start: $0, count: self.count/MemoryLayout<Int16>.size))
}
}
var uint16Array: [UInt16] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<UInt16>(start: $0, count: self.count/MemoryLayout<UInt16>.size))
}
}
var int32Array: [Int32] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<Int32>(start: $0, count: self.count/MemoryLayout<Int32>.size))
}
}
var uint32Array: [UInt32] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<UInt32>(start: $0, count: self.count/MemoryLayout<UInt32>.size))
}
}
var floatArray: [Float] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<Float>(start: $0, count: self.count/MemoryLayout<Float>.size))
}
}
var vec2Array: [GLKVector2] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<GLKVector2>(start: $0, count: self.count/MemoryLayout<GLKVector2>.size))
}
}
var vec3Array: [GLKVector3] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<GLKVector3>(start: $0, count: self.count/MemoryLayout<GLKVector3>.size))
}
}
var vec4Array: [GLKVector4] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<GLKVector4>(start: $0, count: self.count/MemoryLayout<GLKVector4>.size))
}
}
var mat4Array: [GLKMatrix4] {
return withUnsafeBytes {
Array(UnsafeBufferPointer<GLKMatrix4>(start: $0, count: self.count/MemoryLayout<GLKMatrix4>.size))
func array<Type>() -> [Type] {
return withUnsafeBytes { (unsafeBufferPointer:UnsafeRawBufferPointer) -> [Type] in
Array(UnsafeBufferPointer<Type>(start: unsafeBufferPointer.bindMemory(to: Type.self).baseAddress, count: self.count/MemoryLayout<Type>.size))
}
}
}

View File

@ -19,10 +19,13 @@ class gltf_scenekitTests: XCTestCase {
self.measure {
let glTF = try? decoder.decode(GLTF.self, from: jsonData!)
_ = glTF?.convert(renderer:view, directoryPath:nil, multiThread:false)
_ = glTF?.convert(renderer:view, directoryPath:nil, multiThread:false, geometryCompletionHandler: {
})
}
let jsonDataArray = jsonData!.array() as [UInt8]
// XCTAssert(glTF != nil)

View File

@ -951,7 +951,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.12;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -999,7 +999,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MACOSX_DEPLOYMENT_TARGET = 10.12;
OTHER_CFLAGS = "-fembed-bitcode";
OTHER_SWIFT_FLAGS = "-DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
@ -1085,7 +1085,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Draco";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.12;
OTHER_LDFLAGS = (
"$(inherited)",
"-lc++",
@ -1120,7 +1120,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(TOOLCHAIN_DIR)/usr/lib/swift/macosx";
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Draco";
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.12;
OTHER_LDFLAGS = (
"$(inherited)",
"-lc++",