コード例 #1
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    public void RenderCanvas(PaintableObject paintableObject, bool withCursor)
    {
        brushCursor.SetActive(false);

        Transform brushContainer = paintableObject.GetBrushContainer();

        brushContainer.gameObject.SetActive(true);

        baseMaterial.mainTexture = paintableObject.GetBaseTex();

        canvasCam.targetTexture = paintableObject.GetCanvas();
        canvasCam.Render();
        brushContainer.gameObject.SetActive(false);

        if (withCursor)
        {
            brushCursor.SetActive(true);
            baseMaterial.mainTexture = blackTex;
            canvasCam.targetTexture  = paintableObject.m_cursorTex;
            canvasCam.Render();
        }
        else
        {
            baseMaterial.mainTexture = blackTex;
            canvasCam.targetTexture  = paintableObject.m_cursorTex;
            canvasCam.Render();
        }
    }
コード例 #2
0
    void OnEnable()
    {
        Instance       = this;
        _grimeMap      = new Texture2D(_imageSize, _imageSize, TextureFormat.ARGB32, false);
        _grimeMap.name = "Grime Map";
        Color[] pixelColors = _grimeMap.GetPixels();
        _brushColors  = new Color[_brushSize * _brushSize];
        _camera       = Camera.main;
        _touchHistory = new Vector3[10];
        _dishCollider = GetComponent <Collider>();

        Debug.Log(pixelColors.Length);

        for (int y = 0; y < _imageSize; y++)
        {
            for (int x = 0; x < _imageSize; x++)
            {
                pixelColors[x % _imageSize + y * _imageSize
                ] = Color.black;
            }
        }

        _grimeMap.SetPixels(pixelColors, 0);

        ApplyGrime();

        for (int i = 0; i < _brushColors.Length; i++)
        {
            _brushColors[i] = Color.black;
        }

        Dish.material.SetTexture("_GrimeMask", _grimeMap);
    }
コード例 #3
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    public void SaveTexture(PaintableObject paintableObject)
    {
        brushCursor.SetActive(false);

        baseMaterial.mainTexture = paintableObject.GetCanvas();

        canvasCam.targetTexture = paintableObject.GetBaseTex();
        canvasCam.Render();

        baseMaterial.mainTexture = paintableObject.GetBaseTex();

        Transform brushContainer = paintableObject.GetBrushContainer();
        Transform brushes        = brushContainer.GetChild(0);
        Transform drips          = brushContainer.GetChild(1);

        while (brushes.childCount > 0)
        {
            dotPool.FreeDot(brushes.GetChild(0).gameObject);
        }
        for (int i = 0; i < drips.childCount - 1; i++)
        {
            GameObject.Destroy(drips.GetChild(i).gameObject);
        }

        ShowCursor();
    }
コード例 #4
0
ファイル: TexScaleTool.cs プロジェクト: emanmomot/Painting
    private void OpenTool()
    {
        // cant open if were not on a paintable obj
        if (!TexturePainter.singleton.IsOnPaintableObject())
        {
            Debug.LogWarning("Cannot open tex scale tool if you're not hovering on a paintable object");
            isOpen = false;
            return;
        }

        lockMouse.LockCursor(false);

        scaleObj = TexturePainter.singleton.GetPaintableObject();

        toolGUI.SetActive(true);
        xScaleText.text = scaleObj.texScale.x.ToString();
        yScaleText.text = scaleObj.texScale.y.ToString();


        // move reference object in front of and to the right of the player
        referenceObj.SetActive(true);
        referenceObj.transform.forward  = playerTransform.forward;
        referenceObj.transform.position = scaleObj.transform.position - playerTransform.forward * .5f + playerTransform.right * 2.0f;

        Debug.LogWarning("Opened tex scale tool on " + scaleObj.gameObject + ". Starting tex scale: " + scaleObj.texScale.ToString("F4"));
    }
