예제 #1
0
        private void Build_Click(object sender, EventArgs e)
        {
            int.TryParse(TxtWidth.Text, out width);
            int.TryParse(TxtHeight.Text, out height);
            int.TryParse(TxtDepth.Text, out depth);

            FolderBrowserDialog d = new FolderBrowserDialog();

            if (DialogResult.OK != d.ShowDialog())
            {
                return;
            }

            Bindings.vrBegin();
            if (Bindings.vrSettingsFileNameW(d.SelectedPath + "\\Grid.model") == 0)
            {
                return;
            }
            VRT_VECTOR3 xa = new VRT_VECTOR3(1, 0, 0);
            VRT_VECTOR3 ya = new VRT_VECTOR3(0, 1, 0);
            VRT_VECTOR3 za = new VRT_VECTOR3(0, 0, 1);

            Bindings.vrSettingsAxisOrientation(xa, ya, za);
            Bindings.vrSettingsCadVersion("Grid");
            Bindings.vrSettingsUnit("M", 1);

            IntPtr scenenode = Bindings.vrOpenSceneNode(IntPtr.Zero, "Grid", VRT_ENUM_MATTABLE.New);

            long branch = Bindings.vrOpenBranch(0, 0);

            Bindings.vrBranchSetNameW(branch, "GridBranch");
            Bindings.vrCloseBranch(branch);


            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    for (int z = 0; z < depth; z++)
                    {
                        double      dx  = (double)x * 0.5;
                        double      dy  = (double)y * 0.5;
                        double      dz  = (double)z * 0.5;
                        VRT_VECTOR3 min = new VRT_VECTOR3(dx, dy, dz);
                        VRT_VECTOR3 max = new VRT_VECTOR3(dx + 0.5, dy + 0.5, dz + 0.5);
                        IntPtr      elm = Bindings.vrBeginElement();
                        UseColor(GetRandomColor());
                        CreateBox(min, max);
                        Bindings.vrEndElement();
                        Bindings.vrBranchAddElement(branch, elm);
                    }
                }
            }

            Bindings.vrCloseSceneNode(scenenode);

            Bindings.vrEnd();
        }
예제 #2
0
        /// <summary>
        /// Initialize the walkinside exporter sdk. Making it ready to process STL geometry.
        /// </summary>
        /// <param name="projectpath">The folder where the walkinside model will be created.</param>
        /// <param name="projectname">The name of the folder that contains the main walkinside project file (.vrp). </param>
        /// <returns></returns>
        public bool Initialize(string projectpath, string projectname)
        {
            // Initialize the SDK.
            if (0 == Bindings.vrBegin())
            {
                return(false);
            }

            // Define the Walkinside model location.
            if (Bindings.vrSettingsFileNameW(projectpath + "\\" + projectname) == 0)
            {
                return(false);
            }

            // Define the axis transformation to orientate STL geometry according Walkinside Axis.
            // Walkinside:          STL:
            //     X = Right            X = Right
            //     Y = Up               Y = ?
            //     Z = Depth            Z = ?
            VRT_VECTOR3 xa = new VRT_VECTOR3(1, 0, 0);
            VRT_VECTOR3 ya = new VRT_VECTOR3(0, 0, -1);  // ToDo : Possible STL axis is not well defined, and these values need to change depending model.
            VRT_VECTOR3 za = new VRT_VECTOR3(0, 1, 0);

            Bindings.vrSettingsAxisOrientation(xa, ya, za);
            // Just provide some information of origin of walkinside model.
            Bindings.vrSettingsCadVersion("Stl sdk example");
            // Use meter as unit of measure.
            Bindings.vrSettingsUnit("M", 1);
            // Create a scene to store the geomtrical information.
            m_SceneNode = Bindings.vrOpenSceneNode(IntPtr.Zero, "projectname", VRT_ENUM_MATTABLE.New);
            // Create the root element in walkinside cad hierarchy.
            m_RootBranch = Bindings.vrOpenBranch(0, 0);
            Bindings.vrBranchSetNameW(m_RootBranch, projectname);
            Bindings.vrCloseBranch(m_RootBranch);

            return(true);
        }
