コード例 #1
0
        public void SetRenderOptions(bool renderMeshValue, bool renderWireframeValue, bool renderNormalsValue)
        {
            bool changed = false;

            if (renderMesh != renderMeshValue || renderWireframe != renderWireframeValue || renderNormals != renderNormalsValue)
            {
                changed = true;
            }
            renderMesh      = renderMeshValue;
            renderWireframe = renderWireframeValue;
            renderNormals   = renderNormalsValue;

            if (changed)
            {
                List <UnityEngine.Material> materials = MaterialUtils.GetMaterials(this);
                MaterialUtils.AssignMaterials(this, materials);
            }
        }
コード例 #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);
        }
コード例 #3
0
        public bool BuildTriangles()
        {
            if (!trianglesChanged && !mesh.materials.materialsChanged)
            {
                return(false);
            }
            List <UnityEngine.Material> materials = MaterialUtils.GetMaterials(mesh);

            UnityEngine.Material[] materialArray = MaterialUtils.AssignMaterials(mesh, materials);
            mesh.uMesh.subMeshCount = materials.Count;
            List <Materials.MaterialTriangles> materialTriangles = mesh.materials.GetTriangles();

            for (int i = 0; i < materials.Count; i++)
            {
                mesh.uMesh.SetTriangles(materialTriangles[i].triangles.ToArray(), i);
            }
            Selectable selectable = mesh.GetComponent <Selectable>();

            mesh.materials.materialsChanged = false;
            if (selectable != null)
            {
                UnityEngine.Mesh outlineMesh = new UnityEngine.Mesh();
                outlineMesh.vertices  = mesh.uMesh.vertices;
                outlineMesh.triangles = mesh.triangles.triangles.ToArray();
                outlineMesh.RecalculateNormals();
                selectable.outlineMesh         = outlineMesh;
                selectable.unselectedMaterials = materialArray;
                selectable.UpdateSelectedMaterials();
            }
            else
            {
                // BoxSelectionController mesh only
                mesh.uMesh.triangles = triangles.ToArray();
            }
            trianglesChanged = false;
            return(true);
        }