Esempio n. 1
0
        public void TestModelCreationForDinosaur()
        {
            var imageFolder = string.Format(@"{0}\{1}", ExecutionDirInfoHelper.GetInputDirPath(), "dinosaur");
            var outputFolder = ExecutionDirInfoHelper.CreateUniqueOutputPath();

            var contract = new CreateModelContract
            {
                VariationIn3DCoordinates = 5.0f,
                //todo: this wont work AllImgProcessedEventArgs1 uses an old class which will fail deserialization
                ClickInputs = MainProcessor.GetClickInputsFromFile(imageFolder + @"\AllImgProcessedEventArgs.xml"),
                InvalidColor = System.Drawing.Color.FromArgb(1, 200, 200, 200),
                ImageFolder = imageFolder,
                BackgroundStrippingParams = new BackgroundStrippingParams
                {
                    ScreenBasedParams = new ScreenBasedParams
                    {
                        MaxDiffPercent = 99,
                        MinColorOffset = 25,
                        ScreenColorTypes = ScreenColorTypes.BlueScreen
                    }
                },
                SmoothingIterationCount = 2,
                LogFilePath = outputFolder + @"\Log.txt",
                PtDensity = 200
            };
            var modelMeshAndTexture = MainProcessor.CreateDefaultModel(contract);

            XamlWriter.SaveMeshGeometryModel(outputFolder + @"\model.xaml", modelMeshAndTexture.MeshGeometry, modelMeshAndTexture.TextureBitmap);
        }
Esempio n. 2
0
        public void TestNormals()
        {
            var mdlReader         = new MdlFilePolygonDataReader(_inputPath + @"\flowerpetals.mdl");
            var triangles         = Triangle.GetTrianglesFromPts(mdlReader.Points);
            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            Assert.AreEqual(0, meshGeometryModel.Normals.Count);
            XamlWriter.SaveMeshGeometryModel(_outputPath + @"\ModelWithoutSetNormals.xaml", meshGeometryModel, Color.FromRgb(255, 255, 0));

            NormalCalculator.SetNormalsForModel(meshGeometryModel);

            Assert.AreEqual(meshGeometryModel.Positions.Count, meshGeometryModel.Normals.Count);

            XamlWriter.SaveMeshGeometryModel(_outputPath + @"\ModelWithSetNormals.xaml", meshGeometryModel, Color.FromRgb(255, 255, 0));

            var normalModelPts = new List <Point3D>();

            for (var index = 0; index < meshGeometryModel.Normals.Count; index++)
            {
                var normal   = meshGeometryModel.Normals[index];
                var position = meshGeometryModel.Positions[index];

                var p2 = new Point3D(position.X + normal.X, position.Y + normal.Y, position.Z + normal.Z);

                var lineModel = LineDisplayModel.GetLineModel(position, p2, .03);
                normalModelPts.AddRange(lineModel);
            }
            XamlWriter.WritePolygonsToXamlFile("", _outputPath + @"\NormalsAsLines.xaml", normalModelPts, false);
        }
Esempio n. 3
0
        public void TestCreateNormalWithTheDinosaurModel()
        {
            var mdlReader         = new MdlFilePolygonDataReader(_inputPath + @"\dinosaur.mdl");
            var triangles         = Triangle.GetTrianglesFromPts(mdlReader.Points);
            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            Assert.AreEqual(0, meshGeometryModel.Normals.Count);
            NormalCalculator.SetNormalsForModel(meshGeometryModel);
            Assert.AreEqual(meshGeometryModel.Positions.Count, meshGeometryModel.Normals.Count);
            XamlWriter.SaveMeshGeometryModel(_outputPath + @"\ModelWithSetNormals.xaml", meshGeometryModel, Color.FromRgb(255, 255, 0));
        }
Esempio n. 4
0
        public void TestMediumSizedModel()
        {
            var mdlFileReader = new MdlFilePolygonDataReader(_inputPath + @"\v.mdl");
            var triangles     = Triangle.GetTrianglesFromPts(mdlFileReader.Points);

            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\InputModel.xaml", _outputPath), mdlFileReader.Points, false);

            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            XamlWriter.SaveMeshGeometryModel(string.Format(@"{0}\InputModelMeshGeometry.xaml", _outputPath), meshGeometryModel, Color.FromRgb(100, 100, 100));

            var smoothPositions = PaulBourkeSmoother.GetSmoothenedPositions(meshGeometryModel.Positions, meshGeometryModel.TriangleIndices, 6);

            XamlWriter.SavePositionsAndTriangleIndicesAsModel(string.Format(@"{0}\Smoothened_{1}_times.xaml", _outputPath, 6),
                                                              smoothPositions, meshGeometryModel.TriangleIndices, Color.FromRgb(100, 100, 100));
        }
