protected void Disconnect()
 {
     NeuronConnection.Disconnect(boundActor.owner);
     UnregisterCallbacks();
     boundActor = null;
     source     = null;
 }
Example #2
0
        private void ResumeActor(NeuronActor actor)
        {
            lock (actorCreateDestroyLock)
            {
                lock (suspendListLock)
                {
                    suspendedActors.Remove(actor.actorID);
                }

                if (!activeActors.ContainsKey(actor.actorID))
                {
                    activeActors.Add(actor.actorID, actor);
                }
                else
                {
                    Debug.LogError(string.Format("{0} ArgumentException: An element with the same key already exists in the dictionary. {1}", "ResumeActor", actor.actorID));
                }
            }
            Debug.Log(string.Format("[NeuronSource] Resume actor {0}", actor.guid.ToString("N")));

            for (int i = 0; i < resumeActorCallbacks.Count; ++i)
            {
                resumeActorCallbacks[i](actor);
            }
        }
        // apply transforms extracted from actor mocap data to bones
        public static void ApplyMotion(NeuronActor actor, Transform[] transforms, Vector3[] bonePositionOffsets, Vector3[] boneRotationOffsets)
        {
            // apply Hips position
            SetPosition(transforms, InertialBones.Hips, actor.GetReceivedPosition((NeuronBones)InertialBones.Hips));
            SetRotation(transforms, InertialBones.Hips, actor.GetReceivedRotation((NeuronBones)InertialBones.Hips));

            // apply positions
            if (actor.withDisplacement)
            {
                for (int i = 1; i < (int)InertialBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetPosition(transforms, (InertialBones)i, actor.GetReceivedPosition((NeuronBones)i) + bonePositionOffsets[i]);
                    SetRotation(transforms, (InertialBones)i, actor.GetReceivedRotation((NeuronBones)i) + boneRotationOffsets[i]);
                }
                //for (int i = 0; i < (int)InertialBones.NumOfBones; i++)
                //{
                //    SetPosition(transforms, (InertialBones)i, actor.GetReceivedPosition((NeuronBones)i));
                //}
                //for (int i = 0; i < (int)InertialBones.NumOfBones; i++)
                //{
                //    SetRotation(transforms, (InertialBones)i, actor.GetReceivedRotation((NeuronBones)i));
                //}
            }
            else
            {
                // apply rotations
                for (int i = 1; i < (int)InertialBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetRotation(transforms, (InertialBones)i, actor.GetReceivedRotation((NeuronBones)i));
                }
            }
        }
Example #4
0
 public NeuronActor[] GetActors()
 {
     NeuronActor[] actors = new NeuronActor[activeActors.Count + suspendedActors.Count];
     activeActors.Values.CopyTo(actors, 0);
     activeActors.Values.CopyTo(actors, activeActors.Count);
     return(actors);
 }
        // apply transforms extracted from actor mocap data to bones
        public static void ApplyMotion(NeuronActor actor, Transform[] transforms, ref int last_evaluate_time, Vector3[] bonePositionOffsets, Vector3[] boneRotationOffsets)
        {
            float swap_ratio = CalculateSwapRatio(actor.timeStamp, ref last_evaluate_time);

            if (swap_ratio < 0.0f)
            {
                return;
            }

            // apply Hips position
            SetPosition(transforms, NeuronBones.Hips, actor.GetReceivedPosition(NeuronBones.Hips), swap_ratio);
            SetRotation(transforms, NeuronBones.Hips, actor.GetReceivedRotation(NeuronBones.Hips), swap_ratio);

            // apply positions
            if (actor.withDisplacement)
            {
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetPosition(transforms, (NeuronBones)i, actor.GetReceivedPosition((NeuronBones)i) + bonePositionOffsets[i], swap_ratio);
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i) + boneRotationOffsets[i], swap_ratio);
                }
            }
            else
            {
                // apply rotations
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i), swap_ratio);
                }
            }
        }
