Esempio n. 1
0
    void PaintVertexColors()
    {
        if (curMesh)
        {
            Vector3[] verts  = curMesh.vertices;
            Color[]   colors = new Color[0];

            if (curMesh.colors.Length > 0)
            {
                colors = curMesh.colors;
            }
            else
            {
                colors = new Color[verts.Length];
            }

            for (int i = 0; i < verts.Length; i++)
            {
                Vector3 vertPos = curGO.transform.TransformPoint(verts[i]);
                float   sqrMag  = (vertPos - curHit.point).sqrMagnitude;
                if (sqrMag > brushSize)
                {
                    continue;
                }

                float falloff = FindMesh.LinearFalloff(sqrMag, brushSize);
                falloff   = Mathf.Pow(falloff, brushFalloff * 3f) * brushOpacity;
                colors[i] = foregroundColor;
                //Falloff på paintin
                //colors[i] = FindMesh.VtxColorLerp(colors[i], foregroundColor, falloff);
            }

            curMesh.colors = colors;
        }
    }
Esempio n. 2
0
    void PaintVertexColors()
    {
        if (curMesh)
        {
            //Find the vertices off the current mesh and store its current colors in an array
            Vector3[] verts  = curMesh.vertices;
            Color[]   colors = new Color[0];

            if (curMesh.colors.Length > 0)
            {
                colors = curMesh.colors;
            }
            else
            {
                colors = new Color[verts.Length];
            }

            for (int i = 0; i < verts.Length; i++)
            {
                // square the distance we compare with & get the transformPoints off the vertices
                Vector3 vertPos = curGO.transform.TransformPoint(verts[i]);
                float   sqrMag  = (vertPos - curHit.point).sqrMagnitude;
                if (sqrMag > brushSize)
                {
                    continue;
                }

                //Falloff to make it more realistic
                float falloff = FindMesh.LinearFalloff(sqrMag, brushSize);
                falloff   = Mathf.Pow(falloff, brushFalloff * 3f) * brushOpacity;
                colors[i] = FindMesh.VtxColorLerp(colors[i], foregroundColor, falloff);
            }
            curMesh.colors = colors;
        }
    }
Esempio n. 3
0
    void Update()
    {
        Ray worldRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetMouseButton(0) && Physics.Raycast(worldRay, out curHit, 500f))
        {
            //Begin Vertex Painting here
            if (isPainting)
            {
                Debug.Log("Träffar Objects");
                PaintVertexColors();
            }


            if (allowPainting)
            {
                Debug.Log(curHit);
                if (curHit.transform.gameObject != lastGO)
                {
                    curGO   = curHit.transform.gameObject;
                    curMesh = FindMesh.GetMesh(curGO);
                    lastGO  = curGO;

                    if (curGO != null && curMesh != null)
                    {
                        Debug.Log(curGO.name + " : " + curMesh.name);
                    }
                }
            }
        }
        else
        {
            curGO   = null;
            curMesh = null;
            lastGO  = null;
        }
        // save the mesh
        if (Input.GetKeyDown("s"))
        {
            SavePrefab();
        }
    }
Esempio n. 4
0
    void Update()
    {
        //Raycast to see where the
        Ray worldRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetMouseButton(0) && Physics.Raycast(worldRay, out curHit, 500f))
        {
            if (isPainting)
            {
                //Begin vertex painting
                PaintVertexColors();
            }

            if (allowPainting)
            {
                // added alot off "Null checks" to make sure that the player is always aiming at something,
                if (curHit.transform.gameObject != lastGO)
                {
                    curGO   = curHit.transform.gameObject;
                    curMesh = FindMesh.GetMesh(curGO);
                    lastGO  = curGO;
                }
            }
        }
        else
        {
            curGO   = null;
            curMesh = null;
            lastGO  = null;
        }
        // save the mesh
        if (Input.GetKeyDown("s"))
        {
            SavePrefab();
        }
    }