Пример #1
0
    public void SFB_BS_ImportPresetFile(TextAsset presetFile)
    {
        string contents = presetFile.text;

        string[] shapesText;
        shapesText = contents.Split(new string[] { "," }, System.StringSplitOptions.None);
        for (int i = 0; i < shapesText.Length; i++)
        {
            if (shapesText [i] != "*")
            {
                SFB_BlendShapeObject bsObject = blendShapeObjects [inspectorObjects [i].objectID];
                if (bsObject.renderer.gameObject.activeSelf)
                {
                    SFB_BlendShape bsShape = bsObject.blendShapes[inspectorObjects[i].shapeID];
                    if (shapesText [i] == "R")
                    {
                        SFB_BS_SetRandom(bsShape);
                    }
                    else
                    {
                        float shapeValue = float.Parse(shapesText[i]);
                        SetValue(inspectorObjects[i].objectID, inspectorObjects[i].shapeID, inspectorObjects[i].blendShapeID, shapeValue);
                        bsShape.sliderValue = shapeValue;
                    }
                }
            }
        }
    }
Пример #2
0
 public void SFB_BS_ToggleRange(int value)
 {
     for (int i = 0; i < inspectorObjects.Count; i++)
     {
         SFB_InspectorObject inspectorObject = inspectorObjects [i];
         SFB_BlendShape      blendShape      = blendShapeObjects [inspectorObject.objectID].blendShapes [inspectorObject.shapeID];
         if (value == 0)
         {
             blendShape.minValue = value;
             blendShape.maxValue = value;
         }
         else
         {
             if (blendShape.isPlus)
             {
                 blendShape.minValue = -value;
                 blendShape.maxValue = value;
             }
             else
             {
                 blendShape.minValue = 0;
                 blendShape.maxValue = value;
             }
         }
     }
 }
Пример #3
0
    public void AddObject(Mesh newMesh, SkinnedMeshRenderer newRenderer)
    {
        int currentCount = blendShapeObjects.Count;
        SFB_BlendShapeObject newObject = new SFB_BlendShapeObject();

        blendShapeObjects.Add(newObject);
        blendShapeObjects [currentCount]           = new SFB_BlendShapeObject();
        blendShapeObjects[currentCount].name       = newMesh.name;
        blendShapeObjects[currentCount].meshObject = newMesh;
        blendShapeObjects[currentCount].renderer   = newRenderer;
        int primaryShapes = 0;

        for (int i = 0; i < newMesh.blendShapeCount; i++)
        {
            SFB_BlendShape newBlendShape     = new SFB_BlendShape();;
            int            currentShapeCount = blendShapeObjects [currentCount].blendShapes.Count;
            blendShapeObjects[currentCount].blendShapes.Add(newBlendShape);
            blendShapeObjects[currentCount].blendShapes[currentShapeCount]          = new SFB_BlendShape();
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].id       = i;
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].fullName = newMesh.GetBlendShapeName(i);
            string humanName = GetHumanName(newMesh.GetBlendShapeName(i));
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].name      = humanName;
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].isVisible = DisplayThisBlendshape(newMesh.GetBlendShapeName(i));

            if (blendShapeObjects [currentCount].blendShapes [currentShapeCount].isVisible)
            {
                primaryShapes++;
            }

            if (humanName != "")
            {
                int    originalLength = humanName.Length;
                string minusCheck     = humanName.Replace("Minus", "");
                if (minusCheck.Length != originalLength)
                {
                    blendShapeObjects [currentCount].blendShapes [currentShapeCount].isMinus   = true;
                    blendShapeObjects [currentCount].blendShapes [currentShapeCount].isVisible = false;
                }
                else
                {
                    if (blendShapeObjects [currentCount].blendShapes [currentShapeCount].isVisible)
                    {
                        blendShapeObjects [currentCount].blendShapes [currentShapeCount].inspectorID = AddToInspectorObjects(currentCount, currentShapeCount, i);
                    }
                }
                string plusCheck = humanName.Replace("Plus", "");
                if (plusCheck.Length != originalLength)
                {
                    blendShapeObjects [currentCount].blendShapes [currentShapeCount].isPlus = true;
                }
            }
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].value       = blendShapeObjects[currentCount].renderer.GetBlendShapeWeight(i);
            blendShapeObjects[currentCount].blendShapes[currentShapeCount].sliderValue = blendShapeObjects[currentCount].renderer.GetBlendShapeWeight(i);
        }
        blendShapeObjects[currentCount].primaryShapes = primaryShapes;
    }
