private void ProcessFilename(string filename) { IsValidModel = false; IsValidEntity = false; IsBusy = true; OriginalModelSize = new BindableSize3DModel(0, 0, 0); NewModelSize = new BindableSize3DIModel(0, 0, 0); Position = new BindablePoint3DModel(0, 0, 0); if (File.Exists(filename)) { // validate file is a real model. // read model properties. Model3D model; _originalBounds = Modelling.PreviewModelVolmetic(filename, out model); if (!_originalBounds.IsEmpty && _originalBounds.SizeX != 0 && _originalBounds.SizeY != 0 && _originalBounds.SizeZ != 0) { Model = model; var rotateTransform = MeshHelper.TransformVector(new System.Windows.Media.Media3D.Vector3D(0, 0, 0), -RotateRoll, RotateYaw - 90, RotatePitch + 90); var bounds = _originalBounds; if (rotateTransform != null) { bounds = rotateTransform.TransformBounds(bounds); } OriginalModelSize = new BindableSize3DModel(bounds); IsValidModel = true; ProcessModelScale(); } } IsBusy = false; }
private void ProcessFilename(string filename) { IsValidModel = false; IsBusy = true; OriginalModelSize = new BindableSize3DModel(0, 0, 0); NewModelSize = new BindableSize3DIModel(0, 0, 0); Position = new BindablePoint3DModel(0, 0, 0); if (File.Exists(filename)) { // validate file is a real model. // read model properties. Model3D model; var bounds = Modelling.PreviewModelVolmetic(filename, out model); var size = new BindableSize3DModel(bounds); Model = model; if (size != null && size.Height != 0 && size.Width != 0 && size.Depth != 0) { OriginalModelSize = size; BuildDistance = 10; IsValidModel = true; ProcessModelScale(); } } IsBusy = false; }
public void GenerateModelComplexVolumentric() { const string modelFile = @".\TestAssets\algos.obj"; var cubic = Modelling.ReadModelVolmetic(modelFile, 1, null, ModelTraceVoxel.Thin); var cubicCount = Modelling.CountCubic(cubic); var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; Assert.AreEqual(1290600, size, "Array length size must match."); Assert.AreEqual(108, cubic.Length, "Array size must match."); Assert.AreEqual(50, cubic[0].Length, "Array size must match."); Assert.AreEqual(239, cubic[0][0].Length, "Array size must match."); Assert.AreEqual(CubeType.Cube, cubic[54][39][7]); Assert.AreEqual(CubeType.Cube, cubic[54][39][17]); Assert.AreEqual(CubeType.Cube, cubic[54][39][18]); Assert.AreEqual(CubeType.Cube, cubic[54][39][19]); Assert.AreEqual(CubeType.Cube, cubic[54][39][20]); Assert.AreEqual(CubeType.Cube, cubic[54][39][23]); Assert.AreEqual(CubeType.Cube, cubic[54][39][24]); Assert.AreEqual(CubeType.Cube, cubic[54][39][25]); Assert.AreEqual(CubeType.Cube, cubic[54][39][26]); Assert.AreEqual(CubeType.Cube, cubic[54][39][35]); Assert.AreEqual(CubeType.Cube, cubic[54][39][36]); Assert.AreEqual(51921, cubicCount[CubeType.Cube], "Cube count must match."); Assert.AreEqual(188293, cubicCount[CubeType.Interior], "Interior count must match."); }
//造型线程 private void ThreadReadServer7() { Modelling modelling = new Modelling(); int result; try { modelling.ModellingSID = ModellingDAL.GetModellingSID(); modelling.ModellingBoxNum = siemensTcpNet.ReadInt16("DB19.4").Content; //当班次当产品造型箱数 modelling.ModellingBadBoxNum = siemensTcpNet.ReadInt16("DB21.64").Content; //当班次当产品造型坏箱数 modelling.ModellingEmptyBoxNum = siemensTcpNet.ReadInt16("DB19.2").Content; //当班次当产品造型空箱数 modelling.ModellingEndTime = DateTime.Now; result = ModellingDAL.UpdModelling(modelling); if (result == 1) { listBox2.Items.Add("造型写入数据库成功 " + DateTime.Now); } else { listBox2.Items.Add("造型写入数据库失败 " + DateTime.Now); } } catch (Exception ex) { MessageBox.Show("造型出现问题:" + ex.Message); } this.thread7.Abort(); }
public void ResetSignal(Signal newSignal) { CloseAll(); foreach (var page in pages) { page.Reset(newSignal); } Modelling.ResetCounters(); currentSignal = newSignal; oscillogramsPage.Reset(newSignal); if (currentSignal == null) { Logger.Info("Signal was reset to null"); return; } UpdateActiveSegment(0, newSignal.SamplesCount - 1); for (int i = 0; i < currentSignal.channels.Count; i++) { channelsPage.AddChannel(currentSignal.channels[i]); } Logger.Info("Signal was reset successfully"); Logger.Info($"Current signal {newSignal}"); }
public void GenerateModelWithMaterial() { const string modelFile = @".\TestAssets\test.obj"; var cubic = Modelling.ReadModelVolmetic(modelFile, 1, null, ModelTraceVoxel.Thin); //var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; //Assert.AreEqual(480, size, "Array length size must match."); //Assert.AreEqual(8, cubic.Length, "Array size must match."); //Assert.AreEqual(12, cubic[0].Length, "Array size must match."); //Assert.AreEqual(5, cubic[0][0].Length, "Array size must match."); }
public void GenerateModelSimpleVolumentricAltFill() { const string modelFile = @".\TestAssets\t25.obj"; var cubic = Modelling.ReadModelVolmeticAlt(modelFile, 1); //var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; //Assert.AreEqual(480, size, "Array length size must match."); //Assert.AreEqual(8, cubic.Length, "Array size must match."); //Assert.AreEqual(12, cubic[0].Length, "Array size must match."); //Assert.AreEqual(5, cubic[0][0].Length, "Array size must match."); }
public void LoadBrokenModel() { // TODO: finish testing the model. const string modelFile = @".\TestAssets\LibertyStatue.obj"; var cubic = Modelling.ReadModelVolmetic(modelFile, 0, null, ModelTraceVoxel.Thin); //var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; //Assert.AreEqual(72, size, "Array length size must match."); //Assert.AreEqual(4, cubic.Length, "Array size must match."); //Assert.AreEqual(6, cubic[0].Length, "Array size must match."); //Assert.AreEqual(3, cubic[0][0].Length, "Array size must match."); }
public static MyVoxelMap BuildAsteroidFromModel(bool multiThread, string sourceVolumetricFile, byte materialIndex, byte faceMaterialIndex, bool fillObject, byte?interiorMaterialIndex, ModelTraceVoxel traceType, double scale, Transform3D transform, Action <double, double> resetProgress, Action incrementProgress) { var volmeticMap = Modelling.ReadModelVolmetic(sourceVolumetricFile, scale, transform, traceType, resetProgress, incrementProgress); // these large values were to fix issue with large square gaps in voxlized asteroid model. var size = new Vector3I(volmeticMap.Length + 12, volmeticMap[0].Length + 12, volmeticMap[0][0].Length + 12); var action = (Action <MyVoxelBuilderArgs>) delegate(MyVoxelBuilderArgs e) { if (e.CoordinatePoint.X > 5 && e.CoordinatePoint.Y > 5 && e.CoordinatePoint.Z > 5 && (e.CoordinatePoint.X <= volmeticMap.Length + 5) && (e.CoordinatePoint.Y <= volmeticMap[0].Length + 5) && (e.CoordinatePoint.Z <= volmeticMap[0][0].Length + 5)) { var cube = volmeticMap[e.CoordinatePoint.X - 6][e.CoordinatePoint.Y - 6][e.CoordinatePoint.Z - 6]; if (cube == CubeType.Interior && fillObject) { e.Volume = 0xff; // 100% if (interiorMaterialIndex != null) { e.MaterialIndex = interiorMaterialIndex.Value; } } else if (cube == CubeType.Cube) { e.Volume = 0xff; // 100% "11111111" } else if (cube.ToString().StartsWith("InverseCorner")) { e.Volume = 0xD4; // 83% "11010100" } else if (cube.ToString().StartsWith("Slope")) { e.Volume = 0x7F; // 50% "01111111" } else if (cube.ToString().StartsWith("NormalCorner")) { e.Volume = 0x2B; // 16% "00101011" } else { e.Volume = 0x00; // 0% "00000000" } } else { e.Volume = 0x00; } }; return(BuildAsteroid(multiThread, size, materialIndex, faceMaterialIndex, action)); }
public static int UpdModelling(Modelling modelling) { int result = 0; try { result = DataFactory.UpdateEntity(modelling , "ModellingSID,ModellingBoxNum,ModellingBadBoxNum,ModellingEmptyBoxNum,ModellingEndTime", "MW_Modelling_UPD"); } catch (Exception) { result = 0; } return(result); }
//#region 新增打磨信息 //public static int AddPolishInfo(int equipmentSID,int groupSID,int materialSID, int polishNum, int polishTotalNum ,DateTime polishBegimTime, DateTime polishEndTime,decimal polishWorkTime) //{ // Polish polish = new Polish(); // polish.EquipmentSID = equipmentSID; // polish.GroupSID = groupSID; // polish.MaterialSID = materialSID; // polish.PolishNum = polishNum; // polish.PolishTotalNum = polishTotalNum; // polish.PolishBegimTime = polishBegimTime; // polish.PolishEndTime = polishEndTime; // polish.PolishWorkTime = polishWorkTime; // int result = 0; // try // { // result = DataFactory.UpdateEntity(polish, "EquipmentSID,GroupSID,MaterialSID,PolishNum,PolishTotalNum,PolishBegimTime,PolishEndTime,PolishWorkTime", "DG_Polish_INS_MW"); // } // catch (Exception) // { // result = 0; // } // return result; //} //#endregion #region 查询造型最新SID public static int GetModellingSID( ) { List <Modelling> modellings = null; Modelling modelling = new Modelling(); try { modellings = DataFactory.FillEntities <Modelling>(modelling, "", "MW_ModellingSID_SEL"); } catch (Exception) { modellings = new List <Modelling>(); } return(modellings[0].ModellingSID); }
public void GenerateModelSimpleThinSmoothedVolumentric() { const string modelFile = @".\TestAssets\t25.obj"; var cubic = Modelling.ReadModelVolmetic(modelFile, 0, null, ModelTraceVoxel.ThinSmoothed); var cubicCount = Modelling.CountCubic(cubic); var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; Assert.AreEqual(72, size, "Array length size must match."); Assert.AreEqual(4, cubic.Length, "Array size must match."); Assert.AreEqual(6, cubic[0].Length, "Array size must match."); Assert.AreEqual(3, cubic[0][0].Length, "Array size must match."); Assert.AreEqual(36, cubicCount[CubeType.Cube], "Cube count must match."); Assert.AreEqual(4, cubicCount[CubeType.Interior], "Interior count must match."); }
public void GenerateModelComplexVolumentricHalfScale() { const string modelFile = @".\TestAssets\algos.obj"; var cubic = Modelling.ReadModelVolmetic(modelFile, 0.5, null, ModelTraceVoxel.Thin); var cubicCount = Modelling.CountCubic(cubic); var size = cubic.Length * cubic[0].Length * cubic[0][0].Length; Assert.AreEqual(168480, size, "Array length size must match."); Assert.AreEqual(54, cubic.Length, "Array size must match."); Assert.AreEqual(26, cubic[0].Length, "Array size must match."); Assert.AreEqual(120, cubic[0][0].Length, "Array size must match."); Assert.AreEqual(12540, cubicCount[CubeType.Cube], "Cube count must match."); Assert.AreEqual(20651, cubicCount[CubeType.Interior], "Interior count must match."); }
public MyObjectBuilder_CubeGrid BuildEntity() { var entity = new MyObjectBuilder_CubeGrid { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, Skeleton = new System.Collections.Generic.List <BoneInfo>(), LinearVelocity = new VRageMath.Vector3(0, 0, 0), AngularVelocity = new VRageMath.Vector3(0, 0, 0) }; var blockPrefix = ""; switch (ClassType) { case ImportImageClassType.SmallShip: entity.GridSizeEnum = MyCubeSize.Small; blockPrefix += "Small"; entity.IsStatic = false; break; case ImportImageClassType.SmallStation: entity.GridSizeEnum = MyCubeSize.Small; blockPrefix += "Small"; entity.IsStatic = true; Position = Position.RoundOff(MyCubeSize.Small.ToLength()); Forward = Forward.RoundToAxis(); Up = Up.RoundToAxis(); break; case ImportImageClassType.LargeShip: entity.GridSizeEnum = MyCubeSize.Large; blockPrefix += "Large"; entity.IsStatic = false; break; case ImportImageClassType.LargeStation: entity.GridSizeEnum = MyCubeSize.Large; blockPrefix += "Large"; entity.IsStatic = true; Position = Position.RoundOff(MyCubeSize.Large.ToLength()); Forward = Forward.RoundToAxis(); Up = Up.RoundToAxis(); break; } switch (ArmorType) { case ImportArmorType.Heavy: blockPrefix += "HeavyBlockArmor"; break; case ImportArmorType.Light: blockPrefix += "BlockArmor"; break; } entity.PositionAndOrientation = new MyPositionAndOrientation { // TODO: reposition based scale. Position = Position.ToVector3D(), Forward = Forward.ToVector3(), Up = Up.ToVector3() }; // Large|BlockArmor|Corner // Large|RoundArmor_|Corner // Large|HeavyBlockArmor|Block, // Small|BlockArmor|Slope, // Small|HeavyBlockArmor|Corner, entity.CubeBlocks = new System.Collections.Generic.List <MyObjectBuilder_CubeBlock>(); var image = ImageHelper.ResizeImage(_sourceImage, NewImageSize.Size); using (var palatteImage = new Bitmap(image)) { // Optimal order load. from grid coordinate (0,0,0) and up. for (var x = palatteImage.Width - 1; x >= 0; x--) { for (var y = palatteImage.Height - 1; y >= 0; y--) { const int z = 0; var color = palatteImage.GetPixel(x, y); // Specifically ignore anything with less than half "Transparent" Alpha. if (IsAlphaLevel && color.A < AlphaLevel) { continue; } if (IsKeyColor && color.R == KeyColor.R && color.G == KeyColor.G && color.B == KeyColor.B) { continue; } // Parse the string through the Enumeration to check that the 'subtypeid' is still valid in the game engine. var armor = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Block"); MyObjectBuilder_CubeBlock newCube; entity.CubeBlocks.Add(newCube = new MyObjectBuilder_CubeBlock()); newCube.SubtypeName = armor.ToString(); newCube.EntityId = 0; newCube.BlockOrientation = Modelling.GetCubeOrientation(CubeType.Cube); newCube.Min = new VRageMath.Vector3I(palatteImage.Width - x - 1, palatteImage.Height - y - 1, z); newCube.ColorMaskHSV = color.FromPaletteColorToHsvMask(); } } } return(entity); }
private MyObjectBuilder_CubeGrid BuildShipEntity() { var entity = new MyObjectBuilder_CubeGrid { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, Skeleton = new System.Collections.Generic.List <BoneInfo>(), LinearVelocity = new VRageMath.Vector3(0, 0, 0), AngularVelocity = new VRageMath.Vector3(0, 0, 0) }; var blockPrefix = ""; switch (ClassType) { case ImportModelClassType.SmallShip: entity.GridSizeEnum = MyCubeSize.Small; blockPrefix += "Small"; entity.IsStatic = false; break; case ImportModelClassType.SmallStation: entity.GridSizeEnum = MyCubeSize.Small; blockPrefix += "Small"; entity.IsStatic = true; Position = Position.RoundOff(MyCubeSize.Small.ToLength()); Forward = Forward.RoundToAxis(); Up = Up.RoundToAxis(); break; case ImportModelClassType.LargeShip: entity.GridSizeEnum = MyCubeSize.Large; blockPrefix += "Large"; entity.IsStatic = false; break; case ImportModelClassType.LargeStation: entity.GridSizeEnum = MyCubeSize.Large; blockPrefix += "Large"; entity.IsStatic = true; Position = Position.RoundOff(MyCubeSize.Large.ToLength()); Forward = Forward.RoundToAxis(); Up = Up.RoundToAxis(); break; } switch (ArmorType) { case ImportArmorType.Heavy: blockPrefix += "HeavyBlockArmor"; break; case ImportArmorType.Light: blockPrefix += "BlockArmor"; break; // TODO: Rounded Armor. // Currently in development, and only specified as 'Light' on the 'Large' structures. //case ImportArmorType.Round: blockPrefix += "RoundArmor_"; break; } // Large|BlockArmor|Corner // Large|RoundArmor_|Corner // Large|HeavyBlockArmor|Block, // Small|BlockArmor|Slope, // Small|HeavyBlockArmor|Corner, var blockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Block"); var slopeBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Slope"); var cornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Corner"); var inverseCornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "CornerInv"); entity.CubeBlocks = new System.Collections.Generic.List <MyObjectBuilder_CubeBlock>(); double multiplier; if (IsMultipleScale) { multiplier = MultipleScale; } else { multiplier = MaxLengthScale / Math.Max(Math.Max(OriginalModelSize.Height, OriginalModelSize.Width), OriginalModelSize.Depth); } var ccubic = Modelling.ReadModelVolmetic(Filename, multiplier, null, TraceType, MainViewModel.ResetProgress, MainViewModel.IncrementProgress); Modelling.BuildStructureFromCubic(entity, ccubic, FillObject, blockType, slopeBlockType, cornerBlockType, inverseCornerBlockType); MainViewModel.ClearProgress(); entity.PositionAndOrientation = new MyPositionAndOrientation { // TODO: reposition based scale. Position = Position.ToVector3D(), Forward = Forward.ToVector3(), Up = Up.ToVector3() }; IsValidModel = entity.CubeBlocks.Count > 0; return(entity); }
public MyObjectBuilder_CubeGrid BuildTestEntity() { var entity = new MyObjectBuilder_CubeGrid { EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY), PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, Skeleton = new System.Collections.Generic.List <BoneInfo>(), LinearVelocity = new VRageMath.Vector3(0, 0, 0), AngularVelocity = new VRageMath.Vector3(0, 0, 0), GridSizeEnum = MyCubeSize.Large }; var blockPrefix = entity.GridSizeEnum.ToString(); var cornerBlockPrefix = entity.GridSizeEnum.ToString(); entity.IsStatic = false; blockPrefix += "BlockArmor"; // HeavyBlockArmor|BlockArmor; cornerBlockPrefix += "BlockArmor"; // HeavyBlockArmor|BlockArmor|RoundArmor_; // Figure out where the Character is facing, and plant the new constrcut right in front, by "10" units, facing the Character. var vector = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Vector3D; vector.Normalize(); vector = Vector3D.Multiply(vector, 6); Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector)); Forward = new BindableVector3DModel(_dataModel.CharacterPosition.Forward); Up = new BindableVector3DModel(_dataModel.CharacterPosition.Up); entity.PositionAndOrientation = new MyPositionAndOrientation { Position = Position.ToVector3D(), Forward = Forward.ToVector3(), Up = Up.ToVector3() }; // Large|BlockArmor|Corner // Large|RoundArmor_|Corner // Large|HeavyBlockArmor|Block, // Small|BlockArmor|Slope, // Small|HeavyBlockArmor|Corner, var blockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Block"); var slopeBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "Slope"); var cornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "Corner"); var inverseCornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "CornerInv"); entity.CubeBlocks = new System.Collections.Generic.List <MyObjectBuilder_CubeBlock>(); //var smoothObject = true; // Read in voxel and set main cube space. //var ccubic = TestCreateSplayedDiagonalPlane(); //var ccubic = TestCreateSlopedDiagonalPlane(); //var ccubic = TestCreateStaggeredStar(); var ccubic = Modelling.TestCreateTrayShape(); //var ccubic = ReadModelVolmetic(@"..\..\..\..\..\..\building 3D\models\Rhino_corrected.obj", 10, null, ModelTraceVoxel.ThickSmoothedDown); var fillObject = false; //if (smoothObject) //{ // CalculateAddedInverseCorners(ccubic); // CalculateAddedSlopes(ccubic); // CalculateAddedCorners(ccubic); //} Modelling.BuildStructureFromCubic(entity, ccubic, fillObject, blockType, slopeBlockType, cornerBlockType, inverseCornerBlockType); return(entity); }