Пример #1
0
        //--------------------------PRIVATES--------------------------------------------//

        /**
         * Composes a solid based on the faces status of the two operators solids:
         * Face.INSIDE, Face.OUTSIDE, Face.SAME, Face.OPPOSITE
         *
         * @param faceStatus1 status expected for the first solid faces
         * @param faceStatus2 other status expected for the first solid faces
         * (expected a status for the faces coincident with second solid faces)
         * @param faceStatus3 status expected for the second solid faces
         */
        private Solid composeSolid(int faceStatus1, int faceStatus2, int faceStatus3)
        {
            var vertices = new List <Vertex>();
            var indices  = new List <int>();
            var colors   = new List <Color3f>();

            //group the elements of the two solids whose faces fit with the desired status
            groupObjectComponents(object1, vertices, indices, colors, faceStatus1, faceStatus2);
            groupObjectComponents(object2, vertices, indices, colors, faceStatus3, faceStatus3);

            //turn the arrayLists to arrays
            Point3d[] verticesArray = new Point3d[vertices.Count];
            for (int i = 0; i < vertices.Count; i++)
            {
                verticesArray[i] = vertices[i].getPosition();
            }
            int[] indicesArray = new int[indices.Count];
            for (int i = 0; i < indices.Count; i++)
            {
                indicesArray[i] = indices[i];
            }
            Color3f[] colorsArray = new Color3f[colors.Count];
            for (int i = 0; i < colors.Count; i++)
            {
                colorsArray[i] = colors[i].Clone();
            }

            //returns the solid containing the grouped elements
            return(new Solid(verticesArray, indicesArray, colorsArray));
        }
Пример #2
0
        /**
         * Method used to add a vertex properly for internal methods
         *
         * @param pos vertex position
         * @param color vertex color
         * @param status vertex status
         * @return the vertex inserted (if a similar vertex already exists, this is returned)
         */
        private Vertex addVertex(Point3d pos, Color3f color, int status)
        {
            int i;
            //if already there is an equal vertex, it is not inserted
            Vertex vertex = new Vertex(pos, color, status);

            for (i = 0; i < vertices.Count; i++)
            {
                if (vertex.equals(vertices[i]))
                {
                    break;
                }
            }
            if (i == vertices.Count)
            {
                vertices.Add(vertex);
                return(vertex);
            }
            else
            {
                vertex = vertices[i];
                vertex.setStatus(status);
                return(vertex);
            }
        }
Пример #3
0
 /** Gets the vertices colors
  *
  * @return vertices colors
  */
 public Color3f[] getColors()
 {
     Color3f[] newColors = new Color3f[colors.Length];
     for (int i = 0; i < newColors.Length; i++)
     {
         newColors[i] = colors[i];
     }
     return(newColors);
 }
Пример #4
0
    public Net3dBool.Color3f[] getColorArray(int length, Color c)
    {
        var ar = new Net3dBool.Color3f[length];

        for (var i = 0; i < length; i++)
        {
            ar[i] = new Net3dBool.Color3f(c.r, c.g, c.b);
        }
        return(ar);
    }
Пример #5
0
        /**
         * Constructs a vertex with definite status
         *
         * @param position vertex position
         * @param color vertex color
         * @param status vertex status - UNKNOWN, BOUNDARY, INSIDE or OUTSIDE
         */
        public Vertex(Point3d position, Color3f color, int status)
        {
            this.color = color.Clone();

            x = position.x;
            y = position.y;
            z = position.z;

            adjacentVertices = new List <Vertex>();
            this.status      = status;
        }
Пример #6
0
        /**
         * Constructs a vertex with unknown status
         *
         * @param x coordinate on the x axis
         * @param y coordinate on the y axis
         * @param z coordinate on the z axis
         * @param color vertex color
         */
        public Vertex(double x, double y, double z, Color3f color)
        {
            this.color = color.Clone();

            this.x = x;
            this.y = y;
            this.z = z;

            adjacentVertices = new List <Vertex>();
            status           = UNKNOWN;
        }
