protected override void actionFinished(bool success) { lastActionSuccess = success; emitState = emitStates.Send; actionCounter = 0; targetTeleport = Vector3.zero; }
// Decide whether agent has stopped actions // And if we need to capture a new frame private void LateUpdate() { if (emitState == emitStates.Send) { emitState = emitStates.Wait; StartCoroutine(EmitFrame()); } }
protected override void Start() { frameCounter = actionCounter = 0; emitState = emitStates.Send; base.Start(); // always zero out the rotation transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f)); m_Camera.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f); //startingHandPosition = getHand ().transform.localPosition; }
private IEnumerator EmitFrame() { frameCounter += 1; // we should only read the screen buffer after rendering is complete yield return(new WaitForEndOfFrame()); MetadataWrapper metaMessage = generateMetadataWrapper(); metaMessage.lastAction = lastAction; metaMessage.lastActionSuccess = lastActionSuccess; metaMessage.errorMessage = errorMessage; metaMessage.sequenceId = this.currentSequenceId; List <InventoryObject> ios = new List <InventoryObject>(); foreach (string objectId in inventory.Keys) { SimObj so = inventory [objectId]; InventoryObject io = new InventoryObject(); io.objectId = so.UniqueID; io.objectType = Enum.GetName(typeof(SimObjType), so.Type); ios.Add(io); } metaMessage.inventoryObjects = ios.ToArray(); WWWForm form = new WWWForm(); if (!serverSideScreenshot) { // create a texture the size of the screen, RGB24 format int width = Screen.width; int height = Screen.height; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); // read screen contents into the texture tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); // encode texture into JPG - XXX SHOULD SET QUALITY byte[] bytes = tex.EncodeToPNG(); Destroy(tex); form.AddBinaryData("image", bytes, "frame-" + frameCounter.ToString().PadLeft(7, '0') + ".png", "image/png"); } // for testing purposes, also write to a file in the project folder // File.WriteAllBytes(Application.dataPath + "/Screenshots/SavedScreen" + frameCounter.ToString() + ".png", bytes); // Debug.Log ("Frame Bytes: " + bytes.Length.ToString()); //string img_str = System.Convert.ToBase64String (bytes); form.AddField("metadata", JsonUtility.ToJson(metaMessage)); form.AddField("token", robosimsClientToken); WWW w = new WWW("http://127.0.0.1:" + robosimsPort + "/train", form); yield return(w); if (!string.IsNullOrEmpty(w.error)) { Debug.Log("Error: " + w.error); yield break; } else { emitState = emitStates.Received; ProcessControlCommand(w.text); } }