Ejemplo 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;
    }
Ejemplo n.º 2
0
    public OffObject generate_off_obj()
    {
        OffObject obj = new OffObject();

        obj.InitializeVertices(verts, sym);
        obj.InitializeFaces();
        obj.InitializeEdges();
        //calling this would automatically compute face norms and norms and centre
        obj.recalc_centre_norms_and_face_norms();
        //we want the object to have origin as centroid at the beginning
        obj.translate_object(obj.centre);
        ////stretch to vary compactness
        //AppData app = AppData.Instance;
        ////If it is a new session we always vary compactness
        //if (!app.is_saved_session)
        //{
        //    vary_cmpct_dir = UnityEngine.Random.Range(0, 2);
        //    vary_cmpct_fctr = (float)Helper.get_random_double(0.2f, 5.0f);
        //    Debug.Log("Current variance along: " + vary_cmpct_dir.ToString() + " By Fct: " + vary_cmpct_fctr.ToString());
        //    //Matrix4x4 tmp = Matrix4x4.identity;
        //    if (vary_cmpct_dir == 1)
        //    {
        //        Matrix4x4 tmp = Helper.get_rot_Y(90);
        //        obj.modify_object(tmp, vary_cmpct_fctr);
        //        tmp = Matrix4x4.identity;
        //        obj.modify_object(tmp, (1 / vary_cmpct_fctr));
        //    }
        //    else
        //    {
        //        Matrix4x4 tmp = Matrix4x4.identity;
        //        obj.modify_object(tmp, vary_cmpct_fctr);
        //        tmp = Helper.get_rot_Y(90);
        //        obj.modify_object(tmp, (1 / vary_cmpct_fctr));
        //    }
        //}
        //If it is a saved session, there are 2 possibilities:
        //1. The old model files are used which does not vary compactness. In this case,
        // The constructor sets the stretch factor to 1 and so no stretch happens.
        //2. The new model files which vary compactness is used. In this case, the load
        // function would load values for vary_cmpct_dir and vary_cmpct_fctr and the obj
        // would be stretched.

        return(obj);
    }
Ejemplo n.º 3
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);
    }