Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (frameCount < trainingImages + valImages)
     {
         if (frameCount % 1 == 0)
         {
             RandomAwake(comboxes_p1, comboxes_p2);
             RandomMovePosition(comboxes_p1, comboxes_p2, x_offset);
             synth.OnSceneChange();
             Debug.Log($"FrameCount: {frameCount}");
         }
         frameCount++;
         if (save)
         {
             if (frameCount < trainingImages)
             {
                 string filename = $"image_{(frameCount+0).ToString().PadLeft(5, '0')}";
                 synth.Save(filename, 1280, 720, "captures1/train", 2);
             }
             else if (frameCount < trainingImages + valImages)
             {
                 int    valFrameCount = frameCount - trainingImages;
                 string filename      = $"image_{(valFrameCount+0).ToString().PadLeft(5, '0')}";
                 synth.Save(filename, 1280, 720, "captures1/val", 2);
             }
         }
     }
 }
Exemplo n.º 2
0
    private Vector3[] transformCADObject()
    {
        // position
        float newX, newY, newZ;

        newX = UnityEngine.Random.Range(-5.0f, 5.0f);
        newY = UnityEngine.Random.Range(0.0f, -5.0f);
        newZ = UnityEngine.Random.Range(0.0f, 5.0f);

        Vector3 newPosition = new Vector3(newX, newY, newZ);
        // Rotation
        var newRot = Quaternion.Euler(0, UnityEngine.Random.Range(-180, 180), 0);

        //Debug.Log($"initPos  {initPos}");
        cadObj.transform.position = initPos - newPosition;
        cadObj.transform.rotation = newRot * initRot;

        Vector3[] transformedObjPoints = new Vector3[kpLen];
        int       i = 0;

        foreach (var p3D in objPts)
        {
            //Vector3 obj = newRot * (new Vector3(p3D.X, p3D.Y, p3D.Z) - cadObj.transform.position) + cadObj.transform.position;
            Vector3 obj = new Vector3(p3D.X, p3D.Y, p3D.Z);
            // Apply same rotation to points as object
            obj = newRot * obj;
            // Apply same transaltion to points as object
            obj = obj + initPos - newPosition;
            //Debug.Log($"obj after {obj}");
            transformedObjPoints[i] = obj;
            i++;
        }
        Debug.Log($"PoBJECT TRANSFORME ");
        synth.OnSceneChange();
        return(transformedObjPoints);
    }
