Exemple #1
0
    public bool Serialise(ref StringBuilder stringBuilder)
    {
        bool success = false;

        stringBuilder.Append("    dynamic_properties = {\n");

        foreach (KeyValuePair <string, DynamicPropertiesDef> kvp in m_constraintDefinations)
        {
            DynamicPropertiesDef def = kvp.Value;
            stringBuilder.Append("        " + kvp.Key + " = {\n");
            stringBuilder.Append("            stretch = " + def.Stretch.ToString() + ",\n");
            stringBuilder.Append("            compression = " + def.Compression.ToString() + ",\n");
            stringBuilder.Append("            push = " + def.Push.ToString() + ",\n");
            stringBuilder.Append("            damping = " + def.Damping.ToString() + ",\n");
            stringBuilder.Append("            elasticity = " + def.Elasticity.ToString() + ",\n");
            stringBuilder.Append("            stiffness = " + def.Stiffness.ToString() + ",\n");
            stringBuilder.Append("            inert = " + def.Inert.ToString() + ",\n");
            stringBuilder.Append("            amount = " + def.Amount.ToString() + ",\n");
            stringBuilder.Append("            priority = " + def.Priority.ToString() + ",\n");

            if (!string.IsNullOrEmpty(def.VertOrder))
            {
                stringBuilder.Append("            vert_order = '" + def.VertOrder + "',\n");
            }

            stringBuilder.Append("        },\n");
        }

        stringBuilder.Append("    },\n");
        success = true;
        return(success);
    }
Exemple #2
0
    public bool Deserialise(Table dynamicPropertiesTable)
    {
        bool success = false;

        foreach (TablePair pair in dynamicPropertiesTable.Pairs)
        {
            string name            = pair.Key.String;
            Table  propertiesTable = pair.Value.Table;

            int stringIndex = name.LastIndexOf("_") + 1;
            name = name.Remove(0, stringIndex);

            DynamicPropertiesDef definition = new DynamicPropertiesDef();

            definition.Stretch     = (float)propertiesTable.Get("stretch").Number;
            definition.Compression = (float)propertiesTable.Get("compression").Number;
            definition.Push        = (float)propertiesTable.Get("push").Number;
            definition.Elasticity  = (float)propertiesTable.Get("elasticity").Number;
            definition.Stiffness   = (float)propertiesTable.Get("stifness").Number;
            definition.Inert       = (float)propertiesTable.Get("inert").Number;
            definition.Amount      = (float)propertiesTable.Get("amount").Number;
            definition.Priority    = (int)propertiesTable.Get("priority").Number;
            definition.VertOrder   = propertiesTable.Get("vert_order").String;

            m_constraintDefinations.Add(name, definition);
        }

        success = true;

        return(success);
    }
