// SHAPE_DISTRIBUTER :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (P_Input == null || P_Input.DependsOn == null) { return(null); } P_Input.polyTree = null; AXShape.thickenAndOffset(ref P_Input, P_Input.DependsOn); if (P_Output == null) { return(null); } P_Output.polyTree = null; AXShape.thickenAndOffset(ref P_Output, P_Input); deriveStatsETC(P_Output); //base.generate(false, initiator_po, isReplica); calculateBounds(); return(null); }
public void carveTerrain() { Terrain terrain = parametricObject.terrain; if (terrain != null) { if (parametricObject.heightsOrig == null) { memorizeTerrain(); } // BOUNDING_SHAPE if (P_Plan != null && P_Plan.DependsOn != null) { if (planSrc_po != null) { AXShape.thickenAndOffset(ref P_Plan, planSrc_p); // now boundin_p has offset and thickened polytree or paths. } } int hmWidth = terrain.terrainData.heightmapWidth; int hmHeight = terrain.terrainData.heightmapHeight; float[,] heights = new float[hmWidth, hmHeight]; // we set each sample of the terrain in the size to the desired height for (int i = 0; i < hmWidth; i++) { for (int j = 0; j < hmHeight; j++) { // GET i, j in realworld coords float x = terrain.terrainData.size.x * i / hmWidth; float y = terrain.terrainData.size.z * j / hmHeight; if (isInside(y, x)) { //Debug.Log(x+", "+y); heights [i, j] = h; } else { heights [i, j] = parametricObject.heightsOrig[i, j]; } //print(heights[i,j]); } } // set the new height terrain.terrainData.SetHeights(0, 0, heights); } }
public void connect(AXParametricObject po) { AXShape shp = getInputShape(); if (po.is2D ()) { AXParameter out_p = po.generator.getPreferredOutputParameter (); if (out_p != null) shp.addInput().makeDependentOn(out_p); po.intValue ("Axis", parametricObject.intValue ("Axis")); } }
// SHAPE_OFFSETTER :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (P_Input == null || inputSrc_p == null) { return(null); } // PRE_GENERATE preGenerate(); P_Input.polyTree = null; AXShape.thickenAndOffset(ref P_Input, inputSrc_p); if (P_Output == null) { return(null); } P_Output.polyTree = null; //Debug.Log("thickness="+thickness+", offset=" + offset); AXShape.thickenAndOffset(ref P_Output, P_Input); //if (P_Output.polyTree != null) //Debug.Log(" P_Output.polyTree 1="+ Clipper.PolyTreeToPaths(P_Output.polyTree).Count); if (P_Output.polyTree != null) { transformPolyTree(P_Output.polyTree, localMatrix); } else if (P_Output.paths != null) { P_Output.paths = transformPaths(P_Output.paths, localMatrix); P_Output.transformedControlPaths = P_Output.paths; } calculateBounds(); return(null); }
public override void drawControlHandlesofInputParametricObjects(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer) { AXShape inputShape = (parametricObject.generator as ShapeMerger).S_InputShape; if (inputShape == null) { return; } for (int i = 0; i < inputShape.inputs.Count; i++) { AXParameter src = inputShape.inputs[i].DependsOn; if (src == null) { continue; } AXParametricObject srcPO = src.Parent; GeneratorHandler src_gh = getGeneratorHandler(srcPO); if (src_gh != null) { if (srcPO.generator is ShapeMerger) { src_gh.drawControlHandlesofInputParametricObjects(ref visited, consumerM, true); } else { src_gh.drawTransformHandles(visited, consumerM, false); src_gh.drawControlHandles(ref visited, consumerM, false); } } //else // gh.drawTransformHandles(visited, consumerM, true); } }
// GENERATE POLYGON public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { if (parametricObject == null || !parametricObject.isActive || planSrc_po == null) { return(null); } //Debug.Log ("===> [" + parametricObject.Name + "] EXTRUDE generate ... MAKE_GAME_OBJECTS="+makeGameObjects); // RESULTING MESHES ax_meshes = new List <AXMesh>(); preGenerate(); P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); GameObject retGO = generateFirstPass(initiator_po, makeGameObjects, P_Plan, null, Matrix4x4.identity, renderToOutputParameter); // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); // FINISH BOUNDING setBoundaryFromAXMeshes(ax_meshes); return(retGO); }
public override void drawControlHandles(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer) { if (alreadyVisited(ref visited, "ShapeMergerHandler")) { return; } Matrix4x4 prevHandlesMatrix = Handles.matrix; if (parametricObject.model.isSelected(parametricObject)) { base.drawControlHandles(ref visited, consumerM, beingDrawnFromConsumer); } // MATRIX drawControlHandlesofInputParametricObjects(ref visited, generator.parametricObject.worldDisplayMatrix, true); // DRAW THE FINAL MERGED SHAPE AXShape inputShape = (parametricObject.generator as ShapeMerger).S_InputShape; AXParameter out_p = inputShape.getSelectedOutputParameter(); Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * generator.localMatrix.inverse; Color mergeShapeColor = Color.cyan; mergeShapeColor.a *= .75f; Handles.color = mergeShapeColor; drawPaths(out_p); Handles.matrix = prevHandlesMatrix; }
// GENERATE PLAN_SWEEP public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { if (parametricObject == null || !parametricObject.isActive) { return(null); } //Debug.Log("PlanSweep::generate()"); // RESULTING MESHES ax_meshes = new List <AXMesh>(); preGenerate(); // PLAN // The plan may have multiple paths. Each may generate a separate GO. if (P_Plan == null) { return(null); } planSrc_p = getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; if (planSrc_p == null || !planSrc_p.parametricObject.isActive) { return(null); } P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); // SECTION // The plan may have multiple paths. Each may generate a separate GO. if (P_Section == null) { return(null); } sectionSrc_p = getUpstreamSourceParameter(P_Section); sectionSrc_po = (sectionSrc_p != null) ? sectionSrc_p.parametricObject : null; if (sectionSrc_p == null || !sectionSrc_p.parametricObject.isActive) { return(null); } P_Section.polyTree = null; if (lipTop > 0 && P_Section.shapeState == ShapeState.Open && sectionSrc_p.paths != null && sectionSrc_p.paths.Count == 1) { P_Section.paths = new Paths(); Path path = new Path(); foreach (IntPoint ip in sectionSrc_p.paths[0]) { path.Add(new IntPoint(ip.X, ip.Y)); } if (lipBottom > 0) { path.Insert(0, new IntPoint((path[0].X - lipBottom * AXGeometryTools.Utilities.IntPointPrecision), path[0].Y)); if (lipEdge > 0) { path.Insert(0, new IntPoint(path[0].X, (path[0].Y + lipEdge * AXGeometryTools.Utilities.IntPointPrecision))); } } if (lipTop > 0) { path.Add(new IntPoint((path[path.Count - 1].X - lipTop * AXGeometryTools.Utilities.IntPointPrecision), path[path.Count - 1].Y)); if (lipEdge > 0) { path.Add(new IntPoint((path[path.Count - 1].X), (path[path.Count - 1].Y - lipEdge * AXGeometryTools.Utilities.IntPointPrecision))); } } P_Section.paths.Add(path); } else { AXShape.thickenAndOffset(ref P_Section, sectionSrc_p); } //StopWatch sw = new StopWatch(); GameObject retGO = generateFirstPass(initiator_po, makeGameObjects, P_Plan, P_Section, Matrix4x4.identity, renderToOutputParameter); //Debug.Log("PlanSweep ============= Done: " + sw.duration()); // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); // FINISH BOUNDING setBoundaryFromAXMeshes(ax_meshes); //adjustWorldMatrices(); return(retGO); }
// SHAPE_REPEATER_2D :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if ((P_Node == null || inputSrc_p == null) && (P_Cell == null || cellSrc_p == null)) { if (P_Output != null) { P_Output.paths = null; P_Output.polyTree = null; } return(null); } if (repeaterToolU == null || repeaterToolV == null) { return(null); } // PRE_GENERATE preGenerate(); AXParameter P_nodeOutput = new AXParameter(); P_nodeOutput.parametricObject = parametricObject; AXParameter P_cellOutput = new AXParameter(); P_cellOutput.parametricObject = parametricObject; // PROCESS NODE INPUT if (inputSrc_p != null) { P_Node.polyTree = null; AXShape.thickenAndOffset(ref P_Node, inputSrc_p); //P_nodeOutput.polyTree = null; //AXShape.thickenAndOffset(ref P_nodeOutput, P_Node); } if (cellSrc_p != null) { P_Cell.polyTree = null; AXShape.thickenAndOffset(ref P_Cell, cellSrc_p); //P_cellOutput.polyTree = null; //AXShape.thickenAndOffset(ref P_cellOutput, P_Cell); } bool doPolyTreeNodes = false; bool doPolyTreeCells = false; // NODE Matrix4x4 tm = Matrix4x4.identity; Paths tmpPaths = null; Clipper clipper = null; if (nodeSrc_p != null) { if (P_Node.polyTree != null) { tmpPaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Node.polyTree)); doPolyTreeNodes = true; clipper = new Clipper(); } else { tmpPaths = P_Node.getClonePaths(); P_nodeOutput.paths = new Paths(); } //Debug.Log("tmpPaths="+tmpPaths.Count); if (tmpPaths != null && tmpPaths.Count > 0) { for (int i = 0; i <= repeaterToolU.cells; i++) { for (int j = 0; j <= repeaterToolV.cells; j++) { if ((i <= repeaterToolU.edgeCount || i >= repeaterToolU.cells - repeaterToolU.edgeCount) || (j <= repeaterToolV.edgeCount || j >= repeaterToolV.cells - repeaterToolV.edgeCount)) { //tm = Matrix4x4.TRS(new Vector3(2*i-2, 2*j-2, 0), Quaternion.identity, Vector3.one); tm = localMatrixFromAddress(RepeaterItem.Node, i, j); if (doPolyTreeNodes) { clipper.AddPaths(AX.Generators.Generator2D.transformPaths(tmpPaths, tm), PolyType.ptSubject, true); } else { Paths tmp = AX.Generators.Generator2D.transformPaths(tmpPaths, tm); P_nodeOutput.paths.AddRange(tmp); } } } } if (doPolyTreeNodes) { P_nodeOutput.polyTree = new AXClipperLib.PolyTree(); clipper.Execute(ClipType.ctDifference, P_nodeOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero); } } } // CELL // PROCESS CELL INPUT if (cellSrc_p != null) { if (P_Cell.polyTree != null) { tmpPaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Cell.polyTree)); doPolyTreeCells = true; clipper = new Clipper(); } else { tmpPaths = P_Cell.getClonePaths(); P_cellOutput.paths = new Paths(); } if (tmpPaths != null && tmpPaths.Count > 0) { for (int i = 0; i < repeaterToolU.cells; i++) { for (int j = 0; j < repeaterToolV.cells; j++) { tm = localMatrixFromAddress(RepeaterItem.Cell, i, j); if (doPolyTreeCells) { clipper.AddPaths(AX.Generators.Generator2D.transformPaths(tmpPaths, tm), PolyType.ptSubject, true); } else { Paths tmp = AX.Generators.Generator2D.transformPaths(tmpPaths, tm); P_cellOutput.paths.AddRange(tmp); } } } if (doPolyTreeCells) { P_cellOutput.polyTree = new AXClipperLib.PolyTree(); clipper.Execute(ClipType.ctDifference, P_cellOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero); } } } /* * if ( P_Output.polyTree != null) * { * transformPolyTree(P_Output.polyTree, localMatrix); * } * else if (P_Output.paths != null) * { * P_Output.paths = transformPaths(P_Output.paths, localMatrix); * P_Output.transformedControlPaths = P_Output.paths; * } */ P_Output.polyTree = null; if (nodeSrc_p != null && cellSrc_p == null) { // JUST NODES AXShape.thickenAndOffset(ref P_Output, P_nodeOutput); } else if (nodeSrc_p == null && cellSrc_p != null) { // JUST CELLS AXShape.thickenAndOffset(ref P_Output, P_cellOutput); } else { // BOTH TO COMBINE clipper = new Clipper(); if (P_nodeOutput.polyTree == null) { clipper.AddPaths(P_nodeOutput.paths, PolyType.ptSubject, true); } else { clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_nodeOutput.polyTree)), PolyType.ptSubject, true); } if (P_cellOutput.polyTree == null) { clipper.AddPaths(P_cellOutput.paths, PolyType.ptSubject, true); } else { clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_cellOutput.polyTree)), PolyType.ptSubject, true); } P_Output.polyTree = new AXClipperLib.PolyTree(); clipper.Execute(ClipType.ctUnion, P_Output.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero); AXShape.thickenAndOffset(ref P_Output, P_Output); } if (P_Output.polyTree != null) { transformPolyTree(P_Output.polyTree, localMatrix); } else if (P_nodeOutput.paths != null) { P_Output.paths = transformPaths(P_nodeOutput.paths, localMatrix); P_Output.transformedControlPaths = P_nodeOutput.paths; } else if (P_cellOutput.paths != null) { P_Output.paths = transformPaths(P_cellOutput.paths, localMatrix); P_Output.transformedControlPaths = P_cellOutput.paths; } //base.generate(false, initiator_po, isReplica); calculateBounds(); return(null); } // \generate
/* * public override void initializeBays(string pName) * { * if (parametricObject.isInitialized) * return; * * parametricObject.isInitialized = true; * * RadialRepeaterTool gener = repeaterToolU as RadialRepeaterTool; * * switch(pName) * { * case "Node Shape": * if (repeaterToolU != null) * gener.radius = 3.5f * nodeSrc_p.parametricObject.bounds.size.x ; * break; * case "Cell Shape": * if (repeaterToolU != null) * gener.radius = 2.5f * cellSrc_p.parametricObject.bounds.size.x ; * break; * } * } */ // SHAPE_REPEATER_2D :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (parametricObject == null || !parametricObject.isActive) { return(null); } if ((P_Corner == null || cornerSrc_p == null) && (P_Node == null || inputSrc_p == null) && (P_Cell == null || cellSrc_p == null)) { if (P_Output != null) { P_Output.paths = null; P_Output.polyTree = null; } return(null); } // PRE_GENERATE preGenerate(); planSrc_p = P_Plan.DependsOn; // getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); if (P_Plan.reverse) { P_Plan.doReverse(); } planPaths = P_Plan.getPaths(); if (planPaths == null || planPaths.Count == 0) { return(null); } // ** CREATE PLAN_SPLINES ** if (planPaths != null && planPaths.Count > 0) { planSplines = new Spline[planPaths.Count]; if (planSplines != null) { for (int i = 0; i < planSplines.Length; i++) { planSplines[i] = new Spline(planPaths[i], (P_Plan.shapeState == ShapeState.Closed) ? true : false); } } } AXParameter P_cornerOutput = new AXParameter(); P_cornerOutput.parametricObject = parametricObject; AXParameter P_nodeOutput = new AXParameter(); P_nodeOutput.parametricObject = parametricObject; AXParameter P_cellOutput = new AXParameter(); P_cellOutput.parametricObject = parametricObject; // PROCESS SHAPE INPUTS if (cornerSrc_p != null) { P_Corner.polyTree = null; AXShape.thickenAndOffset(ref P_Corner, cornerSrc_p); } if (inputSrc_p != null) { P_Node.polyTree = null; AXShape.thickenAndOffset(ref P_Node, inputSrc_p); } if (cellSrc_p != null) { P_Cell.polyTree = null; AXShape.thickenAndOffset(ref P_Cell, cellSrc_p); } bool doPolyTreeNodes = false; //bool doPolyTreeCells = false; // NODE //Matrix4x4 tm = Matrix4x4.identity; // NODE SHAPES Paths nodeSourcePaths = null; //Clipper nodeClipper = null; if (P_Node != null) { if (P_Node.polyTree != null) { nodeSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Node.polyTree)); doPolyTreeNodes = true; //nodeClipper = new Clipper(); } else { nodeSourcePaths = P_Node.getClonePaths(); P_nodeOutput.paths = new Paths(); } } // CELL SHAPES Paths cellSourcePaths = null; //Clipper cellClipper = null; if (P_Cell != null) { if (P_Cell.polyTree != null) { cellSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Cell.polyTree)); doPolyTreeNodes = true; //cellClipper = new Clipper(); } else { cellSourcePaths = P_Cell.getClonePaths(); P_cornerOutput.paths = new Paths(); } } // BREAK CORNER SHAPES Paths cornerSourcePaths = null; Clipper cornerClipper = null; if (P_Corner != null) { if (P_Corner.polyTree != null) { cornerSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Corner.polyTree)); doPolyTreeNodes = true; cornerClipper = new Clipper(); } else { cornerSourcePaths = P_Corner.getClonePaths(); P_cornerOutput.paths = new Paths(); } } // FOR EACH PATH for (int path_i = 0; path_i < planPaths.Count; path_i++) { // **** PREPARE EACH SPLINE *** // Spline planSpline = planSplines[path_i]; planSpline.breakAngleCorners = cornerBreakAngle; planSpline.shapeState = P_Plan.shapeState; // Create subsplines between each break point planSpline.getSmoothSubsplineIndicies(0, maxSegmentLength); // Debug.Log("planSpline.subsplines.Count="+ planSpline.subsplines.Count ); // foreach(SubsplineIndices si in planSpline.subsplines) // si.print(); planSpline.groupNearBreakAngleVertices(inset * 2); // **** PREPARE EACH SPLINE *** // Matrix4x4 localPlacement_mx = Matrix4x4.identity; if (planSpline.insetSpanSplines != null && planSpline.insetSpanSplines.Count > 0) { for (int si = 0; si < planSpline.insetSpanSplines.Count; si++) { planSpline.insetSpanSplines[si].setRepeaterTransforms(si, inset, bay); } // SPAN NODES - SHAPES ALONG SUBSPLINES if (nodeSrc_p != null && nodeSrc_p.meshes != null) { int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count; for (int i = 0; i < endCount; i++) { //SubsplineIndices rsi = planSpline.subsplines[i]; Spline spanSpline = planSpline.insetSpanSplines[i]; List <Matrix4x4> nodeMatrices = spanSpline.repeaterNodeTransforms; // on each of these nodes, place a nodePlug instance. bool spanNodesAtBreakCorners = true; int starter = spanNodesAtBreakCorners ? 0 : 1; int ender = (inset > 0 || spanNodesAtBreakCorners) ? nodeMatrices.Count : nodeMatrices.Count - 1; //string this_address = ""; if (nodeMatrices != null) { for (int ii = starter; ii < ender; ii++) { //this_address = "node_"+path_i+"_"+i+"_"+ii; //Debug.Log("this_address="+this_address); // LOCAL_PLACEMENT localPlacement_mx = localMatrixFromAddress(RepeaterItem.Node, path_i, i, ii); if (doPolyTreeNodes) { cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx), PolyType.ptSubject, true); } else { Paths tmp = AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx); P_cornerOutput.paths.AddRange(tmp); } } } } } // CELL NODES - SHAPES ALONG SUBSPLINES if (cellSrc_p != null && cellSrc_p.meshes != null) { int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count; for (int i = 0; i < endCount; i++) { //SubsplineIndices rsi = planSpline.subsplines[i]; Spline spanSpline = planSpline.insetSpanSplines[i]; List <Matrix4x4> cellMatrices = spanSpline.repeaterCellTransforms; // on each of these nodes, place a nodePlug instance. bool spanNodesAtBreakCorners = true; int starter = spanNodesAtBreakCorners ? 0 : 1; int ender = (inset > 0 || spanNodesAtBreakCorners) ? cellMatrices.Count : cellMatrices.Count - 1; //string this_address = ""; if (cellMatrices != null) { for (int ii = starter; ii < ender; ii++) { //this_address = "cell_"+path_i+"_"+i+"_"+ii; //Debug.Log("this_address="+this_address); // LOCAL_PLACEMENT localPlacement_mx = localMatrixFromAddress(RepeaterItem.Cell, path_i, i, ii); if (doPolyTreeNodes) { cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(cellSourcePaths, localPlacement_mx), PolyType.ptSubject, true); } else { Paths tmp = AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx); P_cornerOutput.paths.AddRange(tmp); } } } } } } if (cornerSourcePaths != null && cornerSourcePaths.Count > 0) { // CORNERS for (int bi = 0; bi < planSpline.breakIndices.Count; bi++) { //tm = Matrix4x4.TRS(new Vector3(2*i-2, 2*j-2, 0), Quaternion.identity, Vector3.one); localPlacement_mx = localMatrixFromAddress(RepeaterItem.Corner, path_i, planSpline.breakIndices[bi]); if (doPolyTreeNodes) { cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(cornerSourcePaths, localPlacement_mx), PolyType.ptSubject, true); } else { Paths tmp = AX.Generators.Generator2D.transformPaths(cornerSourcePaths, localPlacement_mx); P_cornerOutput.paths.AddRange(tmp); } } } if (doPolyTreeNodes) { P_cornerOutput.polyTree = new AXClipperLib.PolyTree(); cornerClipper.Execute(ClipType.ctDifference, P_cornerOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero); } } P_Output.polyTree = null; if (cornerSrc_p != null || cellSrc_p == null || nodeSrc_p == null) { // JUST NODES AXShape.thickenAndOffset(ref P_Output, P_cornerOutput); } /* * else if (nodeSrc_p != null && (cellSrc_p == null || (P_cellOutput.paths == null && P_cellOutput.polyTree == null))) * { * // JUST NODES * AXShape.thickenAndOffset(ref P_Output, P_nodeOutput); * } * * else if (nodeSrc_p == null && cellSrc_p != null) * { * // JUST CELLS * AXShape.thickenAndOffset(ref P_Output, P_cellOutput); * } * else * { * // BOTH TO COMBINE * clipper = new Clipper(); * * if (P_nodeOutput.polyTree == null) * clipper.AddPaths(P_nodeOutput.paths, PolyType.ptSubject, true); * else * clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_nodeOutput.polyTree)), PolyType.ptSubject, true); * * if (P_cellOutput.polyTree == null) * clipper.AddPaths(P_cellOutput.paths, PolyType.ptSubject, true); * else * clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_cellOutput.polyTree)), PolyType.ptSubject, true); * * * P_Output.polyTree = new AXClipperLib.PolyTree(); * clipper.Execute(ClipType.ctUnion, P_Output.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero); * * AXShape.thickenAndOffset(ref P_Output, P_Output); * } */ if (P_Output.polyTree != null) { transformPolyTree(P_Output.polyTree, localMatrix); } else if (P_nodeOutput.paths != null) { P_Output.paths = transformPaths(P_nodeOutput.paths, localMatrix); P_Output.transformedControlPaths = P_nodeOutput.paths; } //base.generate(false, initiator_po, isReplica); calculateBounds(); return(null); } // \generate
} // OnGUI public static int displayOutput(Rect pRect, AXNodeGraphEditorWindow editor, AXShape shp) { float cur_x = ArchimatixUtils.cur_x; //float box_x = cur_x + ArchimatixUtils.indent; float box_w = ArchimatixUtils.paletteRect.width - cur_x - 3 * ArchimatixUtils.indent; int x1 = (int)pRect.x - ArchimatixUtils.indent; int cur_y = (int)pRect.y; int width = (int)pRect.width; int lineHgt = ArchimatixUtils.lineHgt; int gap = 5; Rect boxRect = pRect; boxRect = new Rect(cur_x + ArchimatixUtils.indent, cur_y, box_w, ArchimatixUtils.lineHgt); Rect lRect = new Rect(x1 + 11, cur_y, 50, lineHgt); Rect bRect = boxRect; lRect.y = cur_y; //cur_y += lineHgt; ArchimatixUtils.cur_x += ArchimatixUtils.indent; bool tmp_boolval; bRect.x = ArchimatixUtils.indent * 3 + 4; //width-lineHgt; // difference shp.difference.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.difference.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; lRect.y = cur_y; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.difference); tmp_boolval = (shp.combineType == AXShape.CombineType.Difference); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.Difference; shp.parametricObject.model.generate(); } // difference shp.differenceRail.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.differenceRail.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.differenceRail); tmp_boolval = (shp.combineType == AXShape.CombineType.DifferenceRail); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.DifferenceRail; shp.parametricObject.model.generate(); } cur_y += gap; // INTERSECTION shp.intersection.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.intersection.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.intersection); tmp_boolval = (shp.combineType == AXShape.CombineType.Intersection); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.Intersection; shp.parametricObject.model.generate(); } // INTERSECTION_RAIL shp.intersectionRail.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.intersectionRail.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.intersectionRail); tmp_boolval = (shp.combineType == AXShape.CombineType.IntersectionRail); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.IntersectionRail; shp.parametricObject.model.generate(); } cur_y += gap; // union shp.union.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.union.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.union); tmp_boolval = (shp.combineType == AXShape.CombineType.Union); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.Union; shp.parametricObject.model.generate(); } cur_y += gap; // grouped if (shp.grouped == null || shp.grouped.Type == AXParameter.DataType.Float) { shp.grouped = shp.createSplineParameter(AXParameter.ParameterType.Output, "Grouped"); } shp.grouped.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); shp.grouped.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); bRect.y = cur_y - 1; cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.grouped); tmp_boolval = (shp.combineType == AXShape.CombineType.Grouped); EditorGUI.BeginChangeCheck(); tmp_boolval = EditorGUI.Toggle(bRect, "", tmp_boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(shp.Parent.model, "value change for combineType"); shp.combineType = AXShape.CombineType.Grouped; shp.parametricObject.model.generate(); } ArchimatixUtils.cur_x -= ArchimatixUtils.indent; //Archimatix.cur_x -= Archimatix.indent; cur_y += lineHgt * 2; return(cur_y); }
// 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); }
// GENERATE PLAN_REPEATER public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { if (parametricObject == null || !parametricObject.isActive) { return(null); } //Debug.Log("yo ******* makeGameObjects="+makeGameObjects); // RESULTING MESHES ax_meshes = new List <AXMesh>(); paths_SubsplineIndices = new List <SubsplineIndices[]>(); preGenerate(); planSrc_p = P_Plan.DependsOn; // getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; //Debug.Log("planSrc_po = " + planSrc_po.Name+"."+planSrc_p.Name + " ... " + planSrc_p.DependsOn.PType + " ..... " + planSrc_p.getPaths()); P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); if (P_Plan.reverse) { P_Plan.doReverse(); } planPaths = P_Plan.getPaths(); if (planPaths == null || planPaths.Count == 0) { return(null); } // ** CREATE PLAN_SPLINES ** if (planPaths != null && planPaths.Count > 0) { planSplines = new Spline[planPaths.Count]; if (planSplines != null) { for (int i = 0; i < planSplines.Length; i++) { planSplines[i] = new Spline(planPaths[i], (P_Plan.shapeState == ShapeState.Closed) ? true : false); } } } //Debug.Log("controlVertices="+ planSplines[0].controlVertices.Count); // CORNER_MESH GameObject cornerPlugGO = null; if (cornerSrc_p != null) { cornerSrc_po = cornerSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { cornerPlugGO = cornerSrc_po.generator.generate(true, initiator_po, renderToOutputParameter); } } // NODE_MESH GameObject nodePlugGO = null; if (nodeSrc_p != null) { nodeSrc_po = nodeSrc_p.parametricObject; //Debug.Log("yo makeGameObjects="+makeGameObjects+", parametricObject.combineMeshes="+parametricObject.combineMeshes); if (makeGameObjects && !parametricObject.combineMeshes) { nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, renderToOutputParameter); } } // CELL_MESH GameObject cellPlugGO = null; if (cellSrc_p != null) { cellSrc_po = cellSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { cellPlugGO = cellSrc_po.generator.generate(true, initiator_po, renderToOutputParameter); } } // Plan // This is the main spline used for the iteration //AXParameter plan_p = ip.DependsOn; // The section spline is used to provide the connective tissue around corners // SECTION // The plan may have multiple paths. Each may generate a separate GO. sectionSrc_p = P_Section.DependsOn; //getUpstreamSourceParameter(P_Section); sectionSrc_po = (sectionSrc_p != null) ? sectionSrc_p.parametricObject : null; if (sectionSrc_po != null) { P_Section.polyTree = null; AXShape.thickenAndOffset(ref P_Section, sectionSrc_p); if (P_Section.reverse) { P_Section.doReverse(); } } float bay_U = parametricObject.floatValue("bay_U"); float bay_V = parametricObject.floatValue("bay_V"); if (bay_U == 0) { bay_U = .1f; } if (bay_V == 0) { bay_V = 10f; } float margin_U = parametricObject.floatValue("margin_U"); Vector2 prevV = new Vector2(); //Vector3 scaler1 = Vector3.one; //float margin = 2.5f; Vector2 firstPM = new Vector2(); Vector2 prevVM = new Vector2(); AXSpline secSpline = null; AXSplineExtrudeGenerator tmpEXSP = null; if (sectionSrc_p != null && sectionSrc_p.spline != null && sectionSrc_p.spline.vertCount > 0) { secSpline = sectionSrc_p.spline; } tmpEXSP = new AXSplineExtrudeGenerator(); Material tmp_mat = parametricObject.axMat.mat; if (parametricObject.axTex != null) { tmpEXSP.uScale = parametricObject.axTex.scale.x; tmpEXSP.vScale = parametricObject.axTex.scale.y; tmpEXSP.uShift = -parametricObject.axTex.shift.x; tmpEXSP.vShift = parametricObject.axTex.shift.y; } float runningU = 0; //ip.spline.getAnglesArray(); //Spline sectionSpline = null; // = new Spline(sectionPath, sectionIsClosed, sec_p.breakGeom, sec_p.breakNorm); GameObject go = null; GameObject planGO = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } // BOUNDING List <AXMesh> boundingMeshes = new List <AXMesh>(); // FOR EACH PATH for (int path_i = 0; path_i < planPaths.Count; path_i++) { if (makeGameObjects && !parametricObject.combineMeshes) { planGO = ArchimatixUtils.createAXGameObject(parametricObject.Name + "_" + path_i, parametricObject); } // **** PREPARE EACH SPLINE *** // Spline planSpline = planSplines[path_i]; planSpline.breakAngleCorners = cornerBreakAngle; planSpline.shapeState = P_Plan.shapeState; // Create subsplines between each break point planSpline.getSmoothSubsplineIndicies(0, maxSegmentLength); // ....... DEBUG //Pather.printPaths(planPaths); planSpline.groupNearBreakAngleVertices(inset * 2); if (planSpline.groupedCornerNodes == null || planSpline.groupedCornerNodes.Count == 0) { inset = 0; } // **** PREPARE EACH SPLINE *** // Matrix4x4 localPlacement_mx = Matrix4x4.identity; // INSET PLANSWEEPS GameObject plansweepGO = null; if (sectionSrc_p != null && inset > 0 && planSpline.insetSplines != null) { // convert planSpline.insetSplines to Paths Paths insetPaths = AXGeometryTools.Utilities.Splines2Paths(planSpline.insetSplines); AXParameter tmpPlanP = new AXParameter(); tmpPlanP.parametricObject = parametricObject; tmpPlanP.paths = insetPaths; tmpPlanP.Type = AXParameter.DataType.Shape; tmpPlanP.shapeState = ShapeState.Open; tmpPlanP.breakGeom = 0; if (planSpline.insetSplines.Count == 1) { tmpPlanP.shapeState = planSpline.insetSplines[0].shapeState; } topCap = false; botCap = false; plansweepGO = generateFirstPass(initiator_po, makeGameObjects, tmpPlanP, P_Section, Matrix4x4.identity, renderToOutputParameter, false); if (makeGameObjects && !parametricObject.combineMeshes && plansweepGO != null) { plansweepGO.transform.parent = go.transform; } } AXMesh tmpMesh = null; if (planSpline.insetSpanSplines != null && planSpline.insetSpanSplines.Count > 0) { //Debug.Log(".....????>> spanSpline.subsplines.Count="+ planSpline.insetSpanSplines.Count + " --- " + planSpline.subsplines.Count ); for (int si = 0; si < planSpline.insetSpanSplines.Count; si++) { planSpline.insetSpanSplines[si].setRepeaterTransforms(si, inset, bay); } // SPAN NODES - MESHES ALONG SUBSPLINES if (nodeSrc_p != null && nodeSrc_p.meshes != null) { //int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.subsplines.Count-1 : planSpline.subsplines.Count; int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count; for (int i = 0; i < endCount; i++) { //SubsplineIndices rsi = planSpline.subsplines[i]; Spline spanSpline = planSpline.insetSpanSplines[i]; //Debug.Log(i + "||||||||||> " + spanSpline.toString()); List <Matrix4x4> nodeMatrices = spanSpline.repeaterNodeTransforms; // on each of these nodes, place a nodePlug instance. bool spanNodesAtBreakCorners = true; int starter = (inset > 0 || spanNodesAtBreakCorners) ? 0 : 1; //Debug.Log("starter="+starter); int ender = (inset > 0 || spanSpline.shapeState == ShapeState.Open || planSpline.subsplines.Count == 1) ? nodeMatrices.Count : nodeMatrices.Count - 1; //Debug.Log("starter="+starter +", ender="+ender + ", nodeMatrices.Count=" + nodeMatrices.Count); //Debug.Log("(inset > 0 && spanNodesAtBreakCorners)="+(inset > 0 && spanNodesAtBreakCorners)+", nodeMatrices.Length="+nodeMatrices.Length+", starter="+starter+", ender="+ender); string this_address = ""; if (nodeMatrices != null) { for (int ii = starter; ii < ender; ii++) { this_address = "node_" + path_i + "_" + i + "_" + ii; //Debug.Log("this_address="+this_address); // LOCAL_PLACEMENT localPlacement_mx = localMatrixFromAddress(RepeaterItem.Node, path_i, i, ii); // AX_MESHES for (int mi = 0; mi < nodeSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = nodeSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(nodeSrc_po.boundsMesh, localPlacement_mx * nodeSrc_po.generator.localMatrix)); //Debug.Log("boundingMeshes: " + boundingMeshes.Count); // GAME_OBJECTS if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(nodePlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); Vector3 newJitterScale = jitterScale + Vector3.one; copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z); copyGO.transform.localScale += jitterScale; AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; //Debug.Log("ADD ADDRESS: " + this_address); } copyGO.name = copyGO.name + "_" + this_address; //Debug.Log("copyGO.name = "+copyGO.name); copyGO.transform.parent = planGO.transform; } } } } } // \NODE MESHES // CELL NODES - MESHES ALONG SUBSPLINES if (cellSrc_p != null && cellSrc_p.meshes != null) { //int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.subsplines.Count-1 : planSpline.subsplines.Count; int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ? planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count; for (int i = 0; i < endCount; i++) { //SubsplineIndices rsi = planSpline.subsplines[i]; Spline spanSpline = planSpline.insetSpanSplines[i]; spanSpline.setRepeaterTransforms(i, inset, bay); List <Matrix4x4> cellMatrices = spanSpline.repeaterCellTransforms; // on each of these cell, place a nodePlug instance. //bool spanNodesAtBreakCorners = true; int starter = 0; //spanNodesAtBreakCorners ? 0 : 1; //int ender = (inset > 0 || spanNodesAtBreakCorners) ? cellMatrices.Count : cellMatrices.Count-1; int ender = cellMatrices.Count; //Debug.Log("(inset > 0 && spanNodesAtBreakCorners)="+(inset > 0 && spanNodesAtBreakCorners)+", nodeMatrices.Length="+nodeMatrices.Length+", starter="+starter+", ender="+ender); string this_address = ""; if (cellMatrices != null) { for (int ii = starter; ii < ender; ii++) { // ADDRESS this_address = "cell_" + path_i + "_" + i + "_" + ii; // LOCAL_PLACEMENT localPlacement_mx = localMatrixFromAddress(RepeaterItem.Cell, path_i, i, ii); // AX_MESHES for (int mi = 0; mi < cellSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = cellSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(cellSrc_po.boundsMesh, localPlacement_mx * cellSrc_po.generator.localMatrix)); // GAME_OBJECTS if (cellPlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(cellPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); Vector3 newJitterScale = jitterScale + Vector3.one; copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z); copyGO.transform.localScale += jitterScale; AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; //Debug.Log("ADD ADDRESS: " + this_address); } copyGO.name = copyGO.name + "_"; // + this_address; //Debug.Log("copyGO.name = "+copyGO.name); copyGO.transform.parent = planGO.transform; } } } } } // \CELL MESHES } // \each spanSpline // BREAK CORNER MESHES if (cornerSrc_p != null && cornerSrc_p.meshes != null) { for (int bi = 0; bi < planSpline.breakIndices.Count; bi++) { // ADDRESS string this_address = "corner_" + path_i + "_" + planSpline.breakIndices[bi]; // LOCAL_PLACEMENT localPlacement_mx = localMatrixFromAddress(RepeaterItem.Corner, path_i, planSpline.breakIndices[bi]); // AX_MESHES for (int mi = 0; mi < cornerSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = cornerSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(cornerSrc_po.boundsMesh, localPlacement_mx * cornerSrc_po.generator.localMatrix)); // GAME_OBJECTS if (cornerPlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * cornerSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(cornerPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); Vector3 newJitterScale = jitterScale + Vector3.one; copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z); copyGO.transform.localScale += jitterScale; AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = planGO.transform; } } } /* * int cells = Mathf.CeilToInt( md/bay_U ); * int nby = Mathf.CeilToInt( height/bay_V ); * * //Debug.Log ("d="+d+", md="+md); * * float actual_bayx = md/cells; * float actual_bayy = height/nby; * * // CREATE VERSIONS OF INPUT BAY_CENTER MESH(ES) USING BOUNDING BOX * // ****************************************************************************** * // someting similar shoud be added to griditerator, stepiterator, and where else? * * // instead of prev, would be better to create a dictionary of bounds and AXMeshes? * if (bay_span_p != null && (prevActuralBayx != actual_bayx || prevActuralBayx != actual_bayy)) * { * // regnerate the input meshes using actual_bayx * bay_span_p.Parent.setParameterValueByName("uScale", parametricObject.floatValue("uScale")); * bay_span_p.Parent.setParameterValueByName("vScale", parametricObject.floatValue("vScale")); * bay_span_p.Parent.setParameterValueByName("uShift", parametricObject.floatValue("uShift")); * bay_span_p.Parent.setParameterValueByName("vShift", parametricObject.floatValue("vShift")); * * //bay_span_p.Parent.generateOutputNow (makeGameObjects, parametricObject, true);//, new Vector3(actual_bayx, actual_bayy, margin_th)); * * } * // ****************************************************************************** * * * // CREATE VERSIONS OF INPUT BAY_CENTER MESH(ES) USING BOUNDING BOX * // ****************************************************************************** * // someting similar shoud be added to griditerator, stepiterator, and where else? * * // instead of prev, would be better to create a dictionary of bounds and AXMeshes? * if (node_p != null && (prevActuralBayx != actual_bayx || prevActuralBayx != actual_bayy)) * { * // regnerate the input meshes using actual_bayx * node_p.Parent.setParameterValueByName("uScale", parametricObject.floatValue("uScale")); * node_p.Parent.setParameterValueByName("vScale", parametricObject.floatValue("vScale")); * node_p.Parent.setParameterValueByName("uShift", parametricObject.floatValue("uShift")); * node_p.Parent.setParameterValueByName("vShift", parametricObject.floatValue("vShift")); * * //node_p.Parent.generateOutputNow (makeGameObjects, parametricObject, true);//, new Vector3(actual_bayx, actual_bayy, margin_th)); * * } * // ****************************************************************************** */ //margin_U = .5f; if (margin_U > 0 && planSpline.isClosed) { AXSpline connSpline2 = new AXSpline(); connSpline2.Push(prevVM); connSpline2.Push(prevV); connSpline2.Push(firstPM); connSpline2.isClosed = false; tmpEXSP.uShift = parametricObject.floatValue("uShift") + (runningU) / tmpEXSP.uScale; Mesh mesh = tmpEXSP.generate(connSpline2, secSpline); ax_meshes.Add(new AXMesh(mesh, Matrix4x4.identity, tmp_mat)); } if (makeGameObjects && !parametricObject.combineMeshes) { planGO.transform.parent = go.transform; } } // end paths //GameObject.DestroyImmediate(bay_spanPlugGO); GameObject.DestroyImmediate(cornerPlugGO); GameObject.DestroyImmediate(nodePlugGO); GameObject.DestroyImmediate(cellPlugGO); // FINISH AX_MESHES //Debug.Log("finish " + ax_meshes.Count); parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); // FINISH BOUNDS CombineInstance[] boundsCombinator = new CombineInstance[boundingMeshes.Count]; for (int bb = 0; bb < boundsCombinator.Length; bb++) { boundsCombinator[bb].mesh = boundingMeshes[bb].mesh; boundsCombinator[bb].transform = boundingMeshes[bb].transMatrix; } setBoundsWithCombinator(boundsCombinator); // FINISH GAME_OBJECTS if (makeGameObjects) { if (parametricObject.combineMeshes) { go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true); } Matrix4x4 tmx = parametricObject.getLocalMatrix(); go.transform.rotation = AXUtilities.QuaternionFromMatrix(tmx); go.transform.position = AXUtilities.GetPosition(tmx); go.transform.localScale = parametricObject.getLocalScaleAxisRotated(); //AXUtilities.GetScale(tmx); if (P_Plan.reverse) { P_Plan.doReverse(); } if (P_Section != null && P_Section.reverse) { P_Section.doReverse(); } return(go); } else { // Submit AXMeshes for realtime rendering //parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); //setBoundaryFromMeshes(ax_meshes); } if (P_Plan.reverse) { P_Plan.doReverse(); } if (P_Section != null && P_Section.reverse) { P_Section.doReverse(); } return(null); }
public static int OnGUI(Rect pRect, AXNodeGraphEditorWindow editor, AXShape shp) { Color shapeColor = editor.getDataColor(AXParameter.DataType.Spline); Color origBG = GUI.backgroundColor; //Rect pRect = new Rect(x1+12, cur_y, width-20,lineHgt); float cur_x = ArchimatixUtils.cur_x; //float box_x = cur_x + ArchimatixUtils.indent; float box_w = ArchimatixUtils.paletteRect.width - cur_x - 3 * ArchimatixUtils.indent; int x1 = (int)pRect.x - ArchimatixUtils.indent; int cur_y = (int)pRect.y; int width = (int)pRect.width; int lineHgt = ArchimatixUtils.lineHgt; int gap = 5; Rect boxRect = pRect; boxRect = new Rect(cur_x + ArchimatixUtils.indent, cur_y, box_w, ArchimatixUtils.lineHgt); Rect lRect = new Rect(x1 + 11, cur_y, 50, lineHgt); if (!shp.isOpen && shp.inputs != null) { foreach (AXParameter sp in shp.inputs) { sp.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); sp.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); } } // Header //EditorGUI.BeginChangeCheck(); //GUI.Button(pRect, Name); GUI.color = Color.white; GUI.backgroundColor = shapeColor; // shp.isOpen = true; if (shp.isOpen) { /* INPUTS */ GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; labelstyle.fixedWidth = 100; labelstyle.fontSize = 12; //Rect boxRect = new Rect (x1 + 22, cur_y, width - 38, lineHgt); //Rect editRect = new Rect (x1 + 22, cur_y, width - 38, lineHgt); //Archimatix.cur_x += Archimatix.indent; // INPUT SHAPE PARAMETERS for (int i = 0; i < shp.inputs.Count; i++) { AXParameter sp = shp.inputs [i]; sp.inputPoint = new Vector2(ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); sp.outputPoint = new Vector2(ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, sp); } //Archimatix.cur_x -= Archimatix.indent; // Empty / New SHAPE PARAMETER if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != AXParameter.DataType.Spline) { GUI.enabled = false; } if (GUI.Button(new Rect(-3, cur_y, lineHgt, lineHgt), "")) { //Debug.Log ("make shape 2"); AXParameter new_p = shp.addInput(); editor.inputSocketClicked(new_p); editor.OutputParameterBeingDragged = null; } GUI.enabled = true; boxRect = new Rect(x1 + 11, cur_y, width - 38, lineHgt); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); //boxRect.x += 10; GUI.Label(boxRect, "Empty Shape"); cur_y += lineHgt + gap; //cur_y += 2*gap; //Rect bRect = boxRect; lRect.y = cur_y; /* SPECIFIC OUTPUT PARAMETERS */ //lRect.y = cur_y; //GUI.Label(lRect, "Output Combinations"); cur_y += gap; //Archimatix.cur_x += Archimatix.indent; GUI.color = Color.white; GUI.backgroundColor = Color.white; //Rect foldRect = new Rect(ArchimatixUtils.indent*2, cur_y, 30,lineHgt); //outputParametersOpen = EditorGUI.Foldout(foldRect, outputParametersOpen, "Merge Results"); /* * if (false && shp.outputParametersOpen) * { * cur_y += lineHgt; * ArchimatixUtils.cur_x += ArchimatixUtils.indent; * * bool tmp_boolval; * bRect.x = ArchimatixUtils.indent*3+4;//width-lineHgt; * * * // difference * shp.difference.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.difference.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * bRect.y = cur_y-2; * lRect.y = cur_y; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width,lineHgt), editor, shp.difference); * * tmp_boolval = (shp.combineType == AXShape.CombineType.Difference); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * shp.combineType = AXShape.CombineType.Difference; * shp.parametricObject.model.autobuild(); * } * * // difference * shp.differenceRail.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.differenceRail.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * * bRect.y = cur_y-2; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.differenceRail); * * tmp_boolval = (shp.combineType == AXShape.CombineType.DifferenceRail); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * shp.combineType = AXShape.CombineType.DifferenceRail; * shp.parametricObject.model.autobuild(); * } * * cur_y += gap; * * * * // INTERSECTION * shp.intersection.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.intersection.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * bRect.y = cur_y-2; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.intersection); * * tmp_boolval = (shp.combineType == AXShape.CombineType.Intersection); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * Debug.Log("YA"); * shp.combineType = AXShape.CombineType.Intersection; * shp.parametricObject.model.autobuild(); * } * * * // INTERSECTION_RAIL * shp.intersectionRail.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.intersectionRail.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * bRect.y = cur_y-2; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.intersectionRail); * * tmp_boolval = (shp.combineType == AXShape.CombineType.IntersectionRail); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * shp.combineType = AXShape.CombineType.IntersectionRail; * shp.parametricObject.model.autobuild(); * } * * cur_y += gap; * * * * // union * shp.union.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.union.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * bRect.y = cur_y-2; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.union); * * tmp_boolval = (shp.combineType == AXShape.CombineType.Union); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * shp.combineType = AXShape.CombineType.Union; * shp.parametricObject.model.autobuild(); * } * * cur_y += gap; * * * * // grouped * if (shp.grouped == null || shp.grouped.Type == AXParameter.DataType.Float) * shp.grouped = shp.createSplineParameter(AXParameter.ParameterType.Output, "Grouped"); * * shp.grouped.inputPoint = new Vector2 (ArchimatixUtils.paletteRect.x, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * shp.grouped.outputPoint = new Vector2 (ArchimatixUtils.paletteRect.x + ArchimatixUtils.paletteRect.width, ArchimatixUtils.paletteRect.y + cur_y + lineHgt / 2); * bRect.y = cur_y-2; * * cur_y = ParameterSplineGUI.OnGUI_Spline(new Rect(x1, cur_y, width, lineHgt), editor, shp.grouped); * * tmp_boolval = (shp.combineType == AXShape.CombineType.Grouped); * EditorGUI.BeginChangeCheck (); * tmp_boolval = EditorGUI.Toggle (bRect, "", tmp_boolval); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (shp.Parent.model, "value change for combineType" ); * shp.combineType = AXShape.CombineType.Grouped; * shp.parametricObject.model.autobuild(); * } * * * * * ArchimatixUtils.cur_x -= ArchimatixUtils.indent; * * * } */ //Archimatix.cur_x -= Archimatix.indent; //cur_y += lineHgt; } GUI.backgroundColor = origBG; return(cur_y); } // OnGUI
// GENERATE // This is the main function for generating a Shape, Mesh, or any other output that a node may be tasked with generating. // You can do pre processing of Inputs here, but that might best be done in an override of pollControlValuesFromParmeters(). // // Often, you will be creating a list of AXMesh objects. AXMesh has a Mesh, a Matrix4x4 and a Material // to be used when drawing the ouput to the scene before creating GameObjects. Your list of AXMeshes generated // is pased to the model via parametricObject.finishMultiAXMeshAndOutput(). // // When generate() is called by AX, it will be either with makeGameObjects set to true or false. // makeGameObjects=False is passed when the user is dragging a parameter and the model is regenerateing multiple times per second. // makeGameObjects=True is passed when the user has stopped editing (for example, OnMouseup from a Handle) and it is time to // build a GameObject hierarchy. public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { planSrc_p = P_Plan.DependsOn; // getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; if (planSrc_p == null) { return(null); } //Debug.Log("planSrc_po = " + planSrc_po.Name+"."+planSrc_p.Name + " ... " + planSrc_p.DependsOn.PType + " ..... " + planSrc_p.getPaths()); P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); if (P_Plan.reverse) { P_Plan.doReverse(); } planPaths = P_Plan.getPaths(); if (planPaths == null || planPaths.Count == 0) { return(null); } // ** CREATE PLAN_SPLINES ** if (planPaths != null && planPaths.Count > 0) { planSplines = new Spline[planPaths.Count]; if (planSplines != null) { for (int i = 0; i < planSplines.Length; i++) { planSplines[i] = new Spline(planPaths[i], (P_Plan.shapeState == ShapeState.Closed) ? true : false); } } } // FOR EACH PATH for (int path_i = 0; path_i < planPaths.Count; path_i++) { Spline planSpline = planSplines[path_i]; planSpline.breakAngleCorners = 35; planSpline.shapeState = P_Plan.shapeState; //Matrix4x4 mm = planSpline.matrixAtLength(4.5f); } if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh")) { return(null); } // At this point the amount variable has been set to the FloatValue of its amount parameter. preGenerate(); //Vector3 center = Vector3.zero; // AXMeshes are the key product of a Generator3D List <AXMesh> ax_meshes = new List <AXMesh>(); AXParameter inputSrc_p = P_Input.DependsOn; AXParametricObject inputSrc_po = inputSrc_p.parametricObject; Spline planSpl = planSplines[0]; if (inputSrc_p != null && inputSrc_p.meshes != null) // Is there an input node connected to this node? { //Debug.Log("P_Input.DependsOn.meshes.Count="+P_Input.DependsOn.meshes.Count + ", "+ P_Input.DependsOn.meshes[0].GetType()); AXMesh amesh = null; // EACH MESH for (int i = 0; i < P_Input.DependsOn.meshes.Count; i++) { // if (amount == 0) // { // amesh = P_Input.DependsOn.meshes [i]; // } // else{ // Instance does not inhereit and build on the transform of its source object. amesh = P_Input.DependsOn.meshes [i].Clone(); Mesh m = amesh.mesh; Vector3[] verts = m.vertices; // ---------- EACH VERTEX ---------------------- for (int j = 0; j < verts.Length; j++) { Vector3 vert = new Vector3(verts[j].x, verts[j].y, verts[j].z); vert = P_Input.DependsOn.meshes[i].drawMeshMatrix.MultiplyPoint3x4(vert); //float scale = modifierCurve.Evaluate( vert.y) * (1-(twist*vert.y)); float scale = modifierCurve.Evaluate(vert.x); //vert = new Vector3(vert.x*scale, vert.y, vert.z*scale); Matrix4x4 warperM = planSpl.matrixAtLength(vert.x); if (turn != 0 || twist != 0 || scale != 0) { warperM *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(vert.x * twist + turn + scale, 0, 0), Vector3.one); } vert = warperM.MultiplyPoint3x4(new Vector3(0, vert.y, vert.z));; // float len = Mathf.Sqrt(vert.x*vert.x + vert.z*vert.z); // // float new_x = vert.x;//+ pval; // float new_y = vert.y - factor*len*len*vert.y/5;// + pval; // float new_z = vert.z;//+ pval; // // //Debug.Log(pval + " :::: " + verts[j].x + " :: " + verts[j].z + " + " + Mathf.PerlinNoise (verts[j].x, verts[j].z)); // verts [j] = new Vector3 (new_x, new_y, new_z); verts [j] = P_Input.DependsOn.meshes[i].drawMeshMatrix.inverse.MultiplyPoint3x4(vert); } // ---------- EACH VERTEX ---------------------- m.vertices = verts; //} amesh.mesh.RecalculateNormals(); ax_meshes.Add(amesh); } parametricObject.bounds = inputSrc_po.bounds; parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); if (makeGameObjects) { return(parametricObject.makeGameObjectsFromAXMeshes(ax_meshes)); } } return(null); }
// SHAPE_OFFSETTER :: GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (P_Input == null || inputSrc_p == null) { return(null); } // PRE_GENERATE preGenerate(); P_Input.polyTree = null; AXShape.thickenAndOffset(ref P_Input, inputSrc_p); //if (P_Input.polyTree != null) //Debug.Log(" P_Input.polyTree 1="+ Clipper.PolyTreeToPaths(P_Input.polyTree).Count); //base.generate(ref visited, initiator_po, isReplica); if (P_Output == null) { return(null); } if (thickness > 0) { P_Output.thickness = thickness; P_Output.endType = AXClipperLib.EndType.etClosedLine; } else { P_Output.endType = AXClipperLib.EndType.etClosedPolygon; } if (P_Output.shapeState == ShapeState.Closed) { // CLOSED P_Output.offset = offset; //P_Output.roundness = roundness; } else { // OPEN switch (P_Output.openEndType) { case AXParameter.OpenEndType.Butt: P_Output.endType = AXClipperLib.EndType.etOpenButt; break; case AXParameter.OpenEndType.Square: P_Output.endType = AXClipperLib.EndType.etOpenSquare; break; case AXParameter.OpenEndType.Round: P_Output.endType = AXClipperLib.EndType.etOpenRound; break; default: P_Output.endType = AXClipperLib.EndType.etOpenSquare; break; } } P_Output.polyTree = null; AXShape.thickenAndOffset(ref P_Output, P_Input); //if (P_Output.polyTree != null) //Debug.Log(" P_Output.polyTree 1="+ Clipper.PolyTreeToPaths(P_Output.polyTree).Count); if (P_Output.polyTree != null) { transformPolyTree(P_Output.polyTree, localMatrix); } else if (P_Output.paths != null) { P_Output.paths = transformPaths(P_Output.paths, localMatrix); P_Output.transformedControlPaths = P_Output.paths; } //Debug.Log("stats"); AX.Generators.Generator2D.deriveStatsETC(P_Output); //P_Output.transformedControlPaths = transformPaths(P_Output.controlPaths, localMatrix); //output.getTransformedControlPaths(); //P_Output.paths = transformPaths(P_Output.controlPaths, localMatrix); // output.getTransformedControlPaths(); // may be altered before generate is over... //Debug.Log(" P_Output.path="+ P_Output.paths); //Debug.Log(" P_Output.transformedControlPaths="+ P_Output.transformedControlPaths); //if (P_Output.polyTree != null) //Debug.Log(" P_Output.polyTree 2="+ Clipper.PolyTreeToPaths(P_Output.polyTree).Count); calculateBounds(); return(null); }
// GENERATE EXTRUDE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { //Debug.Log ("===> [" + parametricObject.Name + "] EXTRUDE generate ... MAKE_GAME_OBJECTS="+makeGameObjects); if (parametricObject == null || !parametricObject.isActive) { return(null); } // RESULTING MESHES ax_meshes = new List <AXMesh>(); //Debug.Log(" ******** A "); preGenerate(); // PLAN - // The plan may have multiple paths. Each may generate a separate GO. if (P_Plan == null || planSrc_p == null || !planSrc_p.parametricObject.isActive) { return(null); } //Debug.Log(" ******** B " + planSrc_p.parametricObject.Name + "." + planSrc_p.Name); // Offset is bevel and !bevelOut float originalOffset = P_Plan.offset; // set back by the max bevel - later consider taper and lip.... if (!bevelOut) { /* * float bevelMax = (bevelTop > bevelBottom) ? bevelTop : bevelBottom; * * if (bevelMax > 0 ) * { * offsetModified -= bevelMax; * //P_Plan.joinType = JoinType.jtMiter; * } */ P_Plan.offset -= (bevelBottom > bevelTop) ? bevelBottom : bevelTop; } // Splitting concave shapes? // THis is a pecial case. An ssumption is mad of no holes // so that we can deal only with paths. if (parametricObject.splitConcaveShapes) //P_Plan.offset != 0) { // SPLIT INTO CONCAVES ** ** ** ** ** ** if no holes, and makeConcave, Paths paths; AXParameter tmpSrc = (!renderToOutputParameter && P_Plan.Dependents != null) ? P_Plan : planSrc_p; if (tmpSrc.polyTree != null) { paths = Clipper.PolyTreeToPaths(tmpSrc.polyTree); } else { paths = tmpSrc.paths; } //Pather.printPaths(P_Plan.paths); if (paths != null) { P_Plan.paths = new Paths(); foreach (Path path in paths) { Paths splitPaths = Pather.splitIntoConvexPaths(path); splitPaths = Pather.offset(splitPaths, P_Plan.offset); P_Plan.paths.AddRange(splitPaths); } } P_Plan.polyTree = null; // SPLIT INTO CONCAVES ** ** ** ** ** ** ** ** if no holes, and makeConcave, } else { //Debug.Log("A: "+planSrc_p.paths[0].Count); P_Plan.polyTree = null; // Debug.Log("EXTRUED " + parametricObject.Name); // Pather.printPaths(P_Plan.paths); if (!renderToOutputParameter && P_Plan.Dependents != null) { // Some Replicant has set the paths of this Plan_P manually AXShape.thickenAndOffset(ref P_Plan, P_Plan); } else { AXShape.thickenAndOffset(ref P_Plan, planSrc_p); } } P_Plan.offset = originalOffset; //Debug.Log("B: " +P_Plan.paths[0].Count); // DEFAULT SECTION -- USING BI_CHAMFER_SIDEflipX Path sectionPath = new Path(); sectionPath = AXTurtle.BiChamferSide(extrude, bevelTop, bevelBottom, bevelSegs, true, taper, lipTop, lipBottom, lipEdge, lipEdgeBottom, segs); AXParameter sec_p = new AXParameter(); sec_p.Parent = parametricObject; sec_p.parametricObject = parametricObject; sec_p.Type = AXParameter.DataType.Shape; sec_p.shapeState = ShapeState.Open; sec_p.paths = new Paths(); sec_p.paths.Add(sectionPath); if (parametricObject.boolValue("Bevel Hard Edge")) { sec_p.breakGeom = 0; sec_p.breakNorm = 0; } //StopWatch sw = new StopWatch(); //Debug.Log("Extrude ===================== "); GameObject retGO = generateFirstPass(initiator_po, makeGameObjects, P_Plan, sec_p, Matrix4x4.identity, renderToOutputParameter); //Debug.Log("Extrude Done ===================== " + sw.duration()); // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, true); //renderToOutputParameter); // FINISH BOUNDING setBoundaryFromAXMeshes(ax_meshes); //Debug.Log("Extrude: "+ parametricObject.bounds); return(retGO); }
// GENERATE EXTRUDE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { //Debug.Log ("===> [" + parametricObject.Name + "] EXTRUDE generate ... MAKE_GAME_OBJECTS="+makeGameObjects); if (parametricObject == null || !parametricObject.isActive) { return(null); } // RESULTING MESHES ax_meshes = new List <AXMesh>(); preGenerate(); // PLAN - // The plan may have multiple paths. Each may generate a separate GO. if (P_Plan == null || planSrc_p == null || !planSrc_p.parametricObject.isActive) { return(null); } // Offset is bevel and !bevelOut float originalOffset = P_Plan.offset; // set back by the max bevel - later consider taper and lip.... if (!bevelOut) { /* * float bevelMax = (bevelTop > bevelBottom) ? bevelTop : bevelBottom; * * if (bevelMax > 0 ) * { * offsetModified -= bevelMax; * //P_Plan.joinType = JoinType.jtMiter; * } */ P_Plan.offset -= (bevelBottom > bevelTop) ? bevelBottom : bevelTop; } //Debug.Log("A: "+planSrc_p.paths[0].Count); P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); P_Plan.offset = originalOffset; //Debug.Log("B: " +P_Plan.paths[0].Count); // DEFAULT SECTION -- USING BI_CHAMFER_SIDEflipX Path sectionPath = new Path(); sectionPath = AXTurtle.BiChamferSide(extrude, bevelTop, bevelBottom, bevelSegs, true, taper, lipTop, lipBottom, lipEdge, lipEdgeBottom, segs); AXParameter sec_p = new AXParameter(); sec_p.Parent = parametricObject; sec_p.parametricObject = parametricObject; sec_p.Type = AXParameter.DataType.Shape; sec_p.shapeState = ShapeState.Open; sec_p.paths = new Paths(); sec_p.paths.Add(sectionPath); if (parametricObject.boolValue("Bevel Hard Edge")) { sec_p.breakGeom = 0; sec_p.breakNorm = 0; } //StopWatch sw = new StopWatch(); //Debug.Log("Extrude ===================== "); GameObject retGO = generateFirstPass(initiator_po, makeGameObjects, P_Plan, sec_p, Matrix4x4.identity, renderToOutputParameter); //Debug.Log("Extrude Done ===================== " + sw.duration()); // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); // FINISH BOUNDING setBoundaryFromAXMeshes(ax_meshes); //Debug.Log("Extrude: "+ parametricObject.bounds); return(retGO); }
public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (parametricObject == null || !parametricObject.isActive) { return(null); } if (P_PrototypePlan == null || P_Prototype == null) { return(null); } preGenerate(); // PLAN planSrc_p = P_Plan.DependsOn; // getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); planPaths = P_Plan.getPaths(); if (planPaths == null || planPaths.Count == 0) { return(null); } prototypePlanSrc_p = P_PrototypePlan.DependsOn; prototypePlanSrc_po = (prototypePlanSrc_p != null) ? prototypePlanSrc_p.parametricObject : null; prototypeSrc_p = P_Prototype.DependsOn; prototypePlanSrc_po = (prototypeSrc_p != null) ? prototypeSrc_p.parametricObject : null; if (prototypePlanSrc_p == null || prototypePlanSrc_po == null || prototypeSrc_po == null) { return(null); } AXParameter srcSrc_p = prototypePlanSrc_p.DependsOn; if (srcSrc_p == null) { return(null); } // AX_MESHES List <AXMesh> ax_meshes = new List <AXMesh>(); GameObject go = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } Perlin perlin = new Perlin(); perlin.OctaveCount = 1; perlin.Frequency = .05f; GameObject replicant = null; foreach (Path plan in planPaths) { // 1. cache source object //prototypeSrc_po.cacheParameterValues(); Paths tmpPaths = new Paths(); tmpPaths.Add(plan); IntPoint planCenter = AXGeometryTools.Utilities.getCenter(tmpPaths); Vector3 centerPt = AXGeometryTools.Utilities.IntPt2Vec3(planCenter); //Debug.Log("Center: " + centerPt); srcSrc_p.paths = tmpPaths; float area = ((float)Clipper.Area(plan)) / 1000000000; //Debug.Log(area); float perlinVal = (float)perlin.GetValue(centerPt); float h = 3 + 100 * (float)Math.Exp(-(.1f * area)) + 5 * perlinVal; // (float) perlin.GetValue(2,3,4); AXParameter sHeight = prototypeSrc_po.getParameter("Height"); sHeight.initiateRipple_setFloatValueFromGUIChange(h); prototypeSrc_po.generator.pollControlValuesFromParmeters(); prototypeSrc_po.isAltered = true; replicant = prototypeSrc_po.generateOutputNow(makeGameObjects, parametricObject, true); if (replicant != null) { replicant.transform.parent = go.transform; } AXParameter output_p = prototypeSrc_po.getParameter("Output Mesh"); foreach (AXMesh amesh in output_p.meshes) { ax_meshes.Add(amesh.Clone(amesh.transMatrix)); } } // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); if (makeGameObjects) { return(go); } return(null); }
// GROUPER::GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { //if (ArchimatixUtils.doDebug) //Debug.Log (parametricObject.Name + " generate +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); if (!parametricObject.isActive) { return(null); } if (parametricObject.Groupees == null) { return(null); } preGenerate(); parametricObject.useMeshInputs = true; if (parametricObject.meshInputs == null) { parametricObject.meshInputs = new List <AXParameter>(); } // PROCESS INPUT SHAPES // pass Input Shape through... //Debug.Log( parametricObject.Name + " <><><><><> PROCESS INPUT SHAPES"); List <AXParameter> inputShapes = parametricObject.getAllInputShapes(); for (int i = 0; i < inputShapes.Count; i++) { AXParameter inputShape = inputShapes[i]; if (inputShape != null) { inputShape.polyTree = null; AXShape.thickenAndOffset(ref inputShape, inputShape.DependsOn); } } GameObject go = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } List <AXMesh> ax_meshes = new List <AXMesh>(); List <AXMesh> boundingMeshes = new List <AXMesh>(); // for each input //List<AXParameter> inputMeshes = parametricObject.getAllInputMeshParameters(); // Reinstate the original functionality of the Grouper as simple combiner in addition to Groupees. if (inputs != null && inputs.Count > 0) { for (int i = 0; i < inputs.Count; i++) { if (inputs[i] != null && inputs[i].DependsOn != null) { if (inputs[i].Dependents != null || inputs[i].Dependents.Count == 0) { AXParameter src_p = inputs[i].DependsOn; AXParametricObject src_po = inputs[i].DependsOn.parametricObject; //if (! parametricObject.visited_pos.Contains (groupee)) //Debug.Log("groupee.generateOutputNow: " + groupee.Name + " isAltered="+groupee.isAltered); if (src_po.isAltered) { src_po.generateOutputNow(makeGameObjects, initiator_po); //Debug.Log("XXXXX: " + groupee.Output.meshes.Count); src_po.isAltered = false; parametricObject.model.AlteredPOs.Remove(src_po); } if (src_p != null && src_p.meshes != null) { for (int j = 0; j < src_p.meshes.Count; j++) { AXMesh dep_amesh = src_p.meshes [j]; ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix)); } } // BOUNDING MESHES //boundsCombinator[i].mesh = input_p.DependsOn.parametricObject.boundsMesh; //boundsCombinator[i].transform = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment; if (src_po.boundsMesh != null) { boundingMeshes.Add(new AXMesh(src_po.boundsMesh, src_po.generator.localMatrixWithAxisRotationAndAlignment)); } // GAME_OBJECTS if (makeGameObjects && !parametricObject.combineMeshes) { GameObject plugGO = src_po.generator.generate(true, initiator_po, isReplica); if (plugGO != null) { plugGO.transform.parent = go.transform; } } } } } } // *** GROUPEES - Generate the groupees here // so that all the inputs (thicknesses, etc.) have been processed first. //List<AXParametricObject> visited_pos = new List<AXParametricObject>(); if (parametricObject.Groupees != null && parametricObject.Groupees.Count > 0) { for (int i = 0; i < parametricObject.Groupees.Count; i++) { AXParametricObject groupee = parametricObject.Groupees [i]; //if (! parametricObject.visited_pos.Contains (groupee)) //Debug.Log("groupee.generateOutputNow: " + groupee.Name + " isAltered="+groupee.isAltered); if (groupee.isAltered) { groupee.generateOutputNow(makeGameObjects, initiator_po); //Debug.Log("XXXXX: " + groupee.Output.meshes.Count); groupee.isAltered = false; parametricObject.model.AlteredPOs.Remove(groupee); } } } // BOUNDING // Process for (int i = 0; i < parametricObject.Groupees.Count; i++) { AXParametricObject groupee = parametricObject.Groupees [i]; //if (input_p != null && input_p.DependsOn != null && input_p.DependsOn.meshes != null && input_p.DependsOn.meshes.Count > 0) { //if (groupee != null && groupee.is3D() && ! groupee.hasDependents() && groupee.Output != null && groupee.Output.meshes != null) if (groupee != null && groupee.is3D() && groupee.shouldRenderSelf(true)) { // AX_MESHES //Debug.Log("(*) (*) (*) (*) groupee: " + groupee.Name + " " +groupee.Output.meshes.Count + " isAltered = " + groupee.isAltered); if (groupee.Output != null && groupee.Output.meshes != null) { for (int j = 0; j < groupee.Output.meshes.Count; j++) { AXMesh dep_amesh = groupee.Output.meshes [j]; ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix)); } } // BOUNDING MESHES //boundsCombinator[i].mesh = input_p.DependsOn.parametricObject.boundsMesh; //boundsCombinator[i].transform = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment; if (groupee.boundsMesh != null) { boundingMeshes.Add(new AXMesh(groupee.boundsMesh, groupee.generator.localMatrixWithAxisRotationAndAlignment)); } // GAME_OBJECTS if (makeGameObjects && !parametricObject.combineMeshes) { GameObject plugGO = groupee.generator.generate(true, initiator_po, isReplica); if (plugGO != null) { plugGO.transform.parent = go.transform; } } } } // FINISH AX_MESHES //Debug.Log("ORG: " + ax_meshes.Count); parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); // FINISH BOUNDS CombineInstance[] boundsCombinator = new CombineInstance[boundingMeshes.Count]; for (int bb = 0; bb < boundsCombinator.Length; bb++) { boundsCombinator[bb].mesh = boundingMeshes[bb].mesh; boundsCombinator[bb].transform = boundingMeshes[bb].transMatrix; } setBoundsWithCombinator(boundsCombinator); if (P_BoundsX != null && !P_BoundsX.hasRelations() && !P_BoundsX.hasExpressions()) { P_BoundsX.FloatVal = parametricObject.bounds.size.x; } if (P_BoundsY != null && !P_BoundsY.hasRelations() && !P_BoundsY.hasExpressions()) { P_BoundsY.FloatVal = parametricObject.bounds.size.y; } if (P_BoundsZ != null && !P_BoundsZ.hasRelations() && !P_BoundsZ.hasExpressions()) { P_BoundsZ.FloatVal = parametricObject.bounds.size.z; } // FINISH GAME_OBJECTS if (makeGameObjects) { if (parametricObject.combineMeshes) { go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true, false); // COMBINE ALL THE MESHES CombineInstance[] combine = new CombineInstance[ax_meshes.Count]; int combineCt = 0; for (int i = 0; i < ax_meshes.Count; i++) { AXMesh _amesh = ax_meshes [i]; combine [combineCt].mesh = _amesh.mesh; combine [combineCt].transform = _amesh.transMatrix; combineCt++; } Mesh combinedMesh = new Mesh(); combinedMesh.CombineMeshes(combine); // If combine, use combined mesh as invisible collider MeshFilter mf = (MeshFilter)go.GetComponent(typeof(MeshFilter)); if (mf == null) { mf = (MeshFilter)go.AddComponent(typeof(MeshFilter)); } if (mf != null) { mf.sharedMesh = combinedMesh; parametricObject.addCollider(go); } } else { Matrix4x4 tmx = parametricObject.getLocalMatrix(); go.transform.rotation = AXUtilities.QuaternionFromMatrix(tmx); go.transform.position = AXUtilities.GetPosition(tmx); go.transform.localScale = parametricObject.getLocalScaleAxisRotated(); } return(go); } //parametricObject.model.sw.milestone(parametricObject.Name + " generate"); return(null); }
public void carveTerrain() { Terrain terrain = parametricObject.terrain; if (terrain != null) { if (parametricObject.heightsOrig == null) { memorizeTerrain(); } // BOUNDING_SHAPE if (P_Plan != null && P_Plan.DependsOn != null) { if (planSrc_po != null) { AXShape.thickenAndOffset(ref P_Plan, planSrc_p); // now boundin_p has offset and thickened polytree or paths. } } int hmWidth = terrain.terrainData.heightmapWidth; int hmHeight = terrain.terrainData.heightmapHeight; Paths subjPaths = P_Plan.getTransformedSubjPaths(); Paths holePaths = P_Plan.getTransformedHolePaths(); //Pather.printPaths(subjPaths); if (subjPaths == null) { return; } IntRect bounds = Clipper.GetBounds(subjPaths); // if (prevBounds.right > 0) // { // bounds.left = ( prevBounds.left < bounds.left ) ? prevBounds.left : bounds.left; // bounds.right = ( prevBounds.right > bounds.right ) ? prevBounds.right : bounds.right; // // // bounds.top = ( prevBounds.top < bounds.top ) ? prevBounds.top : bounds.top; // bounds.bottom = ( prevBounds.bottom > bounds.bottom ) ? prevBounds.bottom : bounds.bottom; // } float percentHgt = height / terrain.terrainData.size.y; //Debug.Log(bounds.left +"->"+bounds.right+" :: " + bounds.top+ "->"+bounds.bottom); int padding = 50000; bounds.left -= padding; bounds.right += padding; bounds.top -= padding; bounds.bottom += padding; int from_i = (int)((bounds.left / AXGeometryTools.Utilities.IntPointPrecision) * hmWidth / terrain.terrainData.size.x); int to_i = (int)((bounds.right / AXGeometryTools.Utilities.IntPointPrecision) * hmWidth / terrain.terrainData.size.x); int from_j = (int)((bounds.top / AXGeometryTools.Utilities.IntPointPrecision) * hmHeight / terrain.terrainData.size.z); int to_j = (int)((bounds.bottom / AXGeometryTools.Utilities.IntPointPrecision) * hmHeight / terrain.terrainData.size.z); //Debug.Log(from_i +"->"+to_i+" :: " + from_j+ "->"+to_j); from_i = Mathf.Max(0, from_i); to_i = Mathf.Min(to_i, hmWidth); from_j = Mathf.Max(0, from_j); to_j = Mathf.Min(to_j, hmHeight); //Debug.Log(from_i +"->"+to_i+" :: " + from_j+ "->"+to_j); // patch to be redrawn float[,] heights = new float[(to_j - from_j), (to_i - from_i)]; //Debug.Log(heights.GetLength(0) +" -- " + heights.GetLength(1)); if (from_i < to_i && from_j < to_j) { // we set each sample of the terrain in the size to the desired height for (int i = from_i; i < to_i; i++) { for (int j = from_j; j < to_j; j++) { // GET i, j in realworld coords float x = terrain.terrainData.size.x * i / hmWidth; float y = terrain.terrainData.size.z * j / hmHeight; //Debug.Log("[" + i + ", " + j + "] :: " + x +", " + y); if (isInside(x, y, subjPaths, holePaths)) { heights [j - from_j, i - from_i] = percentHgt; } else { heights [j - from_j, i - from_i] = parametricObject.heightsOrig [j, i]; } } } // set the new height terrain.terrainData.SetHeights(from_i, from_j, heights); } //prevBounds = bounds; } }
// GENERATE GRID_REPEATER public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { //Debug.Log(parametricObject.Name + " Generate"); if (parametricObject == null || !parametricObject.isActive) { return(null); } if (repeaterToolU == null || repeaterToolV == null) { return(null); } preGenerate(); // NODE_MESH AXParametricObject nodeSrc_po = null; GameObject nodePlugGO = null; if (nodeSrc_p != null) { nodeSrc_po = nodeSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica); } } // CELL_MESH AXParametricObject cellSrc_po = null; GameObject cellPlugGO = null; if (cellSrc_p != null) { cellSrc_po = cellSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { cellPlugGO = cellSrc_po.generator.generate(true, initiator_po, isReplica); } } // BAY_SPAN_U AXParametricObject spanUSrc_po = null; GameObject spanUPlugGO = null; if (spanUSrc_p != null) { spanUSrc_po = spanUSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { spanUPlugGO = spanUSrc_po.generator.generate(true, initiator_po, isReplica); } } // BAY_SPAN_V AXParametricObject spanVSrc_po = null; GameObject spanVPlugGO = null; if (spanVSrc_p != null) { spanVSrc_po = spanVSrc_p.parametricObject; if (makeGameObjects && !parametricObject.combineMeshes) { spanVPlugGO = spanVSrc_po.generator.generate(true, initiator_po, isReplica); } } if (nodeSrc_po == null && cellSrc_po == null && spanUSrc_po == null && spanVSrc_po == null) { AXParameter output_p = getPreferredOutputParameter(); if (output_p != null) { output_p.meshes = null; } return(null); } GameObject go = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } // BOUNDING_SHAPE Paths boundingSolids = null; Paths boundingHoles = null; if (P_BoundingShape != null && P_BoundingShape.DependsOn != null) { AXParameter bounding_src_p = null; if (P_BoundingShape != null) { bounding_src_p = P_BoundingShape.DependsOn; // USING SINGLE SPLINE INPUT } boundingShapeSrc_po = bounding_src_p.parametricObject; AXShape.thickenAndOffset(ref P_BoundingShape, bounding_src_p); // now boundin_p has offset and thickened polytree or paths. boundingSolids = P_BoundingShape.getTransformedSubjPaths(); boundingHoles = P_BoundingShape.getTransformedHolePaths(); } List <AXMesh> ax_meshes = new List <AXMesh>(); Matrix4x4 localPlacement_mx = Matrix4x4.identity; // ----------------------------------- int max_reps = 150; int cellsU = Mathf.Clamp(repeaterToolU.cells, 1, max_reps); float actualBayU = repeaterToolU.actualBay; int cellsV = Mathf.Clamp(repeaterToolV.cells, 1, max_reps); float actualBayV = repeaterToolV.actualBay; shiftU = -cellsU * actualBayU / 2; shiftV = -cellsV * actualBayV / 2; // BAY SPAN // Spanners are meshers that get replicated and sized to fit the bay... // prepare mesh to iterate in each direction //List<AXMesh> ax_meshes_X = new List<AXMesh>(); //List<AXMesh> ax_meshes_Z = new List<AXMesh>(); AXMesh tmpMesh; if (spanUSrc_p != null) { //ax_meshes_X = spanUSrc_p.meshes; //ax_meshes_Z = spanUSrc_p.meshes; } /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE... * if (bay_span_source != null) * { * * // 1. cache source object * bay_span_source.cacheParameterValues(); * * * // Y_AXIS * * AXParameter p_bayv = parametricObject.getParameter("actual_bay_V"); * AXParameter p_bayv_client = null; * if (p_bayv != null) * { * foreach (AXRelation rel in p_bayv.relations) * { * p_bayv_client = rel.getRelatedTo(p_bayv); * p_bayv_client.intiateRipple_setFloatValueFromGUIChange(abayy); * } * } * * * AXParameter p_bayu = parametricObject.getParameter("actual_bay_U"); * AXParameter p_bayu_client = null; * * // X-AXIS * // For now, only set the boundaries. * // Perhaps later, may want to set other like controls as in Replicant * * // If there is a relation to actual_bay_U, propogate it * if (p_bayu != null) * { * foreach (AXRelation rel in p_bayu.relations) * { * p_bayu_client = rel.getRelatedTo(p_bayu); * p_bayu_client.intiateRipple_setFloatValueFromGUIChange(abayx); * } * } * * //bay_span_source.propagateParameterByBinding(1, bayx); * //bay_span_source.propagateParameterByBinding(2, bayy); * * // 2. re_generate with temporary values set by this Replicant * bay_span_source.generateOutputNow (makeGameObjects, parametricObject); * * // 3. Now that the bay_span_source has been regergrab the meshes from the input sources and add them here * AXParameter output_p = bay_span_source.getParameter("Output Mesh"); * foreach (AXMesh amesh in output_p.meshes) * ax_meshes_X.Add (amesh.Clone(amesh.transMatrix)); * * * * // Z-AXIS * // Use the bayz now to generate x * * if (p_bayu != null) * { * foreach (AXRelation rel in p_bayu.relations) * { * p_bayu_client = rel.getRelatedTo(p_bayu); * p_bayu_client.intiateRipple_setFloatValueFromGUIChange(abayz); * } * } * * //bay_span_source.propagateParameterByBinding(1, bayz); * * * // 2. re_generate with temporary values set by this Replicant * bay_span_source.generateOutputNow (makeGameObjects, parametricObject); * * // 3. Now that the bay_span_source has been regergrab the meshes from the input sources and add them here * foreach (AXMesh amesh in output_p.meshes) * ax_meshes_Z.Add (amesh.Clone(amesh.transMatrix)); * * * // 4. restore source object; as though we were never here! * bay_span_source.revertParametersFromCache(); * * //Debug.Log ("HAVE BAY SPAN -- " + output_p.meshes.Count); * * * } */ /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE... * if (cell_center_source != null) * { * // Y-AXIS * // For now, only set the boundaries. * // Perhaps later, may want to set other like controls as in Replicant * // 1. cache source object * cell_center_source.cacheParameterValues(); * * * * //bay_center_source.propagateParameterByBinding(1, bayx); * //bay_center_source.propagateParameterByBinding(3, bayz); * * // 2. re_generate with temporary values set by this Replicant * cell_center_source.generateOutputNow (makeGameObjects, parametricObject); * * // 3. Now that the bay_span_source has been regenerted, grab the meshes from the input sources and add them here * AXParameter bc_output_p = cell_center_source.getParameter("Output Mesh"); * foreach (AXMesh amesh in bc_output_p.meshes) * ax_meshes_Y.Add (amesh.Clone(amesh.transMatrix)); * * // 4. restore source object; as though we were never here! * cell_center_source.revertParametersFromCache(); * * } */ // BOUNDING List <AXMesh> boundingMeshes = new List <AXMesh>(); for (int i = 0; i <= cellsU; i++) { for (int k = 0; k <= cellsV; k++) { bool exclude = false; IntPoint ip = new IntPoint((i * actualBayU + shiftU) * AXGeometryTools.Utilities.IntPointPrecision, (k * actualBayV + shiftV) * AXGeometryTools.Utilities.IntPointPrecision); if (boundingSolids != null) { exclude = true; if (boundingSolids != null) { foreach (Path path in boundingSolids) { if (Clipper.PointInPolygon(ip, path) == 1 && Clipper.Orientation(path)) { exclude = false; break; } } } if (boundingHoles != null) { foreach (Path hole in boundingHoles) { if (Clipper.PointInPolygon(ip, hole) == 1) { exclude = true; break; } } } } exclude = (boundingIsVoid) ? !exclude : exclude; if (exclude) { continue; } // NODES if (nodeSrc_po != null && nodeSrc_p.meshes != null && ((i <= repeaterToolU.edgeCount || i >= cellsU - repeaterToolU.edgeCount) || (k <= repeaterToolV.edgeCount || k >= cellsV - repeaterToolV.edgeCount))) { string this_address = "node_" + i + "_" + k; // LOCAL PLACEMENT NODE localPlacement_mx = localNodeMatrixFromAddress(i, k); // AX_MESHES for (int mi = 0; mi < nodeSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = nodeSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(nodeSrc_po.boundsMesh, localPlacement_mx * nodeSrc_po.generator.localMatrix)); // GAME_OBJECTS if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(nodePlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); #if UNITY_EDITOR //if (parametricObject.model.isSelected(nodeSrc_po) && nodeSrc_po.selectedConsumerAddress == this_address) // Selection.activeGameObject = copyGO; #endif AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } // \NODES // CELL CENTERS if (cellSrc_po != null && cellSrc_p.meshes != null && i < cellsU && k < cellsV && ((i < repeaterToolU.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k < repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1))) { string this_address = "cell_" + i + "_" + k; // LOCAL PLACEMENT localPlacement_mx = localCellMatrixFromAddress(i, k); // AX_MESHES for (int mi = 0; mi < cellSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = cellSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(cellSrc_po.boundsMesh, localPlacement_mx * cellSrc_po.generator.localMatrix)); // GAME_OBJECTS if (cellPlugGO != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(cellPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); #if UNITY_EDITOR //if (parametricObject.model.isSelected(cellSrc_po) && cellSrc_po.selectedConsumerAddress == this_address) //Selection.activeGameObject = copyGO; #endif AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } // SPAN_U if (spanUSrc_po != null && spanUSrc_p.meshes != null && i < cellsU && k <= cellsV && ((i < repeaterToolV.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k <= repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1))) { string this_address = "spanU_" + i + "_" + k; // LOCAL PLACEMENT SPAN_U localPlacement_mx = localSpanUMatrixFromAddress(i, k); // AX_MESHES for (int mi = 0; mi < spanUSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = spanUSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(spanUSrc_po.boundsMesh, localPlacement_mx * spanUSrc_po.generator.localMatrix)); // GAME_OBJECTS if (spanUSrc_po != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * spanUSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(spanUPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); #if UNITY_EDITOR //if (parametricObject.model.isSelected(spanUSrc_po) && spanUSrc_po.selectedConsumerAddress == this_address) // Selection.activeGameObject = copyGO; #endif AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } // SPAN_V if (spanVSrc_po != null && spanVSrc_p.meshes != null && i <= cellsU && k < cellsV && ((i <= repeaterToolU.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k < repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1))) { string this_address = "spanV_" + i + "_" + k; // LOCAL PLACEMENT SPAN_U localPlacement_mx = localSpanVMatrixFromAddress(i, k); // AX_MESHES for (int mi = 0; mi < spanVSrc_p.meshes.Count; mi++) { AXMesh dep_amesh = spanVSrc_p.meshes [mi]; tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix); tmpMesh.subItemAddress = this_address; ax_meshes.Add(tmpMesh); } // BOUNDING boundingMeshes.Add(new AXMesh(spanVSrc_po.boundsMesh, localPlacement_mx * spanVSrc_po.generator.localMatrix)); // GAME_OBJECTS if (spanVSrc_po != null && makeGameObjects && !parametricObject.combineMeshes) { Matrix4x4 mx = localPlacement_mx * spanVSrc_po.generator.localMatrixWithAxisRotationAndAlignment; GameObject copyGO = (GameObject)GameObject.Instantiate(spanVPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx)); copyGO.transform.localScale = new Vector3(copyGO.transform.localScale.x * jitterScale.x, copyGO.transform.localScale.y * jitterScale.y, copyGO.transform.localScale.z * jitterScale.z); #if UNITY_EDITOR //if (parametricObject.model.isSelected(spanVSrc_po) && spanVSrc_po.selectedConsumerAddress == this_address) // Selection.activeGameObject = copyGO; #endif AXGameObject axgo = copyGO.GetComponent <AXGameObject>(); if (axgo != null) { axgo.consumerAddress = this_address; } copyGO.name = copyGO.name + "_" + this_address; copyGO.transform.parent = go.transform; } } } // k } //i GameObject.DestroyImmediate(nodePlugGO); GameObject.DestroyImmediate(cellPlugGO); GameObject.DestroyImmediate(spanUPlugGO); GameObject.DestroyImmediate(spanVPlugGO); // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); // FINISH BOUNDS CombineInstance[] boundsCombinator = new CombineInstance[boundingMeshes.Count]; for (int bb = 0; bb < boundsCombinator.Length; bb++) { boundsCombinator[bb].mesh = boundingMeshes[bb].mesh; boundsCombinator[bb].transform = boundingMeshes[bb].transMatrix; } setBoundsWithCombinator(boundsCombinator); // FINISH GAME_OBJECTS if (makeGameObjects) { if (parametricObject.combineMeshes) { go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true); } Matrix4x4 tmx = parametricObject.generator.localMatrixWithAxisRotationAndAlignment; go.transform.rotation = AXUtilities.QuaternionFromMatrix(tmx); go.transform.position = AXUtilities.GetPosition(tmx); go.transform.localScale = parametricObject.getLocalScaleAxisRotated(); return(go); } return(null); }
// GENERATE LATHE // The only thing a Lathe Node does is prepare a circular Section. Otherwise it is simple a PlanSweep. public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { if (parametricObject == null || !parametricObject.isActive) { return(null); } // RESULTING MESHES ax_meshes = new List <AXMesh>(); preGenerate(); // PLAN - is an arc or circle // generate the plane shape. A circle at .5 radius AXParameter plan_p = new AXParameter(); plan_p.Parent = parametricObject; plan_p.Type = AXParameter.DataType.Shape; plan_p.paths = new Paths(); float actingRadius = radius + MIN_RAD; //Debug.Log("actingRadius="+actingRadius); int msegs = Mathf.Max(1, Mathf.FloorToInt(((float)segs * parametricObject.model.segmentReductionFactor))); if (snappedSweepAngle == 360) { plan_p.paths.Add(AXTurtle.Circle(actingRadius, msegs)); plan_p.shapeState = ShapeState.Closed; } else { plan_p.paths.Add(AXTurtle.Arc(actingRadius, 0, snappedSweepAngle, msegs)); plan_p.shapeState = ShapeState.Open; } //plan_p.breakGeom = 10; plan_p.breakNorm = (faceted ? 10 : 135); plan_p.breakGeom = (continuousU ? 100 : 10); // In order to conceptualize the section as at a vert rather than the normal case for PlanSweep where it is on a length, // shift the section out by: dx = R ( 1 - cos(ß/2)) // http://www.archimatix.com/geometry/compensating-for-plansweep-in-a-lathe-mesher float beta = snappedSweepAngle / segs; float dx = actingRadius * (1 - Mathf.Cos(Mathf.Deg2Rad * beta / 2)); //Debug.Log("actingRadius="+actingRadius+", beta="+beta+", dx="+dx); ShiftRadMatrix = Matrix4x4.TRS(new Vector3(-MIN_RAD + dx, 0, 0), Quaternion.identity, Vector3.one); // SECTION // The plan may have multiple paths. Each may generate a separate GO. if (P_Section == null || sectionSrc_p == null || !sectionSrc_p.parametricObject.isActive) { return(null); } P_Section.polyTree = null; P_Section.thickness = 0; P_Section.offset = 0; AXShape.thickenAndOffset(ref P_Section, sectionSrc_p); //Debug.Log(parametricObject.Name); //Debug.Log(ShiftRadMatrix); if (P_Section.polyTree != null) { AX.Generators.Generator2D.transformPolyTree(P_Section.polyTree, ShiftRadMatrix); } else { P_Section.paths = AX.Generators.Generator2D.transformPaths(P_Section.paths, ShiftRadMatrix); } GameObject retGO = null; if (makeGameObjects && P_Section.polyTree == null && P_Section.paths != null && P_Section.paths.Count > 1) { //Debug.Log("make one for each section"); retGO = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); for (int i = 0; i < P_Section.paths.Count; i++) { AXParameter tmpSecP = new AXParameter(); tmpSecP.shapeState = ShapeState.Open; tmpSecP.parametricObject = parametricObject; Paths tmpPaths = new Paths(); tmpPaths.Add(P_Section.paths[i]); tmpSecP.paths = tmpPaths; GameObject tmpObj = generateFirstPass(initiator_po, makeGameObjects, plan_p, tmpSecP, ShiftRadMatrix, renderToOutputParameter); tmpObj.transform.parent = retGO.transform; } } else { retGO = generateFirstPass(initiator_po, makeGameObjects, plan_p, P_Section, ShiftRadMatrix, renderToOutputParameter); } // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter); // FINISH BOUNDING setBoundaryFromAXMeshes(ax_meshes); if (P_Section.polyTree != null) { AX.Generators.Generator2D.transformPolyTree(P_Section.polyTree, ShiftRadMatrix.inverse); } //else // P_Section.paths = AX.Generators.Generator2D.transformPaths(P_Section.paths, ShiftRadMatrix); return(retGO); }
public static void display(float imagesize = 64, AXNodeGraphEditorWindow editor = null) { //Debug.Log("imagesise="+imagesize); // called from an OnGUI //imagesize = 64; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUIStyle.none); EditorGUILayout.BeginVertical(); string[] itemStrings = null; // Select menu item list if (editor.OutputParameterBeingDragged == null) { if (editor.model != null && editor.model.selectedPOs.Count > 1) { //if (editor.model.selectedPOs[0].is2D()) // itemStrings = ArchimatixEngine.nodeStringsFrom2DMultiSelect; //else itemStrings = ArchimatixEngine.nodeStringsFromMultiSelect; } else { itemStrings = ArchimatixEngine.nodeStrings; } } else if (editor.OutputParameterBeingDragged.parametricObject.is2D()) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else if (editor.OutputParameterBeingDragged.parametricObject.is3D()) { if (editor.OutputParameterBeingDragged.Type == AXParameter.DataType.Spline) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else { itemStrings = ArchimatixEngine.nodeStringsFrom3DOutput; } } else if (editor.OutputParameterBeingDragged.parametricObject.generator is RepeaterTool) { itemStrings = ArchimatixEngine.nodeStringsFromRepeaterTool; } /* * if (Library.last2DItem != null) * { * if (GUILayout.Button(new GUIContent(Library.last2DItem.icon, Library.last2DItem.po.Name), new GUILayoutOption[] {GUILayout.Width(imagesize), GUILayout.Height(imagesize)})) * { * * } * } */ List <string> stringList = null; if (itemStrings != null) { stringList = itemStrings.ToList(); } if (stringList != null) { stringList.AddRange(Archimatix.customNodeNames); } // Build Menu string poName; if (stringList != null) { for (int i = 0; i < stringList.Count; i++) { string nodeName = stringList[i]; Texture2D nodeIcon = null; if (ArchimatixEngine.nodeIcons.ContainsKey(nodeName)) { nodeIcon = ArchimatixEngine.nodeIcons[nodeName]; } else { if (ArchimatixEngine.nodeIcons.ContainsKey("CustomNode")) { nodeIcon = ArchimatixEngine.nodeIcons["CustomNode"]; } else { continue; } } if (nodeIcon != null) { if (GUILayout.Button(new GUIContent(nodeIcon, nodeName), new GUILayoutOption[] { GUILayout.Width(imagesize), GUILayout.Height(imagesize) })) { //if (editor.DraggingOutputParameter != null) //{ AXModel model = AXEditorUtilities.getOrMakeSelectedModel(); Undo.RegisterCompleteObjectUndo(model, "Node Menu Selection"); AXParametricObject mostRecentPO = model.recentlySelectedPO; int index = nodeName.IndexOf("_"); poName = (index > 0) ? nodeName.Substring(0, index) : nodeName; // Support multi-select operation List <AXParametricObject> selectedPOs = new List <AXParametricObject>(); if (model.selectedPOs.Count > 0) { selectedPOs.AddRange(model.selectedPOs); } // ADD NEW PO TO MODEL (only this new po is selected after this) AXParametricObject po = AXEditorUtilities.addNodeToCurrentModel(poName, false); if (po == null || po.generator == null) { return; } float max_x = -AXGeometryTools.Utilities.IntPointPrecision; if (poName == "FreeCurve") { ArchimatixEngine.sceneViewState = ArchimatixEngine.SceneViewState.AddPoint; } // DRAGGING A PARAMETER? THEN RIG'R UP! if (editor.OutputParameterBeingDragged != null) { AXParametricObject draggingPO = editor.OutputParameterBeingDragged.parametricObject; AXParameter new_input_p = null; switch (nodeName) { case "Instance2D": case "ShapeOffsetter": po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeDistributor": List <AXParameter> deps = new List <AXParameter>(); for (int dd = 0; dd < editor.OutputParameterBeingDragged.Dependents.Count; dd++) { deps.Add(editor.OutputParameterBeingDragged.Dependents[dd]); } for (int dd = 0; dd < deps.Count; dd++) { deps[dd].makeDependentOn(po.getParameter("Output Shape")); } po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeMerger": po.generator.getInputShape().addInput().makeDependentOn(editor.OutputParameterBeingDragged); if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } break; case "PlanRepeater2D": case "PlanRepeater2D_Corner": po.getParameter("Corner Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "PlanRepeater_Corner": po.getParameter("Corner Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "PairRepeater2D": case "RadialRepeater2D": case "RadialRepeater2D_Node": case "LinearRepeater2D": case "LinearRepeater2D_Node": case "GridRepeater2D": case "GridRepeater2D_Node": po.getParameter("Node Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "RadialRepeater2D_Cell": case "LinearRepeater2D_Cell": case "GridRepeater2D_Cell": po.getParameter("Cell Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "Grouper": //po.addInputMesh().makeDependentOn(editor.OutputParameterBeingDragged); po.addGroupee(editor.OutputParameterBeingDragged.parametricObject); break; case "PlanRepeater2D_Plan": case "Polygon_Plan": case "Extrude_Plan": case "PlanSweep_Plan": case "PlanRepeater_Plan": case "PlanDeformer_Plan": // SYNC AXES if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } if (nodeName == "Extrude_Plan" && po.intValue("Axis") != (int)Axis.Y) { po.floatValue("Bevel", 0); } // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Plan", "Input Shape"); //if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && editor.OutputParameterBeingDragged.Dependents != null && editor.OutputParameterBeingDragged.Dependents.Count > 0) // model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); //else new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); // the output of the new node should match the shapestate of the input if (po.generator.P_Output != null) { po.generator.P_Output.shapeState = new_input_p.shapeState; } AXNodeGraphEditorWindow.repaintIfOpen(); break; case "Lathe_Section": case "PlanSweep_Section": case "PlanRepeater_Section": //po.getParameter("Section").makeDependentOn(editor.OutputParameterBeingDragged); // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Section"); if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && draggingPO.hasDependents()) { model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); } else { new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); } // the output of the new node should match the shapestate of the input //if (po.generator.P_Output != null) //Debug.Log(new_input_p.Name+" "+new_input_p.shapeState + " :=: " +editor.OutputParameterBeingDragged.Name + " " + editor.OutputParameterBeingDragged.shapeState); AXNodeGraphEditorWindow.repaintIfOpen(); break; case "NoiseDeformer": case "ShearDeformer": case "TwistDeformer": case "DomicalDeformer": case "TaperDeformer": case "InflateDeformer": case "PlanDeformer": po.getParameter("Input Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; //case "PlanDeformer_Plan": case "PairRepeater": case "StepRepeater": case "RadialStepRepeater": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Node": AXParameter nodeMesh_p = po.getParameter("Node Mesh"); nodeMesh_p.makeDependentOn(editor.OutputParameterBeingDragged); // if the src is very long in x, assume you want to repeat in Z if (editor.OutputParameterBeingDragged.parametricObject.bounds.size.x > (6 * editor.OutputParameterBeingDragged.parametricObject.bounds.size.z)) { po.initiateRipple_setBoolParameterValueByName("zAxis", true); } break; case "LinearRepeater_Cell": case "PlanRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Span": po.getParameter("Bay SpanU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater": po.getParameter("RepeaterU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "FloorRepeater": po.getParameter("Floor Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater": case "RadialRepeater_Node": case "GridRepeater_Node": case "PlanRepeater_Node": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater_Span": case "GridRepeater_Span": po.getParameter("Bay SpanU", "SpanU Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "GridRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "ShapeRepeater_Plan": AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Plan").makeDependentOn(editor.OutputParameterBeingDragged); break; default: AXEditorUtilities.addNodeToCurrentModel(nodeName); break; } if (editor.OutputParameterBeingDragged.parametricObject != null) { mostRecentPO = editor.OutputParameterBeingDragged.parametricObject; //po.rect = editor.OutputParameterBeingDragged.parametricObject.rect; //po.rect.x += 325; } /* * else * { * po.rect.x = (model.focusPointInGraphEditor.x)+100;// + UnityEngine.Random.Range(-100, 300); * po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); * } */ } // NO DRAGGING - CONNECT ALL MULTI_SELECTED else if (selectedPOs != null && selectedPOs.Count > 0) { switch (nodeName) { case "ShapeMerger": AXShape shp = po.generator.getInputShape(); for (int j = 0; j < selectedPOs.Count; j++) { AXParametricObject poo = selectedPOs [j]; if (j == 0) { po.intValue("Axis", selectedPOs [j].intValue("Axis")); } max_x = Mathf.Max(max_x, poo.rect.x); if (poo.is2D()) { AXParameter out_p = poo.generator.getPreferredOutputParameter(); if (out_p != null) { shp.addInput().makeDependentOn(out_p); } } } po.rect.x = max_x + 250; break; case "Grouper": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ po.addGroupees(selectedPOs); Rect r = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = r.center.x - po.rect.width / 2; po.rect.y = r.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; case "Channeler": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ foreach (AXParametricObject selpo in selectedPOs) { AXParameter inputer = po.addInputMesh(); inputer.makeDependentOn(selpo.generator.P_Output); } Rect cr = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = cr.center.x - po.rect.width / 2; po.rect.y = cr.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; } } else { switch (nodeName) { case "ShapeMerger": po.assertInputControls(); //po.generator.getInputShape().addInput(); break; } } editor.OutputParameterBeingDragged = null; model.autobuild(); po.generator.adjustWorldMatrices(); if (mostRecentPO != null) { po.rect = mostRecentPO.rect; po.rect.x += (mostRecentPO.rect.width + 50); } else { po.rect.x = (model.focusPointInGraphEditor.x) + 100; // + UnityEngine.Random.Range(-100, 300); po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); } po.rect.height = 700; //AXNodeGraphEditorWindow.zoomToRectIfOpen(po.rect); //model.beginPanningToRect(po.rect); } } } } //GUILayout.Label (GUI.tooltip); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); /* Not sure why I was doing this - it took up a huge amount of CPU! * * * editor.Repaint(); * SceneView sv = SceneView.lastActiveSceneView; * if (sv != null) * sv.Repaint(); * */ }
// POLL INPUTS (only on graph change()) public override void pollInputParmetersAndSetUpLocalReferences() { base.pollInputParmetersAndSetUpLocalReferences(); S_InputShape = parametricObject.getShape("Input Shape"); }