Beispiel #1
0
    // update Unity representation of MuJoCo model
    unsafe private void UpdateModel()
    {
        MJP.TTransform transform;

        // update object states
        for (int i = 0; i < nobject; i++)
        {
            if (objects[i])
            {
                // set transform and visibility
                int visible;
                int selected;
                MJP.GetObjectState(i, &transform, &visible, &selected);
                SetTransform(objects[i], transform);
                objects[i].SetActive(visible > 0);

                // set emission color
                if (selected > 0)
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", selcolor);
                }
                else
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", Color.black);
                }
            }
        }

        // update camera
        MJP.GetCameraState(camindex, &transform);
        SetCamera(thecamera, transform);
        thecamera.fieldOfView = camfov[camindex + 1];
    }
Beispiel #2
0
    // add camera
    private unsafe void AddCamera()
    {
        if (enable_rendering == false)
        {
            Destroy(GameObject.Find("PreviewCamera"));
        }
        else
        {
            Destroy(GameObject.Find("DummyCamera"));
        }


        // add camera under root
        GameObject camobj = new GameObject("camera");

        camobj.layer = LayerMask.NameToLayer("PostProcessing");

        camobj.transform.parent = root.transform;
        Camera thecamera = camobj.AddComponent <Camera>();

        // For Furniture Assembly Environment: remove SITE from the culling mask
        thecamera.cullingMask     = 1 + (1 << 1) + (1 << 2) + (1 << 4) + (1 << 8);
        thecamera.backgroundColor = new Color(1f, 1f, 1f);
        thecamera.clearFlags      = CameraClearFlags.SolidColor;

        Shader             segshader = Shader.Find("Unlit/SegmentationColor");
        SegmentationShader shadersub = camobj.AddComponent <SegmentationShader>();

        DepthShader shaderdepth = camobj.AddComponent <DepthShader>();


        // For Furniture Assembly Environment: no post process
        //GameObject pp_obj = GameObject.Find("PostPocessing");
        //PostProcessLayer pp_layer = camobj.AddComponent<PostProcessLayer>();
        //var resources= Resources.FindObjectsOfTypeAll<PostProcessResources>();
        //pp_layer.Init(resources[0]);
        //pp_layer.volumeTrigger = camobj.transform;
        //pp_layer.volumeLayer = 1 << LayerMask.NameToLayer("PostProcessing");

        // set field of view, near, far
        MJP.TCamera cam;
        MJP.GetCamera(-1, &cam);
        thecamera.fieldOfView = cam.fov;

        // For Furniture Assembly Environment: set znear and zfar independent to model extent.
        thecamera.nearClipPlane = 0.01f;
        thecamera.farClipPlane  = 10f;

        //thecamera.nearClipPlane = cam.znear * this.transform.localScale.x;
        //thecamera.farClipPlane = cam.zfar * this.transform.localScale.x;

        // thecamera.enabled = false;
        //camobj.SetActive(enable_rendering);
        // set transform
        MJP.TTransform transform;
        MJP.GetCameraState(-1, &transform);
        SetCamera(thecamera, transform);
    }
Beispiel #3
0
    // add camera
    private unsafe void AddCamera()
    {
        if (enable_rendering == false)
        {
            Destroy(GameObject.Find("PreviewCamera"));
        }
        else
        {
            Destroy(GameObject.Find("DummyCamera"));
        }


        // add camera under root
        GameObject camobj = new GameObject("camera");

        camobj.layer = LayerMask.NameToLayer("PostProcessing");

        camobj.transform.parent = root.transform;
        Camera thecamera = camobj.AddComponent <Camera>();

        Shader             segshader = Shader.Find("Unlit/SegmentationColor");
        SegmentationShader shadersub = camobj.AddComponent <SegmentationShader>();

        GameObject pp_obj = GameObject.Find("PostPocessing");

        PostProcessLayer pp_layer = camobj.AddComponent <PostProcessLayer>();

        var resources = Resources.FindObjectsOfTypeAll <PostProcessResources>();

        pp_layer.Init(resources[0]);
        pp_layer.volumeTrigger = camobj.transform;
        pp_layer.volumeLayer   = 1 << LayerMask.NameToLayer("PostProcessing");

        // set field of view, near, far
        MJP.TCamera cam;
        MJP.GetCamera(-1, &cam);
        thecamera.fieldOfView   = cam.fov;
        thecamera.nearClipPlane = cam.znear * this.transform.localScale.x;
        thecamera.farClipPlane  = cam.zfar * this.transform.localScale.x;
        thecamera.enabled       = false;
        //camobj.SetActive(enable_rendering);
        // set transform
        MJP.TTransform transform;
        MJP.GetCameraState(-1, &transform);
        SetCamera(thecamera, transform);
    }
Beispiel #4
0
    // update Unity representation of MuJoCo model
    unsafe private void UpdateModel()
    {
        MJP.TTransform transform;

        // update object states
        for (int i = 0; i < nobject; i++)
        {
            if (objects[i])
            {
                // set transform and visibility
                int visible;
                int selected;
                MJP.GetObjectState(i, &transform, &visible, &selected);

                // For Furniture Assembly Environment: apply new geom position
                if (modifiedObjects.ContainsKey(objects[i].name))
                {
                    objects[i].transform.position = modifiedObjects[objects[i].name];
                }
                else
                {
                    SetTransform(objects[i], transform);
                }
                objects[i].SetActive(visible > 0);

                // set emission color
                if (selected > 0)
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", selcolor);
                }
                else
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", Color.black);
                }
            }
        }

        // update camera
        MJP.GetCameraState(camindex, &transform);
        SetCamera(thecamera, transform);
        thecamera.fieldOfView = camfov[camindex + 1];
    }
Beispiel #5
0
    // add camera
    private unsafe void AddCamera()
    {
        // add camera under root
        GameObject camobj = new GameObject("camera");

        camobj.transform.parent = root.transform;
        Camera thecamera = camobj.AddComponent <Camera>();

        // set field of view, near, far
        MJP.TCamera cam;
        MJP.GetCamera(-1, &cam);
        thecamera.fieldOfView   = cam.fov;
        thecamera.nearClipPlane = cam.znear;
        thecamera.farClipPlane  = cam.zfar;

        // set transform
        MJP.TTransform transform;
        MJP.GetCameraState(-1, &transform);
        SetCamera(thecamera, transform);
    }
Beispiel #6
0
    // per-frame update
    unsafe void Update()
    {
        // process input
        ProcessKeyboard();
        if (Input.mousePresent)
        {
            ProcessMouse();
        }

        // update object states
        MJP.TTransform transform;
        for (int i = 0; i < nobject; i++)
        {
            if (objects[i])
            {
                int visible;
                int selected;
                MJP.GetObjectState(i, &transform, &visible, &selected);
                SetTransform(objects[i], transform);
                objects[i].SetActive(visible > 0);

                // set emission color
                if (selected > 0)
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", selcolor);
                }
                else
                {
                    objects[i].GetComponent <Renderer>().material.SetColor("_EmissionColor", Color.black);
                }
            }
        }

        // update camera
        MJP.GetCameraState(camindex, &transform);
        SetCamera(thecamera, transform);
        thecamera.fieldOfView = camfov[camindex + 1];
    }