/// <summary> /// Get the bones from the model and create a bone class object for /// each bone. We use our bone class to do the real animated bone work. /// </summary> protected virtual void ObtainBones() { MyCharacterBone[] characterBones = new MyCharacterBone[Model.Bones.Length]; for (int i = 0; i < Model.Bones.Length; i++) { MyModelBone bone = Model.Bones[i]; Matrix boneTransform = bone.Transform; // Create the bone object and add to the heirarchy MyCharacterBone newBone = new MyCharacterBone(bone.Name, boneTransform, bone.Parent != -1 ? characterBones[bone.Parent] : null); // Add to the bone array for this model characterBones[i] = newBone; } // pass array of bones to animation controller m_compAnimationController.CharacterBones = characterBones; }
private static MyModelBone[] ReadMyModelBoneArray(BinaryReader reader) { var nCount = reader.ReadInt32(); var myModelBoneArray = new MyModelBone[nCount]; for (var i = 0; i < nCount; i++) { var name = reader.ReadString(); var parent = reader.ReadInt32(); var matrix = ReadMatrix(reader); myModelBoneArray[i] = new MyModelBone { Name = name, Parent = parent, Transform = matrix }; } return(myModelBoneArray); }
private static MyModelBone[] ReadBones(BinaryReader reader) { var length = reader.ReadInt32(); var myModelBoneArray = new MyModelBone[length]; var index = 0; while (length-- > 0) { var myModelBone = new MyModelBone(); myModelBoneArray[index] = myModelBone; myModelBone.Name = reader.BaseStream.ReadString(Encoding.ASCII); myModelBone.Index = index++; myModelBone.Parent = reader.ReadInt32(); myModelBone.Transform = ReadMatrix(reader); } return(myModelBoneArray); }
/// <summary> /// Get the bones from the model and create a bone class object for /// each bone. We use our bone class to do the real animated bone work. /// </summary> public virtual void ObtainBones() { MyCharacterBone[] characterBones = new MyCharacterBone[Model.Bones.Length]; Matrix[] relativeTransforms = new Matrix[Model.Bones.Length]; Matrix[] absoluteTransforms = new Matrix[Model.Bones.Length]; for (int i = 0; i < Model.Bones.Length; i++) { MyModelBone bone = Model.Bones[i]; Matrix boneTransform = bone.Transform; // Create the bone object and add to the heirarchy MyCharacterBone parent = bone.Parent != -1 ? characterBones[bone.Parent] : null; MyCharacterBone newBone = new MyCharacterBone( bone.Name, parent, boneTransform, i, relativeTransforms, absoluteTransforms); // Add to the bone array for this model characterBones[i] = newBone; } // pass array of bones to animation controller m_compAnimationController.SetCharacterBones(characterBones, relativeTransforms, absoluteTransforms); }
private static void WriteBone(this BinaryWriter writer, ref MyModelBone bone) { writer.Write(bone.Name); writer.Write(bone.Parent); WriteMatrix(writer, ref bone.Transform); }
private void InitSubparts() { if (!CubeGrid.CreatePhysics) { return; } m_subparts.Clear(); m_subpartIDs.Clear(); m_currentOpening.Clear(); m_currentSpeed.Clear(); m_emitter.Clear(); m_hingePosition.Clear(); m_openingSequence.Clear(); for (int i = 0; i < ((MyAdvancedDoorDefinition)BlockDefinition).Subparts.Length; i++) { MyEntitySubpart foundPart = LoadSubpartFromName(((MyAdvancedDoorDefinition)BlockDefinition).Subparts[i].Name); if (foundPart != null) { m_subparts.Add(foundPart); // save the Subparts hinge (pivot) // if not defined... if (((MyAdvancedDoorDefinition)BlockDefinition).Subparts[i].PivotPosition == null) { // ...try to get pivot from Model... MyModelBone bone = foundPart.Model.Bones.First(b => !b.Name.Contains("Root")); if (bone != null) { m_hingePosition.Add(bone.Transform.Translation); } } else // ...otherwise get from definition { m_hingePosition.Add((Vector3)((MyAdvancedDoorDefinition)BlockDefinition).Subparts[i].PivotPosition); } } } // get the sequence count from definition int openSequenzCount = ((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence.Length; for (int i = 0; i < openSequenzCount; i++) { if (!String.IsNullOrEmpty(((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i].IDs)) { // if one sequence should be applied for multiple subparts (i.e. <IDs>1-3,4,6,8,9</IDs> // add copies to m_openingSequence List // split by comma string[] tmp1 = ((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i].IDs.Split(','); for (int j = 0; j < tmp1.Length; j++) { // split by minus string[] tmp2 = tmp1[j].Split('-'); if (tmp2.Length == 2) { for (int k = Convert.ToInt32(tmp2[0]); k <= Convert.ToInt32(tmp2[1]); k++) { m_openingSequence.Add(((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i]); m_subpartIDs.Add(k); } } else { m_openingSequence.Add(((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i]); m_subpartIDs.Add(Convert.ToInt32(tmp1[j])); } } } else { m_openingSequence.Add(((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i]); m_subpartIDs.Add(((MyAdvancedDoorDefinition)BlockDefinition).OpeningSequence[i].ID); } } for (int i = 0; i < m_openingSequence.Count; i++) { m_currentOpening.Add(0f); m_currentSpeed.Add(0f); m_emitter.Add(new MyEntity3DSoundEmitter(this, true)); // make sure maxOpen is always positive and invert accordingly if (m_openingSequence[i].MaxOpen < 0f) { m_openingSequence[i].MaxOpen *= -1; m_openingSequence[i].InvertRotation = !m_openingSequence[i].InvertRotation; } } m_sequenceCount = m_openingSequence.Count; m_subpartCount = m_subparts.Count; Array.Resize(ref transMat, m_subpartCount); Array.Resize(ref rotMat, m_subpartCount); UpdateDoorPosition(); if (CubeGrid.Projector != null) { //This is a projected grid, don't add collisions for subparts return; } foreach (MyEntitySubpart subpart in m_subparts) { subpart.Physics = null; if (subpart != null && subpart.Physics == null) { if ((subpart.ModelCollision.HavokCollisionShapes != null) && (subpart.ModelCollision.HavokCollisionShapes.Length > 0)) { List <HkShape> shapes = subpart.ModelCollision.HavokCollisionShapes.ToList(); var listShape = new HkListShape(shapes.GetInternalArray(), shapes.Count, HkReferencePolicy.None); subpart.Physics = new Engine.Physics.MyPhysicsBody(subpart, RigidBodyFlag.RBF_DOUBLED_KINEMATIC | RigidBodyFlag.RBF_KINEMATIC); subpart.Physics.IsPhantom = false; (subpart.Physics as MyPhysicsBody).CreateFromCollisionObject((HkShape)listShape, Vector3.Zero, WorldMatrix, null, MyPhysics.CollisionLayers.KinematicDoubledCollisionLayer); subpart.Physics.Enabled = true; listShape.Base.RemoveReference(); } } } CubeGrid.OnHavokSystemIDChanged -= CubeGrid_HavokSystemIDChanged; CubeGrid.OnHavokSystemIDChanged += CubeGrid_HavokSystemIDChanged; CubeGrid.OnPhysicsChanged -= CubeGrid_OnPhysicsChanged; CubeGrid.OnPhysicsChanged += CubeGrid_OnPhysicsChanged; if (CubeGrid.Physics != null) { UpdateHavokCollisionSystemID(CubeGrid.GetPhysicsBody().HavokCollisionSystemID); } }
public bool ExportData(string tagName, MyModelBone[] bones) { WriteTag(tagName); m_writer.Write(bones.Length); foreach (var node in bones) { m_writer.Write(node.Name); m_writer.Write(node.Parent); WriteMatrix(node.Transform); } return true; }
private void InitSubparts() { if (base.CubeGrid.CreatePhysics) { this.m_subparts.Clear(); this.m_subpartIDs.Clear(); this.m_currentOpening.Clear(); this.m_currentSpeed.Clear(); this.m_emitter.Clear(); this.m_hingePosition.Clear(); this.m_openingSequence.Clear(); for (int i = 0; i < this.BlockDefinition.Subparts.Length; i++) { MyEntitySubpart item = this.LoadSubpartFromName(this.BlockDefinition.Subparts[i].Name); if (item != null) { this.m_subparts.Add(item); if (this.BlockDefinition.Subparts[i].PivotPosition != null) { this.m_hingePosition.Add(this.BlockDefinition.Subparts[i].PivotPosition.Value); } else { MyModelBone bone = item.Model.Bones.First <MyModelBone>(b => !b.Name.Contains("Root")); if (bone != null) { this.m_hingePosition.Add(bone.Transform.Translation); } } } } int length = this.BlockDefinition.OpeningSequence.Length; for (int j = 0; j < length; j++) { if (string.IsNullOrEmpty(this.BlockDefinition.OpeningSequence[j].IDs)) { this.m_openingSequence.Add(this.BlockDefinition.OpeningSequence[j]); this.m_subpartIDs.Add(this.BlockDefinition.OpeningSequence[j].ID); } else { char[] separator = new char[] { ',' }; string[] strArray = this.BlockDefinition.OpeningSequence[j].IDs.Split(separator); for (int m = 0; m < strArray.Length; m++) { char[] chArray2 = new char[] { '-' }; string[] strArray2 = strArray[m].Split(chArray2); if (strArray2.Length != 2) { this.m_openingSequence.Add(this.BlockDefinition.OpeningSequence[j]); this.m_subpartIDs.Add(Convert.ToInt32(strArray[m])); } else { for (int n = Convert.ToInt32(strArray2[0]); n <= Convert.ToInt32(strArray2[1]); n++) { this.m_openingSequence.Add(this.BlockDefinition.OpeningSequence[j]); this.m_subpartIDs.Add(n); } } } } } for (int k = 0; k < this.m_openingSequence.Count; k++) { this.m_currentOpening.Add(0f); this.m_currentSpeed.Add(0f); this.m_emitter.Add(new MyEntity3DSoundEmitter(this, true, 1f)); if (this.m_openingSequence[k].MaxOpen < 0f) { MyObjectBuilder_AdvancedDoorDefinition.Opening local2 = this.m_openingSequence[k]; local2.MaxOpen *= -1f; this.m_openingSequence[k].InvertRotation = !this.m_openingSequence[k].InvertRotation; } } this.m_sequenceCount = this.m_openingSequence.Count; this.m_subpartCount = this.m_subparts.Count; Array.Resize <Matrix>(ref this.transMat, this.m_subpartCount); Array.Resize <Matrix>(ref this.rotMat, this.m_subpartCount); this.UpdateDoorPosition(); if (base.CubeGrid.Projector == null) { foreach (MyEntitySubpart subpart2 in this.m_subparts) { if (subpart2.Physics != null) { subpart2.Physics.Close(); subpart2.Physics = null; } if (((subpart2 != null) && ((subpart2.Physics == null) && (subpart2.ModelCollision.HavokCollisionShapes != null))) && (subpart2.ModelCollision.HavokCollisionShapes.Length != 0)) { List <HkShape> list = subpart2.ModelCollision.HavokCollisionShapes.ToList <HkShape>(); HkListShape shape = new HkListShape(list.GetInternalArray <HkShape>(), list.Count, HkReferencePolicy.None); subpart2.Physics = new MyPhysicsBody(subpart2, RigidBodyFlag.RBF_UNLOCKED_SPEEDS | RigidBodyFlag.RBF_KINEMATIC); subpart2.Physics.IsPhantom = false; HkMassProperties?massProperties = null; (subpart2.Physics as MyPhysicsBody).CreateFromCollisionObject((HkShape)shape, Vector3.Zero, base.WorldMatrix, massProperties, 15); subpart2.Physics.Enabled = true; shape.Base.RemoveReference(); } } base.CubeGrid.OnHavokSystemIDChanged -= new Action <int>(this.CubeGrid_HavokSystemIDChanged); base.CubeGrid.OnHavokSystemIDChanged += new Action <int>(this.CubeGrid_HavokSystemIDChanged); base.CubeGrid.OnPhysicsChanged -= new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnPhysicsChanged); base.CubeGrid.OnPhysicsChanged += new Action <VRage.Game.Entity.MyEntity>(this.CubeGrid_OnPhysicsChanged); if (base.CubeGrid.Physics != null) { this.UpdateHavokCollisionSystemID(base.CubeGrid.GetPhysicsBody().HavokCollisionSystemID); } } } }
private static bool ExportData(this BinaryWriter writer, string tagName, MyModelBone[] boneArray) { WriteTag(writer, tagName); writer.Write(boneArray.Length); foreach (var boneVal in boneArray) { var bone = boneVal; WriteBone(writer, ref bone); } return true; }
private static MyModelBone[] ReadMyModelBoneArray(BinaryReader reader) { var nCount = reader.ReadInt32(); var myModelBoneArray = new MyModelBone[nCount]; for (var i = 0; i < nCount; i++) { var name = reader.ReadString(); var parent = reader.ReadInt32(); var matrix = ReadMatrix(reader); myModelBoneArray[i] = new MyModelBone { Name = name, Parent = parent, Transform = matrix }; } return myModelBoneArray; }