Пример #7
0
        //----------------------------------CONSTRUCTORS--------------------------------//

        /**
         * Constructs a vertex with unknown status
         *
         * @param position vertex position
         * @param color vertex color
         */
        public Vertex(Point3d position, Color3f color)
        {
            this.color = color.Clone();

            x = position.x;
            y = position.y;
            z = position.z;

            adjacentVertices = new List <Vertex>();
            status           = UNKNOWN;
        }
Пример #8
0
        /**
         * Constructs a vertex with a definite status
         *
         * @param x coordinate on the x axis
         * @param y coordinate on the y axis
         * @param z coordinate on the z axis
         * @param color vertex color
         * @param status vertex status - UNKNOWN, BOUNDARY, INSIDE or OUTSIDE
         */
        public Vertex(double x, double y, double z, Color3f color, int status)
        {
            this.color = color.Clone();

            this.x = x;
            this.y = y;
            this.z = z;

            adjacentVertices = new List <Vertex>();
            this.status      = status;
        }
Пример #9
0
    Color[] GetColorsMesh(Solid mesh)
    {
        int clen = mesh.getColors().Length;

        Color[] clrs = new Color[clen];
        for (int j = 0; j < clen; j++)
        {
            Net3dBool.Color3f c = mesh.getColors()[j];
            clrs[j] = new Color((float)c.r, (float)c.g, (float)c.b);
        }
        return(clrs);
    }
Пример #10
0
        /**
         * Loads a coordinates file, setting vertices and indices
         *
         * @param solidFile file used to create the solid
         * @param color solid color
         */
        protected void loadCoordinateFile(FileInfo solidFile, Color3f color)
        {
//            try
//            {
//                BufferedReader reader = new BufferedReader(new FileReader(solidFile));
//
//                String line = reader.readLine();
//                int numVertices = Integer.parseInt(line);
//                vertices = new Point3d[numVertices];
//
//                StringTokenizer tokens;
//                String token;
//
//                for(int i=0;i<numVertices;i++)
//                    {
//                        line = reader.readLine();
//                        tokens = new StringTokenizer(line);
//                        tokens.nextToken();
//                        vertices[i]= new Point3d(Double.parseDouble(tokens.nextToken()), Double.parseDouble(tokens.nextToken()), Double.parseDouble(tokens.nextToken()));
//                    }
//
//                reader.readLine();
//
//                line = reader.readLine();
//                int numTriangles = Integer.parseInt(line);
//                indices = new int[numTriangles*3];
//
//                for(int i=0,j=0;i<numTriangles*3;i=i+3,j++)
//                    {
//                        line = reader.readLine();
//                        tokens = new StringTokenizer(line);
//                        tokens.nextToken();
//                        indices[i] = Integer.parseInt(tokens.nextToken());
//                        indices[i+1] = Integer.parseInt(tokens.nextToken());
//                        indices[i+2] = Integer.parseInt(tokens.nextToken());
//                    }
//
//                colors = new Color3f[vertices.Length];
//                Arrays.fill(colors, color);
//
//                defineGeometry();
//            }
//
//            catch(IOException e)
//            {
//                System.out.println("invalid file!");
//                e.printStackTrace();
//            }
        }