コード例 #5
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    //To update at realtime the painting cursor on the mesh
    void UpdateBrushCursor()
    {
        Vector3         uvWorldPosition = Vector3.zero;
        PaintableObject paintableObject = null;

        if (!saving && HitTestUVPosition(ref uvWorldPosition, ref paintableObject))
        {
            Vector2 newBrushPos = new Vector2(uvWorldPosition.x, uvWorldPosition.y);

            // clear cursor out of last canvas
            if (lastPaintableObject != null && lastPaintableObject != paintableObject)
            {
                if (smoothBrush != null)
                {
                    EndPaint();
                    lastPaintableObject = paintableObject;
                    StartPaint(newBrushPos);
                }
                else
                {
                    RenderCanvas(lastPaintableObject, false);
                    lastPaintableObject = paintableObject;
                }
            }
            else
            {
                lastPaintableObject = paintableObject;
            }

            brushCursor.SetActive(true);
            brushCursorScalable.GetComponent <SpriteRenderer> ().color = brushColor;

            brushCursor.transform.localScale         = paintableObject.texScale;
            brushCursorScalable.transform.localScale = Vector3.one * brushSize * .15f;
            brushCursor.transform.localPosition      = uvWorldPosition;

            brushPos = newBrushPos;

            if (PlayerInput.singleton.isTriggerHeld && smoothBrush == null)
            {
                StartPaint(brushPos);
            }
        }
        else if (lastPaintableObject != null)
        {
            if (smoothBrush != null)
            {
                EndPaint();
            }
            else
            {
                RenderCanvas(lastPaintableObject, false);
            }

            lastPaintableObject = null;
        }
    }
コード例 #6
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    //Returns the position on the texuremap according to a hit in the mesh collider
    bool HitTestUVPosition(ref Vector3 uvWorldPosition, ref PaintableObject paintableObject)
    {
        RaycastHit hit;
        //RaycastHit borderHit;

        Vector3 cursorPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f);
        //Vector3 borderOffset = new Vector3 (5, 0, 0);

        Ray cursorRay = sceneCamera.ScreenPointToRay(cursorPos);

        //Ray borderRay = sceneCamera.ScreenPointToRay (cursorPos + borderOffset);

        if (Physics.Raycast(cursorRay, out hit, PAINT_RANGE, paintableLayerMask))
        {
            // cursor is overlapping multiple objects
            //if (hit.collider != borderHit.collider) {
            //	return false;
            //}

            paintableObject = hit.collider.GetComponent <PaintableObject> ();
            if (paintableObject == null)
            {
                return(false);
            }

            MeshCollider meshCollider = hit.collider as MeshCollider;
            if (meshCollider == null || meshCollider.sharedMesh == null)
            {
                return(false);
            }

            Vector2 pixelUV = new Vector2(hit.textureCoord2.x, hit.textureCoord2.y);
            //Vector2 borderUV = new Vector2 (borderHit.textureCoord.x, borderHit.textureCoord.y);

            //texScale = (borderUV - pixelUV).magnitude;
            //Debug.Log (texScale);

            uvWorldPosition.x = pixelUV.x - canvasCam.orthographicSize;            //To center the UV on X
            uvWorldPosition.y = pixelUV.y - canvasCam.orthographicSize;            //To center the UV on Y
            uvWorldPosition.z = 0.0f;

            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #7
0
ファイル: SmoothBrush.cs プロジェクト: emanmomot/Painting
    public SmoothBrush(Vector2 start, float size, float step, PaintableObject obj)
    {
        cps   = new List <Vector2> ();
        ms    = new List <Vector2> ();
        sizes = new List <float> ();

        dots = new List <Transform> ();

        this.stepSize = step;
        this.obj      = obj;

        cps.Add(start);
        // dummy cp
        cps.Add(start + new Vector2(.001f, 0));
        ms.Add(SplineUtil.finiteDiffSlope2D(0, cps));
        ms.Add(SplineUtil.finiteDiffSlope2D(1, cps));
        sizes.Add(size);
        sizes.Add(size);
    }
コード例 #8
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!brushActivated)
        {
            return;
        }
        RaycastHit hit;

        Debug.DrawRay(pointer.position, pointer.forward * rayReach);
        if (Physics.Raycast(pointer.position, pointer.forward, out hit, rayReach, paintLayers.value))
        {
            //Debug.Log ("Raycast hit");
            activeSurface = hit.transform.root.GetComponent <PaintableObject> ();
            if (activeSurface != null)
            {
                draw         = true;
                currentCords = hit.textureCoord;
                if (resetBrushCords || lastSurface != activeSurface)
                {
                    scaledBrush = Instantiate(activeBrush);
                    TextureScale.Bilinear(scaledBrush, (int)(brushSize * ((float)activeSurface.textureSize / 256)), (int)(brushSize * ((float)activeSurface.textureSize / 256)));
                    //Debug.Log (scaledBrush.format);
                    lastUVCords     = currentCords;
                    resetBrushCords = false;
                    activeSurface.RegisterRay(currentCords, scaledBrush, intencity, color);
                    lastUVCords = currentCords;
                    lastSurface = activeSurface;
                    return;
                }

                /// Draw from here
            }
            else
            {
                draw = false;
            }
        }
        else
        {
            draw = false;
        }
    }
