void LoadSim(int idx)
    {
        // read in results from json
        string predFile = Path.Combine(dataInDir, "eval_sim_" + idx.ToString());

        Debug.Log("Visualizing " + predFile);
        var jsonTextFile = Resources.Load <TextAsset>(predFile);

        m_curPred = PredInfo.CreateFromJSON(jsonTextFile.ToString());

        // read in mesh to use
        string meshFile = Path.Combine(m_baseModelDir, m_curPred.shape);

        meshFile += ".obj";
        Debug.Log(meshFile);

        OBJLoader.OBJMesh objLoaderMesh = OBJLoader.LoadOBJMesh(meshFile);
        Debug.Assert(objLoaderMesh.vertices.Count > 0);
        Debug.Assert(objLoaderMesh.faces.Count > 0);
        m_mesh = DataGenUtils.ToUnityMesh(objLoaderMesh);

        // create init object
        m_initObj = new GameObject("Sim" + idx.ToString() + "_Init");
        MeshFilter mfInit = m_initObj.AddComponent <MeshFilter>();

        mfInit.mesh = m_mesh;
        MeshRenderer mrInit = m_initObj.AddComponent <MeshRenderer>();

        mrInit.sharedMaterial           = initMat;
        m_initObj.transform.localScale  = m_curPred.scale;
        m_initObj.transform.position    = m_curPred.gt_pos[0];
        m_initObj.transform.eulerAngles = m_curPred.gt_rot[0];

        // create GT object
        m_gtObj = new GameObject("Sim" + idx.ToString() + "_GT");
        MeshFilter mf = m_gtObj.AddComponent <MeshFilter>();

        mf.mesh = m_mesh;
        MeshRenderer mr = m_gtObj.AddComponent <MeshRenderer>();

        mr.sharedMaterial             = gtMat;
        m_gtObj.transform.localScale  = m_curPred.scale;
        m_gtObj.transform.position    = m_curPred.gt_pos[0];
        m_gtObj.transform.eulerAngles = m_curPred.gt_rot[0];

        // create sampled object
        m_sampObj = new GameObject("Sim" + idx.ToString() + "_Samp");
        MeshFilter mf2 = m_sampObj.AddComponent <MeshFilter>();

        mf2.mesh = m_mesh;
        MeshRenderer mr2 = m_sampObj.AddComponent <MeshRenderer>();

        mr2.sharedMaterial              = sampMat;
        m_sampObj.transform.localScale  = m_curPred.scale;
        m_sampObj.transform.position    = m_curPred.samp_pos[0];
        m_sampObj.transform.eulerAngles = m_curPred.samp_rot[0];
    }
Esempio n. 2
0
    // returns false if we don't want to use this sim
    bool LoadSim(int predIdx, int idx, bool createGt)
    {
        // read in results from json
        string predFile = Path.Combine(m_predDataDirs[predIdx], "eval_sim_" + idx.ToString() + ".json");

        Debug.Log("Visualizing " + predFile);
        string jsonTextFile = ReadFile(predFile);

        m_curPreds.Add(PredInfo.CreateFromJSON(jsonTextFile));

        if (showTopplingOnly && !m_curPreds[predIdx].toppled)
        {
            // don't want to use this
            return(false);
        }

        if (showNonTopplingOnly && m_curPreds[predIdx].toppled)
        {
            return(false);
        }

        // find mesh to use
        string meshFile = "";

        for (int i = 0; i < m_baseModelDirs.Count; i++)
        {
            meshFile  = Path.Combine(m_baseModelDirs[i], m_curPreds[predIdx].shape);
            meshFile += ".obj";
            if (File.Exists(meshFile))
            {
                break;
            }
        }
        Debug.Log(meshFile);
        if (meshFile == "")
        {
            Debug.Log("Couldn't find mesh " + m_curPreds[predIdx].shape + "!");
            Application.Quit();
        }

        OBJLoader.OBJMesh objLoaderMesh = OBJLoader.LoadOBJMesh(meshFile);
        Debug.Assert(objLoaderMesh.vertices.Count > 0);
        Debug.Assert(objLoaderMesh.faces.Count > 0);
        m_mesh = DataGenUtils.ToUnityMesh(objLoaderMesh);

        // create GT object
        if (createGt && !hideGroundTruth)
        {
            m_gtObj = new GameObject("Sim" + idx.ToString() + "_GT");
            MeshFilter mf = m_gtObj.AddComponent <MeshFilter>();
            mf.mesh = m_mesh;
            MeshRenderer mr = m_gtObj.AddComponent <MeshRenderer>();
            mr.sharedMaterial             = gtMat;
            m_gtObj.transform.localScale  = m_curPreds[predIdx].scale;
            m_gtObj.transform.position    = m_curPreds[predIdx].gt_pos[0];
            m_gtObj.transform.eulerAngles = m_curPreds[predIdx].gt_euler_rot[0];
        }

        // create sampled object
        m_predObjs.Add(new GameObject("Sim" + idx.ToString() + "_Pred"));
        MeshFilter mf2 = m_predObjs[predIdx].AddComponent <MeshFilter>();

        mf2.mesh = m_mesh;
        MeshRenderer mr2 = m_predObjs[predIdx].AddComponent <MeshRenderer>();

        mr2.sharedMaterial = predMats[predIdx];
        m_predObjs[predIdx].transform.localScale  = m_curPreds[predIdx].scale;
        m_predObjs[predIdx].transform.position    = m_curPreds[predIdx].pred_pos[0];
        m_predObjs[predIdx].transform.eulerAngles = m_curPreds[predIdx].pred_rot[0];

        return(true);
    }