Пример #11
0
        //----------------------------------CONSTRUCTOR---------------------------------//

        /**
         * Constructs a Object3d object based on a solid file.
         *
         * @param solid solid used to construct the Object3d object
         */
        public Object3D(Solid solid)
        {
            Vertex v1, v2, v3, vertex;

            Point3d[] verticesPoints = solid.getVertices();
            int[]     indices        = solid.getIndices();
            Color3f[] colors         = solid.getColors();
            var       verticesTemp   = new List <Vertex>();

            Dictionary <int, int> revlookup = new Dictionary <int, int> ();

            for (int d = 0; d < indices.Length; d++)
            {
                revlookup [indices [d]] = d;
            }

            //create vertices
            vertices = new List <Vertex>();
            for (int i = 0; i < verticesPoints.Length; i++)
            {
                Color3f col = new Color3f(1, 1, 1);
                if (colors.Length > 0)
                {
                    col = colors[i];
                }

                vertex = addVertex(verticesPoints[i], col, Vertex.UNKNOWN);
                verticesTemp.Add(vertex);
            }

            //create faces
            faces = new List <Face>();
            for (int i = 0; i < indices.Length; i = i + 3)
            {
                v1 = verticesTemp[indices[i]];
                v2 = verticesTemp[indices[i + 1]];
                v3 = verticesTemp[indices[i + 2]];
                addFace(v1, v2, v3);
            }

            //create bound
            bound = new Bound(verticesPoints);
        }
Пример #12
0
    // Update is called once per frame
    public static void GenerateMesh(GameObject go, Material ObjMaterial, Solid mesh)
    {
        MeshFilter mf = go.GetComponent <MeshFilter> ();

        if (mf == null)
        {
            mf = go.AddComponent <MeshFilter> ();
        }

        Mesh tmesh = new Mesh();
        int  mlen  = mesh.getVertices().Length;

        Vector3 [] vertices = new Vector3[mlen];
        for (int i = 0; i < mlen; i++)
        {
            Net3dBool.Point3d p = mesh.getVertices()[i];
            vertices[i] = new Vector3((float)p.x, (float)p.y, (float)p.z);
        }
        tmesh.vertices = vertices;

        tmesh.triangles = mesh.getIndices();
        int clen = mesh.getColors().Length;

        Color [] clrs = new Color[clen];
        for (int j = 0; j < clen; j++)
        {
            Net3dBool.Color3f c = mesh.getColors()[j];
            clrs[j] = new Color((float)c.r, (float)c.g, (float)c.b);
        }
        tmesh.colors = clrs;
        tmesh.RecalculateNormals();
        mf.mesh = tmesh;

        MeshRenderer mr = go.GetComponent <MeshRenderer> ();

        if (mr == null)
        {
            mr = go.AddComponent <MeshRenderer> ();
        }
        mr.sharedMaterials    = new Material[1];
        mr.sharedMaterials[0] = ObjMaterial;
        mr.sharedMaterial     = ObjMaterial;
    }
Пример #13
0
 /**
  * Constructs a solid based on a coordinates file. It contains vertices and indices,
  * and its format is like this:
  *
  * <br><br>4
  * <br>0 -5.00000000000000E-0001 -5.00000000000000E-0001 -5.00000000000000E-0001
  * <br>1  5.00000000000000E-0001 -5.00000000000000E-0001 -5.00000000000000E-0001
  * <br>2 -5.00000000000000E-0001  5.00000000000000E-0001 -5.00000000000000E-0001
  * <br>3  5.00000000000000E-0001  5.00000000000000E-0001 -5.00000000000000E-0001
  *
  * <br><br>2
  * <br>0 0 2 3
  * <br>1 3 1 0
  *
  * @param solidFile file containing the solid coordinates
  * @param color solid color
  */
 public Solid(FileInfo solidFile, Color3f color)
     : this()
 {
     loadCoordinateFile(solidFile, color);
 }
Пример #14
0
 /**
  * Sets the solid data. Defines the same color to all the vertices. An exception may
  * may occur in the case of abnormal arrays (e.g., indices making references to
  * inexistent vertices...)
  *
  * @param vertices array of points defining the solid vertices
  * @param indices array of indices for a array of vertices
  * @param color the color of the vertices (the solid color)
  */
 public void setData(Point3d[] vertices, int[] indices, Color3f color)
 {
     Color3f[] colors = new Color3f[vertices.Length];
     colors.fill(color);
     setData(vertices, indices, colors);
 }