public bool CreateMesh(BrickMesh brickMesh, bool invertNext, short parentBrickColor) { TransformModel(brickMesh.LocalTr); if (!brickMesh.HasVertices()) { return(false); } Vector3[] vts; Color32[] colors; int[] opaqueTris; int[] transparentTris; Mesh mesh = new Mesh(); int matIndexOffset = brickMesh.BfcEnabled ? 0 : (int)BrickMaterial.MatType.DS_OFFSET; brickMesh.GetRenderMeshInfo(invertNext, parentBrickColor, out vts, out colors, out opaqueTris, out transparentTris); mesh.vertices = vts; mesh.colors32 = colors; if (opaqueTris.Length > 0 && transparentTris.Length == 0) { mesh.SetTriangles(opaqueTris, 0); originalMat = new BrickMaterialInfo(BrickMaterial.MatType.Opaque, matIndexOffset, 1); } else if (opaqueTris.Length == 0 && transparentTris.Length > 0) { mesh.SetTriangles(transparentTris, 0); originalMat = new BrickMaterialInfo(BrickMaterial.MatType.Transparent, matIndexOffset, 1); } else if (opaqueTris.Length > 0 && transparentTris.Length > 0) { mesh.subMeshCount = 2; mesh.SetTriangles(opaqueTris, 0); mesh.SetTriangles(transparentTris, 1); originalMat = new BrickMaterialInfo(BrickMaterial.MatType.Opaque, matIndexOffset, 2); } else { return(false); } ChangeMaterial(originalMat); mesh.RecalculateNormals(); mesh.RecalculateBounds(); GetComponent <MeshFilter>().mesh = mesh; GetComponent <MeshFilter>().sharedMesh = mesh; AddBoxCollider(); return(true); }
private void ChangeMaterial(BrickMaterialInfo matInfo) { MeshRenderer renderer = GetComponent <MeshRenderer>(); if (renderer == null) { return; } Material[] customeMaterial = new Material[matInfo.cnt]; for (int i = 0; i < matInfo.cnt; ++i) { customeMaterial[i] = BrickMaterial.Instance.GetMaterial(matInfo.type + matInfo.offset + i); } renderer.sharedMaterials = customeMaterial; }
public bool ReconstructMesh(GameObject go, BrickMesh brickMesh, bool invertNext, short parentBrickColor) { TransformModel(brickMesh.LocalTr); Mesh mesh = go.GetComponent <MeshFilter>().mesh; int matIndexOffset = brickMesh.BfcEnabled ? 0 : (int)BrickMaterial.MatType.DS_OFFSET; // The colors will be created. Color32[] colors; int[] tris; bool isColorModified; bool isMeshModified; bool isMatModified; BrickMaterial.MatType matType; brickMesh.GetRenderMeshReconstructInfo(invertNext, parentBrickColor, mesh, out colors, out tris, out matType, out isColorModified, out isMeshModified, out isMatModified); // assign the array of colors to the Mesh. if (isColorModified) { mesh.colors32 = colors; } if (isMeshModified) { mesh.triangles = tris; mesh.RecalculateNormals(); } if (isMatModified) { originalMat = new BrickMaterialInfo(matType, matIndexOffset, mesh.subMeshCount); ChangeMaterial(originalMat); } return(true); }
public void ShowSilhouette() { BrickMaterialInfo silhouetteMat = new BrickMaterialInfo(BrickMaterial.MatType.Silhouette, 0, 1); ChangeMaterial(silhouetteMat); }