Пример #4
0
 public void SFB_BS_TogglePresetsValue(int objectID, int value)
 {
     for (int i = 0; i < inspectorObjects.Count; i++)
     {
         SFB_InspectorObject inspectorObject = inspectorObjects [i];
         if (inspectorObject.objectID == objectID || objectID == 999999)
         {
             SFB_BlendShape blendShape = blendShapeObjects[inspectorObject.objectID].blendShapes[inspectorObject.shapeID];
             blendShape.presetExportValue = value;
         }
     }
 }
Пример #5
0
 public void SFB_BS_SetRandom(SFB_BlendShape blendShape)
 {
     blendShape.sliderValue = Mathf.Round(UnityEngine.Random.Range(blendShape.minValue, blendShape.maxValue));
     SetValue(inspectorObjects[blendShape.inspectorID].objectID, inspectorObjects[blendShape.inspectorID].shapeID, blendShape.id, blendShape.sliderValue);
     if (blendShape.isPlus)
     {
         int            minusShapeObject = GetMinusShapeObject(blendShape.name);
         int            minusShapeID     = GetMinusShapeID(blendShape.name);
         SFB_BlendShape minusShape       = blendShapeObjects [minusShapeObject].blendShapes [minusShapeID];
         minusShape.sliderValue = -blendShape.sliderValue;
         SetValue(minusShapeObject, minusShapeID, minusShape.id, minusShape.sliderValue);
     }
 }
Пример #6
0
 public void RandomizeAll()
 {
     for (int i = 0; i < inspectorObjects.Count; i++)
     {
         SFB_BlendShapeObject blendShapeObject = blendShapeObjects[inspectorObjects[i].objectID];
         GameObject           inGameObject     = blendShapeObject.renderer.gameObject;
         if (inGameObject.activeSelf)
         {
             SFB_BlendShape blendShape = blendShapeObject.blendShapes[inspectorObjects[i].shapeID];
             SFB_BS_SetRandom(blendShape);
         }
     }
 }
Пример #7
0
    public void SetValueUI(float newValue)
    {
        int            objectID       = inspectorObjects [selectedShape].objectID;
        int            shapeID        = inspectorObjects[selectedShape].shapeID;
        SFB_BlendShape blendShapeData = blendShapeObjects [objectID].blendShapes [shapeID];

        if (blendShapeData.isPlus)
        {
            int            minusShapeObject = GetMinusShapeObject(blendShapeData.name);
            int            minusShapeID     = GetMinusShapeID(blendShapeData.name);
            SFB_BlendShape minusShapeData   = blendShapeObjects [minusShapeObject].blendShapes [minusShapeID];
            blendShapeData.sliderValue = newValue;
            minusShapeData.sliderValue = -newValue;
            SetValue(minusShapeObject, minusShapeID, minusShapeData.id, -newValue);
        }
        SetValue(inspectorObjects[selectedShape].objectID, inspectorObjects[selectedShape].shapeID, inspectorObjects[selectedShape].blendShapeID, newValue);
    }
Пример #8
0
 public void SFB_BS_ResetAll()
 {
     for (int i = 0; i < inspectorObjects.Count; i++)
     {
         SFB_BlendShapeObject bsObject = blendShapeObjects[inspectorObjects[i].objectID];
         SFB_BlendShape       bsShape  = bsObject.blendShapes[inspectorObjects[i].shapeID];
         SetValue(inspectorObjects[i].objectID, inspectorObjects[i].shapeID, inspectorObjects[i].shapeID, 0);
         if (bsShape.isPlus)
         {
             int            minusShapeObject = GetMinusShapeObject(bsShape.name);
             int            minusShapeID     = GetMinusShapeID(bsShape.name);
             SFB_BlendShape minusShapeData   = blendShapeObjects[minusShapeObject].blendShapes[minusShapeID];
             minusShapeData.sliderValue = 0;
             SetValue(minusShapeObject, minusShapeID, minusShapeData.id, 0);
         }
         bsShape.sliderValue = 0;
     }
 }
