public GMesh ClipGeometryToPlane(GClipPlane gcp) { GMesh clip_gm = new GMesh(); // Add the textures first for (int i = 0; i < m_tex_name.Count; i++) { #if OVERLOAD_LEVEL_EDITOR clip_gm.AddTexture(m_tex_gl_id[i], m_tex_name[i]); #else clip_gm.m_tex_name.Add(m_tex_name[i]); #endif } // Copy the clip planes for (int i = 0; i < (int)EdgeOrder.NUM; i++) { clip_gm.m_clip_plane[i] = new GClipPlane(m_clip_plane[i]); } ClipPlane cp = ClipPlane.CreateFrom3Points(gcp.edge_pos1, gcp.edge_pos2, gcp.edge_pos2 + gcp.normal); for (int i = 0; i < m_triangle.Count; i++) { CTriangle ct = new CTriangle(m_triangle[i], m_vertex[m_triangle[i].vert[0]], m_vertex[m_triangle[i].vert[1]], m_vertex[m_triangle[i].vert[2]]); ct.ClipFacePlane(cp); if (ct.clipped_verts.Length < 3) { continue; } int num_triangles = ct.clipped_verts.Length - 2; for (int clipped_tri_idx = 0; clipped_tri_idx < num_triangles; ++clipped_tri_idx) { CTriangle extracted_ct = ct.ExtractClippedTriangle(clipped_tri_idx); if (extracted_ct.HasDegenerateTriangles(false)) { continue; } clip_gm.AddFaceFromCTriangle(extracted_ct); } } return(clip_gm); }
public void GenerateNonClippedGeometry(Decal d, DMesh dm) { // Limit max repeats based on the size of the face // NOTE: This may not the best way to limit repeats, but it works FindBaseAttributes(d); float max_length = d.side.FindLongestDiagonal(); int max_repeats = 2 + (int)(max_length / 4f); int repeat_u = (d.repeat_u > 0 ? d.repeat_u : max_repeats); int repeat_v = (d.repeat_v > 0 ? d.repeat_v : max_repeats); int offset_u = d.offset_u; switch (d.align) { case DecalAlign.EDGE_RIGHT: case DecalAlign.EDGE_DOWN: case DecalAlign.EDGE_UP: case DecalAlign.EDGE_LEFT: // COMPATIBILITY: Due to a bug Offset U was effectively reversed in the original 1.0.1.0 release // For backwards compatibility, retain this behaviour. offset_u = -offset_u; break; default: break; } // Get the implied offset based on the repeats int implied_offset_u = CalculateImpiedOffset(d.repeat_u, repeat_u); int implied_offset_v = CalculateImpiedOffset(d.repeat_v, repeat_v); // Adjust implied_offset_v for EDGE alignment (add 2) if (d.IsEdgeAlign()) { implied_offset_v += 2; } // Temporary DMesh to hold the dm if it has to be mirrored DMesh temp_dm = new DMesh(dm.name); temp_dm.Copy(dm); temp_dm.MaybeFlip(d.mirror); // Create repeats of the geometry for (int i = 0; i < repeat_u; i++) { for (int j = 0; j < repeat_v; j++) { // Before adding, must do WHOLE clipping (can't do it after because we don't have the data then) // Create a CQuad that covers the outline of the expected area Vector3[] v = CreateGhostQuad(m_base_pos + m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4), m_base_rot); CTriangle ct = new CTriangle(v); bool clip = false; // See if that clips against a whole plane, if not add it for (int k = 0; k < (int)EdgeOrder.NUM; k++) { if (m_clip_plane[k].whole) { ClipPlane cp = ClipPlane.CreateFrom3Points(m_clip_plane[k].edge_pos1, m_clip_plane[k].edge_pos2, m_clip_plane[k].edge_pos2 + m_clip_plane[k].normal); if (ct.WouldBeClipped(cp)) { clip = true; } } } if (!clip) { Vector3 offset = m_base_rvec * (implied_offset_u - offset_u + i * 4) + m_base_uvec * (implied_offset_v + d.offset_v + j * 4); Vector3 gcenter = m_base_pos + offset; AddGeometry(temp_dm, gcenter); AddLights(temp_dm, gcenter); } } } // Add the textures for (int i = 0; i < dm.tex_name.Count; i++) { m_tex_name.Add(dm.tex_name[i]); #if OVERLOAD_LEVEL_EDITOR m_tex_gl_id.Add(-1); #endif } }