ARkit初心者です。
現在UnityとXcodeを使い、水平面の他に垂直面の認識が出来ています。
そこで、タップして表示させる3Dオブジェクトを水平面と垂直面それぞれ別々のものを表示させたいと考えています。
どのようなプログラムの追加が必要になりますか?
C#
1using System; 2using System.Runtime.InteropServices; 3 4namespace UnityEngine.XR.iOS 5{ 6 public class UnityARUtility 7 { 8 private MeshCollider meshCollider; //declared to avoid code stripping of class 9 private MeshFilter meshFilter; //declared to avoid code stripping of class 10 private static GameObject planePrefab = null; 11 12 public static void InitializePlanePrefab(GameObject go) 13 { 14 planePrefab = go; 15 } 16 17 public static GameObject CreatePlaneInScene(ARPlaneAnchor arPlaneAnchor) 18{ 19 GameObject plane; 20 if (planePrefab != null) { 21 plane = GameObject.Instantiate(planePrefab); 22 } else { 23 plane = new GameObject (); 24 } 25 26 plane.name = arPlaneAnchor.identifier; 27 28 ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> (); 29 if (apmr != null) { 30 apmr.InitiliazeMesh (arPlaneAnchor); 31 } 32 33 // 平面の向きによって平面オブジェクトの色を変える 34 if(arPlaneAnchor.alignment == ARPlaneAnchorAlignment.ARPlaneAnchorAlignmentVertical) 35 { 36 plane.transform.Find("Plane").GetComponent<MeshRenderer>().material.color = new Color(1,1,0); 37 } 38 return UpdatePlaneWithAnchorTransform(plane, arPlaneAnchor); 39} 40 41 public static GameObject UpdatePlaneWithAnchorTransform(GameObject plane, ARPlaneAnchor arPlaneAnchor) 42 { 43 44 //do coordinate conversion from ARKit to Unity 45 plane.transform.position = UnityARMatrixOps.GetPosition (arPlaneAnchor.transform); 46 plane.transform.rotation = UnityARMatrixOps.GetRotation (arPlaneAnchor.transform); 47 48 ARKitPlaneMeshRender apmr = plane.GetComponent<ARKitPlaneMeshRender> (); 49 if (apmr != null) { 50 apmr.UpdateMesh (arPlaneAnchor); 51 } 52 53 54 MeshFilter mf = plane.GetComponentInChildren<MeshFilter> (); 55 56 if (mf != null) { 57 if (apmr == null) { 58 //since our plane mesh is actually 10mx10m in the world, we scale it here by 0.1f 59 mf.gameObject.transform.localScale = new Vector3 (arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f); 60 61 //convert our center position to unity coords 62 mf.gameObject.transform.localPosition = new Vector3(arPlaneAnchor.center.x,arPlaneAnchor.center.y, -arPlaneAnchor.center.z); 63 } 64 65 } 66 67 return plane; 68 } 69 } 70} 71 72
あなたの回答
tips
プレビュー