public override void Initialize()
        {
            if (face != null && !face.Ready())
            {
                return;
            }
            if (skeleton != null && !skeleton.Ready())
            {
                return;
            }
            // TODO: asap needs some default joints...
            VJoint[] vJoints = new VJoint[0];
            if (skeleton != null)
            {
                vJoints = skeleton.GenerateVJoints();
            }

            IFaceTarget[] faceTargets = new IFaceTarget[0];
            if (face != null)
            {
                faceTargets = face.GetFaceTargets();
            }

            agentSpec = new AgentSpec(agentId, vJoints, faceTargets);
            ASAPToolkitManager atkm = FindObjectOfType <ASAPToolkitManager>();

            if (atkm != null)
            {
                atkm.OnAgentInitialized(this);
            }
            initialized = true;
        }
Exemplo n.º 2
0
        // Use this for initialization
        void Start()
        {
            if (randomNameSuffix)
            {
                transform.name = transform.name + "_" + System.Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 8);
            }
            vjoint = new VJoint(transform.name, transform.position, transform.rotation);
            ASAPToolkitManager manager = FindObjectOfType <ASAPToolkitManager>();

            if (manager != null)
            {
                manager.OnWorldObjectInitialized(vjoint);
            }
        }
Exemplo n.º 3
0
        public override void Initialize()
        {
            Debug.Log("Initializing ASAPAgent_ToonFace " + id);

            VJoint[] vJoints = new VJoint[0];

            List <IFaceTarget> faceTargets = new List <IFaceTarget>();

            foreach (ToonFaceConfiguration ftc in faceTargetConfig)
            {
                faceTargets.Add(new ToonFaceTarget(ftc.name, ftc));
            }


            agentSpec = new AgentSpec(id, vJoints, faceTargets.ToArray());
            Debug.Log("UMA Agent initialized, id=" + this.agentSpec.agentId + " Bones: " + this.agentSpec.skeleton.Length + " faceControls: " + this.agentSpec.faceTargets.Length);

            FindObjectOfType <ASAPManager>().OnAgentInitialized(this);
        }
Exemplo n.º 4
0
        public VJoint[] GenerateVJoints()
        {
            if (vJoints != null && vJoints.Length > 0)
            {
                return(vJoints);
            }
            Animator a = GetComponent <Animator>();

            if (a != null)
            {
                a.enabled = false;
            }
            StoredPoseAsset.ApplyPose(aPose.pose, transform);
            List <BoneMapAsset.HAnimBoneMapping> mergedMap = new List <BoneMapAsset.HAnimBoneMapping>();

            foreach (BoneMapAsset.HAnimBoneMapping m in boneMap.mappings)
            {
                mergedMap.Add(m);
            }
            foreach (BoneMapAsset.ExtraBone eb in boneMap.extraBones)
            {
                string bone_name = eb.hanim_bone.ToString();
                if (eb.hanim_bone == CanonicalRepresentation.HAnimBones.NONE)
                {
                    bone_name = eb.bone_name;
                }
                Transform ebTransform       = transform.FindChildRecursive(bone_name);
                Transform ebParentTransform = transform.FindChildRecursive(eb.parent_src_bone);
                if (ebTransform == null && ebParentTransform != null)
                {
                    ebTransform = (new GameObject(bone_name)).transform;
                    ebTransform.SetParent(ebParentTransform);
                    ebTransform.position      = ebParentTransform.position + eb.localPosition;
                    ebTransform.localRotation = Quaternion.Euler(eb.localEulerRotation.x, eb.localEulerRotation.y, eb.localEulerRotation.z);
                }
                BoneMapAsset.HAnimBoneMapping newMap;
                newMap.hanim_bone = eb.hanim_bone;
                newMap.src_bone   = bone_name;
                mergedMap.Add(newMap);
            }
            rig = new CanonicalRig(transform, mergedMap.ToArray());

            if (rig.boneMap == null)
            {
                _ready = false;
                rig    = null;
                Debug.LogError("Failed to create CanonicalRig");
                return(null);
            }

            VJoint[] res = new VJoint[rig.boneMap.Length];
            Dictionary <string, VJoint> lut = new Dictionary <string, VJoint>();

            for (int b = 0; b < rig.boneMap.Length; b++)
            {
                Transform bone = rig.boneMap[b].bone;
                if (rig.boneMap[b].canonicalBoneName == CanonicalRepresentation.HAnimBones.skullbase)
                {
                    head = bone;
                }
                VJoint     parent = null;
                Vector3    pos    = Vector3.zero;
                Quaternion rot    = rig.boneMap[b].CurrentRotationInCanonical();
                if (b == 0)
                {
                    pos = rootPosition;
                    rot = rot * rootRotation;
                }
                else
                {
                    pos    = (bone.position - bone.parent.position);
                    parent = lut[bone.parent.name];
                    if (parent == null)
                    {
                        Debug.LogError("Parent of " + bone.parent.name + " not added yet");
                        return(null);
                    }
                }
                string hAnimName = "";
                if (rig.boneMap[b].canonicalBoneName != CanonicalRepresentation.HAnimBones.NONE)
                {
                    hAnimName = rig.boneMap[b].canonicalBoneName.ToString();
                }
                res[b] = new VJoint(bone.name, hAnimName, pos, rot, parent);
                lut.Add(bone.name, res[b]);
            }
            vJoints = res;
            _ready  = true;
            return(vJoints);
        }