コード例 #1
0
        /// <summary>Load presets for a json file that contains all weights as defined by the Manuel Bastioni plugin in Blender</summary>
        private static void LoadPresets()
        {
            if (presets != null)
            {
                return;
            }

            presets = new Dictionary <Presets, Dictionary <int, float> >();
            presets[Presets.neutral] = new Dictionary <int, float>();

            // Parsing JSON file
            TextAsset jsonFile   = Resources.Load <TextAsset>("avatarExpressions");
            string    jsonString = jsonFile.text;
            var       parsedJson = JSON.Parse(jsonString).AsObject;

            foreach (KeyValuePair <string, JSONNode> entry in parsedJson)
            {
                // Must cast string to enum (http://stackoverflow.com/a/16104)
                Presets currentExpression = (Presets)Enum.Parse(typeof(Presets), entry.Key, true);
                presets[currentExpression] = new Dictionary <int, float>();

                var subDict = entry.Value.AsObject;
                foreach (KeyValuePair <string, JSONNode> subEntry in subDict)
                {
                    presets[currentExpression].Add(ManuelBastioniBlendShapes.GetIndex(subEntry.Key), subEntry.Value.AsFloat * 100f);
                }
            }
        }
コード例 #2
0
 /// <summary>Apply a set of weights to create the corresponding face expression</summary>
 /// <param name="preset">Array containing all the weights needed</param>
 /// <exception cref="System.ArgumentException">Thrown when the set length is not compatible with the length of the set of blend shapes.</exception>
 public override void ApplyMeshState(MeshState meshState)
 {
     // Base function is overriden to be able to manage eyes movements independently
     for (int i = 0; i < GetBlendShapesCount(); i++)
     {
         if (stateIncludeEyes || !ManuelBastioniBlendShapes.BelongsToZone(ManuelBastioniBlendShapes.Zone.Eyes, i)) // (stateIncludeEyes OR (!stateIncludeEyes AND !BelongsToZone(Eyes, i)))
         {
             ApplyWeight(i, meshState.GetWeight(i));
         }
     }
 }