Example #6
0
        NeuronActor FindSuspendedActor(int actorID)
        {
            NeuronActor actor = null;

            suspendedActors.TryGetValue(actorID, out actor);
            return(actor);
        }
 public virtual void OnResumeFrameData(NeuronActor actor)
 {
     for (int i = 0; i < resumeFrameDataCallbacks.Count; ++i)
     {
         resumeFrameDataCallbacks[i]();
     }
 }
        // apply transforms extracted from actor mocap data to bones
        public static void ApplyMotion(NeuronActor actor, Transform[] transforms, Vector3[] bonePositionOffsets, Vector3[] boneRotationOffsets, float hipOffset)
        {
            // apply Hips position
            Vector3 hipPos = actor.GetReceivedPosition(NeuronBones.Hips);

            SetPosition(transforms, NeuronBones.Hips, new Vector3(hipPos.x, hipPos.y + hipOffset, hipPos.z));               // actor.GetReceivedPosition( NeuronBones.Hips ) );
            SetRotation(transforms, NeuronBones.Hips, actor.GetReceivedRotation(NeuronBones.Hips));

            // apply positions
            if (actor.withDisplacement)
            {
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    //	SetPosition( transforms, (NeuronBones)i, actor.GetReceivedPosition( (NeuronBones)i ));// + bonePositionOffsets[i] );
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i));                       // + boneRotationOffsets[i] );
                }
            }
            else
            {
                // apply rotations
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i));
                }
            }
        }
 public virtual void OnNoFrameData(NeuronActor actor)
 {
     for (int i = 0; i < noFrameDataCallbacks.Count; ++i)
     {
         noFrameDataCallbacks[i]();
     }
 }
Example #10
0
        NeuronActor FindActiveActor(int actorID)
        {
            NeuronActor actor = null;

            activeActors.TryGetValue(actorID, out actor);
            return(actor);
        }
Example #11
0
        // apply transforms extracted from actor mocap data to bones
        public static void ApplyMotion(NeuronActor actor, Transform[] transforms, Vector3[] bonePositionOffsets, Vector3[] boneRotationOffsets)
        {
            // apply Hips position
            SetPosition(transforms, NeuronBones.Hips, actor.GetReceivedPosition(NeuronBones.Hips));
            SetRotation(transforms, NeuronBones.Hips, actor.GetReceivedRotation(NeuronBones.Hips));

            // apply positions
            if (actor.withDisplacement)
            {
                //Debug.Log("With Position");
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetPosition(transforms, (NeuronBones)i, actor.GetReceivedPosition((NeuronBones)i) + bonePositionOffsets[i]);
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i) + boneRotationOffsets[i]);
                }
            }
            else
            {
                //Debug.Log("Without Position");
                // apply rotations
                for (int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i)
                {
                    SetRotation(transforms, (NeuronBones)i, actor.GetReceivedRotation((NeuronBones)i));
                }
            }
        }
        // apply transforms extracted from actor mocap data to bones
        public static void ApplyCalcMotion(NeuronActor actor, Transform[] transforms, Vector3[] bonePositionOffsets,
                                           Vector3[] boneRotationOffsets, float hipOffset)
        {
            var hipPos = actor.GetCalcReceivedPosition(NeuronBones.Hips);

            SetPosition(transforms, NeuronBones.Hips,
                        new Vector3(hipPos.position.x, hipPos.position.y + hipOffset,
                                    hipPos.position.z));

            //Debug.Log("transform length:" + transforms.Length);
            //for (var i = 1; i < 22 && i < transforms.Length; i++)
            for (var i = 1; i < 21; i++)
            {
                var calc = actor.GetCalcReceivedPosition((NeuronBones)i);
                GameObject.Find("debug").GetComponent <debugJoints>().joints[i].transform.position = calc.position;

                var lb = GameObject.Find("debug").GetComponent <debugJoints>().linesBuf[i];
                lb.Dequeue();
                //GameObject.Find("debug").GetComponent<debugJoints>().linesBuf[i].Enqueue(calc.position);
                //Debug.LogError("time:::"+Time.time%100);
                //Debug.LogError(Time.frameCount%100 + ":::"+ Mathf.Lerp(0,100,(Time.frameCount%100)/100f));
                lb.Enqueue(
                    new Vector3(
                        Mathf.Lerp(0, 100, (Time.frameCount % 100) / 100f),
                        calc.velocity.x * 100,
                        0f)
                    );
            }
        }
Example #13
0
 protected void OnDisable()
 {
     if (boundActor != null && standalone)
     {
         Disconnect();
         boundActor = null;
     }
 }
Example #14
0
        protected static float CalculateSwapRatio(int timeStamp, ref int last_evaluate_time)
        {
            int   now        = NeuronActor.GetTimeStamp();
            float swap_ratio = (float)(timeStamp - last_evaluate_time) / (float)(now - last_evaluate_time);

            last_evaluate_time = now;
            return(Mathf.Clamp(swap_ratio, 0.0f, 1.0f));
        }
		public NeuronInstance( NeuronActor boundActor )
		{
			if( boundActor != null )
			{
				this.boundActor = boundActor;
				RegisterCallbacks();
				standalone = false;
			}
		}
Example #16
0
 public NeuronInstance(NeuronActor boundActor)
 {
     if (boundActor != null)
     {
         this.boundActor = boundActor;
         RegisterCallbacks();
         standalone = false;
     }
 }
