private void CreateChild(BrickMesh brickMesh, Transform parent, bool invertNext, short parentBrickColor) { UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Brick.prefab", typeof(GameObject)); GameObject go = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject; bool isMeshExist = go.GetComponent <Brick>().CreateMesh(brickMesh, invertNext, parentBrickColor); go.name = brickMesh.Name; go.GetComponent <Brick>().SetParent(parent); if (needExport && isMeshExist && brickMesh.Children.Count == 0) { if (!export.DoesAssetExist(go.name)) { export.SaveAsset(go.name, go); } } bool accInvert = invertNext ^ brickMesh.InvertNext; short accuColor = LdConstant.GetEffectiveColorIndex(brickMesh.BrickColor, parentBrickColor); for (int i = 0; i < brickMesh.Children.Count; ++i) { CreateChild(brickMesh.Children[i], go.transform, accInvert, accuColor); } }
public void MergeChildBrick(bool accInvertNext, short color, Matrix4x4 trMatrix, BrickMeshInfo childMesh) { int vtCnt = Vertices.Count; for (int i = 0; i < childMesh.Vertices.Count; ++i) { Vertices.Add(trMatrix.MultiplyPoint3x4(childMesh.Vertices[i])); } for (int i = 0; i < childMesh.ColorIndices.Count; ++i) { ColorIndices.Add(LdConstant.GetEffectiveColorIndex(childMesh.ColorIndices[i], color)); } bool inverted = accInvertNext ^ (trMatrix.determinant < 0); for (int i = 0; i < childMesh.Triangles.Count; i += 3) { if (inverted) { Triangles.Add(vtCnt + childMesh.Triangles[i]); Triangles.Add(vtCnt + childMesh.Triangles[i + 2]); Triangles.Add(vtCnt + childMesh.Triangles[i + 1]); } else { Triangles.Add(vtCnt + childMesh.Triangles[i]); Triangles.Add(vtCnt + childMesh.Triangles[i + 1]); Triangles.Add(vtCnt + childMesh.Triangles[i + 2]); } } }
public void GetRenderMeshReconstructInfo(bool invert, short parentBrickColor, Mesh mesh, out Color32[] colors, out int[] tris, out BrickMaterial.MatType matType, out bool isColorModified, out bool isMeshModified, out bool isMatModified) { short effectiveParentColor = LdConstant.GetEffectiveColorIndex(BrickColor, parentBrickColor); isColorModified = GetTobeChangeColors(effectiveParentColor, mesh, out colors); isMeshModified = GetTobeChangedTriangles(invert, mesh, ref colors, out tris); isMatModified = GetTobeChangedMatInfo(mesh, ref colors, out matType); }
private void GetColors(short parentColor, out Color32[] colList) { colList = new Color32[ColorIndices.Count]; for (int i = 0; i < ColorIndices.Count; ++i) { short colorIndex = LdConstant.GetEffectiveColorIndex(ColorIndices[i], parentColor); colList[i] = LdColorTable.Instance.GetColor(colorIndex); } }
public bool GetTobeChangeColors(short parentColor, Mesh mesh, out Color32[] colList) { bool isModified = false; colList = new Color32[mesh.colors.Length]; for (int i = 0; i < mesh.colors.Length; ++i) { short restoreIndex = (short)LdColorTable.Instance.GetColorIndex(mesh.colors[i]); short colorIndex = LdConstant.GetEffectiveColorIndex(restoreIndex, parentColor); colList[i] = LdColorTable.Instance.GetColor(colorIndex); isModified |= (mesh.colors[i] != colList[i]); } return(isModified); }
public void GetRenderMeshInfo(bool invert, short parentBrickColor, out Vector3[] vts, out Color32[] colors, out int[] opaqueTris, out int[] transparentTris) { short effectiveParentColor = LdConstant.GetEffectiveColorIndex(BrickColor, parentBrickColor); if (meshInfo != null) { bool inverted = invert ^ InvertNext; meshInfo.GetRenderMeshInfo(effectiveParentColor, inverted, out vts, out colors, out opaqueTris, out transparentTris); } else { vts = null; colors = null; opaqueTris = null; transparentTris = null; } }