Exemplo n.º 1
0
    void set_display_params()
    {
        float ang_span_Thresh, tmp_scale;

        if (isMonocular)
        {
            m.delta_pos            = new Vector3(513.0f, 0, 0.0f);
            m.pos                  = new Vector3(0.0f, 0, 1000.0f);
            modified_obj.translate = m.pos;
            m.fct                  = 0.75f;
            line_width             = 6.30f;
            wire_frm_dst           = 5.50f;
            ang_span_Thresh        = 28;
            tmp_scale              = 1e-5f;
        }
        else
        {
            m.delta_pos            = new Vector3(0.60f, 0.0f, 0.0f);
            m.pos                  = new Vector3(0.00f, 0, 1.0f);
            modified_obj.translate = m.pos;
            m.fct                  = 0.75f;
            line_width             = 0.006240f;
            wire_frm_dst           = 3.80f;
            ang_span_Thresh        = 28;
            tmp_scale              = 1e-10f;
        }

        //Set scale according to angular span on screen
        obj = new OffObject();
        obj.copy_properties_from(modified_obj);
        Matrix4x4 tmp1 = Matrix4x4.TRS(Vector3.zero, modified_obj.rotation, Vector3.one);

        obj.rotate_object(tmp1);
        //

        obj.scale_object(tmp_scale);
        obj.translate_object(modified_obj.translate);

        while (obj.max_angular_span() < ang_span_Thresh)
        {
            //restore to original scale
            obj.translate_object(-obj.centre);
            obj.scale_object((1.0f / tmp_scale));
            //Rescale to new scale and translate
            tmp_scale *= 1.01f;
            obj.scale_object(tmp_scale);
            obj.translate_object(modified_obj.translate);
        }
        //if (modified_obj.compactess() < 0.14)
        //    tmp_scale *= 1.3f;
        m.scale            = tmp_scale;
        modified_obj.scale = tmp_scale;
    }
Exemplo n.º 2
0
    bool is_view_acceptable()
    {
        obj = new OffObject();
        obj.copy_properties_from(modified_obj);

        //Rotate
        obj.rotate_object(m.rv_rot_mat);
        //scale
        obj.scale_object((float)m.scale);
        //translate
        //m.pos.z *= -1;
        obj.translate_object(m.pos);
        //Unity is left-handed
        for (int k = 0; k < 16; k++)
        {
            obj.verts[k].z *= -1;
        }
        obj.recalc_centre_norms_and_face_norms();
        //
        int[] baze     = { 0, 1, 2, 3, 8, 9, 10, 11 };
        int[] non_baze = { 4, 5, 6, 7, 12, 13, 14, 15 };
        //Among the non-baze, how many are vsible?
        int vis_num = 0;
        int tmpCntr;

        for (int i = 0; i < 8; i++)
        {
            tmpCntr = 0;
            Vector3 cv = obj.verts[non_baze[i]];
            for (int j = 0; j < obj.faces.Length; j++)
            {
                //if the trg contains this vertex
                if (obj.faces[j].x == non_baze[i] || obj.faces[j].y == non_baze[i] || obj.faces[j].z == non_baze[i])
                {
                    tmpCntr++;
                    continue;
                }

                Vector3[] trg = { obj.verts[(int)obj.faces[j].x], obj.verts[(int)obj.faces[j].y], obj.verts[(int)obj.faces[j].z] };
                if (Helper.is_vertex_occluded(trg, cv))
                {
                    break;
                }
                tmpCntr++;
            }
            // if none of the faces block it
            if (tmpCntr++ >= obj.faces.Length)
            {
                vis_num++;
            }
        }
        //Debug.Log("vis_num:" + vis_num.ToString());
        //if atleast 5 of them are not visible, return failed
        if (vis_num < 6)
        {
            //if (cntr == (attLmt - 1))
            //{
            //    Debug.Log("Non-base vertex count fail");
            //}
            return(false);
        }
        //Now we need to check if a total of 10 vertices are visible
        for (int i = 0; i < 8; i++)
        {
            Vector3 cv = obj.verts[baze[i]];
            tmpCntr = 0;
            for (int j = 0; j < obj.faces.Length; j++)
            {
                //if the trg contains this vertex
                if (obj.faces[j].x == baze[i] || obj.faces[j].y == baze[i] || obj.faces[j].z == baze[i])
                {
                    tmpCntr++;
                    continue;
                }
                Vector3[] trg = { obj.verts[(int)obj.faces[j].x], obj.verts[(int)obj.faces[j].y], obj.verts[(int)obj.faces[j].z] };
                if (Helper.is_vertex_occluded(trg, cv))
                {
                    break;
                }
                tmpCntr++;
            }
            if (tmpCntr >= obj.faces.Length)
            {
                vis_num++;
            }

            if (vis_num >= 11)
            {
                return(true);
            }
        }
        //if (cntr == (attLmt - 1))
        //{
        //    Debug.Log("All vertex count fail");
        //}
        return(false);
    }