private static void UpdatePickColors(PaintTarget paintTarget, RenderTexture rt) { if (!paintTarget.validTarget) { return; } if (!paintTarget.bPickDirty) { return; } if (!paintTarget.bHasMeshCollider) { return; } if (!paintTarget.splatTexPick) { paintTarget.splatTexPick = new Texture2D((int)paintTarget.paintTextureSize, (int)paintTarget.paintTextureSize, TextureFormat.ARGB32, false); } Rect rectReadPicture = new Rect(0, 0, rt.width, rt.height); RenderTexture.active = rt; paintTarget.splatTexPick.ReadPixels(rectReadPicture, 0, 0); paintTarget.splatTexPick.Apply(); RenderTexture.active = null; paintTarget.bPickDirty = false; }
private static void PaintRaycast(Ray ray, Brush brush, bool multi = true) { RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000)) { if (multi) { RaycastHit[] hits = Physics.SphereCastAll(hit.point, brush.splatScale, ray.direction); for (int h = 0; h < hits.Length; h++) { PaintTarget paintTarget = hits[h].collider.gameObject.GetComponent <PaintTarget>(); if (paintTarget != null) { PaintObject(paintTarget, hit.point, hits[h].normal, brush); } } } else { PaintTarget paintTarget = hit.collider.gameObject.GetComponent <PaintTarget>(); if (!paintTarget) { return; } PaintObject(paintTarget, hit.point, hit.normal, brush); } } }
private void HandleCollision(Collision collision) { foreach (ContactPoint contact in collision.contacts) { PaintTarget paintTarget = contact.otherCollider.GetComponent <PaintTarget>(); if (paintTarget != null) { if (RandomChannel) { brush.splatChannel = Random.Range(0, 4); } PaintTarget.PaintObject(paintTarget, contact.point, contact.normal, brush); } } }
public static void PaintObject(PaintTarget target, Vector3 point, Vector3 normal, Brush brush) { if (!target) { return; } if (!target.validTarget) { return; } if (splatObject == null) { splatObject = new GameObject(); splatObject.name = "splatObject"; splatObject.hideFlags = HideFlags.HideInHierarchy; } splatObject.transform.position = point; Vector3 leftVec = Vector3.Cross(normal, Vector3.up); if (leftVec.magnitude > 0.001f) { splatObject.transform.rotation = Quaternion.LookRotation(leftVec, normal); } else { splatObject.transform.rotation = Quaternion.identity; } float randScale = Random.Range(brush.splatRandomScaleMin, brush.splatRandomScaleMax); splatObject.transform.RotateAround(point, normal, brush.splatRotation); splatObject.transform.RotateAround(point, normal, Random.Range(-brush.splatRandomRotation, brush.splatRandomRotation)); splatObject.transform.localScale = new Vector3(randScale, randScale, randScale) * brush.splatScale; Paint newPaint = new Paint(); newPaint.paintMatrix = splatObject.transform.worldToLocalMatrix; newPaint.channelMask = brush.getMask(); newPaint.scaleBias = brush.getTile(); newPaint.brush = brush; target.PaintSplat(newPaint); }
private void OnParticleCollision(GameObject other) { PaintTarget paintTarget = other.GetComponent <PaintTarget>(); if (paintTarget != null) { if (RandomChannel) { brush.splatChannel = Random.Range(0, 2); } int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents); for (int i = 0; i < numCollisionEvents; i++) { PaintTarget.PaintObject(paintTarget, collisionEvents[i].intersection, collisionEvents[i].normal, brush); } } }
private void Update() { CameraControl(); if (Input.GetKeyDown(KeyCode.Alpha1)) { brush.splatChannel = 0; } if (Input.GetKeyDown(KeyCode.Alpha2)) { brush.splatChannel = 1; } if (Input.GetKeyDown(KeyCode.Alpha5)) { brush.splatChannel = 4; } if (RandomChannel) { brush.splatChannel = Random.Range(0, 2); } if (Input.GetMouseButton(0)) { if (!SingleShotClick || (SingleShotClick && !HoldingButtonDown)) { if (ClearOnClick) { PaintTarget.ClearAllPaint(); } PaintTarget.PaintCursor(brush); if (IndexBrush) { brush.splatIndex++; } } HoldingButtonDown = true; } else { HoldingButtonDown = false; } }
private void Update() { //CameraControl(); //if (Input.GetKeyDown(KeyCode.Alpha1)) brush.splatChannel = 0; //if (Input.GetKeyDown(KeyCode.Alpha2)) brush.splatChannel = 1; //if (Input.GetKeyDown(KeyCode.Alpha5)) brush.splatChannel = 4; //if (RandomChannel) brush.splatChannel = Random.Range(0, 2); if (Input.GetMouseButton(0)) { if (!HoldingButtonDown) { PaintTarget.PaintCursor(brush); } HoldingButtonDown = true; } else { HoldingButtonDown = false; } }
public static int RayChannel(Ray ray) { RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000)) { PaintTarget paintTarget = hit.collider.gameObject.GetComponent <PaintTarget>(); if (!paintTarget) { return(-1); } if (!paintTarget.validTarget) { return(-1); } if (!paintTarget.bHasMeshCollider) { return(-1); } Renderer r = paintTarget.GetComponent <Renderer>(); if (!r) { return(-1); } RenderTexture rt = (RenderTexture)r.sharedMaterial.GetTexture("_SplatTex"); if (!rt) { return(-1); } UpdatePickColors(paintTarget, rt); Texture2D tc = paintTarget.splatTexPick; if (!tc) { return(-1); } int x = (int)(hit.textureCoord2.x * tc.width); int y = (int)(hit.textureCoord2.y * tc.height); Color pc = tc.GetPixel(x, y); int l = -1; if (pc.r > .5) { l = 0; } if (pc.g > .5) { l = 1; } if (pc.b > .5) { l = 2; } if (pc.a > .5) { l = 3; } return(l); } return(-1); }
public static Color RayColor(Ray ray) { RaycastHit hit; if (Physics.Raycast(ray, out hit, 10000)) { PaintTarget paintTarget = hit.collider.gameObject.GetComponent <PaintTarget>(); if (!paintTarget) { return(Color.black); } if (!paintTarget.validTarget) { return(Color.black); } if (!paintTarget.bHasMeshCollider) { return(Color.black); } Renderer r = paintTarget.GetComponent <Renderer>(); if (!r) { return(Color.black); } RenderTexture rt = (RenderTexture)r.sharedMaterial.GetTexture("_SplatTex"); if (!rt) { return(Color.black); } UpdatePickColors(paintTarget, rt); Texture2D tc = paintTarget.splatTexPick; if (!tc) { return(Color.black); } int x = (int)(hit.textureCoord2.x * tc.width); int y = (int)(hit.textureCoord2.y * tc.height); Color pc = tc.GetPixel(x, y); Color c1 = r.sharedMaterial.GetColor("_SplatColor1"); Color c2 = r.sharedMaterial.GetColor("_SplatColor2"); Color cc = Color.black; if (pc.r > .5) { cc = c1; } if (pc.g > .5) { cc = c2; } return(cc); } return(Color.black); }
private GUIStyle guiStyle = new GUIStyle(); //create a new variable public override void OnInspectorGUI() { PaintTarget script = (PaintTarget)target; GameObject go = (GameObject)script.gameObject; Renderer render = go.GetComponent <Renderer>(); if (Application.isPlaying) { GUILayout.BeginVertical(GUI.skin.box); //EditorGUILayout.ObjectField((Object)script.splatTexPick, typeof(Texture2D), true); script.PaintAllSplats = GUILayout.Toggle(script.PaintAllSplats, "Paint All Splats"); if (GUILayout.Button("Clear Paint")) { script.ClearPaint(); } if (GUILayout.Button("Clear All Paint")) { PaintTarget.ClearAllPaint(); } GUILayout.EndVertical(); } else { GUILayout.BeginVertical(GUI.skin.box); script.paintTextureSize = (TextureSize)EditorGUILayout.EnumPopup("Paint Texture", script.paintTextureSize); script.renderTextureSize = (TextureSize)EditorGUILayout.EnumPopup("Render Texture", script.renderTextureSize); script.SetupOnStart = GUILayout.Toggle(script.SetupOnStart, "Setup On Start"); script.PaintAllSplats = GUILayout.Toggle(script.PaintAllSplats, "Paint All Splats"); GUILayout.EndVertical(); if (render == null) { EditorGUILayout.HelpBox("Missing Render Component", MessageType.Error); } else { foreach (Material mat in render.sharedMaterials) { if (!mat.shader.name.StartsWith("Paint/")) { EditorGUILayout.HelpBox(mat.name + "\nMissing Paint Shader", MessageType.Warning); } } } bool foundCollider = false; bool foundMeshCollider = false; if (go.GetComponent <MeshCollider>()) { foundCollider = true; foundMeshCollider = true; } if (go.GetComponent <BoxCollider>()) { foundCollider = true; } if (go.GetComponent <SphereCollider>()) { foundCollider = true; } if (go.GetComponent <CapsuleCollider>()) { foundCollider = true; } if (!foundCollider) { EditorGUILayout.HelpBox("Missing Collider Component", MessageType.Warning); } if (!foundMeshCollider) { EditorGUILayout.HelpBox("WARNING: Color Pick only works with Mesh Collider", MessageType.Warning); } } }
private void OnGUI() { ShowMenu = GUILayout.Toggle(ShowMenu, ""); if (!ShowMenu) { return; } GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(); if (GUILayout.Button("Channel 0")) { brush.splatChannel = 0; } if (GUILayout.Button("Channel 1")) { brush.splatChannel = 1; } if (GUILayout.Button("Erase")) { brush.splatChannel = 4; RandomChannel = false; ClearOnClick = false; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); RandomChannel = GUILayout.Toggle(RandomChannel, "Random"); SingleShotClick = GUILayout.Toggle(SingleShotClick, "Single Click"); ClearOnClick = GUILayout.Toggle(ClearOnClick, "Clear on Click"); IndexBrush = GUILayout.Toggle(IndexBrush, "Index Brush"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Paint Size"); brush.splatScale = GUILayout.HorizontalSlider(brush.splatScale, .1f, 5f); GUILayout.EndHorizontal(); if (GUILayout.Button("Clear ALL")) { PaintTarget.ClearAllPaint(); } //Texture2D c = new Texture2D(1, 1); colorTex.SetPixel(0, 0, PaintTarget.CursorColor()); colorTex.Apply(); //GUILayout.Box(colorTex, GUILayout.Width(128), GUILayout.Height(32)); //GUILayout.Box("CURSOR COLOR:" + PaintTarget.CursorColor()); GUI.DrawTexture(new Rect(0, Screen.height - 32, 32, 32), colorTex); GUILayout.Box("CURSOR CHANNEL:" + PaintTarget.CursorChannel()); Help = GUILayout.Toggle(Help, "Show Help"); if (Help) { GUILayout.Label("Movement: (Hold Right Mouse Button)"); GUILayout.Label("W/S/A/D - Move Forward/Back/Left/Right"); GUILayout.Label("* SHIFT = FASTER / CTRL = SLOWER"); GUILayout.Label("Q/E - Move Up/Down"); GUILayout.Label("Scroll Wheel - Zoom"); GUILayout.Label("Paint: Left Mouse Button"); } GUILayout.EndVertical(); }