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"); }
public static ModelMeshAndTexture CreateDefaultModel(CreateModelContract inputParams) { var logger = new Logger(inputParams.LogFilePath); Stream moldDataStream; ApplyImages(inputParams, out moldDataStream); var createModelInfo = new CreateModelInfo { MoldData = moldDataStream, Minx = 1, Maxx = inputParams.PtDensity, Miny = 1, Maxy = inputParams.PtDensity, Minz = 1, Maxz = inputParams.PtDensity }; logger.Log("Start model creation from mold points"); var ptsToPolygons = new PointsToPolygons(createModelInfo); var model = ptsToPolygons.Process(); logger.Log("End model creation from mold points."); if (moldDataStream != null) { moldDataStream.Close(); } if (inputParams.SmoothingIterationCount > 0) { logger.Log(string.Format("Start smoothening {0} times", inputParams.SmoothingIterationCount)); model.Positions = PaulBourkeSmoother.GetSmoothenedPositions(model.Positions, model.TriangleIndices, inputParams.SmoothingIterationCount); logger.Log("End smoothening."); } var addTextureInfo = GetAddTextureInfoForFrontAndBackImage(inputParams); var texture = TextureProcessor.GenerateTexture(addTextureInfo, model, inputParams.LogFilePath); logger.Log("Returning model mesh and texture"); if (texture != null) { model.TextureCoordinates = texture.TextureCoordinates; } return(new ModelMeshAndTexture { MeshGeometry = model, TextureBitmap = (texture == null? null : texture.Bitmap) }); }
private void AdjustSkin(object sender, RoutedEventArgs e) { if (_currentTextureType != TextureTypeEnum.FourCorners) { return; } var adjustSkinWindow = new AdjustSkin(_xCoodRangesFor4ImageTexture, _userXCoodRangesFor4ImageTexture); var result = adjustSkinWindow.ShowDialog(); if (!result.HasValue || !result.Value || adjustSkinWindow.ReturnValue == null) { return; } var returnValue = adjustSkinWindow.ReturnValue; if (_4CornerTextureAndBitmap == null) { return; } var indices = MainProcessor.GetIndicesFor4CornerTexture(_createMeshContract.ClickInputs.Angles); if (indices == null) { MessageBox.Show("Error in generating textures: Cannot identify photos for four corners.\nPlease check if photos are available for a full 360 degree view."); return; } var quickProcessingWindow = new QuickProcessingWindowHelper(ParentGrid); var add4CornerTexture = MainProcessor.GetAddTextureInfoForIndexCollection(_createMeshContract, indices); if (add4CornerTexture.ImageInfos != null) { SetUserSuppliedLimit(0, add4CornerTexture, returnValue.FrontPhotoTexCoodValueLimits); SetUserSuppliedLimit(1, add4CornerTexture, returnValue.RightPhotoTexCoodValueLimits); SetUserSuppliedLimit(2, add4CornerTexture, returnValue.BackPhotoTexCoodValueLimits); SetUserSuppliedLimit(3, add4CornerTexture, returnValue.LeftPhotoTexCoodValueLimits); } _userXCoodRangesFor4ImageTexture = returnValue; _4CornerTextureAndBitmap = TextureProcessor.GenerateTexture(add4CornerTexture, (MeshGeometry3D)_currentModel.Geometry, ""); quickProcessingWindow.Close(); ApplyTextureOnCurrentModel(_4CornerTextureAndBitmap); }
private void Generate2CornerTexture() { if (_2CornerTextureAndBitmap != null) { return; } var quickProcessingWindow = new QuickProcessingWindowHelper(ParentGrid); var addTextureInfoForFrontAndBack = MainProcessor.GetAddTextureInfoForFrontAndBackImage(_createMeshContract); if (addTextureInfoForFrontAndBack == null) { MessageBox.Show("Error in generating textures: Cannot identify front and back photos.\nPlease check if photos are available from front to back."); quickProcessingWindow.Close(); return; } _2CornerTextureAndBitmap = TextureProcessor.GenerateTexture(addTextureInfoForFrontAndBack, (MeshGeometry3D)_currentModel.Geometry, ""); quickProcessingWindow.Close(); }
private void Generate8CornerTexture() { if (_8CornerTextureAndBitmap != null) { return; } var indices = MainProcessor.GetIndicesFor8CornerTexture(_createMeshContract.ClickInputs.Angles); if (indices == null) { MessageBox.Show("Error in generating textures: Cannot identify photos for eight corners.\nPlease check if photos are available for a full 360 degree view."); return; } var quickProcessingWindow = new QuickProcessingWindowHelper(ParentGrid); var add8CornerTexture = MainProcessor.GetAddTextureInfoForIndexCollection(_createMeshContract, indices); _8CornerTextureAndBitmap = TextureProcessor.GenerateTexture(add8CornerTexture, (MeshGeometry3D)_currentModel.Geometry, ""); quickProcessingWindow.Close(); if (indices.Length < 8) { MessageBox.Show(string.Format("Texture generated for {0} images as only {0} out of 8 images could be identified.", indices.Length)); } }
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); }