Beispiel #1
0
        public static ShapeAndHoleObject GetShapeAndHoleObject(Shape shape, Option options)
        {
            List <Vector3> ahole;

            ShapeAndHoleObject shapePoints = shape.extractPoints(options.curveSegments);

            List <Vector3>         vertices = shapePoints.shapeVertices;
            List <List <Vector3> > holes    = shapePoints.holes;

            bool reverse = !Shape.Utils.isClockWise(vertices);

            if (reverse)
            {
                vertices.Reverse();

                for (int h = 0, hl = holes.Count; h < hl; h++)
                {
                    ahole = holes[h];

                    if (Shape.Utils.isClockWise(ahole))
                    {
                        ahole.Reverse();
                        holes[h] = ahole;
                    }
                }
            }

            shapePoints.baseShape     = shape;
            shapePoints.shapeVertices = vertices;
            shapePoints.holes         = holes;
            shapePoints.reverse       = reverse;

            return(shapePoints);
        }
        /**
         * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
         */
        void addShape(Shape shape, Option options)
        {
            int curveSegments = options.curveSegments;

            //Material material = options.material;
            //var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
            ExtrudeGeometry.WorldUVGenerator uvgen = options.UVGenerator;
            if (uvgen == null)
            {
                uvgen = new ExtrudeGeometry.WorldUVGenerator();
            }

            //BoundingBox shapebb = this.shapebb;
            //

            int i, l;

            int shapesOffset = this.vertices.Count;
            ShapeAndHoleObject shapePoints = shape.extractPoints(curveSegments);

            List <Vector3>         vertices = shapePoints.shapeVertices;
            List <List <Vector3> > holes    = shapePoints.holes;

            bool reverse = !Shape.Utils.isClockWise(vertices);

            if (reverse)
            {
                //vertices = vertices.reverse();
                vertices.Reverse();

                // Maybe we should also check if holes are in the opposite direction, just to be safe...

                for (i = 0, l = holes.Count; i < l; i++)
                {
                    List <Vector3> hole = holes[i];

                    if (Shape.Utils.isClockWise(hole))
                    {
                        //holes[ i ] = hole.reverse();
                        hole.Reverse();
                        holes[i] = hole;
                    }
                }

                reverse = false;
            }

            List <List <int> > faces = Shape.Utils.triangulateShape(vertices, holes);

            // Vertices
            //var contour = vertices;

            for (i = 0, l = holes.Count; i < l; i++)
            {
                List <Vector3> hole = holes[i];
                //vertices = vertices.concat( hole );
                vertices.AddRange(hole);
            }

            Vector3    vert;
            int        vlen = vertices.Count;
            List <int> face;
            int        flen = faces.Count;

            //var cont;
            //int clen = contour.Count;

            for (i = 0; i < vlen; i++)
            {
                vert = vertices[i];

                this.vertices.Add(new Vector3(vert.x, vert.y, 0));
            }

            for (i = 0; i < flen; i++)
            {
                face = faces[i];

                int a = face[0] + shapesOffset;
                int b = face[1] + shapesOffset;
                int c = face[2] + shapesOffset;

                this.faces.Add(new Face3(a, b, c));

                this.faceVertexUvs.Add(uvgen.generateBottomUV(this, shape, a, b, c));
                //this.faceVertexUvs.Add( new List<Vector2>( new Vector2[]{ new Vector2(0.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(0.0f, 0.0f) })); // debug
            }
        }