arfoundation-samples icon indicating copy to clipboard operation
arfoundation-samples copied to clipboard

accessing blend shape coefficients

Open gilsunshine opened this issue 5 years ago • 5 comments

I'm trying to access just the JawOpen coefficient, using a strategy similar to what @vlobanov posted last summer (see below). When I log index 24 of the blendShapes native array, which I believe should be JawOpen, I get "0" for the coefficient and "BrowLeftDown" for the location. I tried this with a random index (5) and also get "0" for the coefficient and "BrowLeftDown" for the location. I'm new to Unity and C# so it's very possibly something obvious.

face = GetComponent<ARFace>();
if (faceManager != null)
{
    faceSubsystem = (ARKitFaceSubsystem)faceManager.subsystem;
}
using var blendShapes = faceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp);
Debug.Log(blendShapes[24].coefficient);
Debug.Log(blendShapes[24].blendShapeLocation);
Debug.Log(blendShapes[5].coefficient);
Debug.Log(blendShapes[5].blendShapeLocation);

Here is some of the log:

BrowDownLeft UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:Log(Object) EventController:Update()

0 UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:Log(Object) EventController:Update()

BrowDownLeft UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:Log(Object) EventController:Update()

0 UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[]) UnityEngine.Logger:Log(LogType, Object) UnityEngine.Debug:Log(Object) EventController:Update()

Thanks.


This worked for me:

var faceManager = FindObjectOfType<ARFaceManager>();
var face = GetComponent<ARFace>();
ARKitFaceSubsystem faceSubsystem;
if (faceManager != null) {
    faceSubsystem = (ARKitFaceSubsystem)faceManager.subsystem;
}
var ks = new Dictionary<ARKitBlendShapeLocation, float>();
using (var blendShapes = faceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp)) {
    foreach (var featureCoefficient in blendShapes) {
        ks[featureCoefficient.blendShapeLocation] = featureCoefficient.coefficient;
    }
}

Originally posted by @vlobanov in https://github.com/Unity-Technologies/arfoundation-samples/issues/158#issuecomment-523075641

gilsunshine avatar Jun 09 '21 17:06 gilsunshine

I'm not sure whether the coefficients are in the same order on each device, but on my iPhone 12 Pro, BrowDownLeft is the 10th entry and JawOpen is the 19th. Try printing them all out, e.g.,

using var blendShapes = subsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp);
foreach (var shape in blendShapes)
{
    Debug.Log($"{shape.blendShapeLocation}: {shape.coefficient}");
}

What device, iOS version, and AR Foundation version are you using?

tdmowrer avatar Jun 09 '21 18:06 tdmowrer

I'm using AR Foundation 4.1.7 and iOS 14.6. Part of my issue in figuring out what is going on is that when I try to Debug.Log() within a for loop, as you suggest, I don't get any output in the XCode console. I'm using XCode 12.5.

gilsunshine avatar Jun 09 '21 18:06 gilsunshine

when I try to Debug.Log() within a for loop, as you suggest, I don't get any output in the XCode console

Either your code isn't running, or there aren't any blendshapes. Try logging the length of the blendShapes array.

tdmowrer avatar Jun 09 '21 20:06 tdmowrer

Indeed, there were not any blend shapes. I thought I could just access blend shapes from facemanager.subsystem but it seems there's more to it than that, though I'm not clear on what that is. I'm now using the ARKitBlendShapeVisualizer.cs script from the examples on a prefab that is given to the AR Face Manager component (script) in the AR Session Origin and that is working.

Thanks for your help.

gilsunshine avatar Jun 10 '21 12:06 gilsunshine

Indeed, there were not any blend shapes. I thought I could just access blend shapes from facemanager.subsystem but it seems there's more to it than that, though I'm not clear on what that is. I'm now using the ARKitBlendShapeVisualizer.cs script from the examples on a prefab that is given to the AR Face Manager component (script) in the AR Session Origin and that is working.

Thanks for your help.

@gilsunshine Hi, could you please tell more in detail to get the blendshape coefficients, I would like to pass it to let the player movement, like an open mouth to make a player move forward etc. Thank a lot

chavinpat avatar Nov 25 '21 06:11 chavinpat