コード例 #1
0
        public void CanRenderModelWithTextures()
        {
            // Arrange.
            Scene scene = MeshellatorLoader.ImportFromFile("Models/Obj/Tank.obj");

            using (var renderer = new WarpSceneRenderer(scene, 800, 600))
            {
                renderer.Options.TriangleWindingOrderReversed = true;

                Camera camera = new PerspectiveCamera
                {
                    FarPlaneDistance  = 100000,
                    NearPlaneDistance = 1,
                    FieldOfView       = MathUtility.PI_OVER_4,
                    LookDirection     = new Vector3D(-1, -0.3f, 1),
                    Position          = new Point3D(300, 150, -150),
                    UpDirection       = Vector3D.Up
                };

                // Act.
                var bitmap = renderer.Render(camera);

                // Assert.
                Assert.IsNotNull(bitmap);
                SaveImage(bitmap, "tank.jpg");
            }
        }
コード例 #2
0
        public void CanRenderModel()
        {
            // Arrange.
            Scene scene = MeshellatorLoader.ImportFromFile("Models/3ds/85-nissan-fairlady.3ds");

            using (var renderer = new WarpSceneRenderer(scene, 800, 600))
            {
                Camera camera = new PerspectiveCamera
                {
                    FarPlaneDistance  = 100000,
                    NearPlaneDistance = 1,
                    FieldOfView       = MathUtility.PI_OVER_4,
                    LookDirection     = new Vector3D(-1, -0.3f, 1),
                    Position          = new Point3D(3000, 1500, -1500),
                    UpDirection       = Vector3D.Up
                };

                // Act.
                var bitmap = renderer.Render(camera);

                // Assert.
                Assert.IsNotNull(bitmap);
                SaveImage(bitmap, "nissan.jpg");
            }
        }
コード例 #3
0
        public override Scene GetScene(ImageGenerationContext context)
        {
            string resolvedFileName = FileSourceHelper.ResolveFileName(context, FileName);

            if (File.Exists(resolvedFileName))
            {
                return(MeshellatorLoader.ImportFromFile(resolvedFileName));
            }
            return(null);
        }
コード例 #4
0
        public void CanImport3dsFileWithTextures()
        {
            // Act.
            Scene scene = MeshellatorLoader.ImportFromFile(@"Models\3ds\Face\Jane_solid_3ds.3ds");

            // Assert.
            Assert.That(scene.Materials, Has.Count.EqualTo(3));
            Assert.That(scene.Materials[0].DiffuseTextureName, Is.EqualTo(@"Models\3ds\Face\Jane_so1.jpg"));
            Assert.That(scene.Materials[1].DiffuseTextureName, Is.EqualTo(@"Models\3ds\Face\Jane_so2.jpg"));
            Assert.That(scene.Materials[2].DiffuseTextureName, Is.EqualTo(@"Models\3ds\Face\Jane_sol.jpg"));
        }
コード例 #5
0
        public void CanImportBunny()
        {
            // Act.
            Scene scene = MeshellatorLoader.ImportFromFile(@"Models\Ply\Bunny.ply");

            // Assert.
            Assert.That(scene.Meshes, Has.Count.EqualTo(1));
            Assert.That(scene.Meshes[0].Positions, Has.Count.EqualTo(35947));
            Assert.That(scene.Meshes[0].Positions[0], Is.EqualTo(new Point3D(-0.0378297f, 0.12794f, 0.00447467f)));
            Assert.That(scene.Meshes[0].Normals, Has.Count.EqualTo(0));
            Assert.That(scene.Meshes[0].TextureCoordinates, Has.Count.EqualTo(0));
            Assert.That(scene.Meshes[0].Indices, Has.Count.EqualTo(69451 * 3));
            Assert.That(scene.Meshes[0].Indices[0], Is.EqualTo(20399));
            Assert.That(scene.Meshes[0].Indices[1], Is.EqualTo(21215));
            Assert.That(scene.Meshes[0].Indices[2], Is.EqualTo(21216));
        }
