public void updateAttachNodes(Part part, String[] nodeNames, bool userInput, ModelOrientation orientation) { if (nodeNames.Length == 1 && nodeNames[0] == "NONE") { return; } Vector3 basePos = new Vector3(0, currentVerticalPosition, 0); AttachNode node = null; AttachNodeBaseData data; int nodeCount = modelDefinition.attachNodeData.Length; int len = nodeNames.Length; Vector3 pos = Vector3.zero; Vector3 orient = Vector3.up; int size = 2; bool invert = (orientation == ModelOrientation.BOTTOM && modelDefinition.invertForBottom) || (orientation == ModelOrientation.TOP && modelDefinition.invertForTop); for (int i = 0; i < len; i++) { node = part.findAttachNode(nodeNames[i]); if (i < nodeCount) { data = modelDefinition.attachNodeData[i]; size = data.size; pos = data.position * currentHeightScale; if (invert) { pos.y = -pos.y; pos.x = -pos.x; } pos.y += currentVerticalPosition; orient = data.orientation; if (invert) { orient = -orient; } if (node == null)//create it { SSTUAttachNodeUtils.createAttachNode(part, nodeNames[i], pos, orient, size); } else//update its position { SSTUAttachNodeUtils.updateAttachNodePosition(part, node, pos, orient, userInput); } } else//extra node, destroy { if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { SSTUAttachNodeUtils.destroyAttachNode(part, node); } } } }
private void updateAttachNodes(bool userInput) { int len = modelGroups.Length; List <string> enabledNodeNames = new List <string>(); AttachNode attachNode; ModelSwitchGroup group; ModelSwitchData model; for (int i = 0; i < len; i++) { group = modelGroups[i]; model = group.enabledModel; if (!controlledNodes.Contains(group.parentNode)) { continue; } //not a node that we should touch... if (model == null || model.suppressNode) { continue; } enabledNodeNames.Add(group.parentNode); Vector3 pos = group.getModelRootTransform().position; pos = part.transform.InverseTransformPoint(pos); Vector3 rotation = group.getModelRootTransform().up; attachNode = part.findAttachNode(group.parentNode); if (attachNode == null) { attachNode = SSTUAttachNodeUtils.createAttachNode(part, group.parentNode, pos, rotation, 2); } else { SSTUAttachNodeUtils.updateAttachNodePosition(part, attachNode, pos, rotation, userInput); } } List <AttachNode> attachNodes = new List <AttachNode>(); attachNodes.AddRange(part.attachNodes); len = attachNodes.Count; for (int i = 0; i < len; i++) { attachNode = attachNodes[i]; if (!controlledNodes.Contains(attachNode.id)) { continue; } //not a node that we should touch... if (attachNode.attachedPart == null && !enabledNodeNames.Contains(attachNode.id)) { SSTUAttachNodeUtils.destroyAttachNode(part, attachNode); } } }
public void toggleNode() { AttachNode node = part.findAttachNode(nodeName); if (node == null) { currentlyEnabled = true; SSTUAttachNodeUtils.createAttachNode(part, nodeName, nodeDefaultPosition, nodeDefaultOrientation, 2); } else if (node.attachedPart == null) { currentlyEnabled = false; SSTUAttachNodeUtils.destroyAttachNode(part, node); } }
//[KSPEvent(guiName = "Invert Node", guiActiveEditor = false)] //public void invertNodeEvent() //{ // //TODO //} public override void OnStart(PartModule.StartState state) { base.OnStart(state); Events["toggleNodeEvent"].guiName = "Toggle " + nodeName + " node"; if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { if (!initialized) { currentlyEnabled = startsEnabled; initialized = true; AttachNode node = part.findAttachNode(nodeName); if (currentlyEnabled && node == null) { SSTUAttachNodeUtils.createAttachNode(part, nodeName, nodeDefaultPosition, nodeDefaultOrientation, 2); } else if (!currentlyEnabled && node != null && node.attachedPart == null) { SSTUAttachNodeUtils.destroyAttachNode(part, node); } else if (!currentlyEnabled && node != null && node.attachedPart != null)//error, should never occur if things were handled properly { currentlyEnabled = true; } } else { AttachNode node = part.findAttachNode(nodeName); if (currentlyEnabled && node == null) { currentlyEnabled = true; SSTUAttachNodeUtils.createAttachNode(part, nodeName, nodeDefaultPosition, nodeDefaultOrientation, 2); } else if (!currentlyEnabled && node != null && node.attachedPart == null) { currentlyEnabled = false; SSTUAttachNodeUtils.destroyAttachNode(part, node); } } } }
private void updateAttachNodes(bool userInput) { int len = modelGroups.Length; List <string> enabledNodeNames = new List <string>(); AttachNode attachNode; ModelSwitchGroup group; ModelSwitchData model; for (int i = 0; i < len; i++) { //updated node handling routing group = modelGroups[i]; if (!group.groupEnabled)//group disabled { continue; } model = group.enabledModel; if (model == null)//ERROR - no model on enabled group { continue; } //if (model.nodes == null) { continue; }//ERROR - nodes should not be null; let it crash int len2 = model.nodes.Length; if (len2 > 0) { for (int k = 0; k < len2; k++) { if (!controlledNodes.Contains(model.nodes[k].name)) { continue; } //not a node under this modules control if (group.isChildAtNodeEnabled(model.nodes[k].name)) { continue; } //child enabled, let it handle the node setup if (!model.nodes[k].createAttachNode) { continue; } //node is disabled if (enabledNodeNames.Contains(model.nodes[k].name)) { continue; } //node already enabled from other model -- user config/setup ERROR // if it passed all those checks it is a valid model node for attach-node creation; setup the position and rotation relative to this groups base transform Vector3 pos = model.nodes[k].position; Quaternion nr = Quaternion.Euler(model.nodes[k].rotation); Vector3 rot = Vector3.zero; //position will be a local position transformed by group base transform into world space, and then by part transform into local space //rotation will be the base-transforms rotation quaternion multiplied (or inverse) by the local-rotation quaternion from euler-angle of the rotation for the node //and then how to get it as a vector-axis? mult the 'fwd' vector by the quat? attachNode = part.FindAttachNode(model.nodes[k].name); if (attachNode == null) { attachNode = SSTUAttachNodeUtils.createAttachNode(part, group.parentNode, pos, rot, 2); } else { SSTUAttachNodeUtils.updateAttachNodePosition(part, attachNode, pos, rot, userInput); } } //check each node for 'enabled' flag //if enabled check for children //if child is present, let child handle the node //else enable it } else//no model nodes, so no chance for children groups; only nodes defined in the MODEL and flagged for enabled will be enabled; no nodes == no nodes! { //NOOP } // original code block // does not use the 'enableAttachNode' data from the node specifications in the MODELs //group = modelGroups[i]; //model = group.enabledModel; //if (!controlledNodes.Contains(group.parentNode)) { continue; }//not a node that we should touch... //if (model == null || model.suppressNode) { continue; } //enabledNodeNames.Add(group.parentNode); //Vector3 pos = group.getModelRootTransform().position; //pos = part.transform.InverseTransformPoint(pos); //Vector3 rotation = group.getModelRootTransform().up; //attachNode = part.findAttachNode(group.parentNode); //if (attachNode == null) //{ // attachNode = SSTUAttachNodeUtils.createAttachNode(part, group.parentNode, pos, rotation, 2); //} //else //{ // SSTUAttachNodeUtils.updateAttachNodePosition(part, attachNode, pos, rotation, userInput); //} } List <AttachNode> attachNodes = new List <AttachNode>(); attachNodes.AddRange(part.attachNodes); len = attachNodes.Count; for (int i = 0; i < len; i++) { attachNode = attachNodes[i]; if (!controlledNodes.Contains(attachNode.id)) { continue; } //not a node that we should touch... if (attachNode.attachedPart == null && !enabledNodeNames.Contains(attachNode.id)) { SSTUAttachNodeUtils.destroyAttachNode(part, attachNode); } } }
/// <summary> /// Updates the attach nodes on the part for the input list of attach nodes and the current specified nodes for this model. /// Any 'extra' attach nodes from the part will be disabled. /// </summary> /// <param name="part"></param> /// <param name="nodeNames"></param> /// <param name="userInput"></param> /// <param name="orientation"></param> public void updateAttachNodes(Part part, String[] nodeNames, bool userInput, ModelOrientation orientation) { if (nodeNames == null || nodeNames.Length < 1) { return; } if (nodeNames.Length == 1 && (nodeNames[0] == "NONE" || nodeNames[0] == "none")) { return; } float currentVerticalPosition = this.currentVerticalPosition; float offset = getVerticalOffset(); if (orientation == ModelOrientation.BOTTOM) { offset = -offset; } currentVerticalPosition -= offset; AttachNode node = null; AttachNodeBaseData data; int nodeCount = modelDefinition.attachNodeData.Length; int len = nodeNames.Length; Vector3 pos = Vector3.zero; Vector3 orient = Vector3.up; int size = 4; bool invert = modelDefinition.shouldInvert(orientation); for (int i = 0; i < len; i++) { node = part.FindAttachNode(nodeNames[i]); if (i < nodeCount) { data = modelDefinition.attachNodeData[i]; size = Mathf.RoundToInt(data.size * currentDiameterScale); pos = data.position * currentHeightScale; if (invert) { pos.y = -pos.y; pos.x = -pos.x; } pos.y += currentVerticalPosition; orient = data.orientation; if (invert) { orient = -orient; orient.z = -orient.z; } if (node == null)//create it { SSTUAttachNodeUtils.createAttachNode(part, nodeNames[i], pos, orient, size); } else//update its position { SSTUAttachNodeUtils.updateAttachNodePosition(part, node, pos, orient, userInput); } } else//extra node, destroy { if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight) { SSTUAttachNodeUtils.destroyAttachNode(part, node); } } } }