Example #17
0
        private NeuronActor FindSuspendedActor(int actorID)
        {
            NeuronActor actor = null;

            lock (suspendListLock)
            {
                suspendedActors.TryGetValue(actorID, out actor);
            }
            return(actor);
        }
Example #18
0
        void SuspendActor(NeuronActor actor)
        {
            activeActors.Remove(actor.actorID);
            suspendedActors.Add(actor.actorID, actor);

            Debug.Log(string.Format("[NeuronSource] Suspend actor {0}", actor.guid.ToString("N")));
            for (int i = 0; i < suspendActorCallbacks.Count; ++i)
            {
                suspendActorCallbacks[i](actor);
            }
        }
        protected bool Connect()
        {
            source = NeuronConnection.Connect(address, port, commandServerPort, socketType);
            if (source != null)
            {
                boundActor = source.AcquireActor(actorID);
                RegisterCallbacks();
            }

            return(source != null);
        }
Example #20
0
        NeuronActor CreateActor(int actorID)
        {
            NeuronActor find = FindSuspendedActor(actorID);

            if (find == null)
            {
                NeuronActor actor = new NeuronActor(this, actorID);
                suspendedActors.Add(actorID, actor);
                return(actor);
            }
            return(find);
        }
Example #21
0
        void ResumeActor(NeuronActor actor)
        {
            suspendedActors.Remove(actor.actorID);
            activeActors.Add(actor.actorID, actor);

            actor.QueryCombinationMode();
            actor.QueryDataFrequency();
            actor.QueryBoneSizes();

            Debug.Log(string.Format("[NeuronSource] Resume actor {0}", actor.guid.ToString("N")));

            for (int i = 0; i < resumeActorCallbacks.Count; ++i)
            {
                resumeActorCallbacks[i](actor);
            }
        }
Example #22
0
        void ResumeActor(NeuronActor actor)
        {
            lock (suspendListLock)
            {
                suspendedActors.Remove(actor.actorID);
            }

            activeActors.Add(actor.actorID, actor);

            Debug.Log(string.Format("[NeuronSource] Resume actor {0}", actor.guid.ToString("N")));

            for (int i = 0; i < resumeActorCallbacks.Count; ++i)
            {
                resumeActorCallbacks[i](actor);
            }
        }
	void OnSuspendActor( NeuronActor actor )
	{
		NeuronAnimatorInstance instance = null;
		instances.TryGetValue( actor, out instance );
		if( instance != null )
		{
			if( instances.Count > numOfReserveInstances )
			{
				instancesToDestroy.Add( instance );	
			}
			else
			{
				reservedInstances.Add( instance );
				instances.Remove( actor );
			}
		}
	}
Example #24
0
        NeuronActor FindOrCreateActor(int actorID)
        {
            lock (_actorsLock)
            {
                foreach (var actor in _actors)
                {
                    if (actor.ActorID == actorID)
                    {
                        return(actor);
                    }
                }

                var newActor = new NeuronActor(actorID);
                _actors.Add(newActor);

                return(newActor);
            }
        }
Example #25
0
        public NeuronActor AcquireActor(int actorID)
        {
            NeuronActor actor = FindActiveActor(actorID);

            if (actor != null)
            {
                return(actor);
            }

            actor = FindSuspendedActor(actorID);
            if (actor != null)
            {
                return(actor);
            }

            actor = CreateActor(actorID);
            return(actor);
        }
Example #26
0
        private NeuronActor CreateActor(int actorID)
        {
            NeuronActor find = FindSuspendedActor(actorID);

            if (find == null)
            {
                NeuronActor actor = new NeuronActor(this, actorID);

                lock (suspendListLock)
                {
                    if (!suspendedActors.ContainsKey(actorID))
                    {
                        suspendedActors.Add(actorID, actor);
                    }
                }

                return(actor);
            }
            return(find);
        }
Example #27
0
        public void OnUpdate()
        {
            int now = NeuronActor.GetTimeStamp();
            List <NeuronActor> suspend_list = new List <NeuronActor>();

            foreach (KeyValuePair <int, NeuronActor> iter in activeActors)
            {
                if (now - iter.Value.timeStamp > NoDataFrameTimeOut)
                {
                    suspend_list.Add(iter.Value);
                }
            }

            List <NeuronActor> resume_list = new List <NeuronActor>();

            foreach (KeyValuePair <int, NeuronActor> iter in suspendedActors)
            {
                if (now - iter.Value.timeStamp < NoDataFrameTimeOut)
                {
                    resume_list.Add(iter.Value);
                }
            }

            for (int i = 0; i < suspend_list.Count; ++i)
            {
                suspend_list[i].OnNoFrameData(suspend_list[i]);
                SuspendActor(suspend_list[i]);
            }

            for (int i = 0; i < resume_list.Count; ++i)
            {
                resume_list[i].OnResumeFrameData(resume_list[i]);
                ResumeActor(resume_list[i]);
            }

            // if actor suspended or resumed, query for actors count
            //if( suspend_list.Count > 0 || resume_list.Count > 0 )
            //{
            //	QueryNumOfActors();
            //}
        }
