void DrawingPart(string drawingPart) { int nbPart = hashNbPointInEachSubpart[drawingPart]; Texture2D[] tabTextures = new Texture2D[nbPart]; List <string> listSubPart = hashSubpartWithHerPart[drawingPart]; foreach (string subPart in listSubPart) { cpt = 0; List <float> coordonnee = hashPartCoord[subPart]; StartCoroutine(renderCamera.GetTexture2D(text2d => { int x = Mathf.FloorToInt(coordonnee[0]); int y = Mathf.FloorToInt(coordonnee[1]); //rawImage.texture = text2d; // Permet de recuperer la texture complete Color[] pix = text2d.GetPixels(x, y, width, height); Texture2D destTex = new Texture2D(width, height); destTex.SetPixels(pix); destTex.Apply(); tabTextures[cpt] = destTex; if (cpt == nbPart - 1) { Texture2D targetTexture = tabTextures[0]; for (int i = 1; i < nbPart; i++) { if (tabTextures[i] != tabTextures[i - 1] && (tabTextures[i] != Texture2D.whiteTexture || tabTextures[i] != Texture2D.blackTexture)) { targetTexture = tabTextures[i]; } } DrawingGameObjectTarget(drawingPart, targetTexture); cpt = 0; } else { cpt++; } })); } }
void OnTrackablesUpdated() { // Repere la couleur (gris) et applique sur le mesh la couleur équivalente if (mFormatRegistered) { if (mAccessCameraImage) { image = CameraDevice.Instance.GetCameraImage(mPixelFormat); if (image != null) { byte[] pixels = image.Pixels; if (pixels != null && pixels.Length > 0) { //// Couleur appliquée sur le dessin //Color32 drawingColor = new Color32(pixels[0], pixels[1], pixels[2], 1); //// Applique la couleur sur le model //face.GetComponent<Renderer>().material.SetColor("_Color", drawingColor); //Debug.Log("Color components are " + pixels[0] + ", " + pixels[1] + ", " + pixels[2]); StartCoroutine(renderCamera.GetTexture2D(text2d => { int x = Mathf.FloorToInt(sourceRect.x); int y = Mathf.FloorToInt(sourceRect.y); int width = Mathf.FloorToInt(sourceRect.width); int height = Mathf.FloorToInt(sourceRect.height); Color[] pix = text2d.GetPixels(x, y, width, height); Texture2D destTex = new Texture2D(width, height); destTex.SetPixels(pix); destTex.Apply(); // Set the current object's texture to show the // extracted rectangle. face.GetComponent <Renderer>().material.mainTexture = destTex; })); } } } } }