コード例 #9
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    public GameObject MakeDrip(PaintableObject paintableObject, Vector2 pos, float size)
    {
        GameObject newDrip;

        newDrip = GameObject.Instantiate(dripPrefab) as GameObject;
        SpriteRenderer rend = newDrip.GetComponentInChildren <SpriteRenderer>();

        rend.color        = brushColor;  //Set the brush color
        rend.sortingOrder = paintableObject.GetBrushContainer().GetChild(0).childCount;

        //brushColor.a = brushSize * 2.0f; // Brushes have alpha to have a merging effect when painted over.
        newDrip.transform.SetParent(paintableObject.GetBrushContainer().GetChild(1), false);
        //brushObj.transform.parent = paintableObject.GetBrushContainer(); //Add the brush to our container to be wiped later
        newDrip.transform.localPosition = new Vector3(pos.x, pos.y, 0);         //The position of the brush (in the UVMap)

        newDrip.transform.localScale = new Vector3(newDrip.transform.localScale.x * paintableObject.texScale.x,
                                                   newDrip.transform.localScale.y * paintableObject.texScale.y,
                                                   newDrip.transform.localScale.z);
        newDrip.transform.localScale *= size;

        return(newDrip);
    }
コード例 #10
0
ファイル: TexturePainter.cs プロジェクト: emanmomot/Painting
    public GameObject MakeDot(PaintableObject paintableObject, Vector2 pos, float size)
    {
        GameObject brushObj;

        brushObj = dotPool.GetDot();          //Paint a brush
        SpriteRenderer rend = brushObj.GetComponent <SpriteRenderer>();

        rend.color        = brushColor;  //Set the brush color
        rend.sortingOrder = paintableObject.GetBrushContainer().GetChild(0).childCount;

        //brushColor.a = brushSize * 2.0f; // Brushes have alpha to have a merging effect when painted over.
        brushObj.transform.SetParent(paintableObject.GetBrushContainer().GetChild(0), false);
        //brushObj.transform.parent = paintableObject.GetBrushContainer(); //Add the brush to our container to be wiped later
        brushObj.transform.localPosition = new Vector3(pos.x, pos.y, 0);         //The position of the brush (in the UVMap)

        brushObj.transform.localScale = new Vector3(brushObj.transform.localScale.x * paintableObject.texScale.x,
                                                    brushObj.transform.localScale.y * paintableObject.texScale.y,
                                                    brushObj.transform.localScale.z);
        brushObj.transform.localScale *= size;

        return(brushObj);
    }
コード例 #11
0
 public void Init(Vector2 coords, PaintableObject obj)
 {
     m_coords = coords;
     m_obj    = obj;
 }