Пример #1
0
    public void createKNNRig(string headBoneName, string rHandBoneName, string lHandBoneName, float slidingWindowSizeInMS, float slidingWindowOffsetInMS, float pollingRate, bool ignoreRotation, bool bothHandsInFeatureVec, string outputPath)
    {
        var lHandTreeNodes  = new List <int>();
        var lHandTreePoints = new List <float[]>();
        var rHandTreeNodes  = new List <int>();
        var rHandTreePoints = new List <float[]>();

        GameObject rootBoneObj = new GameObject();
        KNNBone    rootBone    = rootBoneObj.AddComponent <KNNBone>();

        Debug.Assert(files != null && files.Count > 0);
        loadFromFile(files[0]);
        setToFrame(0, true, true, true);

        rootBone.initKNNBone(root.transform);

        foreach (string file in files)
        {
            loadFromFile(file);
            FillKNNTrees(rootBone, ignoreRotation, bothHandsInFeatureVec, headBoneName, rHandBoneName, lHandBoneName, slidingWindowSizeInMS, slidingWindowOffsetInMS, pollingRate, lHandTreeNodes, rHandTreeNodes, lHandTreePoints, rHandTreePoints);
        }

        float slidingWindowSize = slidingWindowSizeInMS / 1000.0f;
        float targetFrameTime   = 1.0f / pollingRate;
        int   framesPerWindow   = (int)((slidingWindowSize) / targetFrameTime);
        int   featureVecLength  = 9 * framesPerWindow;

        var rHandTree = new KDTree <float, int>(featureVecLength, rHandTreePoints.ToArray(), rHandTreeNodes.ToArray(), Metrics.WeightedL2Norm);
        var lHandTree = new KDTree <float, int>(featureVecLength, lHandTreePoints.ToArray(), lHandTreeNodes.ToArray(), Metrics.WeightedL2Norm);

        GameObject  kNNSkeleton_     = new GameObject("KNN-Skeleton");
        KNNSkeleton finalKNNSkeleton = kNNSkeleton_.AddComponent <KNNSkeleton>();

        finalKNNSkeleton.SetKNNSkeleton(rootBone, ignoreRotation, lHandTree, rHandTree, featureVecLength);
        finalKNNSkeleton.Save(outputPath);
        DestroyImmediate(kNNSkeleton_);
        DestroyImmediate(rootBoneObj);

        GameObject kNNRig = new GameObject("KNN-Rig");

        KNNRig kNNRigComponent = kNNRig.AddComponent <KNNRig>();

        kNNRigComponent.skeletonPath = outputPath;
    }
Пример #2
0
    public void initKNNBone(Transform rootTransform)
    {
        this.name = rootTransform.name;
        this.transform.localPosition = rootTransform.localPosition;
        this.transform.localRotation = rootTransform.localRotation;
        this.offset    = this.transform.localPosition;
        this.children  = new List <KNNBone>();
        this.rotations = new List <Quaternion>();


        for (int childIdx = 0; childIdx < rootTransform.childCount; childIdx++)
        {
            GameObject childObj = new GameObject();

            KNNBone childBone = (KNNBone)childObj.AddComponent(typeof(KNNBone));
            childBone.parent           = this;
            childBone.transform.parent = this.transform;
            childBone.initKNNBone(rootTransform.GetChild(childIdx));
            children.Add(childBone);
        }
    }