public Vector3 GetReceivedPosition(NeuronBones bone) { if (!positionDelay.ContainsKey(bone)) { positionDelay [bone] = new Queue <Vector3> (); } int offset = 0; if (header.bWithReference != 0) { // skip reference offset += 6; } // got bone position data only when displacement is open or the bone is hips if (header.bWithDisp != 0 || bone == NeuronBones.Hips) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += (int)bone * 6; // Debug.Log (positionDelay.Count); // if (positionDelay.Count != FRAME_DELAY + 1) // positionDelay.Clear (); positionDelay[bone].Enqueue(new Vector3(-data[offset] * NeuronUnityLinearScale, data[offset + 1] * NeuronUnityLinearScale, data[offset + 2] * NeuronUnityLinearScale)); if (positionDelay [bone].Count >= FRAME_DELAY) { return(positionDelay [bone].Dequeue()); } // return new Vector3( -data[offset] * NeuronUnityLinearScale, data[offset+1] * NeuronUnityLinearScale, data[offset+2] * NeuronUnityLinearScale ); } return(Vector3.zero); }
void UpdateBoneRotation( HumanBodyBones humanBone, NeuronBones neuronBone0, NeuronBones neuronBone1 = NeuronBones.NumOfBones, NeuronBones neuronBone2 = NeuronBones.NumOfBones ) { var bone = _animator.GetBoneTransform(humanBone); if (bone == null) { return; } var rot = _actor.GetReceivedRotation(neuronBone0); if (neuronBone1 != NeuronBones.NumOfBones) { rot += _actor.GetReceivedRotation(neuronBone1); } if (neuronBone2 != NeuronBones.NumOfBones) { rot += _actor.GetReceivedRotation(neuronBone2); } var d_rot = _defaultRotations[(int)humanBone]; var r_rot = _resetRotations[(int)humanBone]; var r_rot_inv = Quaternion.Inverse(r_rot); bone.localRotation = r_rot * Quaternion.Euler(rot) * r_rot_inv * d_rot; }
public static void BreakHierarchy(Transform[] transforms) { Transform align_root = transforms[(int)NeuronBones.Hips].parent; for (NeuronBones i = 0; i < NeuronBones.NumOfBones; ++i) { Transform t = transforms[(int)i]; if (t != null) { t.parent = align_root; } } }
// set rotation for bone static void SetRotation(Transform[] transforms, NeuronBones bone, Vector3 rotation) { Transform t = transforms[(int)bone]; if (t != null) { Quaternion rot = Quaternion.Euler(rotation); if (!float.IsNaN(rot.x) && !float.IsNaN(rot.y) && !float.IsNaN(rot.z) && !float.IsNaN(rot.w)) { t.localRotation = rot; } } }
public Vector3 GetReceivedRotation(NeuronBones bone) { // Calculate the data offset. var offset = (_header.bWithReference == 0 ? 3 : 9) + (int)bone * (_header.bWithDisp != 0 ? 6 : 3); // Retrieve the rotation data. var y = -_data[offset++]; var x = _data[offset++]; var z = -_data[offset++]; return(new Vector3(x, y, z)); }
// set position for bone static void SetPosition(Transform[] transforms, NeuronBones bone, Vector3 pos) { Transform t = transforms[(int)bone]; if (t != null) { // calculate position when we have scale pos.Scale(new Vector3(1.0f / t.parent.lossyScale.x, 1.0f / t.parent.lossyScale.y, 1.0f / t.parent.lossyScale.z)); if (!float.IsNaN(pos.x) && !float.IsNaN(pos.y) && !float.IsNaN(pos.z)) { t.localPosition = pos; } } }
public Vector3 GetReceivedPosition(NeuronBones bone) { // Return zero if no position data is available. // (only "Hips" is available when displacement data is disabled) if (_header.bWithDisp == 0 && bone != NeuronBones.Hips) { return(Vector3.zero); } // Calculate the data offset. var offset = (_header.bWithReference == 0 ? 0 : 6) + (int)bone * 6; // Retrieve the position data. var x = -_data[offset++]; var y = _data[offset++]; var z = _data[offset++]; return(new Vector3(x, y, z) * 0.01f); }
public Vector3 GetReceivedPosition(NeuronBones bone) { int offset = 0; if (header.bWithReference != 0) { // skip reference offset += 6; } // got bone position data only when displacement is open or the bone is hips if (header.bWithDisp != 0 || bone == NeuronBones.Hips) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += (int)bone * 6; return(new Vector3(-data[offset] * NeuronUnityLinearScale, data[offset + 1] * NeuronUnityLinearScale, data[offset + 2] * NeuronUnityLinearScale)); } return(Vector3.zero); }
static void AddBoneLineTransform(NeuronBones bone, BoneLine bone_line, params object[] args) { if (args.Length < 3 || bone == NeuronBones.Hips) { return; } Material mat = (Material)args[0]; float parent_width = (float)args[1]; float child_width = (float)args[2]; if (bone >= NeuronBones.LeftHandThumb1 && bone <= NeuronBones.LeftHandPinky3 || bone >= NeuronBones.RightHandThumb1 && bone <= NeuronBones.RightHandPinky3) { bone_line.AddRenderer(mat, parent_width / 3.0f, child_width / 3.0f, bone_line.transform.parent, bone_line.transform); } else { bone_line.AddRenderer(mat, parent_width, child_width, bone_line.transform.parent, bone_line.transform); } }
public Vector3 GetReceivedRotation(NeuronBones bone) { int offset = 0; if (header.bWithReference != 0) { // skip reference offset += 6; } if (header.bWithDisp != 0) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += 3 + (int)bone * 6; } else { // Hips position + Hips rotation + 58 * rotation offset += 3 + (int)bone * 3; } return(new Vector3(data[offset + 1], -data[offset], -data[offset + 2])); }
public Vector3 GetReceivedRotation(NeuronBones bone) { if (!rotationDelay.ContainsKey(bone)) { rotationDelay [bone] = new Queue <Vector3> (); } int offset = 0; if (header.bWithReference != 0) { // skip reference offset += 6; } if (header.bWithDisp != 0) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += 3 + (int)bone * 6; } else { // Hips position + Hips rotation + 58 * rotation offset += 3 + (int)bone * 3; } // if (rotationDelay.Count != FRAME_DELAY) // rotationDelay.Clear (); rotationDelay [bone].Enqueue(new Vector3(data [offset + 1], -data [offset], -data [offset + 2])); if (rotationDelay [bone].Count >= FRAME_DELAY) { return(rotationDelay [bone].Dequeue()); } return(Vector3.zero); // return new Vector3 (data [offset + 1], -data [offset], -data [offset + 2]); }
public Transform GetBoneTransform(NeuronBones bone) { return(bones [(int)bone]); }
public Vector3 GetReceivedRotation( NeuronBones bone ) { int offset = 0; if( header.bWithReference != 0 ) { // skip reference offset += 6; } if( header.bWithDisp != 0 ) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += 3 + (int)bone * 6; } else { // Hips position + Hips rotation + 58 * rotation offset += 3 + (int)bone * 3; } return new Vector3( data[offset+1], -data[offset], -data[offset+2] ); }
static void AddRigidBodyTransform(NeuronBones bone, Rigidbody rigidbody, object[] args) { rigidbody.useGravity = false; rigidbody.isKinematic = true; }
static void AddRigidBodyTransform( NeuronBones bone, Rigidbody rigidbody, object[] args ) { rigidbody.useGravity = false; rigidbody.isKinematic = true; }
// set rotation for bone static void SetRotation( Transform[] transforms, NeuronBones bone, Vector3 rotation, float lerp_ratio ) { Transform t = transforms[(int)bone]; if( t != null ) { Quaternion rot = Quaternion.Slerp( t.localRotation, Quaternion.Euler( rotation ), lerp_ratio ); if( !float.IsNaN( rot.x ) && !float.IsNaN( rot.y ) && !float.IsNaN( rot.z ) && !float.IsNaN( rot.w ) ) { t.localRotation = rot; } } }
// set position for bone static void SetPosition( Transform[] transforms, NeuronBones bone, Vector3 position, float lerp_ratio ) { Transform t = transforms[(int)bone]; if( t != null ) { // calculate position when we have scale position.Scale( new Vector3( 1.0f / t.parent.lossyScale.x, 1.0f / t.parent.lossyScale.y, 1.0f / t.parent.lossyScale.z ) ); Vector3 pos = Vector3.Lerp( t.localPosition, position, lerp_ratio ); if( !float.IsNaN( pos.x ) && !float.IsNaN( pos.y ) && !float.IsNaN( pos.z ) ) { t.localPosition = pos; } } }
static void AddBoneLineTransform( NeuronBones bone, BoneLine bone_line, params object[] args ) { if( args.Length < 3 || bone == NeuronBones.Hips ) { return; } Material mat = (Material)args[0]; float parent_width = (float)args[1]; float child_width = (float)args[2]; if( bone >= NeuronBones.LeftHandThumb1 && bone <= NeuronBones.LeftHandPinky3 || bone >= NeuronBones.RightHandThumb1 && bone <= NeuronBones.RightHandPinky3 ) { bone_line.AddRenderer( mat, parent_width / 3.0f, child_width / 3.0f, bone_line.transform.parent, bone_line.transform ); } else { bone_line.AddRenderer( mat, parent_width, child_width, bone_line.transform.parent, bone_line.transform ); } }
static void RemoveBoneLineTransform( NeuronBones bone, BoneLine bone_line, params object[] args ) { bone_line.RemoveRenderer(); }
public CalcDataBody GetCalcReceivedPosition(NeuronBones bone) { //Debug.Log("getcalcreceive postion:" + bone); var offset = 0; if (header.bWithReference != 0) { // skip reference offset += 16; //6; } //Debug.Log("header:" + header.bWithDisp+", off:"+offset); //Debug.Log("data:" + data.Length + "," + dataCount); // got bone position data only when displacement is open or the bone is hips //if( header.bWithDisp != 0 || bone == NeuronBones.Hips ) if (header.bWithDisp == 0 || bone == NeuronBones.Hips) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += (int)bone * 16; var p = new Vector3( -this.data[offset], -this.data[offset + 2], this.data[offset + 1] ); // var p = new Vector3( // -this.data[offset] * NeuronUnityLinearScale, // this.data[offset+1] * NeuronUnityLinearScale, // this.data[offset+2] * NeuronUnityLinearScale // ); offset += 3; var v = new Vector3( this.data[offset], this.data[offset + 1], this.data[offset + 2] ); offset += 3; var a = new Vector3( this.data[offset], this.data[offset + 1], this.data[offset + 2] ); offset += 3; var q = new Quaternion( this.data[offset + 1], this.data[offset + 2], this.data[offset + 3], this.data[offset] ); offset += 4; var g = new Vector3( this.data[offset], this.data[offset + 1], this.data[offset + 2] ); // contact on ground: right->left offset += 3; var right = data[offset] * NeuronUnityLinearScale; var left = data[offset + 1] * NeuronUnityLinearScale; Debug.Log("foot:" + right + "," + left); Debug.Log("getreceived position :" + "p:" + p.x + "," + p.y + "," + p.z + "," + "v:" + v.x + "," + v.y + "," + v.z + "," + "a:" + a.x + "," + a.y + "," + a.z + "," + "q:" + q.x + "," + q.y + "," + q.z + "," + q.w + "," + "g:" + g.x + "," + g.y + "," + g.z ); return(new CalcDataBody(p, v, a, q, g)); } return(new CalcDataBody()); }
public float GetBoneSize( NeuronBones bone ) { // these are bone sizes of our "robot" model using axis neuron, // they are not being used yet( until we finished model retargeting ) return boneSizes[(int)bone]; }
public Vector3 GetReceivedPosition( NeuronBones bone ) { int offset = 0; if( header.bWithReference != 0 ) { // skip reference offset += 6; } // got bone position data only when displacement is open or the bone is hips if( header.bWithDisp != 0 || bone == NeuronBones.Hips ) { // Hips position + Hips rotation + 58 * ( position + rotation ) offset += (int)bone * 6; return new Vector3( -data[offset] * NeuronUnityLinearScale, data[offset+1] * NeuronUnityLinearScale, data[offset+2] * NeuronUnityLinearScale ); } return Vector3.zero; }
// remove bone line by transform //static NSH.OnRemoveBoneComponentTransform<BoneLine> delegate_remove_bone_line_tranform = new NSH.OnRemoveBoneComponentTransform<BoneLine>( RemoveBoneLineTransform ); static void RemoveBoneLineTransform(NeuronBones bone, BoneLine bone_line, params object[] args) { bone_line.RemoveRenderer(); }
public float GetBoneSize(NeuronBones bone) { // these are bone sizes of our "robot" model using axis neuron, // they are not being used yet( until we finished model retargeting ) return(boneSizes[(int)bone]); }