public void TestXamlTo3DsConversionForNativeAmericanModel() { var inputModelPath = _inputPath + @"\_3ds\nativeamerican\model.xaml"; var models = XamlFormatModelReader.GetModelsFromFile(inputModelPath); _3DSWriter.ExportTo3DS(filePath: _outputPath + @"\output.3ds", modelData: models[0], textureFileData: Image.FromFile(inputModelPath + ".bmp")); }
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"); }