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); } } } }
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); } } } } }
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)); } }
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); } } } } } }