private void ReadSkeletonDescription(List <Actor> actors) { int skeletonId = dataStream.GetNextInt(); // ID string skeletonName = dataStream.GetNextString(); // name // rigid body name should be equal to actor name: search Actor actor = null; foreach (Actor a in actors) { if (a.name.CompareTo(skeletonName) == 0) { actor = a; actor.id = skeletonId; // associate actor and skeleton } } if (actor == null) { // names don't match > try IDs if ((skeletonId >= 0) && (skeletonId < actors.Count)) { actor = actors[skeletonId]; } } if (actor == null) { Debug.LogWarning("Skeleton " + skeletonName + " could not be matched to an actor."); actor = new Actor(scene, skeletonName, skeletonId); actors.Add(actor); } int nBones = dataStream.GetNextInt(); // Skeleton bone count actor.bones = new Bone[nBones]; for (int boneIdx = 0; boneIdx < nBones; boneIdx++) { int id = dataStream.GetNextInt(); // bone ID String name = dataStream.GetNextString(); // bone name Bone bone = new Bone(actor, name, id); int parentId = dataStream.GetNextInt(); // Skeleton parent ID bone.parent = actor.FindBone(parentId); if (bone.parent != null) { // if bone has a parent, update child list of parent bone.parent.children.Add(bone); } bone.BuildChain(); // build chain from root to this bone bone.ox = dataStream.GetNextFloat(); // X offset bone.oy = dataStream.GetNextFloat(); // Y offset bone.oz = dataStream.GetNextFloat(); // Z offset actor.bones[boneIdx] = bone; } }
private void ReadSkeletonDescription(ref List<Actor> actors) { int skeletonId = dataStream.GetInt(); // ID string skeletonName = dataStream.GetString(); // name // rigid body name should be equal to actor name: search Actor actor = null; foreach (Actor a in actors) { if (a.name.CompareTo(skeletonName) == 0) { actor = a; actor.id = skeletonId; // associate actor and skeleton } } if (actor == null) { // names don't match > try IDs if ((skeletonId >= 0) && (skeletonId < actors.Count)) { actor = actors[skeletonId]; } } if (actor == null) { Debug.LogWarning("Skeleton " + skeletonName + " could not be matched to an actor."); actor = new Actor(scene, skeletonName, skeletonId); actors.Add(actor); } int nBones = dataStream.GetInt(); // Skeleton bone count actor.bones = new Bone[nBones]; for (int boneIdx = 0; boneIdx < nBones; boneIdx++) { int id = dataStream.GetInt(); // bone ID String name = dataStream.GetString(); // bone name Bone bone = new Bone(actor, name, id); int parentId = dataStream.GetInt(); // Skeleton parent ID bone.parent = actor.FindBone(parentId); if (bone.parent != null) { // if bone has a parent, update child list of parent bone.parent.children.Add(bone); } bone.BuildChain(); // build chain from root to this bone bone.ox = dataStream.GetFloat(); // X offset bone.oy = dataStream.GetFloat(); // Y offset bone.oz = dataStream.GetFloat(); // Z offset actor.bones[boneIdx] = bone; } }
private void ParseSkeleton(NatNetPacket_In packet, List <Actor> actors) { bool includesBoneNames = // starting at v2.0 (serverInfo.versionNatNet[0] >= 2); String skeletonName = packet.GetString(); // name int skeletonId = packet.GetInt32(); // ID // rigid body name should be equal to actor name: search Actor actor = null; foreach (Actor a in actors) { if (a.name.CompareTo(skeletonName) == 0) { actor = a; actor.id = skeletonId; // associate actor and skeleton } } if (actor == null) { // names don't match > try IDs if ((skeletonId >= 0) && (skeletonId < actors.Count)) { actor = actors[skeletonId]; } } if (actor == null) { Debug.LogWarning("Skeleton " + skeletonName + " could not be matched to an actor."); actor = new Actor(scene, skeletonName, skeletonId); actors.Add(actor); } int nBones = packet.GetInt32(); // Skeleton bone count // TODO: Sanity check on the number before allocating that much space actor.bones = new Bone[nBones]; for (int boneIdx = 0; boneIdx < nBones; boneIdx++) { String name = ""; if (includesBoneNames) { name = packet.GetString(); // bone name } int id = packet.GetInt32(); // bone ID Bone bone = new Bone(actor, name, id); bone.parent = actor.FindBone(packet.GetInt32()); // Skeleton parent ID if (bone.parent != null) { // if bone has a parent, update child list of parent bone.parent.children.Add(bone); } bone.BuildChain(); // build chain from root to this bone bone.ox = packet.GetFloat(); // X offset bone.oy = packet.GetFloat(); // Y offset bone.oz = -packet.GetFloat(); // Z offset actor.bones[boneIdx] = bone; } }
private void ParseSkeleton(NatNetPacket_In packet, List<Actor> actors) { bool includesBoneNames = // starting at v2.0 (serverInfo.versionNatNet[0] >= 2); String skeletonName = packet.GetString(); // name int skeletonId = packet.GetInt32(); // ID // rigid body name should be equal to actor name: search Actor actor = null; foreach (Actor a in actors) { if (a.name.CompareTo(skeletonName) == 0) { actor = a; actor.id = skeletonId; // associate actor and skeleton } } if (actor == null) { // names don't match > try IDs if ((skeletonId >= 0) && (skeletonId < actors.Count)) { actor = actors[skeletonId]; } } if (actor == null) { Debug.LogWarning("Skeleton " + skeletonName + " could not be matched to an actor."); actor = new Actor(scene, skeletonName, skeletonId); actors.Add(actor); } int nBones = packet.GetInt32(); // Skeleton bone count // TODO: Sanity check on the number before allocating that much space actor.bones = new Bone[nBones]; for ( int boneIdx = 0 ; boneIdx < nBones ; boneIdx++ ) { String name = ""; if (includesBoneNames) { name = packet.GetString(); // bone name } int id = packet.GetInt32(); // bone ID Bone bone = new Bone(actor, name, id); bone.parent = actor.FindBone(packet.GetInt32()); // Skeleton parent ID if (bone.parent != null) { // if bone has a parent, update child list of parent bone.parent.children.Add(bone); } bone.BuildChain(); // build chain from root to this bone bone.ox = packet.GetFloat(); // X offset bone.oy = packet.GetFloat(); // Y offset bone.oz = -packet.GetFloat(); // Z offset actor.bones[boneIdx] = bone; } }