private MyEntitySubpart LoadSubpartFromName(string name) { MyEntitySubpart subpart; Subparts.TryGetValue(name, out subpart); // simply return the subpart if it exists in the dictionary if (subpart != null) { return(subpart); } // otherwise load it now and add to dictionary subpart = new MyEntitySubpart(); string fileName = Path.Combine(Path.GetDirectoryName(Model.AssetName), name) + ".mwm"; subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = Render.ColorMaskHsv; subpart.Init(null, fileName, this, null); // add to dictionary Subparts[name] = subpart; if (InScene) { subpart.OnAddedToScene(this); } return(subpart); }
private void CreateConstraint(MyEntitySubpart subpart, ref HkConstraint constraint, ref HkFixedConstraintData constraintData) { if (subpart != null) { bool flag = !Sync.IsServer; if (subpart.Physics == null) { HkShape[] havokCollisionShapes = subpart.ModelCollision.HavokCollisionShapes; if ((havokCollisionShapes != null) && (havokCollisionShapes.Length != 0)) { MyPhysicsBody body = new MyPhysicsBody(subpart, flag ? RigidBodyFlag.RBF_STATIC : (RigidBodyFlag.RBF_UNLOCKED_SPEEDS | RigidBodyFlag.RBF_DOUBLED_KINEMATIC)) { IsSubpart = true }; subpart.Physics = body; HkShape shape = havokCollisionShapes[0]; MyPositionComponentBase positionComp = subpart.PositionComp; Vector3 center = positionComp.LocalVolume.Center; HkMassProperties properties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(positionComp.LocalAABB.HalfExtents, 100f); int collisionFilter = base.CubeGrid.IsStatic ? 9 : 0x10; body.CreateFromCollisionObject(shape, center, positionComp.WorldMatrix, new HkMassProperties?(properties), collisionFilter); } } if (flag) { subpart.Physics.Enabled = true; } else { base.CreateSubpartConstraint(subpart, out constraintData, out constraint); base.CubeGrid.Physics.AddConstraint(constraint); constraint.SetVirtualMassInverse(Vector4.Zero, Vector4.One); } } }
private void RecreateConstraints() { MyCubeGridRenderCell orAddCell = base.CubeGrid.RenderData.GetOrAddCell((Vector3)(base.Position * base.CubeGrid.GridSize), true); using (List <MyEntitySubpart> .Enumerator enumerator = this.m_subparts.GetEnumerator()) { while (true) { if (!enumerator.MoveNext()) { break; } MyEntitySubpart current = enumerator.Current; if (!current.Closed && !current.MarkedForClose) { Matrix?childToParent = null; current.Render.SetParent(0, orAddCell.ParentCullObject, childToParent); current.NeedsWorldMatrix = false; current.InvalidateOnMove = false; continue; } return; } } this.DisposeConstraints(); if ((base.InScene && (base.CubeGrid.Physics != null)) && (base.CubeGrid.Physics.IsInWorld || ((MyPhysicsBody)base.CubeGrid.Physics).IsInWorldWelded())) { this.CreateConstraints(); } if (base.CubeGrid.Physics != null) { this.UpdateHavokCollisionSystemID(base.CubeGrid.GetPhysicsBody().HavokCollisionSystemID, false); } this.UpdateDoorPosition(); }
internal void UpdateHavokCollisionSystemID(int havokCollisionSystemID, bool refreshInPlace) { MyEntitySubpart[] subpartArray1 = new MyEntitySubpart[] { this.m_rightSubpart, this.m_leftSubpart }; foreach (MyEntitySubpart subpart in subpartArray1) { if (subpart != null) { SetupDoorSubpart(subpart, havokCollisionSystemID, refreshInPlace); } } }
protected static void SetupDoorSubpart(MyEntitySubpart subpart, int havokCollisionSystemID, bool refreshInPlace) { if (((subpart != null) && ((subpart.Physics != null) && (subpart.ModelCollision.HavokCollisionShapes != null))) && (subpart.ModelCollision.HavokCollisionShapes.Length != 0)) { uint info = HkGroupFilter.CalcFilterInfo(subpart.GetPhysicsBody().RigidBody.Layer, havokCollisionSystemID, 1, 1); subpart.Physics.RigidBody.SetCollisionFilterInfo(info); if ((subpart.GetPhysicsBody().HavokWorld != null) & refreshInPlace) { subpart.GetPhysicsBody().HavokWorld.RefreshCollisionFilterOnEntity(subpart.Physics.RigidBody); } } }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition) { if (string.IsNullOrEmpty(blockDefinition.Model)) { return; } matrices.Add(matrix); models.Add(blockDefinition.Model); var data = new MyEntitySubpart.Data(); MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; MyModel modelData = MyModels.GetModelOnlyData(blockDefinition.Model); foreach (var dummy in modelData.Dummies) { if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, dummy.Key, dummy.Value, ref data)) { MatrixD mCopy = MatrixD.Multiply(data.InitialTransform, matrix); matrices.Add(mCopy); models.Add(data.File); } else if (MyFakes.ENABLE_SUBBLOCKS && MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, dummy.Key, dummy.Value, false, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { if (!string.IsNullOrEmpty(subBlockDefinition.Model)) { // Repair subblock matrix to have int axes (because preview renderer does not allow such non integer rotation). Vector3I forward = Vector3I.Round(Vector3.DominantAxisProjection(subBlockMatrix.Forward)); Vector3I invForward = Vector3I.One - Vector3I.Abs(forward); Vector3I right = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)subBlockMatrix.Right * invForward)); Vector3I up; Vector3I.Cross(ref right, ref forward, out up); subBlockMatrix.Forward = forward; subBlockMatrix.Right = right; subBlockMatrix.Up = up; MatrixD mCopy = MatrixD.Multiply(subBlockMatrix, matrix); matrices.Add(mCopy); models.Add(subBlockDefinition.Model); } } } }
private MyEntitySubpart LoadSubpartFromName(string name) { MyEntitySubpart subpart; base.Subparts.TryGetValue(name, out subpart); if (subpart == null) { subpart = new MyEntitySubpart(); string model = Path.Combine(Path.GetDirectoryName(base.Model.AssetName), name) + ".mwm"; subpart.Render.EnableColorMaskHsv = base.Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = base.Render.ColorMaskHsv; subpart.Render.TextureChanges = base.Render.TextureChanges; float?scale = null; subpart.Init(null, model, this, scale, null); base.Subparts[name] = subpart; if (base.InScene) { subpart.OnAddedToScene(this); } } return(subpart); }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (string.IsNullOrEmpty(blockDefinition.Model)) { return; } matrices.Add(matrix); models.Add(blockDefinition.Model); var data = new MyEntitySubpart.Data(); MyCubeBlockDefinition subBlockDefinition; MatrixD subBlockMatrix; Vector3 dummyPosition; MyModel modelData = VRage.Game.Models.MyModels.GetModelOnlyData(blockDefinition.Model); modelData.Rescale(gridScale); foreach (var dummy in modelData.Dummies) { if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, dummy.Key, dummy.Value, ref data)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(data.File); if (model != null) { model.Rescale(gridScale); } MatrixD mCopy = MatrixD.Multiply(data.InitialTransform, matrix); matrices.Add(mCopy); models.Add(data.File); } else if (MyFakes.ENABLE_SUBBLOCKS && MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, dummy.Key, dummy.Value, false, out subBlockDefinition, out subBlockMatrix, out dummyPosition)) { if (!string.IsNullOrEmpty(subBlockDefinition.Model)) { // Rescale model var model = VRage.Game.Models.MyModels.GetModelOnlyData(subBlockDefinition.Model); if (model != null) { model.Rescale(gridScale); } // Repair subblock matrix to have int axes (because preview renderer does not allow such non integer rotation). Vector3I forward = Vector3I.Round(Vector3.DominantAxisProjection(subBlockMatrix.Forward)); Vector3I invForward = Vector3I.One - Vector3I.Abs(forward); Vector3I right = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)subBlockMatrix.Right * invForward)); Vector3I up; Vector3I.Cross(ref right, ref forward, out up); subBlockMatrix.Forward = forward; subBlockMatrix.Right = right; subBlockMatrix.Up = up; MatrixD mCopy = MatrixD.Multiply(subBlockMatrix, matrix); matrices.Add(mCopy); models.Add(subBlockDefinition.Model); } } } // Precache models for generated blocks if (MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock && blockDefinition.GeneratedBlockDefinitions != null) { foreach (var generatedBlockDefId in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition generatedBlockDef; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(generatedBlockDefId, out generatedBlockDef)) { var model = VRage.Game.Models.MyModels.GetModelOnlyData(generatedBlockDef.Model); if (model != null) { model.Rescale(gridScale); } } } } }
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... VRage.Import.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 void RefreshModels(string model, string modelCollision) { if (model != null) { Render.ModelStorage = MyModels.GetModelOnlyData(model); PositionComp.LocalVolumeOffset = Render.GetModel().BoundingSphere.Center; } if (modelCollision != null) m_modelCollision = MyModels.GetModelOnlyData(modelCollision); if (Render.ModelStorage != null) { this.PositionComp.LocalAABB = Render.GetModel().BoundingBox; bool idAllocationState = MyEntityIdentifier.AllocationSuspended; try { MyEntityIdentifier.AllocationSuspended = false; if (Subparts == null) Subparts = new Dictionary<string, MyEntitySubpart>(); else { foreach (var existingSubpart in Subparts) { Hierarchy.RemoveChild(existingSubpart.Value); existingSubpart.Value.Close(); } Subparts.Clear(); } MyEntitySubpart.Data data = new MyEntitySubpart.Data(); foreach (var dummy in Render.GetModel().Dummies) { // Check of mirrored matrix of dummy object is under fake, because characters have mirrored dummies if (MyFakes.ENABLE_DUMMY_MIRROR_MATRIX_CHECK) { // This should not be here but if you want to check bad matrices of other types if (!(this is MyCharacter)) { Debug.Assert(!dummy.Value.Matrix.IsMirrored()); } } if (!MyEntitySubpart.GetSubpartFromDummy(model, dummy.Key, dummy.Value, ref data)) continue; MyEntitySubpart subpart = new MyEntitySubpart(); subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = Render.ColorMaskHsv; subpart.Init(null, data.File, this, null); subpart.PositionComp.LocalMatrix = data.InitialTransform; Subparts[data.Name] = subpart; if (InScene) subpart.OnAddedToScene(this); } } finally { MyEntityIdentifier.AllocationSuspended = idAllocationState; } if (Render.GetModel().GlassData != null) { Render.NeedsDraw = true; Render.NeedsDrawFromParent = true; } } else { //entities without model has box with side length = 1 by default float defaultBoxHalfSize = 0.5f; this.PositionComp.LocalAABB = new BoundingBox(new Vector3(-defaultBoxHalfSize), new Vector3(defaultBoxHalfSize)); } }
public void RefreshModels(string model, string modelCollision) { if (model != null) { Render.ModelStorage = MyModels.GetModelOnlyData(model); PositionComp.LocalVolumeOffset = Render.GetModel().BoundingSphere.Center; } if (modelCollision != null) { m_modelCollision = MyModels.GetModelOnlyData(modelCollision); } if (Render.ModelStorage != null) { this.PositionComp.LocalAABB = Render.GetModel().BoundingBox; bool idAllocationState = MyEntityIdentifier.AllocationSuspended; try { MyEntityIdentifier.AllocationSuspended = false; if (Subparts == null) { Subparts = new Dictionary <string, MyEntitySubpart>(); } else { foreach (var existingSubpart in Subparts) { Hierarchy.RemoveChild(existingSubpart.Value); existingSubpart.Value.Close(); } Subparts.Clear(); } MyEntitySubpart.Data data = new MyEntitySubpart.Data(); foreach (var dummy in Render.GetModel().Dummies) { // Check of mirrored matrix of dummy object is under fake, because characters have mirrored dummies if (MyFakes.ENABLE_DUMMY_MIRROR_MATRIX_CHECK) { // This should not be here but if you want to check bad matrices of other types if (!(this is MyCharacter)) { Debug.Assert(!dummy.Value.Matrix.IsMirrored()); } } if (!MyEntitySubpart.GetSubpartFromDummy(model, dummy.Key, dummy.Value, ref data)) { continue; } MyEntitySubpart subpart = new MyEntitySubpart(); subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = Render.ColorMaskHsv; subpart.Init(null, data.File, this, null); subpart.PositionComp.LocalMatrix = data.InitialTransform; Subparts[data.Name] = subpart; if (InScene) { subpart.OnAddedToScene(this); } } } finally { MyEntityIdentifier.AllocationSuspended = idAllocationState; } if (Render.GetModel().GlassData != null) { Render.NeedsDraw = true; Render.NeedsDrawFromParent = true; } } else { //entities without model has box with side length = 1 by default float defaultBoxHalfSize = 0.5f; this.PositionComp.LocalAABB = new BoundingBox(new Vector3(-defaultBoxHalfSize), new Vector3(defaultBoxHalfSize)); } }
private MyEntitySubpart LoadSubpartFromName(string name) { MyEntitySubpart subpart; Subparts.TryGetValue(name, out subpart); // simply return the subpart if it exists in the dictionary if (subpart != null) return subpart; // otherwise load it now and add to dictionary subpart = new MyEntitySubpart(); string fileName = Path.Combine(Path.GetDirectoryName(Model.AssetName), name) + ".mwm"; subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv; subpart.Render.ColorMaskHsv = Render.ColorMaskHsv; subpart.Init(null, fileName, this, null); // add to dictionary Subparts[name] = subpart; if (InScene) subpart.OnAddedToScene(this); return subpart; }
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); } } } }
protected static void AddFastBuildModelWithSubparts(ref MatrixD matrix, List <MatrixD> matrices, List <string> models, MyCubeBlockDefinition blockDefinition, float gridScale) { if (!string.IsNullOrEmpty(blockDefinition.Model)) { matrices.Add(matrix); models.Add(blockDefinition.Model); MyEntitySubpart.Data outData = new MyEntitySubpart.Data(); MyModel modelOnlyData = MyModels.GetModelOnlyData(blockDefinition.Model); modelOnlyData.Rescale(gridScale); foreach (KeyValuePair <string, MyModelDummy> pair in modelOnlyData.Dummies) { MyCubeBlockDefinition definition; MatrixD xd; Vector3 vector; if (MyEntitySubpart.GetSubpartFromDummy(blockDefinition.Model, pair.Key, pair.Value, ref outData)) { MyModel model = MyModels.GetModelOnlyData(outData.File); if (model != null) { model.Rescale(gridScale); } MatrixD item = MatrixD.Multiply(outData.InitialTransform, matrix); matrices.Add(item); models.Add(outData.File); continue; } if (MyFakes.ENABLE_SUBBLOCKS && (MyCubeBlock.GetSubBlockDataFromDummy(blockDefinition, pair.Key, pair.Value, false, out definition, out xd, out vector) && !string.IsNullOrEmpty(definition.Model))) { Vector3I vectori4; MyModel model2 = MyModels.GetModelOnlyData(definition.Model); if (model2 != null) { model2.Rescale(gridScale); } Vector3I vectori = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)xd.Forward)); Vector3I vectori2 = Vector3I.One - Vector3I.Abs(vectori); Vector3I vectori3 = Vector3I.Round(Vector3.DominantAxisProjection((Vector3)(xd.Right * vectori2))); Vector3I.Cross(ref vectori3, ref vectori, out vectori4); xd.Forward = (Vector3D)vectori; xd.Right = (Vector3D)vectori3; xd.Up = (Vector3D)vectori4; MatrixD item = MatrixD.Multiply(xd, matrix); matrices.Add(item); models.Add(definition.Model); } } if ((MyFakes.ENABLE_GENERATED_BLOCKS && !blockDefinition.IsGeneratedBlock) && (blockDefinition.GeneratedBlockDefinitions != null)) { foreach (MyDefinitionId id in blockDefinition.GeneratedBlockDefinitions) { MyCubeBlockDefinition definition2; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(id, out definition2)) { MyModel model3 = MyModels.GetModelOnlyData(definition2.Model); if (model3 != null) { model3.Rescale(gridScale); } } } } } }