Пример #1
0
        public void FlipNormalByTriangle(Triangle triangle)
        {
            int triangleIndex = triangle.index;
            int a_index       = triangles[triangleIndex];
            int b_index       = triangles[triangleIndex + 1];
            int c_index       = triangles[triangleIndex + 2];

            triangles[triangleIndex]     = c_index;
            triangles[triangleIndex + 1] = b_index;
            triangles[triangleIndex + 2] = a_index;

            trianglesChanged = true;
            mesh.persistence.changedSinceLastSave = true;

            if (triangle.instance != null)
            {
                Vertex a = mesh.vertices.vertices[a_index];
                Vertex b = mesh.vertices.vertices[b_index];
                Vertex c = mesh.vertices.vertices[c_index];

                Vector3            center             = mesh.Center(a.position, b.position, c.position);
                TriangleController triangleController = triangle.instance.GetComponent <TriangleController>();
                triangleController.Populate(c, b, a, center);
            }
        }
Пример #2
0
        public void CreateTriangleInstance(int triangleIndex)
        {
            Vertex  a      = mesh.vertices.vertices[triangles[triangleIndex]];
            Vertex  b      = mesh.vertices.vertices[triangles[triangleIndex + 1]];
            Vertex  c      = mesh.vertices.vertices[triangles[triangleIndex + 2]];
            Vector3 center = mesh.Center(a.position, b.position, c.position);

            GameObject triangleInstance = InstantiateOrGetFromPool(center, mesh.transform.rotation);

            triangleInstance.transform.parent        = mesh.transform;
            triangleInstance.transform.localPosition = center;
            TriangleController triangleController = triangleInstance.GetComponent <TriangleController>();

            triangleController.mesh = mesh;
            triangleController.Initialize();

            //Debug.Log("Creating triangle a=" + a + ",b=" + b + ",c=" + c);
            triangleController.Populate(a, b, c, center);

            Triangle triangle = new Triangle();

            triangle.index    = triangleIndex;
            triangle.instance = triangleInstance;
            Material mmMaterial = mesh.materials.MaterialByTriangleIndex(triangleIndex);

            triangle.material = MaterialUtils.MaterialToInstance(mmMaterial, true, true, true);
            //Debug.Log("CreateTriangleInstance fillColor=" + ColorUtility.ToHtmlStringRGBA(meshController.settingsPanelController.GetComponent<SettingsController>().fillColor) + ",mmMaterial.color=" + ColorUtility.ToHtmlStringRGBA(mmMaterial.color) + ",triangle.material.color="+ ColorUtility.ToHtmlStringRGBA(triangle.material.color));

            triangleController.material = triangle.material;
            triangleController.SyncMaterials();

            Selectable selectable = triangleInstance.GetComponent <Selectable>();

            selectable.Initialize();
            selectable.renderMesh      = true;
            selectable.renderWireframe = true;
            selectable.renderNormals   = true;
            triangleController.SetSelectable(triangleInstancesSelectable);
            triangleController.SetStickySelected(false);
            triangleInstance.SetActive(!hideTriangles);
            triangleInstances.Add(triangle);
            //if (log) Debug.Log("CreateTriangleInstance triangle.index=" + triangle.index+ ", triangleInstances.Count - 1="+ (triangleInstances.Count - 1)+", triangle.instance.ID=" + triangle.instance.GetInstanceID());
            triangleInstanceIndexByTriangleIndex.Add(triangle.index, triangleInstances.Count - 1);
        }