// GENERATE FREE_CURVE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { parametricObject.transMatrix = Matrix4x4.TRS(new Vector3(transX, transY, 0), Quaternion.Euler(0, 0, rotZ), new Vector3(1, 1, 1)); //Debug.Log ("IntPoint = " + parametricObject.ip.X + " --- " + parametricObject.TestInt); if (P_Output != null && parametricObject.curve != null) { //Curve transformedCurve = parametricObject.getTransformedCurve(); //Output.spline = Archimatix.curve2Spline (transformedCurve); // ControlPaths P_Output.controlPaths = new Paths(); // not to be altered in base postprocessing for offset and wallthick // use the "curve" to generate the source path // bezier experiment // EACH SEGMENT Path path = new Path(); for (int i = 0; i <= parametricObject.curve.Count - 1; i++) { if (i == parametricObject.curve.Count - 1 && P_Output.shapeState == ShapeState.Open) { break; } CurvePoint a = parametricObject.curve[i]; int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1; CurvePoint b = parametricObject.curve[next_i]; if (a.isPoint() && b.isPoint()) { if (i == 0) { path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(a.position)); } path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(b.position)); } else { int governor = 0; for (float t = 0; t <= (1 + .9f * timetick); t = t + timetick) { if (governor++ > 50) { Debug.Log("governor hit)"); break; } if (i == 0 || t > 0) { Vector2 pt = bezierValue(parametricObject.curve[i], parametricObject.curve[next_i], t); path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(pt)); } } } } /* * if (P_Output.shapeState == ShapeState.Closed && (parametricObject.curve[0] || parametricObject.curve[parametricObject.curve.Count-1].isBezierPoint())) * { * // draw last Bezier curve * * * } */ // path = Clipper.CleanPolygon(path, .01f); // if (path != null) // { // if (! Clipper.Orientation(path)) // path.Reverse(); // // } P_Output.controlPaths.Add(path); P_Output.transformedControlPaths = P_Output.getTransformedControlPaths(); P_Output.paths = P_Output.getTransformedControlPaths(); // may be altered before generate is over... P_Output.polyTree = null; base.generate(false, initiator_po, isReplica); } else { Debug.Log("no path"); } base.generate(false, initiator_po, isReplica); calculateBounds(); return(null); }
// SHAPE :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (inputSrc_p == null) { return(null); } P_Input.polyTree = null; AXShape.thickenAndOffset(ref P_Input, inputSrc_p); P_Output.polyTree = null; AXShape.thickenAndOffset(ref P_Output, P_Input); // now take the output and segment it.... Paths subjPaths = null; if (P_Output.polyTree != null) { subjPaths = Clipper.PolyTreeToPaths(P_Output.polyTree); P_Output.polyTree = null; } else { subjPaths = P_Output.getPaths(); } Path src_path = subjPaths[0]; Paths segmentedPaths = new Paths(); float y0 = 0; float height = parametricObject.floatValue("height"); int segs = parametricObject.intValue("segments"); float segHgt = height / segs; float zone_y; // int zoneCursor = 0; // begin the first zone path (or segment) Path zonePath = new Path(); zonePath.Add(src_path[0]); // loop through segments in path for (int v = 0; v < (src_path.Count - 1); v++) { Debug.Log("v=" + v); IntPoint thisVert = src_path[v]; IntPoint nextVert = src_path[v + 1]; float slope = 0; if (nextVert.Y - thisVert.Y != 0) { slope = (0.0f + (nextVert.X - thisVert.X)) / (0.0f + (nextVert.Y - thisVert.Y)); } // do these y's cross over a segment line? for (int zone = zoneCursor; zone < segs; zone++) { zone_y = (y0 + zone * segHgt) * AXGeometryTools.Utilities.IntPointPrecision; Debug.Log("zone=" + zone + ", zone_y=" + zone_y + ",y0= " + y0 + ", segHgt=" + segHgt + ", segs=" + segs); if (thisVert.Y < zone_y && nextVert.Y > zone_y) { // we have a crossover float newX = (zone_y - thisVert.Y) * slope + thisVert.X; // make a new point IntPoint segPt = new IntPoint(newX, zone_y); zonePath.Add(segPt); segmentedPaths.Add(zonePath); zonePath = new Path(); zonePath.Add(segPt); //no need to look at zone less than this again } } // Now add the upper vert... zonePath.Add(nextVert); } segmentedPaths.Add(zonePath); Debug.Log("segmentedPaths: " + segmentedPaths.Count); P_Output.paths = segmentedPaths; return(null); }