Пример #9
0
    public void ResetAllObjects(SFB_BlendShapeObject bsObject)
    {
        int objectID = GetObjectID(bsObject);

        for (int i = 0; i < bsObject.blendShapes.Count; i++)
        {
            SFB_BlendShape bsShape = bsObject.blendShapes [i];
            SetValue(objectID, i, i, 0);
            if (bsShape.isPlus)
            {
                int            minusShapeObject = GetMinusShapeObject(bsShape.name);
                int            minusShapeID     = GetMinusShapeID(bsShape.name);
                SFB_BlendShape minusShapeData   = blendShapeObjects[minusShapeObject].blendShapes[minusShapeID];
                minusShapeData.sliderValue = 0;
                SetValue(minusShapeObject, minusShapeID, minusShapeData.id, 0);
            }
            bsShape.sliderValue = 0;
        }
    }
    public void SetValue(string objectName, string shapeName, float value)
    {
        //Debug.Log("Set Value " + objectName + " " + shapeName + " " + value);
        int objectIndex = GetObjectIndex(objectName);
        int shapeIndex  = GetShapeIndex(shapeName, objectIndex);

        SetValue(objectIndex, shapeIndex, shapeIndex, value);

        if (blendShapeObjects[objectIndex].blendShapes[shapeIndex].isPlus && GetMinusShapeObject(shapeName) != 999999)
        {
            int minusShapeObject = GetMinusShapeObject(shapeName);
            if (minusShapeObject != 999999)
            {
                int            minusShapeID = GetMinusShapeID(shapeName);
                SFB_BlendShape minusShape   = blendShapeObjects[minusShapeObject].blendShapes[minusShapeID];
                minusShape.sliderValue = -value;
                SetValue(minusShapeObject, minusShapeID, minusShape.id, minusShape.sliderValue);
            }
        }
    }
    public void SFB_BS_ImportPresetFile(TextAsset presetFile)
    {
        string contents = presetFile.text;

        string[] shapesText;
        shapesText = contents.Split(new string[] { "," }, System.StringSplitOptions.None);
        for (int i = 1; i < shapesText.Length; i++)             // START AT 1, since index 0 is the version information
        // Debug.Log("Processing Object " + shapesText[i] + ", Shape " + shapesText[i + 1] + ", Value " + shapesText[i + 2]);
        {
            int objectIndex = GetBlendShapeObjectIndex(shapesText[i]);
            int shapeIndex  = GetBlendShapesIndex(objectIndex, shapesText[i + 1]);

            if (shapeIndex != 999999)
            {
                SFB_BlendShape blendShapeData = blendShapeObjects[objectIndex].blendShapes[shapeIndex];
                if (shapesText[i + 2] == "R")
                {
                    SFB_BS_SetRandom(blendShapeData);
                }
                else
                {
                    float shapeValue = float.Parse(shapesText[i + 2]);
                    blendShapeData.sliderValue = shapeValue;
                    SetValue(objectIndex, shapeIndex, blendShapeData.id, shapeValue);

                    if (blendShapeData.isPlus && GetMinusShapeObject(blendShapeData.name) != 999999)
                    {
                        int minusShapeObject = GetMinusShapeObject(blendShapeData.name);
                        if (minusShapeObject != 999999)
                        {
                            int            minusShapeID = GetMinusShapeID(blendShapeData.name);
                            SFB_BlendShape minusShape   = blendShapeObjects[minusShapeObject].blendShapes[minusShapeID];
                            minusShape.sliderValue = -blendShapeData.sliderValue;
                            SetValue(minusShapeObject, minusShapeID, minusShape.id, minusShape.sliderValue);
                        }
                    }
                }

                if (blendShapeData.isPlus)
                {
                }
            }


            i++;
            i++;

            /*if (shapesText [i] != "*") {
             *                   SFB_BlendShapeObject bsObject = blendShapeObjects [inspectorObjects [i].objectID];
             *                   if (bsObject.renderer.gameObject.activeSelf) {
             *                           SFB_BlendShape bsShape = bsObject.blendShapes[inspectorObjects[i].shapeID];
             *                           if (shapesText [i] == "R") {
             *                                   SFB_BS_SetRandom (bsShape);
             *                           } else {
             *                                   float shapeValue = float.Parse(shapesText[i]);
             *                                   SetValue(inspectorObjects[i].objectID, inspectorObjects[i].shapeID, inspectorObjects[i].blendShapeID, shapeValue);
             *                                   bsShape.sliderValue	= shapeValue;
             *                           }
             *                   }
             *           }*/
        }
    }