예제 #1
0
        public void GenerateHull()
        {
            localPositionList = new List <Vector3>();
            positionList      = new List <Vector3>();

            pointList = new List <GameObject>();
            List <int> indices = new List <int>();

            foreach (var kvp in VRObjectsDict)
            {
                pointList.Add(kvp.Value.gameObject);
                localPositionList.Add(kvp.Value.transform.localPosition);
                positionList.Add(kvp.Value.transform.position);
            }

            if (VRObjectsDict.Count == 1)
            {
                if (!gameObject.GetComponent <CloudChildConvexHull>())
                {
                    gameObject.AddComponent <CloudChildConvexHull>();
                }
                gameObject.GetComponent <CloudChildConvexHull>().id = id;
                Debug.Log(gameObject.GetComponent <CloudChildConvexHull>().id);
                gameObject.AddComponent <BoxCollider>();
            }

            if (VRObjectsDict.Count == 3)
            {
                GetComponent <BoxCollider>().enabled = false;

                mesh = new Mesh();
                foreach (var kvp in VRObjectsDict)
                {
                    indices.Add(kvp.Key);
                    foreach (var kvp2 in VRObjectsDict)
                    {
                        if (kvp2.Key != kvp.Key)
                        {
                            indices.Add(kvp2.Key);
                        }
                    }
                }
                meshrenderer.material = new Material(Shader.Find("Standard"));
                mesh.vertices         = localPositionList.ToArray();
                mesh.SetIndices(indices.ToArray(), MeshTopology.Lines, 0);

                meshfilter.mesh = mesh;
            }
            if (VRObjectsDict.Count >= 4)
            {
                convexhull              = new ConvexHull();
                convexhull.pointList    = pointList;
                convexhull.positionList = localPositionList;
                Mesh mesh = convexhull.CreateMesh();
                meshfilter.mesh = mesh;

                if (!GetComponent <PointSelectorConvexHull>())
                {
                    gameObject.AddComponent <PointSelectorConvexHull>();
                }
                //GetComponent<PointSelectorConvexHull>().creator = this;

                if (!GetComponent <MeshCollider>())
                {
                    gameObject.AddComponent <MeshCollider>();
                    //selector.GetComponent<MeshCollider>().convex = true;
                    //selector.GetComponent<MeshCollider>().isTrigger = true;
                }

                GetComponent <PointSelectorConvexHull>().hullFaces        = convexhull.faces;
                GetComponent <PointSelectorConvexHull>().hullPointList    = pointList;
                GetComponent <PointSelectorConvexHull>().hullPositionList = positionList;
                GetComponent <PointSelectorConvexHull>().findPointsInsideHull();
            }
        }