Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        void addShapeList(List <Shape> shapes, List <ShapeAndHoleObject> shapeAndHoles, Option options)
        {
            int sl = shapeAndHoles.Count;

            for (int s = 0; s < sl; s++)
            {
                ShapeAndHoleObject shapeAndHole = shapeAndHoles[s];
                this.addShape(shapeAndHole, options);
            }
        }
Ejemplo n.º 3
0
        // Get points of shape and holes (keypoints based on segments parameter)

        ShapeAndHoleObject extractAllPoints(float divisions)
        {
            ShapeAndHoleObject obj = new ShapeAndHoleObject();

            obj.shapeVertices = this.getTransformedPoints(divisions, null);
            obj.holes         = this.getPointsHoles(divisions);

            return(obj);
//		return {
//			shape: this.getTransformedPoints( divisions ),
//			holes: this.getPointsHoles( divisions )
//		}
        }
        /**
         * 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
            }
        }
Ejemplo n.º 5
0
        //void addShape(Shape shape, Option options ) {
        void addShape(ShapeAndHoleObject shapePoints, Option options)
        {
            Shape shape  = shapePoints.baseShape;
            int   amount = options.amount;

            float bevelThickness = options.bevelThickness;
            float bevelSize      = options.bevelSize;
            int   bevelSegments  = options.bevelSegments;
            bool  bevelEnabled   = options.bevelEnabled;
            int   curveSegments  = options.curveSegments;
            int   steps          = options.steps;

            Curve extrudePath = options.extrudePath;

            //Material material = options.material;
            //Material extrudeMaterial = options.extrudeMaterial;

            // Use default WorldUVGenerator if no UV generators are specified.

            WorldUVGenerator uvgen = options.UVGenerator;

            if (uvgen == null)
            {
                uvgen = new WorldUVGenerator();
            }

            List <Vector3> extrudePts    = new List <Vector3>();
            bool           extrudeByPath = false;

            THREE.TubeGeometry.FrenetFrames splineTube = null;
            Vector3 binormal, normal, position2;

            bool isClosePath             = false;

            if (extrudePath != null)
            {
                extrudePts    = extrudePath.getSpacedPoints(steps);
                extrudeByPath = true;
                bevelEnabled  = false;                                               // bevels not supported for path extrusion

                isClosePath = (extrudePath.GetType() == typeof(ClosedSplineCurve3)); // add inok

                // SETUP TNB variables
                // Reuse TNB from TubeGeomtry for now.
                splineTube = options.frames;
                if (splineTube == null)
                {
                    splineTube     = new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, isClosePath);
                    options.frames = splineTube;
                }

                binormal  = new Vector3();
                normal    = new Vector3();
                position2 = new Vector3();
            }
            else
            {
                Debug.Log("no extrudePath");
            }

            // Safeguards if bevels are not enabled
            if (!bevelEnabled)
            {
                bevelSegments  = 0;
                bevelThickness = 0;
                bevelSize      = 0;
            }

            // Variables initalization

            //var ahole, h, hl; // looping of holes
            List <Vector3> ahole;

            //int shapesOffset = this.vertices.Count;
            int shapesOffset             = vertIndex;

//			ShapeAndHoleObject shapePoints = shape.extractPoints( curveSegments );
//
//			List<Vector3> vertices = shapePoints.shape;
//			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;
//					}
//				}
//			}
            List <Vector3>         vertices = shapePoints.shapeVertices;
            List <List <Vector3> > holes = shapePoints.holes;
            bool reverse = shapePoints.reverse;

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

            /* Vertices */
            //List<Vector3> contour = vertices; // vertices has all points but contour has only points of circumference
            List <Vector3> contour = new List <Vector3>();           // 上記だとholeが上手くいかない。改良の余地あり

            contour.AddRange(vertices);

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


            float t;
            float z, bs;

            Vector3 vert;
            int     vlen = vertices.Count;
            //Face3 face;

            int flen = faces.Count;

            List <Vector3> contourMovements = new List <Vector3>();

            for (int i = 0, il = contour.Count, j = il - 1, k = i + 1; i < il; i++, j++, k++)
            {
                if (j == il)
                {
                    j = 0;
                }
                if (k == il)
                {
                    k = 0;
                }

                //  (j)---(i)---(k)
                Vector3 bevelVec = getBevelVec(contour[i], contour[j], contour[k]);
                contourMovements.Add(bevelVec);
                //contourMovements[ i ] = bevelVec;
            }

            List <List <Vector3> > holesMovements = new List <List <Vector3> >();
            List <Vector3>         oneHoleMovements;

            //verticesMovements = contourMovements.concat(); // TODO: Check /////////
            List <Vector3> verticesMovements = new List <Vector3>();

            verticesMovements.AddRange(contourMovements);               // COPY????

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

                oneHoleMovements = new List <Vector3>();

                for (int i = 0, il = ahole.Count, j = il - 1, k = i + 1; i < il; i++, j++, k++)
                {
                    if (j == il)
                    {
                        j = 0;
                    }
                    if (k == il)
                    {
                        k = 0;
                    }

                    //  (j)---(i)---(k)
                    //oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
                    Vector3 bevelVec = getBevelVec(ahole[i], ahole[j], ahole[k]);
                    oneHoleMovements.Add(bevelVec);
                }

                holesMovements.Add(oneHoleMovements);
                verticesMovements.AddRange(oneHoleMovements);
            }

            // Loop bevelSegments, 1 for the front, 1 for the back
            for (int b = 0; b < bevelSegments; b++)
            {
                t = (float)b / bevelSegments;
                z = bevelThickness * (1 - t);

                bs = bevelSize * (Mathf.Sin(t * Mathf.PI / 2));                     // curved

                // contract shape
                for (int i = 0, il = contour.Count; i < il; i++)
                {
                    vert = scalePt2(contour[i], contourMovements[i], bs);

                    addVertex(vert.x, vert.y, -z);
                }

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

                    for (int i = 0, il = ahole.Count; i < il; i++)
                    {
                        vert = scalePt2(ahole[i], oneHoleMovements[i], bs);

                        addVertex(vert.x, vert.y, -z);
                    }
                }
            }

            bs = bevelSize;

            // Back facing vertices
            for (int i = 0; i < vlen; i++)
            {
                vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];

                if (!extrudeByPath)
                {
                    addVertex(vert.x, vert.y, 0);
                }
                else
                {
                    normal   = splineTube.normals[0] * (vert.x);
                    binormal = splineTube.binormals[0] * (vert.y);

                    position2 = (extrudePts[0]) + (normal) + (binormal);

                    addVertex(position2.x, position2.y, position2.z);
                }
            }

            // Add stepped vertices...
            // Including front facing vertices

            for (int s = 1; s <= steps; s++)
            {
                for (int i = 0; i < vlen; i++)
                {
                    vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];

                    if (!extrudeByPath)
                    {
                        addVertex(vert.x, vert.y, (float)amount / steps * s);
                    }
                    else
                    {
                        normal    = splineTube.normals[s] * (vert.x);
                        binormal  = (splineTube.binormals[s]) * (vert.y);
                        position2 = (extrudePts[s]) + (normal) + (binormal);

                        addVertex(position2.x, position2.y, position2.z);
                    }
                }
            }


            // Add bevel segments planes
            for (int b = bevelSegments - 1; b >= 0; b--)
            {
                t  = (float)b / bevelSegments;
                z  = bevelThickness * (1.0f - t);
                bs = bevelSize * Mathf.Sin(t * Mathf.PI / 2.0f);

                // contract shape
                for (int i = 0, il = contour.Count; i < il; i++)
                {
                    vert = scalePt2(contour[i], contourMovements[i], bs);
                    addVertex(vert.x, vert.y, (float)amount + z);
                }

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

                    for (int i = 0, il = ahole.Count; i < il; i++)
                    {
                        vert = scalePt2(ahole[i], oneHoleMovements[i], bs);

                        if (!extrudeByPath)
                        {
                            addVertex(vert.x, vert.y, (float)amount + z);
                        }
                        else
                        {
                            addVertex(vert.x, vert.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + z);
                        }
                    }
                }
            }


            /* Faces */
            faceIndex = 0;
            // Top and bottom faces
            if (!isClosePath)
            {
                buildLidFaces(vlen, faces, flen, steps, bevelSegments, bevelEnabled, shapesOffset, shape, uvgen, options, reverse);
            }
            // Sides faces
            buildSideFaces(vlen, contour, holes, steps, bevelSegments, shapesOffset, uvgen, shape, options, isClosePath, reverse);
        }
Ejemplo n.º 6
0
 public void UpdateShape(ShapeAndHoleObject shapePoints, Option options)
 {
     vertIndex = 0;
     addShape(shapePoints, options);
 }
Ejemplo n.º 7
0
        void addShape(Shape shape, Option options)
        {
            ShapeAndHoleObject shapePoints = GetShapeAndHoleObject(shape, options);

            addShape(shapePoints, options);
        }
Ejemplo n.º 8
0
 public ExtrudeGeometry(ShapeAndHoleObject shapeAndHole, Option options)
 {
     this.addShape(shapeAndHole, options);
 }