コード例 #1
0
        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
            }
        }