Exemplo n.º 3
0
    /******************
    * Custom methods *
    ******************/

    void GenerateRandomShapes()
    {
        // Destroy existing objects before creating new ones
        pool.ReclaimAll();

        int objectsThisTime = Random.Range(minObjects, maxObjects);

        // Create objects with random properties
        for (int i = 0; i < objectsThisTime; i++)
        {
            // Pick a random prefab
            int prefabIndex = Random.Range(0, prefabs.Length);

            // Set position
            float newX, newY, newZ;
            newX = Random.Range(-10.0f, 10.0f);
            newY = Random.Range(2.0f, 10.0f);
            newZ = Random.Range(-10.0f, 10.0f);
            Vector3 newPos = new Vector3(newX, newY, newZ);

            // Set rotation
            Quaternion newRot = Random.rotation;

            // Set color
            float newR, newG, newB;
            newR = Random.Range(0.0f, 1.0f);
            newG = Random.Range(0.0f, 1.0f);
            newB = Random.Range(0.0f, 1.0f);
            Color newColor = new Color(newR, newG, newB);

            // Set scale
            float   s        = Random.Range(0.5f, 4.0f);
            Vector3 newScale = new Vector3(s, s, s);

            // Place the prefab in the scene with its new properties
            Shape      shape  = pool.Get((ShapeLabel)prefabIndex);
            GameObject newObj = shape.obj;
            newObj.transform.position   = newPos;
            newObj.transform.localScale = newScale;
            newObj.transform.localScale = newScale;
            newObj.GetComponent <Renderer>().material.color = newColor;
        }

        // Redraw the image for each hidden camera
        synth.OnSceneChange(useGrayScale);
    }
    // Update is called once per frame
    void Update()
    {
        if (frameCount < HowManyImages)
        {
            moveCamera();
            rotateLight();
            string filename = $"{frameCount.ToString().PadLeft(10, '0')}";
            synth.Save(filename, ImgSizeX, ImgSizeY, "syntheticData");

            synth.OnSceneChange();
            frameCount++;
            slider.value = (float)frameCount / (float)HowManyImages;
        }
        else
        {
            EditorApplication.isPlaying = false;
        }
    }
    void GenerateRandom()
    {
        pool.ReclaimAll();
        int objectsThisTime = Random.Range(minObjects, maxObjects);

        for (int i = 0; i < objectsThisTime; i++)
        {
            // pick out a prefab
            int        prefabIndx = Random.Range(0, prefabs.Length);
            GameObject prefab     = prefabs[prefabIndx];

            // Pick a random position
            float newX, newY, newZ;
            newX = Random.Range(13.0f, -13.0f);
            newY = Random.Range(2.0f, 10.0f);
            newZ = Random.Range(13.0f, -13.0f);

            var newPos = new Vector3(newX, newY, newY);

            // Random Rotation
            var newRot = Random.rotation;

            var shape  = pool.Get((ShapeLabel)prefabIndx);
            var newObj = shape.obj;
            newObj.transform.position = newPos;
            newObj.transform.rotation = newRot;

            // Scale
            float   sx       = Random.Range(0.5f, 4.0f);
            Vector3 newScale = new Vector3(sx, sx, sx);
            newObj.transform.localScale = newScale;

            // Color
            float newR, newG, newB;
            newR = Random.Range(0.0f, 1.0f);
            newG = Random.Range(0.0f, 1.0f);
            newB = Random.Range(0.0f, 1.0f);

            var newColor = new Color(newR, newG, newB);
            newObj.GetComponent <Renderer>().material.color = newColor;
        }
        synth.OnSceneChange(grayscale);
    }
Exemplo n.º 6
0
    void GenerateRandom()
    {
        pool.ReclaimAll();
        int objectsThisTime = Random.Range(minObjects, maxObjects);

        for (int i = 0; i < objectsThisTime; i++)
        {
            //Выбираем случайный префаб
            int        prefabIndx = Random.Range(0, prefabs.Length);
            GameObject prefab     = prefabs[prefabIndx];

            //Позиция для префаба
            float newX, newY, newZ;
            newX = Random.Range(-10.0f, 10.0f);
            newY = Random.Range(2.0f, 10.0f);
            newZ = Random.Range(-10.0f, 10.0f);

            Vector3 newPos = new Vector3(newX, newY, newZ);
            var     newRot = Random.rotation;

            var        shape  = pool.Get((ShapeLabel)prefabIndx);
            GameObject newObj = shape.obj;
            newObj.transform.position = newPos;
            newObj.transform.rotation = newRot;

            //Размер
            float   scaleFactor = Random.Range(0.5f, 2.0f);
            Vector3 newScale    = new Vector3(scaleFactor, scaleFactor, scaleFactor);
            newObj.transform.localScale = newScale;

            //Цвет
            float newR, newG, newB;
            newR = Random.Range(0.0f, 1.0f);
            newG = Random.Range(0.0f, 1.0f);
            newB = Random.Range(0.0f, 1.0f);
            var newColor = new Color(newR, newG, newB);
            newObj.GetComponent <Renderer>().material.color = newColor;
        }
        synth.OnSceneChange(grayscale);
    }
