private FaceFlags GetFaceFlag(Vector3 worldNormal) { FaceFlags face = FaceFlags.None; var dir = transform.InverseTransformDirection(worldNormal); if (dir == Vector3.up) { face = FaceFlags.Top; } else if (dir == Vector3.forward) { face = FaceFlags.Front; } else if (dir == Vector3.back) { face = FaceFlags.Back; } else if (dir == Vector3.left) { face = FaceFlags.Left; } else if (dir == Vector3.right) { face = FaceFlags.Right; } return(face); }
private void EndDrag() { if (isDragging) { mDragFace = FaceFlags.None; RefreshFaceHighlightFromMode(); RefreshHighlight(); mColl.enabled = !(mMode == Mode.None || mMode == Mode.Hidden); if (mMode == Mode.Expand) { if (expandCollFront) { expandCollFront.enabled = true; } if (expandCollBack) { expandCollBack.enabled = true; } if (expandCollLeft) { expandCollLeft.enabled = true; } if (expandCollRight) { expandCollRight.enabled = true; } } } }
public MeshFace(MeshFaceVertex[] verticies, ushort material) { this.Vertices = verticies; this.Material = material; this.Flags = 0; IboStartIndex = 0; NormalsIboStartIndex = 0; }
public Face(int nVerts, Vertex[] verts, FaceFlags flags, string texture, string material) { VertexCount = nVerts; Vertices = verts; Flags = flags; Texture = texture; Material = material; }
// Token: 0x06000173 RID: 371 RVA: 0x00005875 File Offset: 0x00003A75 public Face(int nVerts, Vertex[] verts, FaceFlags flags, string texture, string material) { this.NumberOfVertices = nVerts; this.Vertices = verts; this.Flags = flags; this.Texture = texture; this.Material = material; }
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData) { if (mMode == Mode.None || mMode == Mode.Hidden || mMode == Mode.Move) { return; } mFaceHighlightMode = FaceFlags.All; }
/// <summary>Creates a new MeshFace using the specified vertex indicies and the default material</summary> /// <param name="Vertices">The vertex indicies</param> /// <param name="Type">The type of OpenGL face drawing to use</param> public MeshFace(int[] Vertices, FaceFlags Type = FaceFlags.NotSet) { this.Vertices = new MeshFaceVertex[Vertices.Length]; for (int i = 0; i < Vertices.Length; i++) { this.Vertices[i] = new MeshFaceVertex(Vertices[i]); } this.Material = 0; this.Flags = 0; IboStartIndex = 0; NormalsIboStartIndex = 0; if (Type != FaceFlags.NotSet) { Flags |= Type; } }
void IPointerExitHandler.OnPointerExit(PointerEventData eventData) { if (mMode == Mode.None || mMode == Mode.Hidden || mMode == Mode.Move) { return; } if (mFaceHighlightMode != FaceFlags.None) { mFaceHighlightMode = FaceFlags.None; if (!isDragging) { display.faceHighlight = FaceFlags.None; RefreshHighlight(); } } }
private void GbspFlagChanged(bool s, FaceFlags f) { var faces = Document.Selection.GetSelectedFaces().ToList(); for (int x = 0; x < faces.Count; x++) { if (faces[x].Texture.Flags.HasFlag(f) && !s) { faces[x].Texture.Flags -= f; } else if (!faces[x].Texture.Flags.HasFlag(f) && s) { faces[x].Texture.Flags |= f; } faces[x].SetHighlights(); faces[x].SetOpacity(); } }
private void RefreshMode() { mColl.enabled = !(mMode == Mode.None || mMode == Mode.Hidden); if (mMode == Mode.Hidden) { display.faceHighlight = FaceFlags.None; display.isVisible = false; } else { display.isVisible = true; RefreshFaceHighlightFromMode(); RefreshValid(); } RefreshHighlight(); mFaceHighlightMode = FaceFlags.None; EndDrag(); var isExpandCollsEnabled = mMode == Mode.Expand; if (expandCollFront) { expandCollFront.enabled = isExpandCollsEnabled; } if (expandCollBack) { expandCollBack.enabled = isExpandCollsEnabled; } if (expandCollLeft) { expandCollLeft.enabled = isExpandCollsEnabled; } if (expandCollRight) { expandCollRight.enabled = isExpandCollsEnabled; } }
public void OnBeginDrag(PointerEventData eventData) { //ensure there's a selection if (!GridEditController.instance.selected) { return; } //ensure it is valid var cast = eventData.pointerPressRaycast; if (cast.isValid && (cast.gameObject == gameObject || GetFaceFlag(cast.gameObject) != FaceFlags.None || cast.gameObject == GridEditController.instance.selected.gameObject)) { mDragCellIndex.Invalidate(); mDragCellSizeStart = cellSize; if (mode == Mode.Expand) { mDragFace = GetFaceFlag(eventData.pointerPressRaycast.gameObject); if (mDragFace == FaceFlags.None) { //mDragFace = GetFaceFlag(eventData.pointerPressRaycast.worldNormal); mDragFace = FaceFlags.Top; } if ((mDragFace & expandRestrictions) != FaceFlags.None) //do not allow certain faces { mDragFace = FaceFlags.None; } display.faceHighlight = mDragFace; RefreshHighlight(); } else { mDragFace = FaceFlags.All; } if (mDragFace != FaceFlags.None) { mColl.enabled = false; if (mMode == Mode.Expand) { if (expandCollFront) { expandCollFront.enabled = false; } if (expandCollBack) { expandCollBack.enabled = false; } if (expandCollLeft) { expandCollLeft.enabled = false; } if (expandCollRight) { expandCollRight.enabled = false; } } } } }
public bool IsFlagSet(FaceFlags ff) { return((flags & (int)ff) == (int)ff); }
// Token: 0x0600003C RID: 60 RVA: 0x000030D8 File Offset: 0x000012D8 public static byte GetUserValue(this FaceFlags flags) { return((byte)(((long)flags & (long)((ulong)-33554432)) >> 24)); }
// Token: 0x0600003D RID: 61 RVA: 0x000030E7 File Offset: 0x000012E7 public static void SetUserValue(this FaceFlags flags, byte value) { flags &= (FaceFlags)33554431; flags += (int)value << 24; }
/// <inheritdoc /> public override void OptimizeObject(bool PreserveVerticies, int Threshold, bool VertexCulling) { int v = Mesh.Vertices.Length; int m = Mesh.Materials.Length; int f = Mesh.Faces.Length; if (f >= Threshold && currentHost.Platform != HostPlatform.AppleOSX) { /* * HACK: * A forwards compatible GL3 context (required on OS-X) only supports tris * No access to the renderer type here, so let's cheat and assume that OS-X * requires an optimized object (therefore decomposed into tris) in all circumstances */ return; } // eliminate invalid faces and reduce incomplete faces for (int i = 0; i < f; i++) { FaceFlags type = Mesh.Faces[i].Flags & FaceFlags.FaceTypeMask; bool keep; switch (type) { case FaceFlags.Triangles: keep = Mesh.Faces[i].Vertices.Length >= 3; if (keep) { int n = (Mesh.Faces[i].Vertices.Length / 3) * 3; if (Mesh.Faces[i].Vertices.Length != n) { Array.Resize(ref Mesh.Faces[i].Vertices, n); } } break; case FaceFlags.Quads: keep = Mesh.Faces[i].Vertices.Length >= 4; if (keep) { int n = Mesh.Faces[i].Vertices.Length & ~3; if (Mesh.Faces[i].Vertices.Length != n) { Array.Resize(ref Mesh.Faces[i].Vertices, n); } } break; case FaceFlags.QuadStrip: keep = Mesh.Faces[i].Vertices.Length >= 4; if (keep) { int n = Mesh.Faces[i].Vertices.Length & ~1; if (Mesh.Faces[i].Vertices.Length != n) { Array.Resize(ref Mesh.Faces[i].Vertices, n); } } break; default: keep = Mesh.Faces[i].Vertices.Length >= 3; break; } if (!keep) { for (int j = i; j < f - 1; j++) { Mesh.Faces[j] = Mesh.Faces[j + 1]; } f--; i--; } } // eliminate unused materials bool[] materialUsed = new bool[m]; for (int i = 0; i < f; i++) { /* * if (Mesh.Faces[i].Material < m - 1) * { * /* * Our material is out of range * Rather than crashing, add a new blank material * * Array.Resize(ref Mesh.Materials, m + 1); * Mesh.Materials[m] = new MeshMaterial(); * Mesh.Faces[i].Material = (ushort)m; * m++; * Array.Resize(ref materialUsed, m + 1); * } */ materialUsed[Mesh.Faces[i].Material] = true; } for (int i = 0; i < m; i++) { if (!materialUsed[i]) { for (int j = 0; j < f; j++) { if (Mesh.Faces[j].Material > i) { Mesh.Faces[j].Material--; } } for (int j = i; j < m - 1; j++) { Mesh.Materials[j] = Mesh.Materials[j + 1]; materialUsed[j] = materialUsed[j + 1]; } m--; i--; } } // eliminate duplicate materials for (int i = 0; i < m - 1; i++) { for (int j = i + 1; j < m; j++) { if (Mesh.Materials[i] == Mesh.Materials[j]) { for (int k = 0; k < f; k++) { if (Mesh.Faces[k].Material == j) { Mesh.Faces[k].Material = (ushort)i; } else if (Mesh.Faces[k].Material > j) { Mesh.Faces[k].Material--; } } for (int k = j; k < m - 1; k++) { Mesh.Materials[k] = Mesh.Materials[k + 1]; } m--; j--; } } } /* TODO: * Use a hash based technique */ // Cull vertices based on hidden option. // This is disabled by default because it adds a lot of time to the loading process. if (!PreserveVerticies && VertexCulling) { // eliminate unused vertices for (int i = 0; i < v; i++) { bool keep = false; for (int j = 0; j < f; j++) { for (int k = 0; k < Mesh.Faces[j].Vertices.Length; k++) { if (Mesh.Faces[j].Vertices[k].Index == i) { keep = true; break; } } if (keep) { break; } } if (!keep) { for (int j = 0; j < f; j++) { for (int k = 0; k < Mesh.Faces[j].Vertices.Length; k++) { if (Mesh.Faces[j].Vertices[k].Index > i) { Mesh.Faces[j].Vertices[k].Index--; } } } for (int j = i; j < v - 1; j++) { Mesh.Vertices[j] = Mesh.Vertices[j + 1]; } v--; i--; } } // eliminate duplicate vertices for (int i = 0; i < v - 1; i++) { for (int j = i + 1; j < v; j++) { if (Mesh.Vertices[i] == Mesh.Vertices[j]) { for (int k = 0; k < f; k++) { for (int h = 0; h < Mesh.Faces[k].Vertices.Length; h++) { if (Mesh.Faces[k].Vertices[h].Index == j) { Mesh.Faces[k].Vertices[h].Index = (ushort)i; } else if (Mesh.Faces[k].Vertices[h].Index > j) { Mesh.Faces[k].Vertices[h].Index--; } } } for (int k = j; k < v - 1; k++) { Mesh.Vertices[k] = Mesh.Vertices[k + 1]; } v--; j--; } } } } // structure optimization // Trangularize all polygons and quads into triangles for (int i = 0; i < f; ++i) { FaceFlags type = Mesh.Faces[i].Flags & FaceFlags.FaceTypeMask; // Only transform quads and polygons if (type == FaceFlags.Quads || type == FaceFlags.Polygon) { int staring_vertex_count = Mesh.Faces[i].Vertices.Length; // One triange for the first three points, then one for each vertex // Wind order is maintained. // Ex: 0, 1, 2; 0, 2, 3; 0, 3, 4; 0, 4, 5; int tri_count = (staring_vertex_count - 2); int vertex_count = tri_count * 3; // Copy old array for use as we work MeshFaceVertex[] original_poly = (MeshFaceVertex[])Mesh.Faces[i].Vertices.Clone(); // Resize new array Array.Resize(ref Mesh.Faces[i].Vertices, vertex_count); // Reference to output vertices MeshFaceVertex[] out_verts = Mesh.Faces[i].Vertices; // Triangularize for (int tri_index = 0, vert_index = 0, old_vert = 2; tri_index < tri_count; ++tri_index, ++old_vert) { // First vertex is always the 0th out_verts[vert_index] = original_poly[0]; vert_index += 1; // Second vertex is one behind the current working vertex out_verts[vert_index] = original_poly[old_vert - 1]; vert_index += 1; // Third vertex is current working vertex out_verts[vert_index] = original_poly[old_vert]; vert_index += 1; } // Mark as triangle Mesh.Faces[i].Flags &= ~FaceFlags.FaceTypeMask; Mesh.Faces[i].Flags |= FaceFlags.Triangles; } } // decomposit TRIANGLES and QUADS for (int i = 0; i < f; i++) { FaceFlags type = Mesh.Faces[i].Flags & FaceFlags.FaceTypeMask; int face_count = 0; FaceFlags face_bit = 0; if (type == FaceFlags.Triangles) { face_count = 3; face_bit = FaceFlags.Triangles; } else if (type == FaceFlags.Quads) { face_count = 4; face_bit = FaceFlags.Triangles; } if (face_count == 3 || face_count == 4) { if (Mesh.Faces[i].Vertices.Length > face_count) { int n = (Mesh.Faces[i].Vertices.Length - face_count) / face_count; while (f + n > Mesh.Faces.Length) { Array.Resize(ref Mesh.Faces, Mesh.Faces.Length << 1); } for (int j = 0; j < n; j++) { Mesh.Faces[f + j].Vertices = new MeshFaceVertex[face_count]; for (int k = 0; k < face_count; k++) { Mesh.Faces[f + j].Vertices[k] = Mesh.Faces[i].Vertices[face_count + face_count * j + k]; } Mesh.Faces[f + j].Material = Mesh.Faces[i].Material; Mesh.Faces[f + j].Flags = Mesh.Faces[i].Flags; Mesh.Faces[i].Flags &= ~FaceFlags.FaceTypeMask; Mesh.Faces[i].Flags |= face_bit; } Array.Resize(ref Mesh.Faces[i].Vertices, face_count); f += n; } } } // Squish faces that have the same material. { bool[] can_merge = new bool[f]; for (int i = 0; i < f - 1; ++i) { int merge_vertices = 0; // Type of current face FaceFlags type = Mesh.Faces[i].Flags & FaceFlags.FaceTypeMask; FaceFlags face = Mesh.Faces[i].Flags & FaceFlags.Face2Mask; // Find faces that can be merged for (int j = i + 1; j < f; ++j) { FaceFlags type2 = Mesh.Faces[j].Flags & FaceFlags.FaceTypeMask; FaceFlags face2 = Mesh.Faces[j].Flags & FaceFlags.Face2Mask; // Conditions for face merger bool mergeable = (type == FaceFlags.Triangles) && (type == type2) && (face == face2) && (Mesh.Faces[i].Material == Mesh.Faces[j].Material); can_merge[j] = mergeable; merge_vertices += mergeable ? Mesh.Faces[j].Vertices.Length : 0; } if (merge_vertices == 0) { continue; } // Current end of array index int last_vertex_it = Mesh.Faces[i].Vertices.Length; // Resize current face's vertices to have enough room Array.Resize(ref Mesh.Faces[i].Vertices, last_vertex_it + merge_vertices); // Merge faces for (int j = i + 1; j < f; ++j) { if (can_merge[j]) { // Copy vertices Mesh.Faces[j].Vertices.CopyTo(Mesh.Faces[i].Vertices, last_vertex_it); // Adjust index last_vertex_it += Mesh.Faces[j].Vertices.Length; } } // Remove now unused faces int jump = 0; for (int j = i + 1; j < f; ++j) { if (can_merge[j]) { jump += 1; } else if (jump > 0) { Mesh.Faces[j - jump] = Mesh.Faces[j]; } } // Remove faces removed from face count f -= jump; } } // finalize arrays if (v != Mesh.Vertices.Length) { Array.Resize(ref Mesh.Vertices, v); } if (m != Mesh.Materials.Length) { Array.Resize(ref Mesh.Materials, m); } if (f != Mesh.Faces.Length) { Array.Resize(ref Mesh.Faces, f); } }