Example #28
0
        public void OnUpdate()
        {
            if (Time.frameCount % UnityEngine.Random.Range(5, 10) == 0)
            {
                int now = NeuronActor.GetTimeStamp();
                List <NeuronActor> suspend_list = new List <NeuronActor>();
                foreach (KeyValuePair <int, NeuronActor> iter in activeActors)
                {
                    if (now - iter.Value.timeStamp > NoDataFrameTimeOut)
                    {
                        suspend_list.Add(iter.Value);
                    }
                }

                List <NeuronActor> resume_list = new List <NeuronActor>();
                foreach (KeyValuePair <int, NeuronActor> iter in suspendedActors)
                {
                    if (iter.Value == null)
                    {
                        continue;
                    }
                    if (now - iter.Value.timeStamp < NoDataFrameTimeOut)
                    {
                        resume_list.Add(iter.Value);
                    }
                }

                for (int i = 0; i < suspend_list.Count; ++i)
                {
                    suspend_list[i].OnNoFrameData(suspend_list[i]);
                    SuspendActor(suspend_list[i]);
                }

                for (int i = 0; i < resume_list.Count; ++i)
                {
                    resume_list[i].OnResumeFrameData(resume_list[i]);
                    ResumeActor(resume_list[i]);
                }
            }
        }
Example #29
0
        private void SuspendActor(NeuronActor actor)
        {
            lock (actorCreateDestroyLock)
            {
                activeActors.Remove(actor.actorID);
            }
            lock (suspendListLock)
            {
                suspendedActors.Add(actor.actorID, actor);
            }

            Debug.Log(string.Format("[NeuronSource] Suspend actor {0}", actor.guid.ToString("N")));
            for (int i = 0; i < suspendActorCallbacks.Count; ++i)
            {
                if (suspendActorCallbacks[i] == null)
                {
                    Debug.LogErrorFormat("suspendActorCallbacks {0} is null", i);
                    continue;
                }
                suspendActorCallbacks[i](actor);
            }
        }