Exemple #3
0
    public DynamicPropertiesDef GetDynamicPropertiesDef(string name)
    {
        DynamicPropertiesDef def = m_propertiesTable.GetPropertiesDef(name);

        Debug.Assert(def != null, "you are trying to get a definition that doesn't exist");

        return(def);
    }
    private void DynamicPropertiesDisplay(ClothSimEntity clothSimEntity)
    {
        Dictionary <string, DynamicPropertiesDef> dynamicProperties = clothSimEntity.GetConstraintDefinitions();

        string[] options = new string[0];

        if (dynamicProperties.Count > 0)
        {
            options = dynamicProperties.Keys.ToArray();

            m_foldoutState = EditorGUILayout.BeginFoldoutHeaderGroup(m_foldoutState, "DynamicProperties");
            EditorGUILayout.BeginHorizontal();
            int newIndex = EditorGUILayout.Popup(m_currentPropertiesIndex, options, EditorStyles.popup);

            DynamicPropertiesDef def = dynamicProperties[options[m_currentPropertiesIndex]];

            def.RenderColour = EditorGUILayout.ColorField(def.RenderColour);
            EditorGUILayout.EndHorizontal();
            def.Stretch     = EditorGUILayout.FloatField("Stretch", def.Stretch);
            def.Compression = EditorGUILayout.FloatField("Compression", def.Compression);
            def.Push        = EditorGUILayout.FloatField("Push", def.Push);
            def.Damping     = EditorGUILayout.FloatField("Damping", def.Damping);
            def.Elasticity  = EditorGUILayout.FloatField("Elasticity", def.Elasticity);
            def.Inert       = EditorGUILayout.FloatField("Inert", def.Inert);
            def.Amount      = EditorGUILayout.FloatField("Amount", def.Amount);
            def.Priority    = EditorGUILayout.IntField("Priority", def.Priority);

            string[] vertOrders = clothSimEntity.GetVertOrders().Keys.ToArray();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("VertOrder");
            m_selectedVertOrderIndex = EditorGUILayout.Popup(m_selectedVertOrderIndex, vertOrders);
            def.VertOrder            = vertOrders.Count() > 0 ? vertOrders[m_selectedVertOrderIndex] : "";
            EditorGUILayout.EndHorizontal();

            m_currentPropertiesIndex = (newIndex != m_currentPropertiesIndex) ? newIndex : m_currentPropertiesIndex;
        }

        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
        EditorGUILayout.LabelField("Dynamic Properties");
        EditorGUILayout.BeginHorizontal();
        m_newProperiesName = EditorGUILayout.TextField("Name", m_newProperiesName);
        string errorString = "";

        if (GUILayout.Button("Create"))
        {
            if (dynamicProperties.TryGetValue(m_newProperiesName, out DynamicPropertiesDef propDef))
            {
                errorString = "ERROR: This name already exists. The name needs to be unique.";
            }
            else
            {
                dynamicProperties.Add(m_newProperiesName, new DynamicPropertiesDef());
            }
        }

        if (options.Count() > 0)
        {
            if (GUILayout.Button("Delete"))
            {
                dynamicProperties.Remove(options[m_currentPropertiesIndex]);
            }
        }

        EditorGUILayout.TextField("", errorString);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndFoldoutHeaderGroup();
    }
    private void OnGUI()
    {
        if ((ParticleComponent != null))
        {
            GUILayout.Label("Cloth Simulation Constraints for VertID " + ParticleComponent.name, EditorStyles.boldLabel);
            ClothSimEntity clothSimEntity = ParticleComponent.ClothSimEntity;
            Dictionary <string, DynamicPropertiesDef> constraintProperties = clothSimEntity.GetConstraintDefinitions();
            Event currentEvent = Event.current;

            List <ConstraintInfo> constraintInfo = ParticleComponent.ConstraintParticles;
            List <ConstraintDef>  defs           = ParticleComponent.ParticleInfo.VertInfo.ConstraintsTable.ConstraintsDefs;
            Dictionary <string, DynamicPropertiesDef> dynamicProperties = clothSimEntity.GetConstraintDefinitions();
            List <string> keys    = dynamicProperties.Keys.ToList();
            string[]      options = keys.ToArray();

            int defIndex = 0;
            foreach (ConstraintDef def in defs)
            {
                EditorGUILayout.BeginHorizontal();
                m_selected[defIndex] = EditorGUILayout.Toggle(m_selected[defIndex]);
                int index    = keys.IndexOf(def.ConstraintType);
                int newIndex = EditorGUILayout.Popup(index, options, EditorStyles.popup);

                if (newIndex != index)
                {
                    def.ConstraintType = options[newIndex];
                    DynamicPropertiesDef newDef = constraintProperties[def.ConstraintType];
                    ConstraintInfo       info   = ParticleComponent.ConstraintParticles.FirstOrDefault(c => def.TargetVert == c.ConstraintParticle.ParticleInfo.VertInfo.VertID);
                    info.DynamicProperties = newDef;
                }


                def.TargetVert = EditorGUILayout.IntField("Target Vert ID", def.TargetVert);
                EditorGUILayout.EndHorizontal();

                ++defIndex;
            }

            ParticleComponent.Selected = m_selected;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Delete"))
            {
                int         index         = 0;
                List <bool> isSelectedSet = new List <bool>(m_selected);
                foreach (bool isSelected in isSelectedSet)
                {
                    if (isSelected)
                    {
                        ConstraintDef def = defs[index];
                        defs.Remove(def);
                        constraintInfo.Remove(
                            constraintInfo.First(i => i.ConstraintParticle.ParticleInfo.VertInfo.VertID == def.TargetVert));

                        m_selected.RemoveAt(index);
                    }

                    ++index;
                }
            }

            if (GUILayout.Button("Add"))
            {
                foreach (GameObject gameObject in Selection.gameObjects)
                {
                    DynamicParticleComponent dynamicParticle = gameObject.GetComponent <DynamicParticleComponent>();

                    ConstraintDef def = new ConstraintDef
                    {
                        ConstraintType = options.Count() > 0 ? options[0] : "Invalid",
                        TargetVert     = dynamicParticle.ParticleInfo.VertInfo.VertID
                    };

                    defs.Add(def);

                    ConstraintInfo info = new ConstraintInfo
                    {
                        ConstraintParticle = dynamicParticle
                    };

                    if (dynamicProperties.TryGetValue(def.ConstraintType, out DynamicPropertiesDef dynamicPropertiesDef))
                    {
                        info.DynamicProperties = dynamicPropertiesDef;
                    }

                    constraintInfo.Add(info);

                    m_selected.Add(false);
                }
            }

            if (GUILayout.Button("Change"))
            {
                int         index         = 0;
                List <bool> isSelectedSet = new List <bool>(m_selected);
                foreach (bool isSelected in isSelectedSet)
                {
                    if (isSelected)
                    {
                        ConstraintDef  def  = defs[index];
                        ConstraintInfo info = constraintInfo.First(i => i.ConstraintParticle.ParticleInfo.VertInfo.VertID == def.TargetVert);

                        GameObject gameObject = Selection.activeGameObject;

                        DynamicParticleComponent particle = gameObject.GetComponent <DynamicParticleComponent>();

                        def.TargetVert          = particle.ParticleInfo.VertInfo.VertID;
                        info.ConstraintParticle = particle;
                    }

                    ++index;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }