본문 바로가기

전체 글

(385)
[Metal] AR 얼굴인식 및 obj 렌더링 AR 환경에서 얼굴의 anchor 에 obj 파일을 렌더링 하는 내용을 다룬다. 다른 환경으로의 전달을 위해 별도의 렌더타겟을 만들고, CVPixelBuffer로 복사하는 방식 사용하며, 실제 뷰 렌더링은 다루지 않는다. 공유타입 #include typedef struct { matrix_float4x4 projectionMatrix; matrix_float4x4 viewMatrix; matrix_float4x4 modelMatrix; matrix_float3x3 normalMatrix; vector_float3 ambientLightColor; vector_float3 directionalLightDirection; vector_float3 directionalLightColor; float mater..
[Metal] Render to Texture 버텍스 let vertexData:[Float] = [ -1.0, -1.0, 0.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, ] 버퍼 let size = vertexData.count * MemoryLayout.size // var vertexBuffer:MTLBuffer vertexBuffer = device.makeBuffer(bytes: vertexData, length: size) vertexBuffer.label = "VertexBuffer" 렌더타겟용 텍스처 생성 렌더링에 사용할 텍스처는 MTKTextureLoader 등으로 별로 생성 let texDescriptor = MTLTextureDescriptor() t..
UIButton selected + highlighted image 버튼에 selected 상태의 이미지가 별도로 있는 경우 highlighted 이미지를 selected 이미지로 설정하기 override var isSelected: Bool { didSet { if isSelected { if let img = self.image(for: .selected) { self.setImage(img, for: UIControl.State.selected.union(.highlighted)) } } } }
CaptureSession 카메라, 마이크 var captureSession: AVCaptureSession! var videoPreviewLayer: AVCaptureVideoPreviewLayer! viewDidLoad 퍼미션 체크, 요청 switch AVCaptureDevice.authorizationStatus(for: .video) { case .notDetermined: break case .restricted: break case .denied: if let url = URL(string: UIApplication.openSettingsURLString) { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHa..
Codable for Dictionary extension Encodable { func getValue() throws -> [String:Any] { let data = try JSONEncoder().encode(self) if let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String:Any] { return dictionary } throw NSError() } } extension Decodable { func setValue(from: [String:Any] ) throws { let data = try JSONSerialization.data(withJSONObject: from, options: .prettyP..
[Python] 직접 실행과 import 시 실행 분리 직접실행하는 경우 __name__ 값은 '__main__' 값으로 지정되는데 이 값으로 직접 실행되었는지 import 되었는지를 체크할 수 있음. import 하는 경우 파일명(모듈명) import sys def main(): . . return 0 if __name__ == '__main__': sys.exit(main())
[WebRTC] 안드로이드 I420 Buffer관련 클래스 WebRTC 에서는 VideoFrame을 위해 TextureBuffer와 I420Buffer를 사용. I420Buffer는 Buffer 클래스를 상속받은 클래스이며, Buffer 는 네이티브(jni) 라이브러리에게 버퍼의 크기나 포인터를 알려주는 역할이며, I420Buffer는 YUV 포인터의 위치를 전달하는 역할을 하게된다. TextureBuffer 일반 rgb bitmap 이미지를 VideoFrame으로 변경하려면 대략 아래처럼 처리가 이루어진다. // 텍스처 생성 int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); // TextureBuffer 생성 Matrix transform = new Matrix(); YuvConverter ..
UITableView , UICollectionView 테이블뷰 UITableViewController 테이블뷰의 특정 기능에 대한 지원이 추가된 UIViewController 테이블뷰가 이미 생성되어 있음 정적 테이블 구성으로 스토리보드나 IB에서 디자인이 수월하나 변경에 제약이 많음 커스텀이 필요한경우 UIViewController에 UITableView을 추가해 사용 주요클래스 UITableView UITableViewCell UITableViewDelegate UITableViewDataSource cell class IB에서 클래스를 지정하고, Identity 를 지정한다. 해당 id는 datasource구현시 재사용큐에서 cell을 얻어올때 사용한다. class CustomCell : UITableViewCell { } 컨트롤러 class Test..