Example #30
0
        public virtual void OnFrameDataReceived(IntPtr DataHeader, IntPtr data)
        {
            BvhDataHeader header = new BvhDataHeader();

            try
            {
                header = (BvhDataHeader)Marshal.PtrToStructure(DataHeader, typeof(BvhDataHeader));
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            int         actorID = (int)header.AvatarIndex;
            NeuronActor actor   = null;

            lock (actorCreateDestroyLock)
            {
                // find active actor
                actor = FindActiveActor(actorID);
                if (actor != null)
                {
                    // if actor is active
                    actor.OnReceivedMotionData(header, data);
                }
                else
                {
                    // find suspended actor
                    actor = FindSuspendedActor(actorID);
                    if (actor == null)
                    {
                        // if no such actor, create one
                        actor = CreateActor(actorID);
                    }

                    actor.OnReceivedMotionData(header, data);
                }
            }
        }
		public void SetBoundActor( NeuronActor actor )
		{
			if( boundActor != null )
			{
				UnregisterCallbacks();
			}
			
			if( actor != null )
			{
				boundActor = actor;
				RegisterCallbacks();
				actorID = actor.actorID;
				
				NeuronSource source = actor.owner;
				address = source.address;
				port = source.port;
				commandServerPort = source.commandServerPort;
				socketType = source.socketType;
				
				standalone = false;
			}
		}
Example #32
0
        public void SetBoundActor(NeuronActor actor)
        {
            if (boundActor != null)
            {
                UnregisterCallbacks();
            }

            if (actor != null)
            {
                boundActor = actor;
                RegisterCallbacks();
                actorID = actor.actorID;

                NeuronSource source = actor.owner;
                address           = source.address;
                port              = source.port;
                commandServerPort = source.commandServerPort;
                socketType        = source.socketType;

                standalone = false;
            }
        }
		void ResumeActor( NeuronActor actor )
		{
			suspendedActors.Remove( actor.actorID );
			activeActors.Add( actor.actorID, actor );

			actor.QueryCombinationMode();
			actor.QueryDataFrequency();
			actor.QueryBoneSizes();
			
			Debug.Log( string.Format( "[NeuronSource] Resume actor {0}", actor.guid.ToString( "N" ) ) );
			
			for( int i = 0; i < resumeActorCallbacks.Count; ++i )
			{
				resumeActorCallbacks[i]( actor );
			}
		}
Example #34
0
 public NeuronTransformsInstance(NeuronActor actor)
     : base(actor)
 {
     //Debug.Log("4");
 }
	// apply transforms extracted from actor mocap data to transforms of animator bones
	public static void ApplyMotion( NeuronActor actor, Animator animator, ref int last_evaluate_time, Vector3[] positionOffsets, Vector3[] rotationOffsets )
	{
		float swap_ratio = CalculateSwapRatio( actor.timeStamp, ref last_evaluate_time );
		if( swap_ratio <= 0.0f )
		{
			return;
		}
		
		// apply Hips position
		SetPosition( animator, HumanBodyBones.Hips, actor.GetReceivedPosition( NeuronBones.Hips ) + positionOffsets[(int)HumanBodyBones.Hips], swap_ratio );
		SetRotation( animator, HumanBodyBones.Hips, actor.GetReceivedRotation( NeuronBones.Hips ), swap_ratio );
		
		// apply positions
		if( actor.withDisplacement )
		{
			// legs
			SetPosition( animator, HumanBodyBones.RightUpperLeg,			actor.GetReceivedPosition( NeuronBones.RightUpLeg ) + positionOffsets[(int)HumanBodyBones.RightUpperLeg], swap_ratio );
			SetPosition( animator, HumanBodyBones.RightLowerLeg, 			actor.GetReceivedPosition( NeuronBones.RightLeg ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightFoot, 				actor.GetReceivedPosition( NeuronBones.RightFoot ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftUpperLeg,				actor.GetReceivedPosition( NeuronBones.LeftUpLeg ) + positionOffsets[(int)HumanBodyBones.LeftUpperLeg], swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftLowerLeg,				actor.GetReceivedPosition( NeuronBones.LeftLeg ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftFoot,					actor.GetReceivedPosition( NeuronBones.LeftFoot ), swap_ratio );
			
			// spine
			SetPosition( animator, HumanBodyBones.Spine,					actor.GetReceivedPosition( NeuronBones.Spine ), swap_ratio );
			SetPosition( animator, HumanBodyBones.Chest,					actor.GetReceivedPosition( NeuronBones.Spine3 ), swap_ratio ); 
			SetPosition( animator, HumanBodyBones.Neck,						actor.GetReceivedPosition( NeuronBones.Neck ), swap_ratio );
			SetPosition( animator, HumanBodyBones.Head,						actor.GetReceivedPosition( NeuronBones.Head ), swap_ratio );
			
			// right arm
			SetPosition( animator, HumanBodyBones.RightShoulder,			actor.GetReceivedPosition( NeuronBones.RightShoulder ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightUpperArm,			actor.GetReceivedPosition( NeuronBones.RightArm ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightLowerArm,			actor.GetReceivedPosition( NeuronBones.RightForeArm ), swap_ratio );
			
			// right hand
			SetPosition( animator, HumanBodyBones.RightHand,				actor.GetReceivedPosition( NeuronBones.RightHand ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightThumbProximal,		actor.GetReceivedPosition( NeuronBones.RightHandThumb1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightThumbIntermediate,	actor.GetReceivedPosition( NeuronBones.RightHandThumb2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightThumbDistal,			actor.GetReceivedPosition( NeuronBones.RightHandThumb3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.RightIndexProximal,		actor.GetReceivedPosition( NeuronBones.RightHandIndex1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightIndexIntermediate,	actor.GetReceivedPosition( NeuronBones.RightHandIndex2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightIndexDistal,			actor.GetReceivedPosition( NeuronBones.RightHandIndex3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.RightMiddleProximal,		actor.GetReceivedPosition( NeuronBones.RightHandMiddle1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightMiddleIntermediate,	actor.GetReceivedPosition( NeuronBones.RightHandMiddle2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightMiddleDistal,		actor.GetReceivedPosition( NeuronBones.RightHandMiddle3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.RightRingProximal,		actor.GetReceivedPosition( NeuronBones.RightHandRing1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightRingIntermediate,	actor.GetReceivedPosition( NeuronBones.RightHandRing2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightRingDistal,			actor.GetReceivedPosition( NeuronBones.RightHandRing3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.RightLittleProximal,		actor.GetReceivedPosition( NeuronBones.RightHandPinky1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightLittleIntermediate,	actor.GetReceivedPosition( NeuronBones.RightHandPinky2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.RightLittleDistal,		actor.GetReceivedPosition( NeuronBones.RightHandPinky3 ), swap_ratio );
			
			// left arm
			SetPosition( animator, HumanBodyBones.LeftShoulder,				actor.GetReceivedPosition( NeuronBones.LeftShoulder ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftUpperArm,				actor.GetReceivedPosition( NeuronBones.LeftArm ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftLowerArm,				actor.GetReceivedPosition( NeuronBones.LeftForeArm ), swap_ratio );
			
			// left hand
			SetPosition( animator, HumanBodyBones.LeftHand,					actor.GetReceivedPosition( NeuronBones.LeftHand ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftThumbProximal,		actor.GetReceivedPosition( NeuronBones.LeftHandThumb1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftThumbIntermediate,	actor.GetReceivedPosition( NeuronBones.LeftHandThumb2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftThumbDistal,			actor.GetReceivedPosition( NeuronBones.LeftHandThumb3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.LeftIndexProximal,		actor.GetReceivedPosition( NeuronBones.LeftHandIndex1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftIndexIntermediate,	actor.GetReceivedPosition( NeuronBones.LeftHandIndex2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftIndexDistal,			actor.GetReceivedPosition( NeuronBones.LeftHandIndex3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.LeftMiddleProximal,		actor.GetReceivedPosition( NeuronBones.LeftHandMiddle1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftMiddleIntermediate,	actor.GetReceivedPosition( NeuronBones.LeftHandMiddle2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftMiddleDistal,			actor.GetReceivedPosition( NeuronBones.LeftHandMiddle3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.LeftRingProximal,			actor.GetReceivedPosition( NeuronBones.LeftHandRing1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftRingIntermediate,		actor.GetReceivedPosition( NeuronBones.LeftHandRing2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftRingDistal,			actor.GetReceivedPosition( NeuronBones.LeftHandRing3 ), swap_ratio );
			
			SetPosition( animator, HumanBodyBones.LeftLittleProximal,		actor.GetReceivedPosition( NeuronBones.LeftHandPinky1 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftLittleIntermediate,	actor.GetReceivedPosition( NeuronBones.LeftHandPinky2 ), swap_ratio );
			SetPosition( animator, HumanBodyBones.LeftLittleDistal,			actor.GetReceivedPosition( NeuronBones.LeftHandPinky3 ), swap_ratio );
		}
		
		// apply rotations
		
		// legs
		SetRotation( animator, HumanBodyBones.RightUpperLeg,			actor.GetReceivedRotation( NeuronBones.RightUpLeg ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightLowerLeg, 			actor.GetReceivedRotation( NeuronBones.RightLeg ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightFoot, 				actor.GetReceivedRotation( NeuronBones.RightFoot ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftUpperLeg,				actor.GetReceivedRotation( NeuronBones.LeftUpLeg ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftLowerLeg,				actor.GetReceivedRotation( NeuronBones.LeftLeg ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftFoot,					actor.GetReceivedRotation( NeuronBones.LeftFoot ), swap_ratio );
		
		// spine
		SetRotation( animator, HumanBodyBones.Spine,					actor.GetReceivedRotation( NeuronBones.Spine ), swap_ratio );
		SetRotation( animator, HumanBodyBones.Chest,					actor.GetReceivedRotation( NeuronBones.Spine1 ) + actor.GetReceivedRotation( NeuronBones.Spine2 ) + actor.GetReceivedRotation( NeuronBones.Spine3 ), swap_ratio ); 
		SetRotation( animator, HumanBodyBones.Neck,						actor.GetReceivedRotation( NeuronBones.Neck ), swap_ratio );
		SetRotation( animator, HumanBodyBones.Head,						actor.GetReceivedRotation( NeuronBones.Head ), swap_ratio );
		
		// right arm
		SetRotation( animator, HumanBodyBones.RightShoulder,			actor.GetReceivedRotation( NeuronBones.RightShoulder ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightUpperArm,			actor.GetReceivedRotation( NeuronBones.RightArm ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightLowerArm,			actor.GetReceivedRotation( NeuronBones.RightForeArm ), swap_ratio );
		
		// right hand
		SetRotation( animator, HumanBodyBones.RightHand,				actor.GetReceivedRotation( NeuronBones.RightHand ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightThumbProximal,		actor.GetReceivedRotation( NeuronBones.RightHandThumb1 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightThumbIntermediate,	actor.GetReceivedRotation( NeuronBones.RightHandThumb2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightThumbDistal,			actor.GetReceivedRotation( NeuronBones.RightHandThumb3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.RightIndexProximal,		actor.GetReceivedRotation( NeuronBones.RightHandIndex1 ) + actor.GetReceivedRotation( NeuronBones.RightInHandIndex ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightIndexIntermediate,	actor.GetReceivedRotation( NeuronBones.RightHandIndex2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightIndexDistal,			actor.GetReceivedRotation( NeuronBones.RightHandIndex3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.RightMiddleProximal,		actor.GetReceivedRotation( NeuronBones.RightHandMiddle1 ) + actor.GetReceivedRotation( NeuronBones.RightInHandMiddle ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightMiddleIntermediate,	actor.GetReceivedRotation( NeuronBones.RightHandMiddle2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightMiddleDistal,		actor.GetReceivedRotation( NeuronBones.RightHandMiddle3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.RightRingProximal,		actor.GetReceivedRotation( NeuronBones.RightHandRing1 ) + actor.GetReceivedRotation( NeuronBones.RightInHandRing ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightRingIntermediate,	actor.GetReceivedRotation( NeuronBones.RightHandRing2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightRingDistal,			actor.GetReceivedRotation( NeuronBones.RightHandRing3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.RightLittleProximal,		actor.GetReceivedRotation( NeuronBones.RightHandPinky1 ) + actor.GetReceivedRotation( NeuronBones.RightInHandPinky ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightLittleIntermediate,	actor.GetReceivedRotation( NeuronBones.RightHandPinky2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.RightLittleDistal,		actor.GetReceivedRotation( NeuronBones.RightHandPinky3 ), swap_ratio );
		
		// left arm
		SetRotation( animator, HumanBodyBones.LeftShoulder,				actor.GetReceivedRotation( NeuronBones.LeftShoulder ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftUpperArm,				actor.GetReceivedRotation( NeuronBones.LeftArm ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftLowerArm,				actor.GetReceivedRotation( NeuronBones.LeftForeArm ), swap_ratio );
		
		// left hand
		SetRotation( animator, HumanBodyBones.LeftHand,					actor.GetReceivedRotation( NeuronBones.LeftHand ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftThumbProximal,		actor.GetReceivedRotation( NeuronBones.LeftHandThumb1 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftThumbIntermediate,	actor.GetReceivedRotation( NeuronBones.LeftHandThumb2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftThumbDistal,			actor.GetReceivedRotation( NeuronBones.LeftHandThumb3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.LeftIndexProximal,		actor.GetReceivedRotation( NeuronBones.LeftHandIndex1 ) + actor.GetReceivedRotation( NeuronBones.LeftInHandIndex ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftIndexIntermediate,	actor.GetReceivedRotation( NeuronBones.LeftHandIndex2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftIndexDistal,			actor.GetReceivedRotation( NeuronBones.LeftHandIndex3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.LeftMiddleProximal,		actor.GetReceivedRotation( NeuronBones.LeftHandMiddle1 ) + actor.GetReceivedRotation( NeuronBones.LeftInHandMiddle ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftMiddleIntermediate,	actor.GetReceivedRotation( NeuronBones.LeftHandMiddle2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftMiddleDistal,			actor.GetReceivedRotation( NeuronBones.LeftHandMiddle3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.LeftRingProximal,			actor.GetReceivedRotation( NeuronBones.LeftHandRing1 ) + actor.GetReceivedRotation( NeuronBones.LeftInHandRing ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftRingIntermediate,		actor.GetReceivedRotation( NeuronBones.LeftHandRing2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftRingDistal,			actor.GetReceivedRotation( NeuronBones.LeftHandRing3 ), swap_ratio );
		
		SetRotation( animator, HumanBodyBones.LeftLittleProximal,		actor.GetReceivedRotation( NeuronBones.LeftHandPinky1 ) + actor.GetReceivedRotation( NeuronBones.LeftInHandPinky ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftLittleIntermediate,	actor.GetReceivedRotation( NeuronBones.LeftHandPinky2 ), swap_ratio );
		SetRotation( animator, HumanBodyBones.LeftLittleDistal,			actor.GetReceivedRotation( NeuronBones.LeftHandPinky3 ), swap_ratio );		
	}
	public NeuronAnimatorInstance( NeuronActor actor )
		:base( actor )
	{
	}
	public NeuronAnimatorInstance( Animator animator, NeuronActor actor )
		:base( actor )
	{
		boundAnimator = animator;
		UpdateOffset();
	}
		public virtual void OnNoFrameData( NeuronActor actor )
		{
			for( int i = 0; i < noFrameDataCallbacks.Count; ++i )
			{
				noFrameDataCallbacks[i]();
			}
		}		
		protected void OnDisable()
		{
			if( boundActor != null && standalone )
			{
				Disconnect();
				boundActor = null;
			}
		}
	bool SpawnInstance( NeuronActor actor )
	{
		if( actor == null || !ValidatePrefab() )
		{
			return false;
		}
		
		NeuronAnimatorInstance instance = null;
		if( reservedInstances.Count == 0 )
		{
			GameObject obj = GameObject.Instantiate( replicaPrefab, Vector3.zero, Quaternion.identity ) as GameObject;
			instance = obj.GetComponent<NeuronAnimatorInstance>();
			Debug.Log( string.Format( "[NeuronInstancesManager] Bound instance {0} actor {1}", obj.name, actor.guid.ToString( "N" ) ) );
			instance.SetBoundActor( actor );
		}
		else
		{
			instance = reservedInstances[reservedInstances.Count - 1];
			reservedInstances.RemoveAt( reservedInstances.Count - 1 );
			Debug.Log( string.Format( "[NeuronInstancesManager] Bound instance {0} actor {1}", instance.gameObject.name, actor.guid.ToString( "N" ) ) );
			instance.SetBoundActor( actor );
		}
		
		if( instance != null )
		{
			instances.Add( actor, instance );
		}
		
		return true;
	}
		protected void Disconnect()
		{
			NeuronConnection.Disconnect( boundActor.owner );
			UnregisterCallbacks();
			boundActor = null;
		}
		// apply transforms extracted from actor mocap data to bones
		public static void ApplyMotion( NeuronActor actor, Transform[] transforms, ref int last_evaluate_time, Vector3[] bonePositionOffsets, Vector3[] boneRotationOffsets )
		{		
			float swap_ratio = CalculateSwapRatio( actor.timeStamp, ref last_evaluate_time );
			if( swap_ratio < 0.0f )
			{
				return;
			}
			
			// apply Hips position
			SetPosition( transforms, NeuronBones.Hips, actor.GetReceivedPosition( NeuronBones.Hips ), swap_ratio );
			SetRotation( transforms, NeuronBones.Hips, actor.GetReceivedRotation( NeuronBones.Hips ), swap_ratio );
			
			// apply positions
			if( actor.withDisplacement )
			{
				for( int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i )
				{
					SetPosition( transforms, (NeuronBones)i, actor.GetReceivedPosition( (NeuronBones)i ) + bonePositionOffsets[i], swap_ratio );
					SetRotation( transforms, (NeuronBones)i, actor.GetReceivedRotation( (NeuronBones)i ) + boneRotationOffsets[i], swap_ratio );
				}
			}
			else
			{
				// apply rotations
				for( int i = 1; i < (int)NeuronBones.NumOfBones && i < transforms.Length; ++i )
				{
					SetRotation( transforms, (NeuronBones)i, actor.GetReceivedRotation( (NeuronBones)i ), swap_ratio );
				}
			}
		}
	void OnResumeActor( NeuronActor actor )
	{
		actorsToInstantiate.Add( actor );
	}
		public NeuronTransformsInstance( Transform root, string prefix, NeuronActor actor )
			:base( actor )
		{
			Bind( root, prefix );
		}
		public NeuronTransformsInstance( NeuronActor actor )
			:base( actor )
		{
		}
		public virtual void OnResumeFrameData( NeuronActor actor  )
		{
			for( int i = 0; i < resumeFrameDataCallbacks.Count; ++i )
			{
				resumeFrameDataCallbacks[i]();
			}
		}
		void SuspendActor( NeuronActor actor )
		{
			activeActors.Remove( actor.actorID );
			suspendedActors.Add( actor.actorID, actor );
			
			Debug.Log( string.Format( "[NeuronSource] Suspend actor {0}", actor.guid.ToString( "N" ) ) );
			for( int i = 0; i < suspendActorCallbacks.Count; ++i )
			{
				suspendActorCallbacks[i]( actor );
			}
		}
		protected bool Connect()
		{		
			NeuronSource source = NeuronConnection.Connect( address, port, commandServerPort, socketType );
			if( source != null )
			{
				boundActor = source.AcquireActor( actorID );
				RegisterCallbacks();
			}
			
			return source != null;
		}
		public NeuronActor[] GetActors()
		{
			NeuronActor[] actors = new NeuronActor[activeActors.Count + suspendedActors.Count];
			activeActors.Values.CopyTo( actors, 0 );
			activeActors.Values.CopyTo( actors, activeActors.Count );
			return actors;
		}
		NeuronActor CreateActor( int actorID )
		{
			NeuronActor find = FindSuspendedActor( actorID );
			if( find == null )
			{
				NeuronActor actor = new NeuronActor( this, actorID );
				suspendedActors.Add( actorID, actor );
				return actor;
			}
			return find;
		}