Ejemplo n.º 1
0
        public void Execute(Sculptor sculptor)
        {
            _writer = new StreamWriter(String.Format("{0}.obj", ModelName));
            _out    = new IndentedTextWriter(_writer);
            try
            {
                _out.WriteLine("# Exported by Perspective for WPF, {0}", Perspective.Core.LibraryInfo.Copyright);
                _out.WriteLine("g {0}", this.ModelName);
                _out.WriteLine();


                //foreach (int vertexIndice in Element.Sculptor.Mesh.TriangleIndices)
                //{
                //    Generator.MakeVertex(Element.Sculptor.Mesh.Positions[vertexIndice]);
                //    /*
                //    Point p = Element.Sculptor.Mesh.TextureCoordinates[vertexIndice];
                //    Generator.MakeTextureCoordinates(p);
                //    if (Element.Sculptor.Mesh.Normals.Count >= vertexIndice + 1)
                //    {
                //        Vector3D v = Element.Sculptor.Mesh.Normals[vertexIndice];
                //        Generator.MakeNormal(v);
                //    }
                //     * */
                //}

                for (int vertexIndice = sculptor.Mesh.TriangleIndices.Count - 1; vertexIndice >= 0; vertexIndice--)
                // foreach (int vertexIndice in sculptor.Mesh.TriangleIndices)
                {
                    //if (vertexIndice % 3 == 0)
                    //{
                    //    Generator.MakeFaceIndicesHeader(); // OBJ
                    //}
                    //Generator.MakeFaceIndice(vertexIndice); // OBJ
                    //Generator.MakeFaceIndice(
                    //    vertexIndice,
                    //    sculptor.Mesh.TextureCoordinates.IndexOf(
                    //        sculptor.Mesh.TextureCoordinates[vertexIndice]),
                    //    sculptor.Mesh.Normals.IndexOf(
                    //        sculptor.Mesh.Normals[vertexIndice]));


                    Point3D p = sculptor.Mesh.Positions[vertexIndice];
                    _out.WriteLine("v {0} {1} {2}", p.X, p.Y, p.Z);

                    if (vertexIndice % 3 == 0)
                    {
                        // _out.WriteLine("f {0} {1} {2}", vertexIndice - 2, vertexIndice - 1, vertexIndice);
                        // _out.WriteLine("f {0} {1} {2}", vertexIndice, vertexIndice - 1, vertexIndice - 2);
                        // _out.WriteLine("f {0} {1} {2}", vertexIndice, vertexIndice + 1, vertexIndice + 2);
                        _out.WriteLine("f {0} {1} {2}", vertexIndice + 2, vertexIndice + 1, vertexIndice);
                        _out.WriteLine();
                    }
                }
                _out.WriteLine();
            }
            finally
            {
                _writer.Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invalidates the mesh of the visual.
        /// </summary>
        public void InvalidateMesh()
        {
            GraphicsDevice graphicsDevice = Helper3D.GraphicsDevice;

            _sculptor = CreateSculptor();
            _sculptor.BuildMesh();
            _vertexBuffer = new DynamicVertexBuffer(    // DynamicVertexBuffer enables dynamic scene modification
                graphicsDevice,
                VertexPositionTextureNormal.VertexDeclaration,
                _sculptor.VertexPositionTextureNormals.Length,
                BufferUsage.WriteOnly);

            // code block moved to OnRender to enable GraphicsDevice.SetVertexBuffer(null)
            //graphicsDevice.SetVertexBuffer(null);   // to prevent InvalidOperationException during _vertexBuffer.SetData()
            //_vertexBuffer.SetData(0, _sculptor.VertexPositionTextureNormals, 0, _sculptor.VertexPositionTextureNormals.Length, 0);
            //graphicsDevice.SetVertexBuffer(_vertexBuffer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the data in a STL file.
        /// </summary>
        public void Save()
        {
            var sculptor = new Sculptor(Sculptor);

            if (PointsTransform != null)
            {
                sculptor.Transform(PointsTransform);
            }
            _writer = new StreamWriter(String.Format("{0}.stl", ModelName));
            _out    = new IndentedTextWriter(_writer);
            _out.WriteLine("solid {0}", ModelName);
            _out.Indent++;
            try
            {
                foreach (int vertexIndice in sculptor.Mesh.TriangleIndices)
                {
                    if (vertexIndice % 3 == 0)
                    {
                        _out.WriteLine("facet");
                        _out.Indent++;
                        _out.WriteLine("outer loop");
                        _out.Indent++;
                    }

                    Point3D p = sculptor.Mesh.Positions[vertexIndice];
                    _out.WriteLine("vertex {0} {1} {2}", p.X, p.Y, p.Z);

                    if (vertexIndice % 3 == 2)
                    {
                        _out.Indent--;
                        _out.WriteLine("endloop");
                        _out.Indent--;
                        _out.WriteLine("endfacet");
                    }
                }
                _out.Indent--;
                _out.WriteLine("endsolid ", ModelName);
            }
            finally
            {
                _writer.Close();
            }
        }