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