void Update()
        {
            // demo: press space to modify existing point positions and colors
            // TODO should do exporting in another thread, now it hangs mainthread while processing
            if (Input.GetKeyDown(KeyCode.Space) && !isSaving)
            {
                isSaving = true;
                // assign export settings
                var importSettings = new ImportSettings();
                importSettings.batch        = false;
                importSettings.exportFormat = PointCloudConverter.Structs.ExportFormat.UCPC;
                var outputFile = Path.Combine(Application.streamingAssetsPath, "export.ucpc");
                importSettings.outputFile = outputFile;
                importSettings.packColors = false;
                importSettings.randomize  = false;
                importSettings.writer     = new UCPC();

                int pointCount = binaryViewerDX11.GetPointCount();
                importSettings.writer.InitWriter(importSettings, pointCount);

                // loop all points
                for (int i = 0, len = pointCount; i < len; i++)
                {
                    binaryViewerDX11.points[i]     += Random.insideUnitSphere * 0.25f;
                    binaryViewerDX11.pointColors[i] = new Vector3(1 - binaryViewerDX11.pointColors[i].x, 1 - binaryViewerDX11.pointColors[i].y, 1 - binaryViewerDX11.pointColors[i].z);

                    float x = binaryViewerDX11.points[i].x;
                    float y = binaryViewerDX11.points[i].y;
                    float z = binaryViewerDX11.points[i].z;
                    float r = binaryViewerDX11.pointColors[i].x;
                    float g = binaryViewerDX11.pointColors[i].y;
                    float b = binaryViewerDX11.pointColors[i].z;

                    importSettings.writer.AddPoint(i, x, y, z, r, g, b);
                }

                // update data to gpu
                binaryViewerDX11.UpdatePointData();
                binaryViewerDX11.UpdateColorData();

                Debug.Log("Saving file: " + outputFile);
                importSettings.writer.Save();

                isSaving = false;
            }
        }
Пример #2
0
        void Update()
        {
            // demo: press space to randomize new data
            if (Input.GetKeyDown(KeyCode.Space))
            {
                // generate random example dataset, instead of this, you would load/generate your own data
                var randomPoints = new Vector3[totalPoints];
                var randomColors = new Vector3[totalPoints];
                for (int i = 0; i < totalPoints; i++)
                {
                    randomPoints[i] = Random.insideUnitSphere * 15;
                    var c = Random.ColorHSV(0, 1, 0, 1, 0, 1);
                    randomColors[i] = new Vector3(c.r, c.g, c.b);
                }

                // after you have your own data, send them into viewer
                binaryViewerDX11.points = randomPoints;
                binaryViewerDX11.UpdatePointData();

                binaryViewerDX11.pointColors = randomColors;
                binaryViewerDX11.UpdateColorData();
            }
        }
        void Update()
        {
            // update area selection on F5
            if (Input.GetKeyDown(selectPointsKey))
            {
                // we need to keep track which clouds contributed into selection (since its possible to measure/select from multiple clouds)
                var uniqueClouds = new List <int>();

                if (createSeparateCloudFromSelection == true)
                {
                    // TODO clear previously generated cloud or just overwrite later?
                }
                else // use original points
                {
                    // first invert old selected point colors back to original (if we had something selected)
                    if (selectedPoints != null && selectedPoints.Count > 0)
                    {
                        for (int i = 0, len = selectedPoints.Count; i < len; i++)
                        {
                            var pdata      = selectedPoints[i];
                            int cloudIndex = pointCloudManager.clouds[pdata.cloudIndex].viewerIndex;
                            var c          = pointCloudManager.viewers[cloudIndex].pointColors[pdata.pointIndex];
                            // restore inverted colors
                            c.x = 1 - c.x;
                            c.y = 1 - c.y;
                            c.z = 1 - c.z;
                            pointCloudManager.viewers[cloudIndex].pointColors[pdata.pointIndex] = c;

                            // collect clouds that we need to refresh colors for
                            if (uniqueClouds.Contains(cloudIndex) == false)
                            {
                                uniqueClouds.Add(cloudIndex);
                            }
                        }
                    }
                }

                // collect area selection points (child objects of the root)
                var points = new List <Vector3>();
                foreach (Transform t in selectionRoot)
                {
                    points.Add(t.position);
                }

                // get selection results form BoxSelect
                selectedPoints = pointCloudManager.ConvexHullSelectPoints(gameObject, points);

                if (selectedPoints != null)
                {
                    Debug.Log("Selected " + selectedPoints.Count + " points");
                    if (createSeparateCloudFromSelection == true)
                    {
                        // build new cloud from selection points
                        var selectedPointsTemp = new Vector3[selectedPoints.Count];
                        for (int i = 0, len = selectedPoints.Count; i < len; i++)
                        {
                            var pdata      = selectedPoints[i];
                            int cloudIndex = pointCloudManager.clouds[pdata.cloudIndex].viewerIndex;
                            var p          = pointCloudManager.viewers[cloudIndex].points[pdata.pointIndex];
                            selectedPointsTemp[i] = p;
                        }

                        // create new cloud on temporary viewer
                        tempPointCloudViewerDX11.InitDX11Buffers();
                        tempPointCloudViewerDX11.points = selectedPointsTemp;
                        tempPointCloudViewerDX11.UpdatePointData();

                        // set custom color for points, NOTE should use special material/shader that uses fixed color AND zoffset?
                        tempPointCloudViewerDX11.cloudMaterial.SetColor("_Color", selectedPointColor);
                        // NOTE we take pointsize from first cloud only
                        //tempPointCloudViewerDX11.cloudMaterial.SetFloat("_Size", pointCloudManager.viewers[0].cloudMaterial.GetFloat("_Size"));
                    }
                    else // we are using original cloud points
                    {
                        for (int i = 0, len = selectedPoints.Count; i < len; i++)
                        {
                            // set point colors (but really would be faster to create new owndata cloud for those usually..)
                            var pdata = selectedPoints[i];

                            // get point index from that cloudo
                            int cloudIndex = pointCloudManager.clouds[pdata.cloudIndex].viewerIndex;

                            // TODO, if want to use custom color create new cloud or point mesh, otherwise invert color or swap colors
                            var c = pointCloudManager.viewers[cloudIndex].pointColors[pdata.pointIndex];
                            c.x = 1 - c.x;
                            c.y = 1 - c.y;
                            c.z = 1 - c.z;
                            pointCloudManager.viewers[cloudIndex].pointColors[pdata.pointIndex] = c;

                            // get list of unique clouds that we need to update
                            if (uniqueClouds.Contains(cloudIndex) == false)
                            {
                                uniqueClouds.Add(cloudIndex);
                            }
                        }
                    }
                }

                // refresh colors for each existing cloud
                foreach (int cloudIndex in uniqueClouds)
                {
                    pointCloudManager.viewers[cloudIndex].UpdateColorData();
                }
            }
        } // Update