Exemplo n.º 7
0
    void GenerateRandom()
    {
        pool.ReclaimAll();

        for (int i = 0; i < maxObjects; i++)
        {
            int        perfabIndx = Random.Range(0, prefabs.Length);
            GameObject prefab     = prefabs[perfabIndx];

            float newX, newY, newZ;
            newX = Random.Range(-10.0f, -10.0f);
            newY = Random.Range(-2.0f, 10.0f);
            newZ = Random.Range(-8.0f, 6.0f);

            Vector3 newPos = new Vector3(newX, newY, newZ);

            var newRot = Random.rotation;

            var shape  = pool.Get((ShapeLabel)perfabIndx);
            var newObj = shape.obj;
            newObj.transform.position = newPos;
            newObj.transform.rotation = newRot;

            float   xs       = Random.Range(0.5f, 4.0f);
            Vector3 newScale = new Vector3(xs, xs, xs);
            newObj.transform.localScale = newScale;

            //color
            float newR, newG, newB;
            newR = Random.Range(0.0f, 1.0f);
            newG = Random.Range(0.0f, 1.0f);
            newB = Random.Range(0.0f, 1.0f);

            var newColor = new Color(newR, newG, newB);
            newObj.GetComponent <Renderer>().material.color = newColor;
        }
        synth.OnSceneChange();
    }
