HelloARの中身をあさる その1
うえから順にみてこー
ARCoreDevice
UnityシーンでARCore セッションを管理するコンポーネント
そのまますぎる
なんだか Session Config ってのから設定値とってARの設定をうんたらかんたらするやつらしい
ARCoreSessionConfig
MatchCameraFramerate
チェックつけると"デバイスのカメラフレームレートにあわせて"、Unity側のフレームレートを遅延させるPlaneFindingMode
使用する平面検索モードを選択します。
水平だけ、垂直だけ、両方、無効 のいずれかを設定する
EnableLightEstimation
環境光推定のOn/Off
簡単に、暗くなったらARもそれにあわせて暗くなるよ、みたいなことらしい
これについてはこんど「Environment Light」といっしょにみてくEnableCloudAnchor
クラウドアンカーをつかうかどうか
HelloARではfalse
だった
なんでも、アプリで生成したアンカーをネットワークを介して他のユーザーと共有できるものらしい
なんかおもしろそうなので今度触ってみたい!!
inon29.hateblo.jp
AugmentedImageDatabase
AugmentedImageDatabase をつかうかどうか、なんだけど
こいつについてはしょうみよくわからなかったのでもうちょっと調査が必要、、、CameraFocusMode 固定か、オートフォーカスか
まぁもろもろのAR設定をするやつだな、うん
HelloARController
HelloARController.csより抜粋
タップからオブジェクト生成まで
// If the player has not touched the screen, we are done with this update. Touch touch; if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { return; } // Should not handle input if the player is pointing on UI. if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { return; } // Raycast against the location the player touched to search for planes. TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit)) { // Use hit pose and camera pose to check if hittest is from the // back of the plane, if it is, no need to create the anchor. if ((hit.Trackable is DetectedPlane) && Vector3.Dot(FirstPersonCamera.transform.position - hit.Pose.position, hit.Pose.rotation * Vector3.up) < 0) { Debug.Log("Hit at back of the current DetectedPlane"); } else { if (DepthMenu != null) { // Show depth card window if necessary. DepthMenu.ConfigureDepthBeforePlacingFirstAsset(); } // Choose the prefab based on the Trackable that got hit. GameObject prefab; if (hit.Trackable is FeaturePoint) { prefab = GameObjectPointPrefab; } else if (hit.Trackable is DetectedPlane) { DetectedPlane detectedPlane = hit.Trackable as DetectedPlane; if (detectedPlane.PlaneType == DetectedPlaneType.Vertical) { prefab = GameObjectVerticalPlanePrefab; } else { prefab = GameObjectHorizontalPlanePrefab; } } else { prefab = GameObjectHorizontalPlanePrefab; } // Instantiate prefab at the hit pose. var gameObject = Instantiate(prefab, hit.Pose.position, hit.Pose.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. // camera). gameObject.transform.Rotate(0, k_PrefabRotation, 0, Space.Self); // Create an anchor to allow ARCore to track the hitpoint as understanding of // the physical world evolves. var anchor = hit.Trackable.CreateAnchor(hit.Pose); // Make game object a child of the anchor. gameObject.transform.parent = anchor.transform; } } }
座標取得箇所
TrackableHit hit;
TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon |
TrackableHitFlags.FeaturePointWithSurfaceNormal;
if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
{
Frame.Raycast
関数
タップしたとこが平面(ARCoreで検知した)であればtrue
を返しその座標をhit
に代入することで座標を取得でき
取得した座標にオブジェクトを配置することで平面上に物がおかれているようにみえるってことだーね
PlaneGenerator
平面検出時に表示する格子状のやつ
↓これね
あきたのでいったんおわり!のこりは その2でやろうそうしよう