void OnMouseDown() { Debug.Log("print funct start"); //1. get canvas image (Texture2D) GameObject canvas = GameObject.Find("canvas"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI> (); Texture2D canvasTex; if (canvasScript == null) { Sandart sandartCanvasScript = canvas.GetComponent <Sandart> (); canvasTex = sandartCanvasScript.GetCanvasTex(); } else { canvasTex = canvasScript.GetCanvasTex(); } byte[] canvasPng = canvasTex.EncodeToPNG(); string galleryPath = Application.dataPath + "/galleryData/"; File.WriteAllBytes(galleryPath + "temp.png", canvasPng); fnPrint_PngFilePrint(galleryPath + "temp.png"); File.Delete(galleryPath + "temp.png"); Debug.Log("Print Ok!"); }
void OnMouseDown() { /*step * 1. get canvas image (Texture2D) * 2. encode the image to png file * 3. save file to specific directory */ //1. get canvas image (Texture2D) GameObject canvas = GameObject.Find("canvas"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI> (); Texture2D canvasTex; if (canvasScript == null) { Sandart sandartCanvasScript = canvas.GetComponent <Sandart> (); canvasTex = sandartCanvasScript.GetCanvasTex(); } else { canvasTex = canvasScript.GetCanvasTex(); } //2. encode the image to png file byte[] canvasPng = canvasTex.EncodeToPNG(); string galleryPath = Application.dataPath + "/galleryData/"; //3. save file to specific directory int fcount = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories).Length; // Count the number of file(파일개수) string[] files = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories); // String array(save screenshot file) int limit = 6; // if file number reached at limit number, then delete the oldest file if (fcount == limit) { string filename = files[0].Substring(files[0].Length - 18, 14); // 'a.png' -> 'a' File.Delete(files [0]); if (File.Exists(galleryPath + filename + ".data")) { string[] data = Directory.GetFiles(galleryPath, filename + ".data", SearchOption.AllDirectories); string[] buf = Directory.GetFiles(galleryPath, filename + ".buf", SearchOption.AllDirectories); File.Delete(data [0]); File.Delete(buf [0]); } } File.WriteAllBytes(galleryPath + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".png", canvasPng); }
void OnMouseDown() { if (Input.GetMouseButtonDown(0)) // left button down { paintobj = GameObject.Find("pallete/paint4"); Color color = paintobj.renderer.material.color; GameObject canvas = GameObject.Find("canvas"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI>(); canvasScript.OnColorChange(color); GameObject view = GameObject.Find("colorview"); view.renderer.material.color = color; GameObject palobj = GameObject.Find("pallete"); pal = palobj.GetComponent <palette>(); pal.check = 0; } }
public void OnCanvasDown() { paintobj = GameObject.Find("pallete/paint4"); Color color = paintobj.renderer.material.color; GameObject canvas = GameObject.Find("canvas"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI>(); canvasScript.OnColorChange(color); GameObject view = GameObject.Find("colorview"); view.renderer.material.color = color; GameObject palobj = GameObject.Find("pallete"); pal = palobj.GetComponent <palette>(); pal.check = 0; }
// Use this for initialization void Start() { string dataname = PlayerPrefs.GetString("art"); // Receive datafile's name /* If datafile's name is not empty, load datafile to wateroil scene */ if (PlayerPrefs.HasKey("art")) { Debug.Log("dataname : " + dataname); GameObject canvas = GameObject.Find("canvas"); GameObject pallete = GameObject.Find("pallete"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI>(); palette palleteScript = pallete.GetComponent <palette>(); palleteScript.init(dataname + ".data"); canvasScript.init(dataname + ".buf"); } PlayerPrefs.DeleteKey("art"); }
private void callGameObjByKinect(short[] depthBuf) { //Color32[] img = new Color32[depthBuf.Length]; minDepth = 0; // initialize mindepth per frame minPoint.Set(0, 0); for (int pix = 0; pix < depthBuf.Length; pix += 2) { // 's' key was pressed and two canvas vertex(leftTop, rightBottom) are not detected // restrict depth range from 800mm to 1000mm b/c IR noise (kinect depth accruacy decreases with increasing distance from the sensor) if (depthSnapshot != null && pointCount == 2 && depthBuf [pix] >= 700 && depthSnapshot [pix] <= 1000) // pointCount != 2 -> two points were detected { Vector2 currentPtr = valueToPoint(pix, 320); if (currentPtr.x > ROIVertex [0].x && currentPtr.x <ROIVertex [1].x && currentPtr.y> ROIVertex[0].y && currentPtr.y < ROIVertex [1].y) { short depthDiff = (short)(depthSnapshot [pix] - depthBuf [pix]); if (minDepth < depthDiff) // find greatest depth diff //Debug.Log("point detected "+depthSnapshot[pix]+","+depthBuf[pix]); { minPoint = currentPtr; minDepth = depthDiff; } } } } Debug.Log("mindep : " + minDepth); // if(minDepth <= errorRange){ // stable state // if(isDetected == false){ // Debug.Log("stable state"); // } // isDetected = true; // }else{ // // } // // if (minDepth > 30 && isDetected == true && pointCount < 2) { // Debug.Log((pointCount + 1)+" point detected"); // ROIVertex [pointCount++] = minPoint; // // isDetected = false; // until canvas state turn back to stable state // } //test// if (pointCount == 2 && minDepth > errorRange) { if (isDetected == false) { isDetected = true; } float x, y; //find x,y ratio x = (minPoint.x - ROIVertex[0].x) / (ROIVertex[1].x - ROIVertex[0].x); y = (minPoint.y - ROIVertex[0].y) / (ROIVertex[1].y - ROIVertex[0].y); // b/c kinect look at the canvas in reverse // coordinates transformation from kinect to unity y = 1 - y; // for debuging if (guiT != null) { guiT.transform.position = new Vector3(x, y, 0f); } //y -= 0.06f; // adjust calibration manually text.guiText.text = "spandex pos : " + x + "," + y; Vector2 worldPoint = new Vector2(Screen.width * x, Screen.height * y); //2. find game object by kinect input(2D coordinates) GameObject gameObject = findGameObject(worldPoint.x, worldPoint.y); GameObject colorSelector = findColorSelector(worldPoint.x, worldPoint.y); //3. call the onSpandexDown method if (gameObject != null) { if (gameObject.name == "canvas") { drawingOnGUI canvasScript = gameObject.GetComponent <drawingOnGUI>(); canvasScript.OnCanvasDown(worldPoint, minDepth); // TODO complete params } else if (colorSelector != null) { GameObject.Find("Control - Circular Color Picker").SendMessage("OnCanvasDown", worldPoint); } else { gameObject.SendMessage("OnCanvasDown"); } //Debug.Log ("gameobject found : " + gameObject.name); } prevMinPtr = worldPoint; } else if (pointCount == 2 && minDepth < errorRange && isDetected == true) { isDetected = false; if (findGameObject(prevMinPtr.x, prevMinPtr.y).name == "canvas") // 'spandex canvas up' on 'drawing canvas' { GameObject.Find("canvas").SendMessage("OnCanvasUp"); } prevMinPtr.Set(0, 0); } }
void OnMouseDown() { // file : screenshot, paint + scene, drawing data /* Step * 1. sence name * 2. paint * 3. */ GameObject canvas = GameObject.Find("canvas"); drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI> (); if (canvasScript.isCanvasChange() == false) // no change in canvas { return; } string galleryPath = Application.dataPath + "/galleryData/"; string canvasID = canvasScript.getCanvasID(); string fileName = string.Empty; if (canvasID == string.Empty) // new art space { fileName = galleryPath + System.DateTime.Now.ToString("yyyyMMddHHmmss"); } else // old art space { fileName = galleryPath + canvasID; } // screenshot int fcount = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories).Length; // Count the number of file(파일개수) string[] files = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories); // String array(save screenshot file) int limit = 6; // if file number reached at limit number, then delete the oldest file if (fcount == limit && canvasID == string.Empty) { string filename = files[0].Substring(files[0].Length - 18, 14); // 'C:\user\20140512123123.png' -> '20140512123123' File.Delete(files [0]); // delete png if (File.Exists(galleryPath + filename + ".data")) { string[] data = Directory.GetFiles(galleryPath, filename + ".data", SearchOption.AllDirectories); string[] buf = Directory.GetFiles(galleryPath, filename + ".buf", SearchOption.AllDirectories); File.Delete(data [0]); File.Delete(buf [0]); } } Application.CaptureScreenshot(fileName + ".png"); // paint + scence GameObject pallete = GameObject.Find("pallete"); palette palleteScript = pallete.GetComponent <palette> (); Color[] paintsColor = palleteScript.getPaintsColor(); StreamWriter sw = new StreamWriter(File.Open(fileName + ".data", FileMode.Create)); sw.WriteLine("wateroil"); sw.WriteLine(paintsColor.Length); for (int i = 0; i < paintsColor.Length; i++) { sw.WriteLine(paintsColor[i].r.ToString() + " " + paintsColor[i].g.ToString() + " " + paintsColor[i].b.ToString() + " " + paintsColor[i].a.ToString()); } sw.Close(); // drawing data short[] canvasBuf = canvasScript.getCanvasBuf(); using (BinaryWriter writer = new BinaryWriter(File.Open(fileName + ".buf", FileMode.Create))){ foreach (short elem in canvasBuf) { writer.Write(elem); } } Debug.Log("working spaced saved!"); }
private void callGameObjByKinect(StSendData kinectInput) { if (isDetected == false) // for canvas up event { isDetected = true; } float x, y; //find x,y ratio x = kinectInput.fSymbolPosX; y = kinectInput.fSymbolPosY; // coordinates transformation from kinect to unity y = 1 - y; // adjust calibration manually //y -= 0.03f; //real valid input Vector2 worldPoint = new Vector2(Screen.width * x, Screen.height * y); //2. find game object by kinect input(2D coordinates) GameObject gameObject = findGameObject(worldPoint.x, worldPoint.y); GameObject colorSelector = findColorSelector(worldPoint.x, worldPoint.y); //Debug.Log (gameObject.name); //3. call the onSpandexDown method if (gameObject != null) { if (gameObject.name == "canvas") { isOnCanvas = true; //TODO Sandart drawingOnGUI canvasScript = gameObject.GetComponent <drawingOnGUI>(); if (canvasScript != null) { canvasScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth); // TODO complete params } else { Sandart sandScript = gameObject.GetComponent <Sandart>(); sandScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth); } } else if (colorSelector != null) { GameObject.Find("Control - Circular Color Picker").SendMessage("OnCanvasDown", worldPoint); if (isOnCanvas == true) { isOnCanvas = false; GameObject.Find("canvas").SendMessage("OnCanvasUp"); } } else { if (isOnCanvas == true) { isOnCanvas = false; GameObject.Find("canvas").SendMessage("OnCanvasUp"); } gameObject.SendMessage("OnCanvasDown"); } Debug.Log("gameobject found : " + gameObject.name); } prevMinPtr = worldPoint; // for canvas up event // else if(pointCount == 2 && minDepth < errorRange && isDetected == true){ // End of canvas down // isDetected = false; // // if(findGameObject(prevMinPtr.x,prevMinPtr.y).name == "canvas") // 'spandex canvas up' on 'drawing canvas' // GameObject.Find("canvas").SendMessage("OnCanvasUp"); // // prevMinPtr.Set (0,0); // } }