コード例 #6
0
        public void CanImportWuson()
        {
            // Act.
            Scene scene = MeshellatorLoader.ImportFromFile(@"Models\Ply\Wuson.ply");

            // Assert.
            Assert.That(scene.Meshes, Has.Count.EqualTo(1));
            Assert.That(scene.Meshes[0].Positions, Has.Count.EqualTo(11184));
            Assert.That(scene.Meshes[0].Positions[0], Is.EqualTo(new Point3D(0.163313f, 0.540615f, -0.268688f)));
            Assert.That(scene.Meshes[0].Normals, Has.Count.EqualTo(11184));
            Assert.That(scene.Meshes[0].Normals[0], Is.EqualTo(new Vector3D(0.241919f, -0.961129f, 0.133063f)));
            Assert.That(scene.Meshes[0].TextureCoordinates, Has.Count.EqualTo(11184));
            Assert.That(scene.Meshes[0].TextureCoordinates[0], Is.EqualTo(new Point3D(0.681180f, 0.275678f, 0)));
            Assert.That(scene.Meshes[0].Indices, Has.Count.EqualTo(3732 * 3));
            Assert.That(scene.Meshes[0].Indices[0], Is.EqualTo(0));
            Assert.That(scene.Meshes[0].Indices[1], Is.EqualTo(1));
            Assert.That(scene.Meshes[0].Indices[2], Is.EqualTo(2));
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: cupid725/dotwarp
        public static void Main(string[] args)
        {
            string modelFileName = args[0];
            string outFileName   = args[1];

            // Arrange.
            Scene scene = MeshellatorLoader.ImportFromFile(modelFileName);

            using (var renderer = new WarpSceneRenderer(scene, 800, 600))
            {
                Camera camera = PerspectiveCamera.CreateFromBounds(scene.Bounds,
                                                                   new Viewport(0, 0, 800, 600), MathUtility.PI_OVER_4, 0, 0, 1);

                // Act.
                BitmapSource bitmap = renderer.Render(camera);

                var e = new PngBitmapEncoder();
                e.Frames.Add(BitmapFrame.Create(bitmap));
                using (Stream stream = File.OpenWrite(outFileName))
                    e.Save(stream);
            }
        }
コード例 #8
0
 public IDocument Create(string path)
 {
     return(new ModelEditorViewModel(new SceneViewModel(MeshellatorLoader.ImportFromFile(path)), Path.GetFileName(path)));
 }
コード例 #9
0
        /// <summary>
        /// The importer's entry point.
        /// Called by the framework when importing a game asset.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">
        /// Contains information for importing a game asset, such as a logger interface.
        /// </param>
        /// <returns>Resulting game asset.</returns>
        public override NodeContent Import(string filename, ContentImporterContext context)
        {
            NodeContent rootNode = new NodeContent
            {
                Identity = new ContentIdentity(filename),
                Name     = Path.GetFileNameWithoutExtension(filename)
            };

            try
            {
                // Import file using Meshellator.
                Scene scene = MeshellatorLoader.ImportFromFile(filename);

                // Create materials.
                //System.Diagnostics.Debugger.Launch();
                Dictionary <Material, MaterialContent> materials = GetMaterials(scene);

                // Convert Meshellator scene to XNA mesh.
                foreach (Mesh mesh in scene.Meshes)
                {
                    MeshContent meshContent = new MeshContent
                    {
                        Name = mesh.Name
                    };
                    foreach (Point3D position in mesh.Positions)
                    {
                        meshContent.Positions.Add(ConvertPoint3D(position));
                    }

                    MaterialContent material = (mesh.Material != null)
                                                                        ? materials[mesh.Material]
                                                                        : new BasicMaterialContent
                    {
                        DiffuseColor       = new Vector3(0.5f),
                        VertexColorEnabled = false
                    };
                    GeometryContent geometryContent = new GeometryContent
                    {
                        Material = material
                    };
                    meshContent.Geometry.Add(geometryContent);

                    geometryContent.Indices.AddRange(mesh.Indices);

                    for (int i = 0; i < mesh.Positions.Count; ++i)
                    {
                        geometryContent.Vertices.Add(i);
                    }

                    List <Vector2> textureCoordinates = new List <Vector2>();
                    for (int i = 0; i < mesh.Positions.Count; ++i)
                    {
                        Vector2 textureCoordinate = (i < mesh.TextureCoordinates.Count)
                                                        ? ConvertTextureCoordinate(mesh.TextureCoordinates[i])
                                                        : Vector2.Zero;
                        textureCoordinates.Add(textureCoordinate);
                    }
                    geometryContent.Vertices.Channels.Add(VertexChannelNames.TextureCoordinate(0), textureCoordinates);

                    List <Vector3> normals = new List <Vector3>();
                    foreach (Vector3D normal in mesh.Normals)
                    {
                        normals.Add(ConvertVector3D(normal));
                    }
                    geometryContent.Vertices.Channels.Add(VertexChannelNames.Normal(), normals);

                    // Finish the mesh and set the transform.
                    if (SwapWindingOrder)
                    {
                        MeshHelper.SwapWindingOrder(meshContent);
                    }
                    meshContent.Transform = ConvertTransform(mesh.Transform);

                    // Add the mesh to the model
                    rootNode.Children.Add(meshContent);
                }

                return(rootNode);
            }
            catch (InvalidContentException)
            {
                // InvalidContentExceptions do not need further processing
                throw;
            }
            catch (Exception e)
            {
                // Wrap exception with content identity (includes line number)
                throw new InvalidContentException(
                          "Unable to parse file. Exception:\n" + e.ToString(),
                          rootNode.Identity, e);
            }
        }
コード例 #10
0
 public void CanImport3dsFile()
 {
     Scene scene = MeshellatorLoader.ImportFromFile(@"Models\3ds\85-nissan-fairlady.3ds");
 }