Exemplo n.º 8
0
    private Vector3[] transformCADObject(string folder, string filename)
    {
        TextWriter rotFile   = new StreamWriter(Path.Combine(folder, filename + "_img-Rot.txt"));
        TextWriter transFile = new StreamWriter(Path.Combine(folder, filename + "_img-Trans.txt"));

        // position
        float newX, newY, newZ;

        newX = UnityEngine.Random.Range(-30.0f, 30.0f);
        newY = UnityEngine.Random.Range(-5.0f, -10.0f);
        newZ = UnityEngine.Random.Range(20.0f, -30.0f);

        Vector3 newPosition = new Vector3(newX, newY, newZ);
        // Rotation
        var newRot = Quaternion.Euler(0, UnityEngine.Random.Range(-180, 180), 0);

        //Debug.Log($"initPos  {initPos}");
        cadObj.transform.position = initPos - newPosition;
        cadObj.transform.rotation = newRot * initRot;

        var newTrasform = cadObj.transform;

        Vector3[] transformedObjPoints = new Vector3[kpLen];
        int       i = 0;

        foreach (var p3D in objPts)
        {
            //Vector3 obj = newRot * (new Vector3(p3D.X, p3D.Y, p3D.Z) - cadObj.transform.position) + cadObj.transform.position;
            Vector3 obj = new Vector3(p3D.X, p3D.Y, p3D.Z);
            // Apply same rotation to points as object
            obj = newRot * obj;
            // Apply same transaltion to points as object
            obj = obj + initPos - newPosition;
            //Debug.Log($"obj 2 after {obj}");

            transformedObjPoints[i] = obj;
            i++;
        }

        //### Code written for calculating rotation and translation,
        var objTransform = cadObj.transform;
        var r            = objTransform.localRotation;
        var t            = objTransform.localPosition;
        var s            = objTransform.localScale;

        Matrix4x4 m = Matrix4x4.identity;

        m.SetTRS(t, r, s);

        // CHangin sign of row 0,2,3, as Y-coordinate is inverted in Python and then normalized the values.
        rotFile.WriteLine((-m[0, 0] / s.x) + " " + (-m[0, 1] / s.y) + " " + (-m[0, 2] / s.z));
        rotFile.WriteLine(m[1, 0] / s.x + " " + m[1, 1] / s.y + " " + m[1, 2] / s.z);
        rotFile.WriteLine((-m[2, 0] / s.x) + " " + (-m[2, 1] / s.y) + " " + (-m[2, 2] / s.z));
        transFile.WriteLine((-m[0, 3] / s.x) + " " + m[1, 3] / s.y + " " + (-m[2, 3] / s.z));

        rotFile.Flush();
        transFile.Flush();

        //Debug.Log($"PoBJECT TRANSFORME ");
        synth.OnSceneChange();
        return(transformedObjPoints);
    }
    void GenerateRandom()
    {
        pool.ReclaimAll();
        int objectsThisTime = 8;

        for (int i = 0; i < objectsThisTime; i++)
        {
            //pick out prefab
            int prefabIndx = 0;
            if (i == 0 || i == 1)
            {
                prefabIndx = 0;
            }
            else if (i == 2 || i == 3)
            {
                prefabIndx = 1;
            }
            else if (i == 4 || i == 6) //Careful to include the correct index here, in the Scene Controller prefab2 should be Jawlft and prefab3 should be jaw right
            {
                prefabIndx = 2;
            }
            else
            {
                prefabIndx = 3;
            }

            GameObject prefab = prefabs[prefabIndx];


            if (i == 0)
            {
                //OBJECT 1 SHAFT RIGHT ARM

                /*
                 * DATA from Python script
                 * JOINT 4 PSM_1 SHAFT RIGHT ARM Orientation in quaternions  WXYZ [ 0.06844   0.458484 -0.60438   0.647945]
                 * JOINT 4 PSM_1 SHAFT RIGHT ARM Position in mm [14.620537  3.197187 64.227186]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = 14.620537f;
                newY = 3.197186f;
                newZ = 64.227186f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.458484f;
                float quatY = -0.60438f;
                float quatZ = 0.647945f;
                float quatW = 0.06844f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 1)
            {
                //OBJECT 2 SHAFT LEFT ARM

                /*
                 * DATA from Python script
                 *
                 * JOINT 4 PSM_2 SHAFT LEFT ARM Orientation in quaternions  WXYZ [ 0.647431 -0.618062 -0.015413 -0.44564 ]
                 * JOINT 4 PSM_2 SHAFT LEFT ARM Position in mm [-29.382017  11.433768  96.028443]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = -29.382016f;
                newY = 11.433768f;
                newZ = 96.028442f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = -0.618062f;
                float quatY = -0.015413f;
                float quatZ = -0.44564f;
                float quatW = 0.647431f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 2)
            {
                //OBJECT 3 LOGO BODY RIGHT ARM

                /*
                 * DATA from Python script
                 *
                 * JOINT 5 PSM_1 LOGO BODY RIGHT ARM Orientation in quaternions  WXYZ [ 0.85215  -0.171896  0.181329 -0.459795]
                 * JOINT 5 PSM_1 LOGO BODY RIGHT ARM Position in mm [14.620537  3.197187 64.227186]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = 14.620537f;
                newY = 3.197187f;
                newZ = 64.227186f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = -0.171896f;
                float quatY = 0.181329f;
                float quatZ = -0.459795f;
                float quatW = 0.85215f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 3)
            {
                //OBJECT 4 LOGO BODY LEFT ARM

                /*
                 * DATA from Python script
                 *
                 * JOINT 5 PSM_2 LOGO BODY LEFT ARM Orientation in quaternions  WXYZ [ 0.873159  0.055205 -0.104977  0.472785]
                 * JOINT 5 PSM_2 LOGO BODY RIGHT ARM Position in mm [-29.382017  11.433768  96.028443]
                 */

                //Position
                float newX, newY, newZ;
                newX = -29.382017f;
                newY = 11.433768f;
                newZ = 96.028443f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.055205f;
                float quatY = -0.104977f;
                float quatZ = 0.472785f;
                float quatW = 0.873159f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 4)
            {
                //OBJECT 5  LEFT-JAW RIGHT-ARM

                /*
                 * DATA from Python script
                 *
                 * OLD - JAWS_TOGETHER
                 * JOINT 6 PSM_1 JAW RIGHT ARM Orientation in quaternions  WXYZ [ 0.207232  0.472756  0.228358 -0.825475]
                 * JOINT 6 PSM_1 JAW RIGHT ARM Position in mm [ 8.056809 -1.517353 68.410556]
                 *
                 * NEW
                 * JOINT 6 PSM_1 LEFT-JAW RIGHT-ARM Orientation in quaternions  WXYZ [ 0.096489  0.507083  0.038358 -0.85562 ]
                 * JOINT 6 PSM_1 LEFT-JAW RIGHT-ARM Position in mm [ 8.056809 -1.517353 68.410556]
                 *
                 *
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = 8.056809f;
                newY = -1.517353f;
                newZ = 68.410556f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.507083f;
                float quatY = 0.038358f;
                float quatZ = -0.85562f;
                float quatW = 0.096489f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 5)
            {
                //OBJECT 6 RIGHT-JAW RIGHT-ARM

                /*
                 * DATA from Python script
                 * OLD - JAWS_TOGETHER
                 * JOINT 6 PSM_1 JAW RIGHT ARM Orientation in quaternions  WXYZ [ 0.207232  0.472756  0.228358 -0.825475]
                 * JOINT 6 PSM_1 JAW RIGHT ARM Position in mm [ 8.056809 -1.517353 68.410556]
                 *
                 * NEW
                 * JOINT 6 PSM_1 RIGHT-JAW RIGHT-ARM Orientation in quaternions  WXYZ [ 0.30752   0.414578  0.406837 -0.753684]
                 * JOINT 6 PSM_1 RIGHT-JAW RIGHT-ARM Position in mm [ 8.056809 -1.517353 68.410556]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = 8.056809f;
                newY = -1.517353f;
                newZ = 68.410556f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.414578f;
                float quatY = 0.406837f;
                float quatZ = -0.753684f;
                float quatW = 0.30752f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else if (i == 6)
            {
                //OBJECT 7 LEFT-JAW LEFT-ARM

                /*
                 * DATA from Python script
                 * OLD - JAWS_TOGETHER
                 * JOINT 6 PSM_2 JAW LEFT ARM Orientation in quaternions  WXYZ [ 0.684541  0.311392  0.642027 -0.149132]
                 * JOINT 6 PSM_2 JAW LEFT ARM Position in mm [-21.763284   6.4574    96.054437]
                 *
                 * NEW
                 * JOINT 6 PSM_2 LEFT-JAW LEFT-ARM Orientation in quaternions  WXYZ [ 0.581031  0.477455  0.581818 -0.309721]
                 * JOINT 6 PSM_2 LEFT-JAW LEFT-ARM Position in mm [-21.763284   6.4574    96.054437]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = -21.763284f;
                newY = 6.4574f;
                newZ = 96.054437f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.477455f;
                float quatY = 0.581818f;
                float quatZ = -0.309721f;
                float quatW = 0.581031f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
            else
            {
                //OBJECT 8 RIGHT-JAW LEFT-ARM

                /*
                 * DATA from Python script
                 * OLD - JAWS_TOGETHER
                 * JOINT 6 PSM_2 JAW LEFT ARM Orientation in quaternions  WXYZ [ 0.684541  0.311392  0.642027 -0.149132]
                 * JOINT 6 PSM_2 JAW LEFT ARM Position in mm [-21.763284   6.4574    96.054437]
                 *
                 * NEW_DATA
                 * JOINT 6 PSM_2 RIGHT-JAW LEFT-ARM Orientation in quaternions  WXYZ [0.741704 0.124245 0.658767 0.021553]
                 * JOINT 6 PSM_2 RIGHT-JAW LEFT-ARM Position in mm [-21.763284   6.4574    96.054437]
                 *
                 */

                //Position
                float newX, newY, newZ;
                newX = -21.763284f;
                newY = 6.4574f;
                newZ = 96.054437f;
                var newPos = new Vector3(newX, newY, newZ);

                var shape  = pool.Get((ShapeLabel)prefabIndx);
                var newObj = shape.obj;
                newObj.transform.position = newPos;

                //Rotation

                float quatX = 0.124245f;
                float quatY = 0.658767f;
                float quatZ = 0.021553f;
                float quatW = 0.741704f;
                newObj.transform.rotation = new Quaternion(quatX, quatY, quatZ, quatW);

                //Scale
                float   sx       = 100.0f;
                Vector3 newScale = new Vector3(sx, sx, sx);
                newObj.transform.localScale = newScale;

                // Color

                /*
                 * float newR, newG, newB;
                 * newR = Random.Range(0.0f, 1.0f);
                 * newG = Random.Range(0.0f, 1.0f);
                 * newB = Random.Range(0.0f, 1.0f);
                 *
                 * var newColor = new Color(newR, newG, newB);
                 * newObj.GetComponent<Renderer>().material.color = newColor;
                 */
            }
        }
        synth.OnSceneChange(grayscale);
    }
