示例#1
0
        public static UnityEngine.Material FillTriangle(Mesh mesh, Triangle triangle)
        {
            Material mmMaterial = mesh.materials.FillTriangle(triangle);

            UnityEngine.Material material = MaterialToInstance(mmMaterial, true, true, true);
            if (!mesh.materials.materialsChanged)
            {
                return(material);
            }
            TriangleController triangleController = triangle.instance.GetComponent <TriangleController>();

            triangleController.material = material;
            triangleController.SyncMaterials();
            return(material);
        }
示例#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);
        }