internal override void Apply(ShapeBatch shapeBatch, MeshSlice slice, VertigoState state, int effectDataIndex) { T effectData = default; if (effectDataIndex >= 0 && effectDataIndex <= stateBuffer.Count) { effectData = stateBuffer.Array[effectDataIndex]; } Apply(shapeBatch, state, effectData, slice); }
public override void OnInspectorGUI() { Island island = (Island)target; Painter[] painters = GameObject.FindObjectsOfType(typeof(Painter)) as Painter[]; System.Array.Sort(painters); int count = 0; foreach (var painter in painters) { GUI.enabled = true; GUILayout.BeginHorizontal(); painter.ShouldPaint = GUILayout.Toggle(painter.ShouldPaint, "", GUILayout.Width(20), GUILayout.Height(15)); GUI.enabled = painter.ShouldPaint; GUILayout.Label(painter.GetName()); if (count > 0) { if (GUILayout.Button("+", GUILayout.Width(25), GUILayout.Height(15))) { int index = painter.Index; painter.Index = painters[count - 1].Index; painters[count - 1].Index = index; } } if (count < painters.Length - 1) { if (GUILayout.Button("-", GUILayout.Width(25), GUILayout.Height(15))) { int index = painter.Index; painter.Index = painters[count + 1].Index; painters[count + 1].Index = index; } } GUILayout.EndHorizontal(); count++; } System.Array.Sort(painters); count = 0; foreach (var painter in painters) { painter.Index = count; count++; } GUI.enabled = true; if (GUILayout.Button("Repaint")) { AssetDatabase.StartAssetEditing(); island.StartPainting(); ClearSplatMap(); foreach (var painter in painters) { if (painter.ShouldPaint) { painter.Paint(island); } } island.ApplyPaintChanges(); island.SaveTextures(); for (int x = 0; x < island.SectionsX; x++) { for (int y = 0; y < island.SectionsY; y++) { string path = "Assets/Textures/Terrain Maps/splat_" + x + "_" + y + ".png"; AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport); } } AssetDatabase.StopAssetEditing(); EditorUtility.ClearProgressBar(); } island.IslandBaseMaterial = EditorGUILayout.ObjectField(island.IslandBaseMaterial, typeof(Material), true) as Material; island.IslandSourceMesh = EditorGUILayout.ObjectField(island.IslandSourceMesh, typeof(Mesh), true) as Mesh; island.SectionsX = EditorGUILayout.IntField("Slices X", island.SectionsX); island.SectionsY = EditorGUILayout.IntField("Slices Y", island.SectionsY); if (GUILayout.Button("Slice Mesh")) { if (island.IslandSourceMesh != null) { EditorUtility.DisplayProgressBar("Slicing Terrain", "Slicing...", 0.0f); Mesh[,] meshes = MeshSlice.Slice(island.IslandSourceMesh, island.SectionsX, island.SectionsY, true, true); GameObject meshesObject = GameObjectHelper.FindChild(island.gameObject, "meshes", true); island.Sections = new GameObject[meshes.GetLength(0) * meshes.GetLength(1)]; island.MinBounds = new Vector2(island.IslandSourceMesh.bounds.min.x, island.IslandSourceMesh.bounds.min.z); island.MaxBounds = new Vector2(island.IslandSourceMesh.bounds.max.x, island.IslandSourceMesh.bounds.max.z); AssetDatabase.StartAssetEditing(); for (int x = 0; x < meshes.GetLength(0); x++) { for (int y = 0; y < meshes.GetLength(1); y++) { EditorUtility.DisplayProgressBar("Slicing Terrain", "Generating Meshes and Textures...", (float)(x * meshes.GetLength(1) + y) / (float)(meshes.GetLength(0) * meshes.GetLength(1))); Mesh mesh = meshes[x, y]; mesh.Optimize(); GameObject newObject = new GameObject("island_section_" + x + "_" + y); // if(mesh.triangles.Length > 0) { // GameObjectUtility.SetStaticEditorFlags(newObject, StaticEditorFlags.NavigationStatic); } Debug.Log("Mesh has " + mesh.triangles.Length + " count"); newObject.transform.parent = meshesObject.transform; newObject.transform.localPosition = Vector3.zero; MeshRenderer renderer = newObject.AddComponent <MeshRenderer>(); Material newMaterial = new Material(island.IslandBaseMaterial); string path = "Assets/Textures/Terrain Maps/splat_" + x + "_" + y + ".png"; TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; // TODO: What a load of rotten crow-c**k. // This is required to make the textures editable for island-painting. // Sort out not having f*****g great un-compressed textures when running the game. if (importer != null) { TextureImporterSettings settings = new TextureImporterSettings(); importer.wrapMode = TextureWrapMode.Clamp; importer.textureType = TextureImporterType.Advanced; importer.ReadTextureSettings(settings); importer.textureFormat = TextureImporterFormat.ARGB32; importer.isReadable = true; importer.compressionQuality = 0; importer.textureFormat = TextureImporterFormat.ARGB32; settings.readable = true; settings.textureFormat = TextureImporterFormat.ARGB32; settings.compressionQuality = 0; importer.SetTextureSettings(settings); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport); } Texture2D tex = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; if (tex == null) { Debug.LogError("Failed to locate splat-map " + x + "_" + y); } tex.GetPixels32(); newMaterial.SetTexture("_Splat", tex); renderer.sharedMaterial = newMaterial; MeshFilter filter = newObject.AddComponent <MeshFilter>(); filter.mesh = mesh; island.Sections[y * island.SectionsX + x] = newObject; } } AssetDatabase.StopAssetEditing(); } EditorUtility.ClearProgressBar(); } if (GUILayout.Button("Create initial splat-maps")) { ClearSplatMap(); } return; }
public override void OnInspectorGUI() { Island island = (Island)target; island.IslandSourceMesh = EditorGUILayout.ObjectField(island.IslandSourceMesh, typeof(Mesh), true) as Mesh; island.SectionsX = EditorGUILayout.IntField("Slices X", island.SectionsX); island.SectionsY = EditorGUILayout.IntField("Slices Y", island.SectionsY); if (GUILayout.Button("Slice Mesh")) { if (island.IslandSourceMesh != null) { Mesh[,] meshes = MeshSlice.Slice(island.IslandSourceMesh, island.SectionsX, island.SectionsY, true, true); GameObject meshesObject = GameObjectHelper.FindChild(island.gameObject, "meshes", true); int i = 0; foreach (var mesh in meshes) { mesh.Optimize(); GameObject newObject = new GameObject("island_slice_" + i); newObject.transform.parent = meshesObject.transform; newObject.transform.localPosition = Vector3.zero; newObject.AddComponent <MeshRenderer>(); MeshFilter filter = newObject.AddComponent <MeshFilter>(); filter.mesh = mesh; i++; } } } if (GUILayout.Button("Reset")) { island.m_triangles.Clear(); MeshSlice.Triangle tri = new MeshSlice.Triangle(); tri.p0 = new Vector2(-1.0f, -1.0f); tri.p1 = new Vector2(1.0f, -1.0f); tri.p2 = new Vector2(0.0f, 1.0f); island.m_triangles.Add(tri); } if (GUILayout.Button("Slice")) { List <MeshSlice.Triangle> tris = island.m_triangles; List <MeshSlice.Triangle> outTris = new List <MeshSlice.Triangle>(); Vector2 v0, v1; foreach (var tri in tris) { if (MathsHelper.LineTriIntersect(island.sliceStart, island.sliceEnd, tri.p0, tri.p1, tri.p2, out v0, out v1)) { outTris.AddRange(MeshSlice.SliceTri(tri, island.sliceStart, island.sliceEnd)); } else { outTris.Add(tri); } } island.m_triangles = outTris; } }
private static IntVector3 FindSliceCoordForFace(MeshSlice slice, MeshSliceFace face, Axis3 axis, Axis3 paxis1, Axis3 paxis2) { var verts = slice.Positions; var first = verts[face.StartIndex]; int xmin = first[paxis1]; int ymin = first[paxis2]; int xmax = xmin, ymax = ymin; for (int i = face.StartIndex + 1; i < face.EndIndex; ++i) { var vt = verts[i]; int x = vt[paxis1], y = vt[paxis2]; xmin = Math.Min(xmin, x); ymin = Math.Min(ymin, y); xmax = Math.Max(xmax, x); ymax = Math.Max(ymax, y); } if (xmax > xmin + 1 || ymax > ymin + 1) { throw new InvalidOperationException("The input mesh has a face covering two voxels " + ", which is not supported by " + nameof(SimpleMeshTextureGenerator) + "."); } return new IntVector3(xmin, ymin, first[axis]); }
public MeshSlices GenerateSlices(VoxelModel model, IProgressListener progress) { var slices = new MeshSlices(); var dims = model.Dimensions; int totalsteps = 2 * (model.Width + model.Height + model.Depth); int step = 0; progress?.Report("Generating slices"); for (int iaxis = 0; iaxis < 3; ++iaxis) { for (int iface = 0; iface < 2; ++iface) { var axis = (Axis3) iaxis; var paxis1 = (Axis3) ((iaxis + 1) % 3); var paxis2 = (Axis3) ((iaxis + 2) % 3); bool face = iface != 0; int dim0 = dims[axis]; int dim1 = dims[paxis1]; int dim2 = dims[paxis2]; var slicelist = new MeshSlice[dim0]; slices[axis, face] = slicelist; for (int layer = 0; layer < dim0; ++layer) { ++step; progress?.Report((double)step / totalsteps); var faces = new List<int>(); var ret = new List<IntVector3>(); var pt1 = new IntVector3(); pt1[axis] = layer; for (int x = 0; x < dim1; ++x) { pt1[paxis1] = x; for (int y = 0; y < dim2; ++y) { pt1[paxis2] = y; bool solid1 = model.IsVoxelSolid(pt1); var pt2 = pt1; bool solid2 = false; if (face) { pt2[axis] += 1; if (pt2[axis] < dim0) { solid2 = model.IsVoxelSolid(pt2); } } else { pt2[axis] -= 1; if (pt2[axis] >= 0) { solid2 = model.IsVoxelSolid(pt2); } } if (!solid1 || solid2) { continue; } // Create quad var qpt1 = pt1; if (face) { qpt1[axis] += 1; qpt1[paxis2] += 1; } var qpt2 = qpt1; qpt2[paxis1] += 1; var qpt3 = qpt1; var qpt4 = qpt2; if (face) { qpt3[paxis2] -= 1; qpt4[paxis2] -= 1; } else { qpt3[paxis2] += 1; qpt4[paxis2] += 1; } // Emit polygons faces.Add(ret.Count); ret.Add(qpt3); ret.Add(qpt4); ret.Add(qpt2); ret.Add(qpt1); } // for y } // for x slicelist[layer] = new MeshSlice() { Positions = ret.ToArray(), Faces = faces.ToArray(), Face = face, Axis = axis, Layer = layer }; } // for slice } // iface } // iaxis return slices; }