Exemplo n.º 10
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        //print ("steps: " + GetStepCount ());
        rs_action = false;
        if (GetStepCount() < 1)
        {
            imgSyn.OnSceneChange();
        }
        if (vectorAction [0] == 0)
        {
            Menuver(MenuverType.Xplus);
        }
        else if (vectorAction [0] == 1)
        {
            Menuver(MenuverType.Xminus);
        }
        else if (vectorAction [0] == 2)
        {
            Menuver(MenuverType.Yplus);
        }
        else if (vectorAction [0] == 3)
        {
            Menuver(MenuverType.Yminus);
        }
        else if (vectorAction [0] == 4)
        {
            Menuver(MenuverType.Zplus);
        }

        else if (vectorAction[0] == 5 || vectorAction[0] == 6)      // 5/6 = up/down resolution
        {
            Menuver(MenuverType.None);
            //rs_action = true;
            //RequestDecision ();
        }

        /*if (vectorAction [0] == 5)
         *      Menuver (MenuverType.Zminus);*/

        distance = Vector3.Distance(transform.position, TargetRb.position);
        if (GetStepCount() >= 1)
        {
            //print ("old" + old_distance + "dis:" + distance);
            AddReward(0.1f * (old_distance - distance));
        }
        AddReward(-0.0002f);          //timestep penalty
        old_distance           = distance;
        Monitor.verticalOffset = 300f;
        Monitor.Log("Action", vectorAction [0], MonitorType.text);



        /*
         * else if (!ckp1 && transform.position.magnitude < 2 )
         * {
         *      //AddReward (0.5f);
         *      ckp1 = true;
         * }
         * else if (!ckp2 && transform.position.magnitude < 5)
         * {
         *      //AddReward (0.3f);
         *      ckp2 = true;
         * }*/
    }
