public override Matrix4x4 getLocalConsumerMatrixPerInputSocket(AXParametricObject caller) { // use shift too // use caller address if (caller == null) { return(Matrix4x4.identity); } Matrix4x4 optionalLocalM = Matrix4x4.identity; if (caller.selectedConsumer == null || caller.selectedConsumer != this.parametricObject || String.IsNullOrEmpty(caller.selectedConsumerAddress)) { caller.selectedConsumerAddress = "node_0"; optionalLocalM = caller.getLocalMatrix() * caller.getAxisRotationMatrix().inverse; } string[] address = caller.selectedConsumerAddress.Split('_'); if (address.Length < 2) { return(Matrix4x4.identity); } string meshInput = address[0]; // e.g., "node", "cell", "spanU", "spanV" int indexU = int.Parse(address[1]); int indexV = 0; if (address.Length > 2) { indexV = int.Parse(address[2]); } //Debug.Log("indexU="+indexU+", indexV="+indexV); if (indexU == 1) { } // Find out which input this caller is fed into Node Mesh, Bay Span or Cell Mesh? if (meshInput == "node" && nodeSrc_p != null && caller == nodeSrc_p.Parent) { return(localNodeMatrixFromAddress(indexU, indexV) * optionalLocalM); } return(Matrix4x4.identity); }
/* * public override Matrix4x4 getLocalConsumerMatrixPerInputSocket(AXParametricObject input, AXParameter input_p=null) * { * Debug.Log("planSrc_po="+planSrc_po); * if (planSrc_po != null) * { * //Debug.Log(input.Name + " -- " + planSrc_po.Name); * if (planSrc_po!= null && input == planSrc_po) * return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one); * * //return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), Vector3.one); * } * return Matrix4x4.identity; * } * * * // GET_LOCAL_CONSUMER_MATRIX_PER_INPUT_SOCKET * public override Matrix4x4 getLocalConsumerMatrixPerInputSocket(AXParametricObject input_po) * { * //Debug.Log ("input_po.Name=" + input_po.Name);// + " -- " + endCapHandleTransform); * // PLAN * if (input_po == planSrc_po) * return Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one); * * * // SECTION * if (input_po == sectionSrc_po) * return sectionHandleTransform * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one); * * // ENDCAP * if (P_EndCapMesh != null && P_EndCapMesh.DependsOn != null && input_po == P_EndCapMesh.DependsOn.Parent) * return endCapHandleTransform; * * return Matrix4x4.identity ; * } */ public override Matrix4x4 getLocalConsumerMatrixPerInputSocket(AXParametricObject input_po, AXParameter input_P) { // use shift too // use caller address if (input_po == null) { return(Matrix4x4.identity); } bool addressIsNull = (input_po.selectedConsumer == null || input_po.selectedConsumer != this.parametricObject || String.IsNullOrEmpty(input_po.selectedConsumerAddress)); if (input_P != null) { if (input_P.Name == "Plan") { return(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one)); } if (input_P.Name == "Section") { //Debug.Log("the section ****"); //Debug.Log(sectionHandleTransform); return(sectionHandleTransform * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one)); } } // PLAN if (input_po == planSrc_po) { return(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one)); } // SECTION if (input_po == sectionSrc_po) { return(sectionHandleTransform * Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(90, 0, 0), Vector3.one)); } // PARSE ADDRESS Matrix4x4 optionalLocalM = Matrix4x4.identity; if (addressIsNull) { // set default address if (nodeSrc_po != null && input_po == nodeSrc_po) { input_po.selectedConsumerAddress = "node_0_0_0"; } else if (cellSrc_po != null && input_po == cellSrc_po) { input_po.selectedConsumerAddress = "cell_0_0_0"; } else if (cornerSrc_po != null && input_po == cornerSrc_po) { input_po.selectedConsumerAddress = "corner_0_0"; } optionalLocalM = input_po.getLocalMatrix() * input_po.getAxisRotationMatrix().inverse; } addressIsNull = (input_po.selectedConsumer == null || input_po.selectedConsumer != this.parametricObject || String.IsNullOrEmpty(input_po.selectedConsumerAddress)); if (!addressIsNull) { string[] address = input_po.selectedConsumerAddress.Split('_'); if (address.Length < 3) { return(Matrix4x4.identity); } string meshInput = address[0]; // e.g., "node", "cell", "spanU", "spanV", "corner" // Find out which input this caller is fed into Node Mesh, Bay Span or Cell Mesh? //Debug.Log(input_po.selectedConsumerAddress); // CORNER if (meshInput == "corner" && cornerSrc_po != null && input_po == cornerSrc_po) { int path_i = int.Parse(address[1]); int vert_i = int.Parse(address[2]); return(localMatrixFromAddress(RepeaterItem.Corner, path_i, vert_i) * optionalLocalM); } if (meshInput == "node" && nodeSrc_po != null && input_po == nodeSrc_po && address.Length == 4) { int path_i = int.Parse(address[1]); int subspline_i = int.Parse(address[2]); int node_i = int.Parse(address[3]); return(localMatrixFromAddress(RepeaterItem.Node, path_i, subspline_i, node_i) * optionalLocalM); } if (meshInput == "cell" && cellSrc_po != null && input_po == cellSrc_po && address.Length == 4) { int path_i = int.Parse(address[1]); int subspline_i = int.Parse(address[2]); int node_i = int.Parse(address[3]); return(localMatrixFromAddress(RepeaterItem.Cell, path_i, subspline_i, node_i) * optionalLocalM); } } return(Matrix4x4.identity); }
// GENERATE REPLICANT public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter) { //Debug.Log ("===> " + parametricObject.Name + " generate"); if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh")) { return(null); } if (!parametricObject.isActive) { return(null); } preGenerate(); AXParameter input_p = parametricObject.getParameter("Input Mesh"); if (parametricObject == null || input_p == null || input_p.DependsOn == null) { return(null); } AXParametricObject src_po = input_p.DependsOn.Parent; if (src_po == null) { return(null); } Matrix4x4 srcLocalM = src_po.getLocalMatrix().inverse; // 1. cache source object List <AXParameter> geometryControlParameterList = parametricObject.getAllParametersOfPType(AXParameter.ParameterType.GeometryControl); src_po.cacheAndSetParameters(geometryControlParameterList); if (!makeGameObjects) { // 2. re_generate source PO with temporary values set by this Replicant src_po.generateOutputNow(false, parametricObject, false); // 3. Now that the input_sourcePO has been regenerated, // grab the temporaryOutputMeshes meshes // from the input sources and add them here List <AXMesh> ax_meshes = new List <AXMesh>(); if (src_po.temporaryOutputMeshes != null) { for (int mi = 0; mi < src_po.temporaryOutputMeshes.Count; mi++) { AXMesh amesh = src_po.temporaryOutputMeshes [mi]; ax_meshes.Add(amesh.Clone(srcLocalM * amesh.transMatrix)); } } parametricObject.finishMultiAXMeshAndOutput(ax_meshes); setBoundaryFromAXMeshes(ax_meshes); } // 4. Make GAME OBJECTS GameObject go = null; if (makeGameObjects) { go = src_po.generator.generate(true, initiator_po, false); go.name = src_po.Name + " Replicant"; AXGameObject axgo = go.GetComponent <AXGameObject>(); if (axgo != null) { axgo.makerPO_GUID = parametricObject.Guid; } } // 5. restore source object; as though we were never here! src_po.revertParametersFromCache(); // Turn ax_meshes into GameObjects if (makeGameObjects) { Matrix4x4 tmx = parametricObject.getLocalMatrix(); go.transform.rotation = AXUtilities.QuaternionFromMatrix(tmx); go.transform.position = AXUtilities.GetPosition(tmx); go.transform.localScale = parametricObject.getLocalScaleAxisRotated(); return(go); } return(null); }