Exemplo n.º 1
0
 private void Awake()
 {
     //waterMesh = GetComponent<WaterMesh>();
     delaunayMesh  = GetComponent <DelaunayMesh>();
     wallPlacement = GetComponent <WallPlacement>();
     entireCSVData = CSV_extended.ParseCsvFileUsingResources(pathToCSV);
     generateMeshButton.interactable = true;
     informationCanvas.enabled       = false;
     settingsCanvas.enabled          = false;
     aRTransformationManager         = ARTransformationManager.Instance;
     aRLocationProvider = ARLocationProvider.Instance;
     DisableInformationText();
 }
Exemplo n.º 2
0
    private void CalculateClosestPointAndGenerateMesh()
    {
        if (wallPlacement.IsGroundPlaneSet())
        {
            // get device location
            var deviceLocation = aRLocationProvider.LastLocation;
            lastScannedPosition = aRCamera.transform.position;

            // get the points around the user
            var locationsToCreateMeshWith = CSV_extended.PointsWithinRadius(entireCSVData, radius, deviceLocation.ToLocation());

            // get the closest point
            closestPoint   = CSV_extended.ClosestPointGPS(locationsToCreateMeshWith, deviceLocation.ToLocation());
            heightAtCamera = (float)closestPoint.Height;
            //lastScannedHeight = heightAtCamera;

            Debug.Log("Height at camera:" + heightAtCamera);

            // Convert GPS data to local data.
            var localPositionsToGenerate = new List <Vector3>();

            //float currentWaterHeight = 0;
            foreach (var gpsLocation in locationsToCreateMeshWith)
            {
                var unityPosition = aRTransformationManager.GpsToArWorld(gpsLocation);

                // Om detta behövs senare sätt in det i en egen funktion
                float calculatedHeight = 0;

                float height                = (float)gpsLocation.Height;
                float waterheight           = (float)gpsLocation.WaterHeight;
                bool  insidebuilding        = gpsLocation.Building;
                float nearestneighborheight = (float)gpsLocation.NearestNeighborHeight;
                float nearestneighborwater  = (float)gpsLocation.NearestNeighborWater;

                if (insidebuilding)
                {
                    if (nearestneighborheight != -9999)
                    {
                        calculatedHeight = CalculateRelativeHeight(heightAtCamera, nearestneighborheight, nearestneighborwater);
                        //currentWaterHeight = nearestneighborwater;
                    }
                }
                else
                {
                    calculatedHeight = CalculateRelativeHeight(heightAtCamera, height, waterheight);
                    //currentWaterHeight = waterheight;
                }

                Debug.Log("Calculated height: " + calculatedHeight);

                unityPosition.y = calculatedHeight;
                localPositionsToGenerate.Add(unityPosition);
            }

            meshGenerated = GenerateMesh(localPositionsToGenerate);

            if (meshGenerated)
            {
                //EnableWallPlacementAndUpdateCurrentWater(currentWaterHeight);
                //EnableWallPlacement();
                wallPlacement.WaterMeshGenerated(true);
                wallPlacement.SetWallPlacementEnabled(true);
                Debug.Log("Wallplacement enabled");
                // Send data to wallplacement class for measuring stick calculations
                wallPlacement.SetCurrentGlobalLocalPositions(locationsToCreateMeshWith, localPositionsToGenerate);
                timeSinceLastCalculation = 0;
            }
        }
    }