Esempio n. 5
0
        public void TestPartModelCreation()
        {
            const string moldFilename    = "nativeamerican100ptmold.mld";
            var          moldFilePath    = _inputFolderPath + @"\" + moldFilename;
            var          createModelInfo = new CreateModelInfo
            {
                FilePath = moldFilePath,
                Minx     = 1,
                Maxx     = 100,
                Miny     = 13,
                Maxy     = 100,
                Minz     = 1,
                Maxz     = 100
            };
            var testobj = new PointsToPolygons(createModelInfo);
            var result  = testobj.Process();

            XamlWriter.SaveMeshGeometryModel(_outputFolderPath + @"\nativeamericanpartmodel.xaml", result, Color.FromRgb(100, 100, 100));
        }
Esempio n. 6
0
        public void TestDinosaurModelCreation()
        {
            const string moldFilename    = "dinosaur.mld";
            var          moldFilePath    = _inputFolderPath + @"\" + moldFilename;
            var          createModelInfo = new CreateModelInfo
            {
                FilePath = moldFilePath,
                Minx     = 1,
                Maxx     = 200,
                Miny     = 24,
                Maxy     = 200,
                Minz     = 1,
                Maxz     = 200
            };
            var testobj = new PointsToPolygons(createModelInfo);
            var result  = testobj.Process();

            XamlWriter.SaveMeshGeometryModel(_outputFolderPath + @"\dinosaur.xaml", result, Color.FromRgb(100, 100, 100));
            Assert.AreEqual(42850 * 3, result.TriangleIndices.Count);
        }
Esempio n. 7
0
        public void TestModelCreation()
        {
            const string moldFilename    = "nativeamerican100ptmold.mld";
            var          moldFilePath    = _inputFolderPath + @"\" + moldFilename;
            var          createModelInfo = new CreateModelInfo
            {
                FilePath = moldFilePath,
                Minx     = 0,
                Maxx     = 0,
                Miny     = 0,
                Maxy     = 0,
                Minz     = 0,
                Maxz     = 0
            };
            var testobj = new PointsToPolygons(createModelInfo);
            var result  = testobj.Process();

            XamlWriter.SaveMeshGeometryModel(_outputFolderPath + @"\nativeamericanfullmodel.xaml", result, Color.FromRgb(100, 100, 100));
            Assert.AreEqual(29516 * 3, result.TriangleIndices.Count);
        }
Esempio n. 8
0
        public void TestGetSmoothenedPositions()
        {
            var mdlFileReader = new MdlFilePolygonDataReader(_inputPath + @"\flowerpetals.mdl");
            var triangles     = Triangle.GetTrianglesFromPts(mdlFileReader.Points);

            XamlWriter.WritePolygonsToXamlFile("", string.Format(@"{0}\InputModel.xaml", _outputPath), mdlFileReader.Points, false);

            var meshGeometryModel = PaulBourkeSmoother.CreateMeshGeometry3DFromTriangles(triangles);

            XamlWriter.SaveMeshGeometryModel(string.Format(@"{0}\InputModelMeshGeometry.xaml", _outputPath), meshGeometryModel, Color.FromRgb(100, 100, 100));

            var currentPositions  = meshGeometryModel.Positions;
            var positionNeighbors = PaulBourkeSmoother.GetPositionNeighbors(currentPositions.Count, meshGeometryModel.TriangleIndices);

            for (var ctr = 1; ctr <= 10; ctr++)
            {
                var newPositions = PaulBourkeSmoother.GetSmoothenedPositions(currentPositions, meshGeometryModel.TriangleIndices, positionNeighbors);
                XamlWriter.SavePositionsAndTriangleIndicesAsModel(string.Format(@"{0}\Smoothing_Iteration_{1}.xaml", _outputPath, ctr),
                                                                  newPositions, meshGeometryModel.TriangleIndices, Color.FromRgb(100, 100, 100));
                currentPositions = newPositions;
            }
        }
        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);
        }
Esempio n. 10
0
        public static void SaveAsXaml(string filePath, MeshGeometry3D modelData, Bitmap bitmapTextureImg)
        {
            AddADefaultSetOfTextureCoordinatesIfNone(modelData);

            XamlWriter.SaveMeshGeometryModel(filePath, modelData, bitmapTextureImg);
        }