Beispiel #1
0
        private void calculate_morph(string morph_name, float val, bool add_vertices_to_update)
        {
            Morph morph = Morph.GetFromListByName(this.morph_data, morph_name);

            if (morph != null)
            {
                float real_val = val - Morph.GetFromListByName(this.morph_data, morph_name).morph_values;
                //if (this.morph_values.ContainsKey(real_val))
                if (real_val != 0.0f)
                {
                    foreach (KeyValuePair <uint, Vector3> kv in morph.morph_data)
                    {
                        int     i     = Convert.ToInt32(kv.Key);
                        Vector3 delta = kv.Value;
                        this.m_engine.final_form[i] = this.m_engine.final_form[i] + delta * real_val;
                    }

                    if (add_vertices_to_update)
                    {
                        this.m_engine.verts_to_update = this.m_engine.verts_to_update.Union(morph.morph_modified_verts).ToList <uint>();
                    }

                    Morph.GetFromListByName(this.morph_data, morph_name).morph_values = val;
                    //this.morph_values[morph_name] = val;
                }
            }
        }
Beispiel #2
0
        private List <Morph> load_morphs_database(string fileName)
        {
            List <Morph> listMorphs = new List <Morph>();

            Dictionary <string, List <float[]> > listMorphsRead = JsonConvert.DeserializeObject <Dictionary <string, List <float[]> > >(File.ReadAllText(fileName));


            foreach (var oMorph in listMorphsRead)
            {
                Morph m = new Morph();
                m.morph_name = oMorph.Key;


                Dictionary <uint, Vector3> vDeltas = new Dictionary <uint, Vector3>();
                List <uint> vVerts = new List <uint>();

                foreach (var oDelta in oMorph.Value)
                {
                    uint    ui = Convert.ToUInt32(oDelta[0]);
                    Vector3 v  = new Vector3(oDelta[1], oDelta[2], oDelta[3]);
                    vDeltas.Add(ui, v); //append in python
                    vVerts.Add(ui);     //add in python
                    ////vVerts.Insert(0, ui);//add in python
                }


                m.morph_data           = vDeltas;
                m.morph_modified_verts = vVerts;
                m.morph_values         = 0f;
                listMorphs.Add(m);
            }

            return(listMorphs);
        }
Beispiel #3
0
        private void combine_morphings(HumanModifier modifier, bool refresh_only, bool add_vertices_to_update)
        {
            //Dictionary<float, float> values = new Dictionary<float, float>();
            List <KeyValuePair <float, float> > values = new List <KeyValuePair <float, float> >();

            foreach (string prop in modifier.properties)
            {
                float val = this.character_data[prop];
                if (val > 1.0f)
                {
                    val = 1.0f;
                }
                if (val < 0f)
                {
                    val = 0f;
                }
                float val1 = function_modifier_a(val);
                float val2 = function_modifier_b(val);
                values.Add(new KeyValuePair <float, float> (val1, val2));
            }
            List <float>  weights;
            List <string> names;

            smart_combo(modifier.name, values, out names, out weights);

            for (int i = 0; i < names.Count; i++)
            {
                if (refresh_only)
                {
                    Morph.GetFromListByName(this.morph_data, names[i]).morph_values = weights[i];
                }
                else
                {
                    this.calculate_morph(names[i], weights[i], true);
                }
            }
        }