public bool Deserialise(Table vertInfoTable)
    {
        bool success = false;

        foreach (DynValue entry in vertInfoTable.Values)
        {
            Table vertDefTable = entry.Table;

            VertInfo info = new VertInfo();

            info.VertID              = (int)vertDefTable.Get("vert_id").Number;
            info.IsStatic            = vertDefTable.Get("static").Boolean;
            info.MassScale           = (float)vertDefTable.Get("mass_scale").Number;
            info.PullToSkinScale     = (float)vertDefTable.Get("pull_to_skin_scale").Number;
            info.ColliderRadiusScale = (float)vertDefTable.Get("collider_radius_scale").Number;
            info.Position            = vertDefTable.Get("position").ToObject <Vector3>();

            Debug.Assert(info.BodyShapeOffsetTable.Deserialise(vertDefTable.Get("body_shape_offset").Table));
            Debug.Assert(info.SkinWeightsTable.Deserialise(vertDefTable.Get("skin_weights").Table));
            Debug.Assert(info.ConstraintsTable.Deserialise(vertDefTable.Get("constraints").Table));

            m_vertInfoList.Add(info);
        }

        success = true;

        return(success);
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        foreach (MeshFilter meshSource in meshSources)
        {
            Vector3[]  verts    = meshSource.mesh.vertices;
            Vector3[]  normals  = meshSource.mesh.normals;
            VertInfo[] vertInfo = new VertInfo[verts.Length];
            for (int i = 0; i < verts.Length; i++)
            {
                vertInfo[i] = new VertInfo()
                {
                    vert      = verts[i],
                    origIndex = i,
                    normal    = normals[i]
                };
            }
            var        groups            = vertInfo.GroupBy(x => x.vert);
            VertInfo[] processedVertInfo = new VertInfo[vertInfo.Length];
            int        index             = 0;
            foreach (IGrouping <Vector3, VertInfo> group in groups)
            {
                Vector3 avgNormal = zeroVec;
                foreach (VertInfo item in group)
                {
                    avgNormal += item.normal;
                }
                avgNormal = avgNormal / group.Count();
                foreach (VertInfo item in group)
                {
                    processedVertInfo[index] = new VertInfo()
                    {
                        vert           = item.vert,
                        origIndex      = item.origIndex,
                        normal         = item.normal,
                        averagedNormal = avgNormal
                    };
                    index++;
                }
            }
            Color[] colors = new Color[verts.Length];
            for (int i = 0; i < processedVertInfo.Length; i++)
            {
                VertInfo info = processedVertInfo[i];

                int     origIndex = info.origIndex;
                Vector3 normal    = info.averagedNormal;
                Color   normColor = new Color(normal.x, normal.y, normal.z, 1);
                colors[origIndex] = normColor;
            }
            meshSource.mesh.colors = colors;
        }
    }
Пример #3
0
 public void RemoveVert(VertInfo vertInfo)
 {
     m_vertInfoTable.RemoveVertInfo(vertInfo);
 }