예제 #3
0
        private void CreateBox(VRT_VECTOR3 minimum, VRT_VECTOR3 maximum)
        {
            // ---- calculate the 8 corner points ----
            VRT_VECTOR3[] verCorner = new VRT_VECTOR3[8];

            // corners are:
            // 0 =  x -y -z
            // 1 =  x -y  z
            // 2 = -x -y  z
            // 3 = -x -y -z
            // 4 =  x  y -z
            // 5 =  x  y  z
            // 6 = -x  y  z
            // 7 = -x  y -z

            // set vertex corner coordinates
            verCorner[0].x = maximum.x; verCorner[0].y = minimum.y; verCorner[0].z = minimum.z;
            verCorner[1].x = maximum.x; verCorner[1].y = minimum.y; verCorner[1].z = maximum.z;
            verCorner[2].x = minimum.x; verCorner[2].y = minimum.y; verCorner[2].z = maximum.z;
            verCorner[3].x = minimum.x; verCorner[3].y = minimum.y; verCorner[3].z = minimum.z;
            verCorner[4].x = maximum.x; verCorner[4].y = maximum.y; verCorner[4].z = minimum.z;
            verCorner[5].x = maximum.x; verCorner[5].y = maximum.y; verCorner[5].z = maximum.z;
            verCorner[6].x = minimum.x; verCorner[6].y = maximum.y; verCorner[6].z = maximum.z;
            verCorner[7].x = minimum.x; verCorner[7].y = maximum.y; verCorner[7].z = minimum.z;

            // now write the polys to the file
            // polys are formed from corner points:
            // face 0 = 0 1 2 3
            // face 1 = 4 5 1 0
            // face 2 = 7 6 5 4
            // face 3 = 3 2 6 7
            // face 4 = 3 7 4 0
            // face 5 = 6 2 1 5


            VRT_VECTOR3[] verts = new VRT_VECTOR3[4];

            int[] coord = new int[4];

            // Begin the primitive solution.
            Bindings.vrBeginPrimitive();

            for (int nrFaces = 0; nrFaces < 6; nrFaces++)
            {
                switch (nrFaces)
                {
                case 0:
                    coord[0] = 0; coord[1] = 1; coord[2] = 2; coord[3] = 3;
                    break;

                case 1:
                    coord[0] = 0; coord[1] = 4; coord[2] = 5; coord[3] = 1;
                    break;

                case 2:
                    coord[0] = 4; coord[1] = 7; coord[2] = 6; coord[3] = 5;
                    break;

                case 3:
                    coord[0] = 7; coord[1] = 3; coord[2] = 2; coord[3] = 6;
                    break;

                case 4:
                    coord[0] = 0; coord[1] = 3; coord[2] = 7; coord[3] = 4;
                    break;

                case 5:
                    coord[0] = 5; coord[1] = 6; coord[2] = 2; coord[3] = 1;
                    break;
                }

                int counter = 0;
                for (counter = 0; counter < 4; counter++)
                {
                    verts[counter].x = verCorner[coord[counter]].x;
                    verts[counter].y = verCorner[coord[counter]].y;
                    verts[counter].z = verCorner[coord[counter]].z;
                }

                Bindings.vrBeginPolygon();
                Bindings.vrPolyVertexArray(4, verts, 0);
                Bindings.vrEndPolygon();
            }

            Bindings.vrEndPrimitive();
        }
예제 #4
0
        public bool ExportFile(string filename)
        {
            using (BinaryReader reader = new BinaryReader(System.IO.File.Open(filename, FileMode.Open)))
            {
                // Read string of element (must be 80)
                char[] header = reader.ReadChars(80);
                string text   = new string(header);

                // Define a CAD Hierarchy element to reference the 3D. (Not required, but allows the user to select the element in 3D)
                long cadbranch = Bindings.vrOpenBranch(m_RootBranch, 10);
                Bindings.vrBranchSetNameW(cadbranch, text);
                Bindings.vrCloseBranch(cadbranch);

                // Create the 3D element and assign it to the CAD Hierarchy item.
                IntPtr element = Bindings.vrBeginElement();
                Bindings.vrBranchAddElement(cadbranch, element);

                // Read number of facets in STL file.
                uint nbFacets = reader.ReadUInt32();

                // Start describing the 3d primitive that will contain the mesh.
                Bindings.vrBeginPrimitive();


                // Iterate all facets.
                for (ulong i = 0; i < nbFacets; i++)
                {
                    // Read the normal of the facet.
                    VRT_VECTOR3 normal = new VRT_VECTOR3();
                    normal.x = reader.ReadSingle();
                    normal.y = reader.ReadSingle();
                    normal.z = reader.ReadSingle();

                    // Read the 3 vertices of the triangle (= facet).
                    VRT_VECTOR3[] vertices = new VRT_VECTOR3[3];
                    for (int v = 0; v < 3; v++)
                    {
                        vertices[v]   = new VRT_VECTOR3();
                        vertices[v].x = reader.ReadSingle();
                        vertices[v].y = reader.ReadSingle();
                        vertices[v].z = reader.ReadSingle();
                    }
                    // The attribute count should be 0 according spec.
                    ushort attributebytecount = reader.ReadUInt16();
                    System.Diagnostics.Debug.Assert(attributebytecount == 0);

                    // Start describing a polygon.
                    Bindings.vrBeginPolygon();

                    // Send the information as an array of normals and vertices.
                    var normals = new VRT_VECTOR3[3] {
                        normal, normal, normal
                    };
                    Bindings.vrPolyNormalArray(3, normals, 0);
                    Bindings.vrPolyVertexArray(3, vertices, 0);

                    Bindings.vrEndPolygon();
                }

                Bindings.vrEndPrimitive();

                Bindings.vrEndElement();
            }
            return(true);
        }