コード例 #1
0
        //-----------------------------------------------------------------------------------
        private void GetFieldLocators(CNFieldController fieldController, out Vector3[] arrLocations)
        {
            GameObject[] gameObjects = fieldController.GetUnityGameObjects();

            List <Vector3> listLocatorPosition = new List <Vector3>();

            switch (Data.CreationMode)
            {
            case CNJointGroups.CreationModeEnum.AtLocatorsPositions:
                for (int i = 0; i < gameObjects.Length; i++)
                {
                    Transform tr = gameObjects[i].transform;
                    if (tr.childCount == 0)
                    {
                        listLocatorPosition.Add(tr.position);
                    }
                }
                break;

            case CNJointGroups.CreationModeEnum.AtLocatorsBBoxCenters:
                for (int i = 0; i < gameObjects.Length; ++i)
                {
                    Renderer renderer = gameObjects[i].GetComponent <Renderer>();
                    if (renderer != null)
                    {
                        Bounds bbox = renderer.bounds;
                        listLocatorPosition.Add(bbox.center);
                    }
                }
                break;

            case CNJointGroups.CreationModeEnum.AtLocatorsVertexes:
                for (int i = 0; i < gameObjects.Length; ++i)
                {
                    GameObject go         = gameObjects[i];
                    MeshFilter meshFilter = go.GetComponent <MeshFilter>();

                    if (meshFilter != null && meshFilter.sharedMesh != null)
                    {
                        UnityEngine.Mesh mesh = meshFilter.sharedMesh;
                        UnityEngine.Mesh meshTransformed;

                        CarGeometryUtils.CreateMeshTransformed(mesh, go.transform.localToWorldMatrix, out meshTransformed);
                        Vector3[] meshVertices = meshTransformed.vertices;
                        for (int j = 0; j < meshVertices.Length; ++j)
                        {
                            listLocatorPosition.Add(meshVertices[j]);
                        }

                        UnityEngine.Object.DestroyImmediate(meshTransformed);
                    }
                }
                break;

            default:
                break;
            }

            arrLocations = listLocatorPosition.ToArray();
        }
コード例 #2
0
        public void ClassifySelection()
        {
            GameObject selectorGO = Data.SelectorGO;

            if (selectorGO == null)
            {
                EditorUtility.DisplayDialog("CaronteFX", "A selector geometry is mandatory", "Ok");
                return;
            }

            Mesh selectorMesh = selectorGO.GetMesh();

            if (selectorMesh == null)
            {
                EditorUtility.DisplayDialog("CaronteFX", "A selector geometry is mandatory", "Ok");
                return;
            }

            EditorUtility.DisplayProgressBar(Data.Name, "Selecting...", 1.0f);
            GameObject[] arrGOtoClassify = FieldController.GetUnityGameObjects();

            Mesh auxSelectorMesh;

            CarGeometryUtils.CreateMeshTransformed(selectorMesh, selectorGO.transform.localToWorldMatrix, out auxSelectorMesh);

            MeshSimple auxCropMesh_un = new MeshSimple();

            auxCropMesh_un.Set(auxSelectorMesh);
            Object.DestroyImmediate(auxSelectorMesh);

            int nGameObjectToClassify = arrGOtoClassify.Length;

            List <GameObject> listGOToClassify         = new List <GameObject>();
            List <MeshSimple> listAuxMeshToClassify_un = new List <MeshSimple>();

            for (int i = 0; i < nGameObjectToClassify; i++)
            {
                GameObject go             = arrGOtoClassify[i];
                Mesh       meshToClassify = go.GetMesh();

                if (meshToClassify != null)
                {
                    listGOToClassify.Add(go);

                    Mesh auxMeshToClassify;
                    CarGeometryUtils.CreateMeshTransformed(meshToClassify, go.transform.localToWorldMatrix, out auxMeshToClassify);
                    MeshSimple auxMeshToClassify_un = new MeshSimple();
                    auxMeshToClassify_un.Set(auxMeshToClassify);

                    Object.DestroyImmediate(auxMeshToClassify);
                    listAuxMeshToClassify_un.Add(auxMeshToClassify_un);
                }
            }

            int[] arrIdxClassified;
            CaronteSharp.Tools.SplitInsideOutsideByGeometry(listAuxMeshToClassify_un.ToArray(), auxCropMesh_un, out arrIdxClassified, Data.FrontierPieces, true);

            List <GameObject> listGameObjectOutside = new List <GameObject>();
            List <GameObject> listGameObjectInside  = new List <GameObject>();

            for (int i = 0; i < arrIdxClassified.Length; i++)
            {
                int idxClassified = arrIdxClassified[i];

                GameObject go = listGOToClassify[i];

                if (idxClassified == 0)
                {
                    listGameObjectOutside.Add(go);
                }
                else if (idxClassified == 1)
                {
                    listGameObjectInside.Add(go);
                }
            }

            if (Data.SelectionMode == CNSelector.SELECTION_MODE.OUTSIDE)
            {
                if (Data.Complementary)
                {
                    Selection.objects = listGameObjectInside.ToArray();
                }
                else
                {
                    Selection.objects = listGameObjectOutside.ToArray();
                }
            }
            else if (Data.SelectionMode == CNSelector.SELECTION_MODE.INSIDE)
            {
                if (Data.Complementary)
                {
                    Selection.objects = listGameObjectOutside.ToArray();
                }
                else
                {
                    Selection.objects = listGameObjectInside.ToArray();
                }
            }

            EditorUtility.ClearProgressBar();
        }