getIndices() 공개 메소드

public getIndices ( ) : int[]
리턴 int[]
예제 #1
0
        //BoundsOctree<int> octree = new BoundsOctree<int>();

        /// <summary>
        /// Constructs a Object3d object based on a solid file.
        /// </summary>
        /// <param name="solid">solid used to construct the Object3d object</param>
        public CsgObject3D(Solid solid)
        {
            Vertex v1, v2, v3, vertex;

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

            AxisAlignedBoundingBox totalBounds = new AxisAlignedBoundingBox(verticesPoints[0], verticesPoints[0]);

            //create vertices
            vertices = new List <Vertex>();
            for (int i = 0; i < verticesPoints.Length; i++)
            {
                vertex = AddVertex(verticesPoints[i], FaceStatus.Unknown);
                totalBounds.ExpandToInclude(verticesPoints[i]);
                verticesTemp.Add(vertex);
            }

            //create faces
            totalBounds.Expand(1);
            Faces = new Octree <CsgFace>(5, totalBounds);
            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
            Bounds = new AxisAlignedBoundingBox(verticesPoints);
        }
예제 #2
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>();

            //create vertices
            vertices = new List <Vertex>();
            for (int i = 0; i < verticesPoints.Length; i++)
            {
                vertex = addVertex(verticesPoints[i], colors[i], 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);
        }
예제 #3
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;
    }
예제 #4
0
    Tuple <GameObject, Solid> DrawHole3D(Vector3 pos, Quaternion rotation)
    {
        GameObject gameObject = new GameObject();

        gameObject.name = "Hole";

        float w = 1;
        float h = 1;
        float g = 1;

        Vector3[] vertices =
        {
            new Vector3(pos.x - w / 2, pos.y - h / 2, pos.z + g / 2),
            new Vector3(pos.x - w / 2, pos.y - h / 2, pos.z - g / 2),
            new Vector3(pos.x - w / 2, pos.y + h / 2, pos.z - g / 2),
            new Vector3(pos.x - w / 2, pos.y + h / 2, pos.z + g / 2),
            new Vector3(pos.x + w / 2, pos.y + h / 2, pos.z + g / 2),
            new Vector3(pos.x + w / 2, pos.y + h / 2, pos.z - g / 2),
            new Vector3(pos.x + w / 2, pos.y - h / 2, pos.z - g / 2),
            new Vector3(pos.x + w / 2, pos.y - h / 2, pos.z + g / 2),
        };

        Point3d[] points3d = vertices.Select(v => new Point3d(v.x, v.y, v.z)).ToArray();

        int[] triangles =
        {
            0, 2, 1, //face front
            0, 3, 2,
            2, 3, 4, //face top
            2, 4, 5,
            1, 2, 5, //face right
            1, 5, 6,
            0, 7, 4, //face left
            0, 4, 3,
            5, 4, 7, //face back
            5, 7, 6,
            0, 6, 7, //face bottom
            0, 1, 6
        };

        var obj = new Net3dBool.Solid(points3d, triangles, getColorArray(8, Color.black));

        MeshFilter mf    = gameObject.AddComponent <MeshFilter>();
        Mesh       tmesh = new Mesh();

        tmesh.vertices  = GetVertices(obj);
        tmesh.triangles = obj.getIndices();
        tmesh.colors    = GetColorsMesh(obj);
        tmesh.RecalculateNormals();
        mf.mesh = tmesh;
        MeshRenderer mr = gameObject.AddComponent <MeshRenderer>();

        //gameObject.transform.Translate(new Vector3(2000, 0, 0), Space.World);

        gameObject.transform.parent = area3D.transform;


        return(new Tuple <GameObject, Solid>(gameObject, obj));
    }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
0
    public Tuple <GameObject, Solid> DrawMesh3D(Vector3 startPoint, Vector3 endPoint, float width, float height, string name)
    {
        activeFloor = currentStatusDoma.activeFloor;
        startPoint  = new Vector3(startPoint.x, activeFloor.LevelBottom, startPoint.z);
        endPoint    = new Vector3(endPoint.x, activeFloor.LevelBottom, endPoint.z);
        float h = height;

        GameObject gameObject = new GameObject();

        gameObject.name = name;

        var between  = endPoint - startPoint;
        var distance = Vector3.Distance(startPoint, endPoint);

        Vector3 vNormalized    = endPoint - startPoint;
        Vector3 vPerpendicular = Vector3.Normalize(Vector3.Cross(vNormalized, Vector3.up));

        var P1 = startPoint + vPerpendicular * width / 2;
        var P2 = startPoint - vPerpendicular * width / 2;
        var P3 = endPoint - vPerpendicular * width / 2;
        var P4 = endPoint + vPerpendicular * width / 2;

        Vector3[] vertices =
        {
            P1,
            P2,
            new Vector3(P2.x,P2.y + h,  P2.z),
            new Vector3(P1.x,P1.y + h,  P1.z),
            new Vector3(P4.x,P4.y + h,  P4.z),
            new Vector3(P3.x,P3.y + h,  P3.z),
            P3,
            P4,
        };

        Point3d[] points3d = vertices.Select(v => new Point3d(v.x, v.y, v.z)).ToArray();

        int[] triangles =
        {
            0, 2, 1, //face front
            0, 3, 2,
            2, 3, 4, //face top
            2, 4, 5,
            1, 2, 5, //face right
            1, 5, 6,
            0, 7, 4, //face left
            0, 4, 3,
            5, 4, 7, //face back
            5, 7, 6,
            0, 6, 7, //face bottom
            0, 1, 6
        };

        // UVs dla tekstury
        Vector2[] uvs = new Vector2[vertices.Length];
        for (int i = 0; i < uvs.Length; i++)
        {
            uvs[i] = new Vector2(vertices[i].x, vertices[i].y);
        }


        var obj = new Net3dBool.Solid(points3d, triangles, getColorArray(8, Color.black));

        MeshFilter mf    = gameObject.AddComponent <MeshFilter>();
        Mesh       tmesh = new Mesh();

        tmesh.vertices  = GetVertices(obj);
        tmesh.triangles = obj.getIndices();
        tmesh.uv        = uvs;
        //tmesh.colors = GetColorsMesh(obj);
        tmesh.RecalculateNormals();
        mf.mesh = tmesh;
        MeshRenderer mr = gameObject.AddComponent <MeshRenderer>();

        gameObject.transform.Translate(new Vector3(2000, 0, 0), Space.World);

        gameObject.GetComponent <MeshRenderer>().material = material;

        gameObject.transform.parent = area3D.transform;

        // Doda Collider gdy ściana ma długość min. 20 cm
        if (Vector3.Distance(startPoint, endPoint) > 0.2f)
        {
            gameObject.AddComponent <MeshCollider>();
        }

        gameObject.tag   = "Wall";
        gameObject.layer = LayerMask.NameToLayer("3DArea");

        return(new Tuple <GameObject, Solid>(gameObject, obj));
    }