Exemplo n.º 11
0
        public void RandomInitialize(ServerAction response)
        {
            bool success = true;

            this.excludeObjectIds = response.excludeObjectIds;

            Dictionary <SimObjType, HashSet <SimObjType> > receptacleObjects = new Dictionary <SimObjType, HashSet <SimObjType> > ();
            HashSet <SimObjType> pickupable = new HashSet <SimObjType> ();

            foreach (ReceptacleObjectList rol in response.receptacleObjects)
            {
                HashSet <SimObjType> objectTypes    = new HashSet <SimObjType> ();
                SimObjType           receptacleType = (SimObjType)Enum.Parse(typeof(SimObjType), rol.receptacleObjectType);
                foreach (string itemObjectType in rol.itemObjectTypes)
                {
                    objectTypes.Add((SimObjType)Enum.Parse(typeof(SimObjType), itemObjectType));
                    pickupable.Add((SimObjType)Enum.Parse(typeof(SimObjType), itemObjectType));
                }
                receptacleObjects.Add(receptacleType, objectTypes);
            }
            Debug.Log("random seed:Z " + response.randomSeed);
            System.Random rnd = new System.Random(response.randomSeed);


            SimObj[] simObjects = GameObject.FindObjectsOfType(typeof(SimObj)) as SimObj[];
            // Sorting to ensure that our randomization is deterministic when using a seed
            // without sorting, there is no guarantee how the objects will get returned from from FindObjectsOfType
            // so the shuffle becomes non-deterministic
            Array.Sort(simObjects, delegate(SimObj a, SimObj b) {
                return(a.UniqueID.CompareTo(b.UniqueID));
            });

            int pickupableCount = 0;

            for (int i = 0; i < simObjects.Length; i++)
            {
                SimObj so = simObjects [i];
                if (IsPickupable(so))
                {
                    pickupableCount++;
                    SimUtil.TakeItem(so);
                }


                if (IsOpenable(so) && response.randomizeOpen)
                {
                    if (rnd.NextDouble() < 0.5)
                    {
                        openSimObj(so);
                    }
                    else
                    {
                        closeSimObj(so);
                    }
                }
            }

            //shuffle objects
            rnd = new System.Random(response.randomSeed);

            for (int i = 0; i < simObjects.Length; i++)
            {
                SimObj so          = simObjects [i];
                int    randomIndex = rnd.Next(i, simObjects.Length);
                simObjects [i]           = simObjects [randomIndex];
                simObjects [randomIndex] = so;
            }



            rnd = new System.Random(response.randomSeed);
            List <SimObj> simObjectsFiltered = new List <SimObj> ();

            for (int i = 0; i < simObjects.Length; i++)
            {
                SimObj so = simObjects [i];

                if (IsPickupable(so) && pickupable.Contains(so.Type))
                {
                    double val = rnd.NextDouble();


                    if (val > response.removeProb)
                    {
                        // Keep the item
                        int numRepeats = 1;
                        if (response.maxNumRepeats > 1)
                        {
                            numRepeats = rnd.Next(1, response.maxNumRepeats);
                        }
                        for (int j = 0; j < numRepeats; j++)
                        {
                            // Add a copy of the item.
                            SimObj copy = Instantiate(so);
                            copy.name    += "" + j;
                            copy.UniqueID = so.UniqueID + "_copy_" + j;
                            simObjectsFiltered.Add(copy);
                        }
                    }
                    else
                    {
                        pickupableCount--;
                    }
                }
                else
                {
                    simObjectsFiltered.Add(simObjects [i]);
                }
            }


            simObjects = simObjectsFiltered.ToArray();
            int randomTries = 0;
            HashSet <SimObjType> seenObjTypes = new HashSet <SimObjType> ();

            rnd = new System.Random(response.randomSeed);
            while (pickupableCount > 0)
            {
                if (randomTries > 5)
                {
                    Debug.Log("Pickupable count still at, but couldn't place all objects: " + pickupableCount);
                    success = false;
                    break;
                }
                randomTries++;

                int[] randomOrder = new int[simObjects.Length];
                for (int rr = simObjects.Length - 1; rr >= 0; rr--)
                {
                    int randomLoc = simObjects.Length - 1 - rnd.Next(0, (simObjects.Length - rr));
                    randomOrder [rr]        = randomOrder [randomLoc];
                    randomOrder [randomLoc] = rr;
                }
                for (int ss = 0; ss < simObjects.Length; ss++)
                {
                    int j = randomOrder [ss];
                    foreach (SimObj so in simObjects)
                    {
                        if (so.IsReceptacle && !excludeObject(so))
                        {
                            if (response.excludeReceptacleObjectPairs != null &&
                                Array.Exists(response.excludeReceptacleObjectPairs, e => e.objectId == simObjects [j].UniqueID && e.receptacleObjectId == so.UniqueID))
                            {
                                //Debug.Log ("skipping object id receptacle id pair, " + simObjects [j].UniqueID + " " + so.UniqueID);
                                continue;
                            }

                            if (IsPickupable(simObjects [j]) &&
                                receptacleObjects.ContainsKey(so.Type) &&
                                receptacleObjects [so.Type].Contains(simObjects [j].Type) &&
                                (!response.uniquePickupableObjectTypes || !seenObjTypes.Contains(simObjects [j].Type)) &&
                                SimUtil.AddItemToReceptacle(simObjects [j], so.Receptacle))
                            {
                                //Debug.Log ("Put " + simObjects [j].Type + " " + simObjects[j].name + " in " + so.Type);
                                seenObjTypes.Add(simObjects [j].Type);
                                pickupableCount--;
                                break;
                            }
                        }
                    }
                }
            }

            if (response.randomizeObjectAppearance)
            {
                // Use a random texture for each object individually.
                rnd = new System.Random(response.randomSeed);
                for (int i = 0; i < simObjects.Length; i++)
                {
                    SimObj so = simObjects [i];
                    if (so.gameObject.activeSelf)
                    {
                        Randomizer randomizer = (so.gameObject.GetComponentInChildren <Randomizer> () as Randomizer);
                        if (randomizer != null)
                        {
                            randomizer.Randomize(rnd.Next(0, 2147483647));
                        }
                    }
                }
            }


            if (imageSynthesis != null)
            {
                imageSynthesis.OnSceneChange();
            }

            actionFinished(success);
        }