unity texelsize c# unity3d paint

c# - texelsize unity



Unity3D busca setPixels ejemplo para pintar con textura en C# (3)

Necesita dos Kit de activos;

1- https://www.assetstore.unity3d.com/#/content/2682 para pintura (cepillo vs)
o
https://www.assetstore.unity3d.com/#/content/11735 para pintura (aerógrafo vs)

2- https://www.assetstore.unity3d.com/#/content/908 para sprites works (cortar, agregar, eliminar)

Necesito encontrar una manera que me permita pintar un gameObject usando una textura, el objetivo es hacer una copia de este juego

Ya pensé que puedo falsificar la función de pintura utilizando la solución depthMask que aquí expliqué, sin embargo, después de muchas horas de investigación, parece que setPixels, setPixel y setPixels32 se pueden usar para crear una pintura real, pero por alguna razón todos los setPixels relacionados los temas de la guía de referencia están en JavaScript, traté de portarlo a c # pero siempre recibí errores, además, es un enfoque algo complicado y la referencia del guión no lo explica muy bien, así que espero que cualquiera pueda escribirme. un ejemplo usando setPixels para cambiar una parte de una textura de objeto usando otra textura? o tal vez podemos establecer el objeto entero alfa en 0, y cuando hacemos clic en él, ¿cambiamos una parte de esa textura alfa por 1?

Realmente espero que este tema no se cierre debido a su variedad, intenté hacer mi mejor esfuerzo para hacer una pregunta directa mientras explicaba toda la situación.

Gracias

EDITAR:

Después de un par de horas, he alcanzado un resultado bastante bueno, y creo que esta puede ser la mejor forma de alcanzar mi objetivo, este script permite reemplazar un píxel específico en una textura de material con otra textura elegida (la textura del objetivo debe estar en el mismo tamaño y legible)

// the texture that i will paint with public Texture2D targetTexture ; //temporary texture Texture2D tmpTexture; void Start () { //setting temp texture width and height tmpTexture = new Texture2D (targetTexture.width, targetTexture.height); for (int y =0; y<tmpTexture.height; y++) { for (int x = 0; x<tmpTexture.width; x++) { //filling the temporary texture with the target texture tmpTexture.SetPixel (x, y, targetTexture.GetPixel (x, y)); } } //Apply tmpTexture.Apply (); //change the object main texture renderer.material.mainTexture = tmpTexture; }

Ahora creo que el problema solo será "cómo saber qué píxel debo reemplazar en función de la posición del mouse sobre el objeto"



Dado en el clavo !!

Este código funciona perfectamente como se esperaba, está muy comentado y muestra todo lo que hice, no permite pintar dinámicamente un objeto ya que aún estoy buscando cómo obtener la coordenada de textura después de hacer clic en el objeto, sin embargo, puede ingresar manualmente su coordine y elija la textura del objetivo que con el que desea pintar su objeto original, espero que esto sea útil para otra persona en el futuro, Código:

using UnityEngine; using System.Collections; public class BasicPainting : MonoBehaviour { // the texture that i will paint with and the original texture (for saving) public Texture2D targetTexture, originalTexture ; //temporary texture public Texture2D tmpTexture; void Start () { //setting temp texture width and height tmpTexture = new Texture2D (originalTexture.width, originalTexture.height); //fill the new texture with the original one (to avoid "empty" pixels) for (int y =0; y<tmpTexture.height; y++) { for (int x = 0; x<tmpTexture.width; x++) { tmpTexture.SetPixel (x, y, originalTexture.GetPixel (x, y)); } } print (tmpTexture.height); //filling a part of the temporary texture with the target texture for (int y =0; y<tmpTexture.height-40; y++) { for (int x = 0; x<tmpTexture.width; x++) { tmpTexture.SetPixel (x, y, targetTexture.GetPixel (x, y)); } } //Apply tmpTexture.Apply (); //change the object main texture renderer.material.mainTexture = tmpTexture; } }