Jump to content
Sign in to follow this  
ItsDangerous

Could use a better workflow maybe

Recommended Posts

The problem I'm having is that whenever I update my model using sketchup (really any modeler will do the same thing) I have to delete and replace the entire model to see the actual changes. That basically clears all vertex colors which will then have to be painted again at some point.

 

If polybrush could just detect or have a "refresh model" option, the workflow could be much better. You could program it to repaint the new updated model from the colors in the old model.

 

In terms of a workflow for a large game level, this could make visualizing your progress more easy being that you can paint as you model things. As it is now, it only makes sense to paint the model when it's finished as it's a waste of time to paint if it's just going to be cleared with your next update anyway. 

Share this post


Link to post
Share on other sites

The trouble with refreshing a mesh is that if any of the attribute sizes have been modified the vertex colors can no longer be applied.  However, there's currently a ticket open to change Polybrush to use additionalVertexStreams when applying mesh attributes, which means that we could at least check if the refreshed mesh is compatible and save the modifications in most cases.

Share this post


Link to post
Share on other sites

Maybe a radial projection or nearest point projection to re-apply/transfer the point info from the pbrushed mesh to the new mesh?  In most cases that would be close enough.  Some detail might have to be repainted but that would get the user 90% there most of the time.

Share this post


Link to post
Share on other sites

Has anything from this topic been implemented yet? I think technically speaking, you could just iterate through all the vertices in the old model and then check for vertices in the new model that are closer than 0.01 then transfer the colors to the new one. Of course, the process might take a while to compute. So I don't know what optimizations you have built in that you can use. 64000 times 64000 is a lot of iterations.

Share this post


Link to post
Share on other sites

I went ahead and attempted this myself. It isn't quite right.. Lots of random glitches which causes the colors to get lost. I really don't know what I'm doing.

 

Could anyone look at this and tell me what I'm doing wrong? It seems to work the first try but then the second time I try updating my model, all the colors disappear.

 

Here's basically all the code I'm using. You can see how I used it in this video. I didn't mean to add an extra z_AditionalVertexStream script. Sometimes it automatically spawns in the mesh and sometimes it doesn't. 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;



namespace Polybrush
{
    [ExecuteInEditMode]

    public class SaveLoadVertexColors : MonoBehaviour
    {
        public Mesh referenceMesh;
        public bool load;

        //Debug info
        public List<Vector3> verticies = new List<Vector3>();
        public List<Color> colors = new List<Color>();
        
        public bool transfer;
        private Mesh streamMesh;//The temporary mesh that we will have
        public z_AdditionalVertexStreams targetMesh;
        private Mesh newMeshToEdit;//The mesh that the modeler updated to
        
        public List<Color> colorsN = new List<Color>();



        void Update()
        {

            if (load)
            {

                referenceMesh = GetComponent<z_AdditionalVertexStreams>().m_AdditionalVertexStreamMesh;

                referenceMesh.GetVertices(verticies);
                

                referenceMesh.GetColors(colors);


                //Create our own stream mesh
                newMeshToEdit = targetMesh.gameObject.GetComponent<MeshFilter>().sharedMesh;//Gets an error if it's not shared
                streamMesh = newMeshToEdit;
                colorsN.Clear();

                
                load = false;
            }

            if (transfer)
            {

                int iterate = 0;
                foreach (Vector3 nVer in newMeshToEdit.vertices)
                {
                    colorsN.Add(Color.white);
                    int iterate2 = 0;
                    foreach (Vector3 vert in verticies)
                    {
                        if ((vert - nVer).magnitude < 0.0001f)//Then they are the same
                        {
                            colorsN[iterate] = colors[iterate2];
                        }
                        iterate2++;
                    }
                    iterate++;
                }


                streamMesh.SetColors(colorsN);

                targetMesh.SetAdditionalVertexStreamsMesh(streamMesh);//That should do it


                transfer = false;
            }
        }
    }
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×