Пример #4
0
 public void AddVert(VertInfo vertInfo)
 {
     m_vertInfoTable.AddVertInfo(vertInfo);
 }
    private void ConvertMeshes(Transform a_meshObject)
    {
        // Check for object children, if so then convert their meshes too
        if (a_meshObject.childCount > 0)
        {
            for (int i = 0; i < a_meshObject.childCount; ++i)
            {
                ConvertMeshes(a_meshObject.GetChild(i));
            }
        }

        MeshFilter meshSource = a_meshObject.GetComponent <MeshFilter>();

        // Early out if this object doesn't have a mesh filter
        if (meshSource == null)
        {
            return;
        }

        m_objectCount++;

        // Check if an object with the same model has already been converted
        foreach (MeshFilter m in m_converted)
        {
            // If there is a model that has already been converted then set
            // this meshfilter to the converted one
            if (m.sharedMesh == meshSource.sharedMesh)
            {
                meshSource = m;
                return;
            }
        }

        Vector3[]  verts    = meshSource.sharedMesh.vertices;
        Vector3[]  normals  = meshSource.sharedMesh.normals;
        VertInfo[] vertInfo = new VertInfo[verts.Length];

        for (int i = 0; i < verts.Length; i++)
        {
            vertInfo[i] = new VertInfo()
            {
                vert      = verts[i],
                origIndex = i,
                normal    = normals[i]
            };
        }

        var groups = vertInfo.GroupBy(x => x.vert);

        VertInfo[] processedVertInfo = new VertInfo[vertInfo.Length];
        int        index             = 0;

        foreach (IGrouping <Vector3, VertInfo> group in groups)
        {
            Vector3 avgNormal = zeroVec;

            foreach (VertInfo item in group)
            {
                avgNormal += item.normal;
            }

            avgNormal = avgNormal / group.Count();

            foreach (VertInfo item in group)
            {
                processedVertInfo[index] = new VertInfo()
                {
                    vert           = item.vert,
                    origIndex      = item.origIndex,
                    normal         = item.normal,
                    averagedNormal = avgNormal
                };

                index++;
            }
        }

        Color[] colors = new Color[verts.Length];

        for (int i = 0; i < processedVertInfo.Length; i++)
        {
            VertInfo info = processedVertInfo[i];

            int     origIndex = info.origIndex;
            Vector3 normal    = info.averagedNormal;
            Color   normColor = new Color(normal.x, normal.y, normal.z, 1);
            colors[origIndex] = normColor;
        }

        meshSource.sharedMesh.colors = colors;

        meshSource.sharedMesh.RecalculateNormals();

        // Add the converted mesh to the converted list
        m_converted.Add(meshSource);
    }
 public void RemoveVertInfo(VertInfo vertInfo)
 {
     m_vertInfoList.Remove(vertInfo);
 }
 public void AddVertInfo(VertInfo vertInfo)
 {
     m_vertInfoList.Add(vertInfo);
 }
Пример #8
0
    public override void OnInspectorGUI()
    {
        DynamicParticleComponent dynamicParticle = (DynamicParticleComponent)target;
        ClothSimEntity           clothSimEntity  = dynamicParticle.ClothSimEntity;

        VertInfo vertInfo = dynamicParticle.ParticleInfo.VertInfo;

        JointInfoTable.JointInfoDefinition jointInfo = dynamicParticle.ParticleInfo.JointInfo;
        BodyShapeOffSetTable bodyShapesOffsetsTable  = dynamicParticle.ParticleInfo.VertInfo.BodyShapeOffsetTable;

        int vertID = vertInfo.VertID;

        vertInfo.VertID = EditorGUILayout.IntField("Vert ID", vertID);
        dynamicParticle.gameObject.name = vertInfo.VertID != vertID ? "Particle VertID : " + vertInfo.VertID.ToString() : dynamicParticle.gameObject.name;

        vertInfo.MassScale           = EditorGUILayout.FloatField("Mass Scale", vertInfo.MassScale);
        vertInfo.PullToSkinScale     = EditorGUILayout.FloatField("Pull To Skin Scale", vertInfo.PullToSkinScale);
        vertInfo.ColliderRadiusScale = EditorGUILayout.FloatField("Collider Radius Scale", vertInfo.ColliderRadiusScale);
        vertInfo.Position            = EditorGUILayout.Vector3Field("Position", vertInfo.Position);
        vertInfo.IsStatic            = EditorGUILayout.Toggle("Static", vertInfo.IsStatic);

        //update vert id.


        JointInfoDisplay(jointInfo);

        if (GUILayout.Button("Skin Weights Editor"))
        {
        }

        if (GUILayout.Button("Constraints Editor"))
        {
            ClothSimConstraintsEditorWindow constraintsWindow = EditorWindow.GetWindow <ClothSimConstraintsEditorWindow>();
            constraintsWindow.ParticleComponent = dynamicParticle;
            constraintsWindow.Show();
        }

        if (jointInfo == null)
        {
            if (GUILayout.Button("AddJointInfo"))
            {
                JointInfoTable.JointInfoDefinition newJointInfo = new JointInfoTable.JointInfoDefinition();

                clothSimEntity.AddJointInfo(newJointInfo);
                dynamicParticle.ParticleInfo.JointInfo = newJointInfo;
            }
        }
        else
        {
            if (GUILayout.Button("RemoveJointInfo"))
            {
                clothSimEntity.RemoveJointInfo(jointInfo);
                dynamicParticle.ParticleInfo.JointInfo = null;
            }
        }

        if (GUILayout.Button("Delete Patricle"))
        {
            clothSimEntity.DeleteParticle(dynamicParticle.gameObject);
        }

        BlendShapeEditor(clothSimEntity, dynamicParticle, dynamicParticle.ParticleInfo.VertInfo.BodyShapeOffsetTable);
    }