void MyARAnchorAdded(ARPlaneAnchor anchorData) //若成功识别出新平面,则: { _generatePlane.SendMessage("AdjustPlane", anchorData); height_y = UnityARMatrixOps.GetPosition(anchorData.transform).y; //height_y = FindPlaneHeight(anchorData); // Debug.Log("add"); //GameObject test = Instantiate(testObj, UnityARMatrixOps.GetPosition(anchorData.transform), new Quaternion(0f, 0f, 0f, 0f)); //planeIdentifier = anchorData.identifier; //_string = planeIdentifier + "/Plane"; //StartCoroutine(Test(anchorData)); //ShowPlane(); //Debug.Log("add "+UnityARMatrixOps.GetPosition(anchorData.transform)); if (!isARReady) { //音效 currentObj = GameObject.Instantiate(obj) as GameObject; currentObj.transform.position = UnityARMatrixOps.GetPosition(anchorData.transform); //Debug.Log(currentObj.transform.position); currentObj.transform.LookAt(new Vector3(Camera.main.transform.position.x, currentObj.transform.position.y, Camera.main.transform.position.z)); //MainChatBox.SetActive(true); MainChatBox.GetComponentInChildren <Text>().text = "你成功召唤了我!请告诉我,你想去哪里呀?"; GameObject.Find("UserInput").SendMessage("ShowInputField"); //currentObj.transform.parent = GameObject.FindWithTag("YCtrl").transform; isARReady = true; } if (isARReady)//跟随模式要用 { RayStart.x = Screen.width / 2; RayStart.y = Screen.height / 2; RayStart.z = 0; ray = Camera.main.ScreenPointToRay(RayStart); if (Physics.Raycast(ray, out hit)) { targetPos = hit.point; } else { targetPos = UnityARMatrixOps.GetPosition(anchorData.transform); } } }
public void CheckIfObjectShouldMoveOntoPlane(ARPlaneAnchor anchor, SCNNode planeAnchorNode) { foreach (var vo in VirtualObjects) { // Get the object's position in the plane's coordinate system. var objectPos = planeAnchorNode.ConvertPositionToNode(vo.Position, vo.ParentNode); if (Math.Abs(objectPos.Y) < float.Epsilon) { return; // The object is already on the plane - nothing to do here. } // Add 10% tolerance to the corners of the plane. var tolerance = 0.1f; var minX = anchor.Center.X - anchor.Extent.X / 2f - anchor.Extent.X * tolerance; var maxX = anchor.Center.X + anchor.Extent.X / 2f + anchor.Extent.X * tolerance; var minZ = anchor.Center.Z - anchor.Extent.Z / 2f - anchor.Extent.Z * tolerance; var maxZ = anchor.Center.Z + anchor.Extent.Z / 2f + anchor.Extent.Z * tolerance; if (objectPos.X < minX || objectPos.X > maxX || objectPos.Z < minZ || objectPos.Z > maxZ) { return; } // Drop the object onto the plane if it is near it. var verticalAllowance = 0.05f; var epsilon = 0.001; // Do not bother updating if the difference is less than a mm. var distanceToPlane = Math.Abs(objectPos.Y); if (distanceToPlane > epsilon && distanceToPlane < verticalAllowance) { Delegate.DidMoveObjectOntoNearbyPlane(this, vo); SCNTransaction.Begin(); SCNTransaction.AnimationDuration = distanceToPlane * 500; // Move 2mm per second SCNTransaction.AnimationTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut); vo.Position = new SCNVector3(vo.Position.X, anchor.Transform.M32, vo.Position.Z); SCNTransaction.Commit(); } } }
GameObject UpdatePlane(GameObject plane, ARPlaneAnchor arPlaneAnchor) { plane.transform.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform); plane.transform.rotation = UnityARMatrixOps.GetRotation(arPlaneAnchor.transform); MeshFilter mf = plane.GetComponentInChildren <MeshFilter>(); if (mf != null) { mf.gameObject.transform.localScale = new Vector3( arPlaneAnchor.extent.x * 0.1f, arPlaneAnchor.extent.y * 0.1f, arPlaneAnchor.extent.z * 0.1f); mf.gameObject.transform.localPosition = new Vector3( arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z); } return(plane); }
public override SCNNode CreateARPlaneNode(ARPlaneAnchor anchor, UIColor color) { Console.WriteLine($"ADD: {anchor.Alignment}, {anchor.Extent}"); var material = new SCNMaterial(); material.Diffuse.Contents = color; var geometry = ARSCNPlaneGeometry.Create(SCNView.Device); geometry.FirstMaterial = material; geometry.Update(anchor.Geometry); var planeNode = new SCNNode { Geometry = geometry, Position = new SCNVector3(anchor.Center.X, -.015f, anchor.Center.Z), PhysicsBody = CreatePlanePhysics(geometry) }; return(planeNode); }
public void PlaceOnAnchor(ARPlaneAnchor anchor) { Debug.Log("Anchor Values: " + "Pos: " + UnityARMatrixOps.GetPosition(anchor.transform)); Debug.Log("anchor placed"); var pos = UnityARMatrixOps.GetPosition(anchor.transform); var rot = UnityARMatrixOps.GetRotation(anchor.transform); var portal = Instantiate(_portalParent); portal.transform.position = pos; portal.transform.rotation = rot; var child = portal.GetComponentInChildren <Transform>(); child.localPosition = anchor.center; //var rot = UnityARMatrixOps.GetRotation(anchor.transform); //rot.eulerAngles = new Vector3(rot.x, rot.y + 180f, rot.z); //child.rotation = rot; }
void GetLargestPlane() { List <ARPlaneAnchorGameObject> arpags = unityARAnchorManager.GetCurrentPlaneAnchors(); if (arpags.Count > 0) { if (mainPlane.Equals(default(ARPlaneAnchor))) { mainPlane = arpags[0].planeAnchor; Debug.Log("mainPlane was set"); } foreach (ARPlaneAnchorGameObject argo in arpags) { //If there's a larger plane, update the mainPlane as the larger one if (argo.planeAnchor.extent.sqrMagnitude > mainPlane.extent.sqrMagnitude) { mainPlane = argo.planeAnchor; Debug.Log("Larger mainPlane was replaced"); } } } }
public void UpdateMesh(ARPlaneAnchor arPlaneAnchor) { if (UnityARSessionNativeInterface.IsARKit_1_5_Supported()) //otherwise we cannot access planeGeometry { if (arPlaneAnchor.planeGeometry.vertices.Length != planeMesh.vertices.Length || arPlaneAnchor.planeGeometry.textureCoordinates.Length != planeMesh.uv.Length || arPlaneAnchor.planeGeometry.triangleIndices.Length != planeMesh.triangles.Length) { planeMesh.Clear(); } planeMesh.vertices = arPlaneAnchor.planeGeometry.vertices; planeMesh.uv = arPlaneAnchor.planeGeometry.textureCoordinates; planeMesh.triangles = arPlaneAnchor.planeGeometry.triangleIndices; lineRenderer.positionCount = arPlaneAnchor.planeGeometry.boundaryVertexCount; lineRenderer.SetPositions(arPlaneAnchor.planeGeometry.boundaryVertices); // Assign the mesh object and update it. planeMesh.RecalculateBounds(); planeMesh.RecalculateNormals(); } }
void AddPlaneNode(ARPlaneAnchor anchor, SCNNode node, NSObject contents) { var geometry = SCNPlane.Create(anchor.Extent.X, anchor.Extent.Z); var material = geometry.Materials.FirstOrDefault() ?? throw new Exception(); switch (contents) { case SCNProgram program: material.Program = program; break; default: material.Diffuse.Contents = contents; break; } var planeNode = SCNNode.FromGeometry(geometry); SceneKit.SCNMatrix4.CreateFromAxisAngle(new SCNVector3(1, 0, 0), (float)(-Math.PI / 2.0), out var m4); planeNode.Transform = m4; DispatchQueue.MainQueue.DispatchAsync(() => node.AddChildNode(planeNode)); }
public static GameObject CreatePlaneInScene(ARPlaneAnchor arPlaneAnchor) { GameObject plane; if (planePrefab != null) { plane = GameObject.Instantiate(planePrefab); } else { plane = new GameObject(); //put in a blank gameObject to get at least a transform to manipulate } plane.name = arPlaneAnchor.identifier; PlacenotePlaneMeshRender ppmr = plane.GetComponent <PlacenotePlaneMeshRender>(); if (ppmr != null) { ppmr.InitiliazeMesh(arPlaneAnchor); } return(UpdatePlaneWithAnchorTransform(plane, arPlaneAnchor)); }
private void UpdateAnchor(ARPlaneAnchor _anchor) { Debug.Assert(_anchor != null); OnPlaneUpdated(GetTrackedPlane(_anchor)); }
// Please import Unity ARKit Plugin if you are seeing a compiler error here. void UpdateMapPositionWithAnchor(ARPlaneAnchor arPlaneAnchor) { //Setting the position of our map to match the position of anchor wrldMapParent.position = UnityARMatrixOps.GetPosition(arPlaneAnchor.transform); }
public void UpdateAnchor(ARPlaneAnchor anchor) { this.anchor = anchor; UnityARUtility.UpdatePlaneWithAnchorTransform(planeObject, anchor); }
private void PlanesFound(ARPlaneAnchor anchorData) { instructionText.text = "Plane detected!! Now place portal to the room of your choice and shoot a ball."; // User instruction to notify users about placing the portal after plane detection }
void AddAnchor(ARPlaneAnchor anchorData) { UnityARSessionNativeInterface.ARAnchorAddedEvent -= AddAnchor; _isStable = true; AddNode(_target.localPosition); }
public static Quaternion GetRotation(ARPlaneAnchor planeAnchor) { return(UnityARMatrixOps.GetRotation(planeAnchor.transform)); }
public static Vector3 GetPosition(ARPlaneAnchor planeAnchor) { return(UnityARMatrixOps.GetPosition(planeAnchor.transform)); }
//void ShowPlane(){ // Centerpos.transform.position=lastPlane.center; // Apos.transform.position = lastPlane.center+new Vector3(lastPlane.xhalf, 0,lastPlane.zhalf); // Bpos.transform.position = lastPlane.center+ new Vector3(lastPlane.xhalf, 0, -lastPlane.zhalf); // Cpos.transform.position = lastPlane.center+ new Vector3(-lastPlane.xhalf, 0, lastPlane.zhalf); // Dpos.transform.position = lastPlane.center+ new Vector3(-lastPlane.xhalf, 0, -lastPlane.zhalf); // } public float FindPlaneHeight(ARPlaneAnchor anchorData) { float _y = UnityARMatrixOps.GetPosition(anchorData.transform).y; return(_y); }
private void RemoveAnchor(ARPlaneAnchor _anchor) { Debug.Assert(_anchor != null); OnPlaneRemoved(GetTrackedPlane(_anchor)); }
public void OnPlaneRemoved(ARPlaneAnchor anchor) { Destroy(_storedPlaneAnchors[anchor.identifier].planeObject); _storedPlaneAnchors.Remove(anchor.identifier); }
private void RemoveARPlane(ARPlaneAnchor arPlane) { _arPlaneAligmentMapping.Remove(arPlane.identifier); }
private void AddARPlane(ARPlaneAnchor arPlane) { _arPlaneAligmentMapping[arPlane.identifier] = arPlane.alignment; }
private void AnchorAdded(ARPlaneAnchor arPlaneAnchor) { planeFound = true; }
private Vector3 GetWorldPosition(ARPlaneAnchor arPlaneAnchor) { return(UnityARMatrixOps.GetPosition(arPlaneAnchor.transform) + new Vector3(arPlaneAnchor.center.x, arPlaneAnchor.center.y, -arPlaneAnchor.center.z)); }
private void AddAnchor(ARPlaneAnchor arPlaneAnchor) { OnPlaneAdded(GetBoundedPlane(arPlaneAnchor)); }
public void AddAnchor(ARPlaneAnchor arPlaneAnchor) { planeAnchorMap.Add(arPlaneAnchor.identifier, arPlaneAnchor); }
private void RemoveAnchor(ARPlaneAnchor arPlaneAnchor) { OnPlaneRemoved(GetBoundedPlane(arPlaneAnchor)); }
public PlaneNode(ARPlaneAnchor planeAnchor) { Geometry = (planeGeometry = CreateGeometry(planeAnchor)); Position = new SCNVector3(0, -PlaneHeight / 2, 0); PhysicsBody = SCNPhysicsBody.CreateKinematicBody(); }
private void UpdateAnchor(ARPlaneAnchor arPlaneAnchor) { OnPlaneUpdated(GetBoundedPlane(arPlaneAnchor)); }
public void InitiliazeMesh(ARPlaneAnchor arPlaneAnchor) { planeMesh = new Mesh(); UpdateMesh(arPlaneAnchor); meshFilter.mesh = planeMesh; }
public static void VirtualAnchor(string color, ARPlaneAnchor planeAnchor) { GameObject sphere = createSphere(color, PlaneTools.GetRealPosition(planeAnchor)); sphere.GetComponent <Renderer>().material.color = getColor(color); }