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); }
// GENERATE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh")) { return(null); } preGenerate(); float amount = parametricObject.floatValue("amount"); List <AXMesh> ax_meshes = new List <AXMesh>(); AXParameter input_p = parametricObject.getParameter("Input Mesh"); AXParametricObject input_parent = input_p.DependsOn.Parent; Matrix4x4 sourceLocalTrans = input_parent.getLocalTransformMatrix(); Matrix4x4 sourceLocalAxis = input_parent.getAxisRotationMatrix(); Matrix4x4 sourceLocalAlign = input_parent.generator.getLocalAlignMatrix(); // just pass it through, but use grandparent's transform! for (int i = 0; i < input_p.DependsOn.meshes.Count; i++) { // Instance does not inhereit and build on the transform of its source object. AXMesh amesh = input_p.DependsOn.meshes [i]; Mesh m = amesh.mesh; Vector3[] verts = m.vertices; for (int j = 0; j < verts.Length; j++) { float new_y = (verts [j].y < .01) ? verts [j].y : verts [j].y + amount * (Mathf.PerlinNoise(verts [j].x, verts [j].z) * .5f); verts [j] = new Vector3(verts [j].x, new_y, verts [j].z); } m.vertices = verts; ax_meshes.Add(amesh.Clone(amesh.transMatrix * sourceLocalAlign.inverse * sourceLocalAxis.inverse * sourceLocalTrans.inverse)); } parametricObject.bounds = input_parent.bounds; parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); return(null); }
/* * 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 public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh")) { return(null); } preGenerate(); Terrain terrain = parametricObject.terrain; //float terrainY = 0; //float amount = parametricObject.floatValue("amount"); List <AXMesh> ax_meshes = new List <AXMesh>(); AXParameter input_p = parametricObject.getParameter("Input Mesh"); AXParameter inputSrc_p = input_p.DependsOn; AXParametricObject inputSrc_po = inputSrc_p.parametricObject; Matrix4x4 sourceLocalTrans = inputSrc_po.getLocalTransformMatrix(); Matrix4x4 sourceLocalAxis = inputSrc_po.getAxisRotationMatrix(); Matrix4x4 sourceLocalAlign = inputSrc_po.getLocalAlignMatrix(); // just pass it through, but use grandparent's transform! //inputSrc_po.generator.generate(false, null, true); if (inputSrc_p != null && inputSrc_p.meshes != null) { for (int i = 0; i < inputSrc_p.meshes.Count; i++) { // Instance does not inhereit and build on the transform of its source object. AXMesh amesh = inputSrc_p.meshes [i].Clone(); Mesh m = amesh.mesh; Vector3[] verts = m.vertices; for (int j = 0; j < verts.Length; j++) { //float new_y = (verts[i].y < .01) ? verts[i].y : verts[i].y+amount* (Mathf.PerlinNoise(verts[i].x, verts[i].z) * .5f); float new_y = (terrain == null) ? verts [j].y : verts [j].y + terrain.SampleHeight(parametricObject.model.gameObject.transform.TransformPoint(parametricObject.localMatrix.MultiplyPoint(verts [j]))); verts [j] = new Vector3(verts [j].x, new_y, verts [j].z); } m.vertices = verts; ax_meshes.Add(amesh.Clone(amesh.transMatrix * sourceLocalAlign.inverse * sourceLocalAxis.inverse * sourceLocalTrans.inverse)); } parametricObject.bounds = inputSrc_po.bounds; parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); if (makeGameObjects) { return(parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true)); } } return(null); }
// Update is called once per frame void Update() { if (!Application.isPlaying) { return; } bool byPlane = true; if (handle == null) { return; } AXParametricObject parametricObject = handle.parametricObject; // GET POSITION if (parametricObject.is2D()) { context = parametricObject.model.transform.localToWorldMatrix * parametricObject.worldDisplayMatrix; if (parametricObject.generator.hasOutputsConnected() || parametricObject.is2D()) { context *= parametricObject.generator.localMatrix.inverse; } else { context *= parametricObject.getAxisRotationMatrix().inverse *parametricObject.generator.localMatrix.inverse *parametricObject.getAxisRotationMatrix(); } } else { // GROUPER MATRIX NOT WORKING.... context = parametricObject.model.transform.localToWorldMatrix * parametricObject.generator.parametricObject.worldDisplayMatrix * (parametricObject.getAxisRotationMatrix() * parametricObject.generator.getLocalAlignMatrix()).inverse * parametricObject.generator.localMatrix.inverse; } // position handle by parmeters. positionHandleGameObject(); double h_diff = 0; double v_diff = 0; if (mouseIsDown) { if (Input.touchCount == 1) { // touch input - works better with deltaPosition var touch = Input.GetTouch(0); //var dx = touch.deltaPosition.x; h_diff = (100.0 / Screen.width) * touch.deltaPosition.x; v_diff = (100.0 / Screen.width) * touch.deltaPosition.y; } else { // 0 touches: must be mouse input h_diff = (5000 / Screen.width) * Input.GetAxis("Mouse X"); v_diff = (5000 / Screen.width) * Input.GetAxis("Mouse Y"); } h_diff /= 5; v_diff /= 5; //Debug.Log(h_diff +", " + v_diff); //using plane if (byPlane) { establishDrawingSurface(); //Vector3 prevPosition = transform.position; } // BASED ON PLANE Vector3 world_pos = transform.position; if (byPlane) { Vector3 hit_position3D = sampleHitPoint(); world_pos = hit_position3D - mouseDownDiff; transform.position = world_pos; } Vector3 localPosition = context.inverse.MultiplyPoint3x4(world_pos); //transform.position = world_pos; //if (transform.position != prevPosition) if (h_diff != 0 || v_diff != 0) { //Debug.Log("moved"); // Determine the orientation of the camera //The normal OperatingSystemFamily the handle plane //Debug.Log (lookV); float threshold = .707f; double diffX = -v_diff; double diffZ = h_diff; // This logic works with a normal vector if (!byPlane) { if (lookV.x > 0 && lookV.z < 0) { diffX = (1 - lookV.x) * h_diff - lookV.x * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; } else if (lookV.x > 0 && lookV.z > 0) { diffX = -((lookV.x)) * h_diff - lookV.x * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; } else if (lookV.x < 0 && lookV.z > 0) { diffX = (1 + lookV.x) * h_diff + lookV.x * v_diff; diffZ = (1 - lookV.z) * h_diff + lookV.z * v_diff; } else if (lookV.x > 0 && lookV.z > 0) { diffX = -((lookV.x)) * h_diff - (lookV.x) * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; //(-lookV.x + lookV.z) * v_diff; } else if (lookV.z > threshold) // pointing forwards { diffX = -h_diff; diffZ = -v_diff; } else if (lookV.z < -threshold) { // pointing backwards diffX = h_diff; diffZ = v_diff; } else if (lookV.x > 0) { // pointing right diffX = -h_diff; diffZ = v_diff; } else { // pointing left diffX = v_diff; diffZ = -h_diff; } } AXHandle han = handle; string hanString = "han_y"; float posV = localPosition.y; if (parametricObject.is3D()) { hanString = "han_z"; posV = localPosition.z; } if (byPlane) { parametricObject.setVar("han_x", (localPosition.x)); if (parametricObject.is3D()) { parametricObject.setVar("han_z", world_pos.z); } else { parametricObject.setVar("han_y", localPosition.y); } } else { // Relative slide of cursor parametricObject.setVar("han_x", (localPosition.x + (float)diffX)); parametricObject.setVar(hanString, (posV + (float)diffZ)); } // From plane // parametricObject.setVar("han_x", localPosition.x); // parametricObject.setVar("han_y", localPosition.y); // parametricObject.setVar("han_z", localPosition.z); // EACH EXPRESSION for (int i = 0; i < han.expressions.Count; i++) { if (han.expressions [i] == "") { continue; } string expression = Regex.Replace(han.expressions [i], @"\s+", ""); string paramName = expression.Substring(0, expression.IndexOf("=")); string definition = expression.Substring(expression.IndexOf("=") + 1); //Debug.Log (param + " --- " + definition); try { if (parametricObject.getParameter(paramName).Type == AXParameter.DataType.Int) { parametricObject.initiateRipple_setIntValueFromGUIChange(paramName, Mathf.RoundToInt((float)parametricObject.parseMath(definition))); } else { parametricObject.initiateRipple_setFloatValueFromGUIChange(paramName, (float)parametricObject.parseMath(definition)); } } catch (System.Exception e) { parametricObject.codeWarning = "10. Handle error: Please check syntax of: \"" + definition + "\" " + e.Message; } } parametricObject.model.isAltered(); //parametricObject.model.autobuild(); } } }