public void TestNativeAmerican() { var camPos1 = new Point3D(0.000000, 0.000000, 1239.995361); var lookingAtPt1 = new Point3D(-0.810811, 0.000000, 0.000000); var image1 = (Bitmap)Image.FromFile(_inputPath + @"\native_american_front.jpg"); var frontTexImageInfo = new AddTexImageInfo { CameraLocation = camPos1, ImageBitmap = image1, LookingAt = lookingAtPt1 }; var camPos2 = new Point3D(-54.005825, 0.000000, -1238.818726); var lookingAtPt2 = new Point3D(0.810041, 0.000000, -0.035313); var image2 = (Bitmap)Image.FromFile(_inputPath + @"\native_american_back.jpg"); var backTexImageInfo = new AddTexImageInfo { CameraLocation = camPos2, ImageBitmap = image2, LookingAt = lookingAtPt2 }; var cameraRatio = Te(); var addTextureInfo = new AddTextureInfo { CameraRatio = cameraRatio, ImageInfos = new[] { frontTexImageInfo, backTexImageInfo } }; var mdlFilePath = _inputPath + @"\native_american.mdl"; var mdlReader = new MdlFilePolygonDataReader(mdlFilePath); var triangles = Triangle.GetTrianglesFromPts(mdlReader.Points);; var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles); Assert.AreEqual(0, meshGeometryModel.Normals.Count); //make the model smoother var currentPositions = meshGeometryModel.Positions; var positionNeighbors = PaulBourkeSmoother.GetPositionNeighbors(currentPositions.Count, meshGeometryModel.TriangleIndices); for (var ctr = 1; ctr <= 4; ctr++) { var newPositions = PaulBourkeSmoother.GetSmoothenedPositions(currentPositions, meshGeometryModel.TriangleIndices, positionNeighbors); currentPositions = newPositions; } meshGeometryModel.Positions = currentPositions; var result = TextureProcessor.GenerateTexture(addTextureInfo, meshGeometryModel, _outputPath + @"\log.txt"); var textureImageName = _outputPath + @"\" + "native_american.bmp"; result.Bitmap.Save(textureImageName); meshGeometryModel.TextureCoordinates = result.TextureCoordinates; var geometryModel3D = new GeometryModel3D { Geometry = meshGeometryModel, Material = new DiffuseMaterial { Brush = new ImageBrush { ImageSource = new BitmapImage(new Uri(textureImageName, UriKind.Relative)), ViewportUnits = BrushMappingMode.Absolute } } }; XamlWriter.SaveGeometryModel3D(_outputPath + @"\native_american_ModelWithTexture.xaml", geometryModel3D); MdlToXamlConverter.SaveAsGeometryModel3D(mdlFilePath, _outputPath + @"\Orig_native_american_Model_WithTexture.xaml"); }
public void TestDinosaurModel() { var camPos1 = new Point3D(0.000000, 0.000000, 40.000000); var lookingAtPt1 = new Point3D(0.449719, 0.000000, 0.000000); var image1 = (Bitmap)Image.FromFile(_inputPath + @"\dinosaur_front.bmp"); var frontTexImageInfo = new AddTexImageInfo { CameraLocation = camPos1, ImageBitmap = image1, LookingAt = lookingAtPt1 }; var camPos2 = new Point3D(9.568636, 0.000000, -38.838657); var lookingAtPt2 = new Point3D(-0.436662, 0.000000, -0.107580); var image2 = (Bitmap)Image.FromFile(_inputPath + @"\dinosaur_back.bmp"); var backTexImageInfo = new AddTexImageInfo { CameraLocation = camPos2, ImageBitmap = image2, LookingAt = lookingAtPt2 }; var cameraRatio = new CameraRatio { XRangeAtInfinity = 30.000000, YRangeAtInfinity = 22.504684 }; var addTextureInfo = new AddTextureInfo { CameraRatio = cameraRatio, ImageInfos = new[] { frontTexImageInfo, backTexImageInfo } }; var models = XamlFormatModelReader.GetModelsFromFile(_inputPath + @"\dinosaur_with_normals.xaml"); var meshGeometryModel = (MeshGeometry3D)models[0].Geometry; //make the model smoother var currentPositions = meshGeometryModel.Positions; var positionNeighbors = PaulBourkeSmoother.GetPositionNeighbors(currentPositions.Count, meshGeometryModel.TriangleIndices); for (var ctr = 1; ctr <= 21; ctr++) { var newPositions = PaulBourkeSmoother.GetSmoothenedPositions(currentPositions, meshGeometryModel.TriangleIndices, positionNeighbors); currentPositions = newPositions; } meshGeometryModel.Positions = currentPositions; var result = TextureProcessor.GenerateTexture(addTextureInfo, meshGeometryModel, _outputPath + @"\log.txt"); var textureImageName = _outputPath + @"\" + "dinosaur_texture.bmp"; result.Bitmap.Save(textureImageName); meshGeometryModel.TextureCoordinates = result.TextureCoordinates; var geometryModel3D = new GeometryModel3D { Geometry = meshGeometryModel, Material = new DiffuseMaterial { Brush = new ImageBrush { ImageSource = new BitmapImage(new Uri(textureImageName, UriKind.Relative)), ViewportUnits = BrushMappingMode.Absolute } } }; XamlWriter.SaveGeometryModel3D(_outputPath + @"\ModelWithTexture.xaml", geometryModel3D); MdlToXamlConverter.SaveAsGeometryModel3D(_inputPath + @"\dinosaur.mdl", _outputPath + @"\Orig_dinosaur_Model_WithTexture.xaml"); }
private static void SetUserSuppliedLimit(int index, AddTextureInfo target, MinAndMaxTexCoodValueLimits limits) { if (target.ImageInfos.Length >= index + 1 && ValidLimitSupplied(limits)) { target.ImageInfos[index].AllowedXLimits = new MinAndMaxTexCoodValueLimits { Min = limits.Min, Max = limits.Max } } ; } }
public static AddTextureInfo GetAddTextureInfoForIndexCollection(CreateMeshContract inputParams, ICollection <int> indexCollection) { var logger = new Logger(inputParams.LogFilePath); logger.Log("Start GetAddTextureInfoForIndexCollection"); var angles = inputParams.ClickInputs.Angles; var addTextureInfo = new AddTextureInfo { ImageInfos = new AddTexImageInfo[indexCollection.Count] }; var imageAlterationParams = new ImageAlterationParams { MoldPtDensity = inputParams.PtDensity, MinImageHeightRatio = inputParams.MinImageHeightRatio, PercentExtraWidth = inputParams.PercentExtraWidth, ImageFolder = inputParams.ImageFolder, InvalidColor = inputParams.InvalidColor, ResizeType = ResizeType.ResizeSufficiently, BottomPaddingPercent = inputParams.BottomPaddingPercent }; var ctr = 0; foreach (var index in indexCollection) { var clickInput = inputParams.ClickInputs.ImageClickInputDetailsList[index]; var angle = angles[index]; var imageParams = ImageProcessor.GetImageParams(inputParams.VariationIn3DCoordinates, inputParams.BackgroundStrippingParams, clickInput, angle, imageAlterationParams); addTextureInfo.ImageInfos[ctr] = new AddTexImageInfo { CameraLocation = imageParams.cameraLocation, ImageBitmap = imageParams.Image, LookingAt = imageParams.lookingAt }; if (ctr == 0) { //set the camera ratio addTextureInfo.CameraRatio = new TextureGenerator.CameraRatio { XRangeAtInfinity = imageParams.CameraRatio.xRangeAtInfinity, YRangeAtInfinity = imageParams.CameraRatio.yRangeAtInfinity }; } //make sure the rest of the images are resized to the same size as the first one so that all texture images are of the same ht imageAlterationParams.ResizeType = ResizeType.ToSpecifiedSizes; imageAlterationParams.SpecificResizeHeight = imageParams.Image.Height; imageAlterationParams.SpecificResizeWidth = imageParams.Image.Width; ctr++; } logger.Log("End GetAddTextureInfoForIndexCollection"); return(addTextureInfo); }
public void TestWithABlankCube() { var camPos1 = new Point3D(0.000000, 0.000000, 1239.995361); var lookingAtPt1 = new Point3D(0.0, 0.000000, 0.000000); var image1 = (Bitmap)Image.FromFile(_inputPath + @"\native_american_front.jpg"); var frontTexImageInfo = new AddTexImageInfo { CameraLocation = camPos1, ImageBitmap = image1, LookingAt = lookingAtPt1 }; var camPos2 = new Point3D(0, 0.000000, -1238.818726); var lookingAtPt2 = new Point3D(0.0, 0.000000, 0); var image2 = (Bitmap)Image.FromFile(_inputPath + @"\native_american_back.jpg"); var backTexImageInfo = new AddTexImageInfo { CameraLocation = camPos2, ImageBitmap = image2, LookingAt = lookingAtPt2 }; var cameraRatio = new CameraRatio { XRangeAtInfinity = 2.0, YRangeAtInfinity = 2.0 }; var addTextureInfo = new AddTextureInfo { CameraRatio = cameraRatio, ImageInfos = new[] { frontTexImageInfo, backTexImageInfo } }; var points = PolygonsGetter.GetBoxPolygonsAroundAPoint(new Point3D(0, 0, 0), 20); var triangles = Triangle.GetTrianglesFromPts(points); var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles); Assert.AreEqual(0, meshGeometryModel.Normals.Count); var result = TextureProcessor.GenerateTexture(addTextureInfo, meshGeometryModel, _outputPath + @"\log.txt"); var textureImageName = _outputPath + @"\" + "native_american.bmp"; result.Bitmap.Save(textureImageName); meshGeometryModel.TextureCoordinates = result.TextureCoordinates; XamlWriter.SaveMeshGeometryModel(_outputPath + @"\blank_cube_model_with_native_american_texture.xaml", meshGeometryModel, result.Bitmap); }
public void TestBatmanModelCreationWithSmootheningAndFrontBackTexture() { const string moldFilename = "batman.mld"; var moldFilePath = _inputFolderPath + @"\" + moldFilename; var createModelInfo = new CreateModelInfo { FilePath = moldFilePath, Minx = 1, Maxx = 296, Miny = 109, Maxy = 296, Minz = 1, Maxz = 296 }; var testobj = new PointsToPolygons(createModelInfo); var meshGeometry3D = testobj.Process(); Assert.AreEqual(42422 * 3, meshGeometry3D.TriangleIndices.Count); //smoothen the model five times meshGeometry3D.Positions = PaulBourkeSmoother.GetSmoothenedPositions(meshGeometry3D.Positions, meshGeometry3D.TriangleIndices, 5); //Add textures //SETCAMERAPARAMS_INFINITY 20.000000, 26.661116 //ADDFRONTBACKTEXTURE "C:\Documents and Settings\Vishal Kumar\Desktop\batman\capture_00003.jpg", 0.000000, 0.000000, 40.000000, -0.549542, 0.000000, 0.000000, //"C:\Documents and Settings\Vishal Kumar\Desktop\batman\capture_00031.jpg", 0.476956, 0.000000, -39.997158, 0.549503, 0.000000, 0.006553, "C:\Documents and Settings\Vishal Kumar\Desktop\batman\IBModelerFiles\modelfull.mdl" var camPos1 = new Point3D(0.000000, 0.000000, 40.000); var lookingAtPt1 = new Point3D(-0.549542, 0.000000, 0.000000); var image1 = (Bitmap)Image.FromFile(_inputFolderPath + @"\batmanfront.jpg"); var frontTexImageInfo = new AddTexImageInfo { CameraLocation = camPos1, ImageBitmap = image1, LookingAt = lookingAtPt1 }; var camPos2 = new Point3D(0.476956, 0.000000, -39.997158); var lookingAtPt2 = new Point3D(0.549503, 0.000000, 0.006553); var image2 = (Bitmap)Image.FromFile(_inputFolderPath + @"\batmanback.jpg"); var backTexImageInfo = new AddTexImageInfo { CameraLocation = camPos2, ImageBitmap = image2, LookingAt = lookingAtPt2 }; var cameraRatio = new CameraRatio { XRangeAtInfinity = 26.661116, YRangeAtInfinity = 20.000000 }; var addTextureInfo = new AddTextureInfo { BackImageInfo = backTexImageInfo, CameraRatio = cameraRatio, FrontImageInfo = frontTexImageInfo }; var result = TextureProcessor.GetModelWithFrontAndBackTexture(addTextureInfo, meshGeometry3D); var textureImageName = _outputFolderPath + @"\" + "batman.bmp"; result.BitmapTextureImg.Save(textureImageName); var geometryModel3D = new GeometryModel3D { Geometry = result.MeshGeometry, Material = new DiffuseMaterial { Brush = new ImageBrush { ImageSource = new BitmapImage(new Uri(textureImageName, UriKind.Relative)), ViewportUnits = BrushMappingMode.Absolute } } }; XamlWriter.SaveGeometryModel3D(_outputFolderPath + @"\batman.xaml", geometryModel3D); }