SHARE
TWEET

Untitled

a guest Sep 19th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ARKit;
  2.  
  3.  
  4. //#import "CodableUtils.h"
  5.  
  6. class CodableUtils : NSObject {
  7.  
  8.     class func convertSimdFloat3ToString(vector:simd_float3) -> String {
  9.         return String(format:"%f %f %f", vector[0], vector[1], vector[2])
  10.     }
  11.  
  12.     class func convertSimdFloat4x4ToString(matrix:simd_float4x4) -> String {
  13.         let ret:NSMutableString = NSMutableString(capacity:0)
  14.         for var i:Int=0 ; i< 4 ; i++ {  
  15.             for var j:Int=0 ; j< 4 ; j++ {  
  16.                 ret.appendString(String(format:"%f ", matrix.columns[i][j]))
  17.              }
  18.          }
  19.         return ret
  20.     }
  21.  
  22.     class func convertARAnchorToDictionary(anchor:ARAnchor) -> NSDictionary {
  23.         let params:NSMutableDictionary = ["identifier": anchor.identifier.UUIDString(),
  24.                                                                "transform": CodableUtils.convertSimdFloat4x4ToString(anchor.transform)
  25.                                                                ].mutableCopy()
  26.         if anchor.isMemberOfClass(ARPlaneAnchor.self) {
  27.             let plane:ARPlaneAnchor = anchor
  28.             params.setObject("planeAnchor", forKey:"anchorType")
  29.             params.setObject(CodableUtils.convertSimdFloat3ToString(plane.center), forKey:"center")
  30.             params.setObject(CodableUtils.convertSimdFloat3ToString(plane.extent), forKey:"extent")
  31.         }
  32.         if anchor.isMemberOfClass(ARImageAnchor.self) {
  33.             let image:ARImageAnchor = anchor
  34.             params.setObject("imageAnchor", forKey:"anchorType")
  35.             params.setObject(image.referenceImage.name, forKey:"referenceImageName")
  36.         }
  37.         if anchor.isMemberOfClass(ARFaceAnchor.self) {
  38.             params.setObject("faceAnchor", forKey:"anchorType")
  39.             let faceAnchor:ARFaceAnchor = anchor
  40.             params.setObject(CodableUtils.convertSimdFloat4x4ToString(faceAnchor.leftEyeTransform), forKey:"leftEyeTransform")
  41.             params.setObject(CodableUtils.convertSimdFloat4x4ToString(faceAnchor.rightEyeTransform), forKey:"rightEyeTransform")
  42.             params.setObject(faceAnchor.blendShapes, forKey:"blendShapes")
  43.         }
  44.         return params
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top