- 用Reality Composer編輯物件『屬性』,勾選『物理效果』『加入』
- 將ARFrame.capturedImage轉成CVPixelBuffer
func session(_ session: ARSession, didUpdate frame: ARFrame) {
guard let arView = arView else {return}
// Do not enqueue other buffers for processing while another Vision task is still running.
// The camera stream has only a finite amount of buffers available; holding too many buffers for analysis would starve the camera.
guard currentBuffer == nil, case .normal = frame.camera.trackingState else {
return
}
// Retain the image buffer for Vision processing.
let currentBuffer = frame.capturedImage
}
- 利用Vision偵測食指
let requestHandler = VNImageRequestHandler(cvPixelBuffer: currentBuffer, orientation: orientation)
visionQueue.async {
do {
// Perform VNDetectHumanHandPoseRequest
try requestHandler.perform([self.handPoseRequest])
// Continue only when a hand was detected in the frame.
// Since we set the maximumHandCount property of the request to 1, there will be at most one observation.
guard let observation = self.handPoseRequest.results?.first else {
return
}
// Get points for index finger.
let indexFingerPoints = try observation.recognizedPoints(.indexFinger)
// Look for tip points.
guard let indexTipPoint = indexFingerPoints[.indexTip] else {
return
}
// Ignore low confidence points.
guard indexTipPoint.confidence > 0.3 else {
return
}
} catch {
print("Error: Vision request failed with error \"\(error)\"")
}
}
- 將Vision的座標轉成ARView的座標
// Convert points from Vision coordinates to ARView coordinates.
let point = indexTipPoint.location
let tip = CGPoint(x: point.x * width, y: (1 - point.y) * height)
2022年2月11日 星期五
RealityKit 判斷手指觸摸物件
2022年2月10日 星期四
RealityKit 判斷物件點擊方法2
- 用Reality Composer編輯物件『屬性』,勾選『物理效果』『加入』
- 替arView加上手勢功能
arView.addGestureRecognizer(
UITapGestureRecognizer(
target: xxxx,
action: #selector(XXXX.handleTap(recognizer:))
)
)
@objc func handleTap(recognizer: UITapGestureRecognizer) {
let tapLocation = recognizer.location(in: arView)
let entity = arView.entity(at: tapLocation)
guard entity == boxAnchor?.steelBox else { return }
// entity 即點擊物件
}
2021年8月25日 星期三
2019年5月2日 星期四
在Heroku上發佈MochiWeb
注意:
- 官方https://github.com/heroku/heroku-buildpack-erlang.git過舊(OTP和cebar),所以需要替代方案
- Heroku的port是亂數產生,所以需要動態拿到port
2018年7月20日 星期五
2018年6月7日 星期四
iOS hot reloading
1. 安裝
InjectionIII 並啟動
2. 打開 XCode 和 專案
3. 在appDelegate加入
PS.
已經秀出來的view並未改變。但是,新present出的view確實已經改變
如需要改變已秀出來的view,需在每個controller上實作
建議的懶人法
2. 打開 XCode 和 專案
3. 在appDelegate加入
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.z
#if DEBUG
#if targetEnvironment(simulator)
#if os(iOS)
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
#elseif os(tvOS)
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle")?.load()
#endif
#elseif os(macOS)
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle")?.load()
#endif
#endif
return true
}
PS.
已經秀出來的view並未改變。但是,新present出的view確實已經改變
如需要改變已秀出來的view,需在每個controller上實作
@objc func injected() {
// 可馬上更新的code
}
建議的懶人法
@objc func injected() {
// 移除全部vc/view
if self.childViewControllers.count > 0{
let viewControllers:[UIViewController] = self.childViewControllers
for viewContoller in viewControllers{
viewContoller.willMove(toParentViewController: nil)
viewContoller.view.removeFromSuperview()
viewContoller.removeFromParentViewController()
}
}
configureView()
}
func configureView() {
}
override func viewDidLoad() {
super.viewDidLoad()
configureView()
}
訂閱:
文章 (Atom)

