private void updateTextureSet(bool useDefaults) { if (mpf == null) { return; } TextureSet s = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); RecoloringData[] colors = useDefaults ? s.maskColors : getSectionColors(string.Empty); Material fm = mpf.FairingMaterial; s.textureData[0].apply(fm);//TODO -- bit of an ugly hack; should at least pull a ref to whatever index that slot goes to s.textureData[0].apply(mpf.FairingMaterial); s.textureData[0].applyRecoloring(mpf.FairingMaterial, colors); s.textureData[0].apply(mpf.FairingConeMaterial); s.textureData[0].applyRecoloring(mpf.FairingConeMaterial, colors); List <Transform> trs = new List <Transform>(); foreach (ProceduralFairings.FairingPanel fp in mpf.Panels) { s.enable(fp.go.transform, colors); } if (useDefaults) { recolorHandler.setColorData(colors); } SSTUModInterop.onPartTextureUpdated(part); }
private void initialize() { if (initialized) { return; } initialized = true; recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); mpf = part.GetComponent <ModuleProceduralFairing>(); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); string[] names = node.GetStringValues("textureSet"); string[] titles = SSTUUtils.getNames(TexturesUnlimitedLoader.getTextureSets(names), m => m.title); TextureSet t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); if (t == null) { currentTextureSet = names[0]; t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(t.maskColors); } this.updateUIChooseOptionControl(nameof(currentTextureSet), names, titles, true, currentTextureSet); Fields[nameof(currentTextureSet)].guiActiveEditor = names.Length > 1; }
private void initialize() { if (initialized) { return; } initialized = true; recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); string[] names = node.GetStringValues("textureSet"); string[] titles = SSTUUtils.getNames(TexturesUnlimitedLoader.getTextureSets(names), m => m.title); TextureSet currentTextureSetData = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); if (currentTextureSetData == null) { currentTextureSet = names[0]; currentTextureSetData = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(currentTextureSetData.maskColors); } this.updateUIChooseOptionControl(nameof(currentTextureSet), names, titles, true, currentTextureSet); Fields[nameof(currentTextureSet)].guiActiveEditor = names.Length > 1; fuelType = VolumeContainerLoader.getPreset(fuelPreset); Transform modelBase = part.transform.FindRecursive("model"); //Set up the engine models container ConfigNode[] modelNodes = node.GetNodes("MODEL"); engineModelRoot = modelBase.FindOrCreate(engineModelRootName); ModelDefinitionLayoutOptions[] models = SSTUModelData.getModelDefinitions(modelNodes); engineModels = new ModelModule <SSTUInterstageDecoupler>(part, this, engineModelRoot, ModelOrientation.CENTRAL, nameof(currentEngineModel), nameof(currentEngineLayout), nameof(currentEngineTextureSet), nameof(customEngineColorData), null, null, null, null); engineModels.getSymmetryModule = m => m.engineModels; engineModels.getValidOptions = () => models; engineModels.getLayoutPositionScalar = () => currentBottomDiameter * 0.5f; //engineModels.getLayoutScaleScalar = () => currentEngineScale; engineModels.setupModelList(models); engineModels.setupModel(); engineModels.updateSelections(); updateEnginePositionAndScale(); //set up the fairing container minHeight = engineModels.moduleHeight; Transform fairingContainerRoot = modelBase.FindOrCreate(baseTransformName); fairingBase = new FairingContainer(fairingContainerRoot.gameObject, cylinderSides, numberOfPanels, wallThickness); updateEditorFields(); buildFairing(); updateEnginePositionAndScale(); updateFairingTextureSet(false); updateNodePositions(false); updatePartMass(); }
public void enableTextureSet(string name, RecoloringData[] userColors) { TextureSet s = TexturesUnlimitedLoader.getTextureSet(name); if (s != null) { s.enable(root.transform, userColors); } }
private void updateTextureSet(bool useDefaults) { TextureSet s = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); RecoloringData[] colors = useDefaults ? s.maskColors : getSectionColors(string.Empty); fairingBase.enableTextureSet(currentTextureSet, colors); if (useDefaults) { recolorHandler.setColorData(colors); } SSTUModInterop.onPartTextureUpdated(part); }
public void enableTextureSet(string name, RecoloringData[] userColors) { TextureSet set = TexturesUnlimitedLoader.getTextureSet(name); if (set != null) { set.enable(rootObject.transform, userColors); } else { MonoBehaviour.print("ERROR: " + name + " is not a valid texture set for fairing."); } }
//IRecolorable override public TextureSet getSectionTexture(string section) { switch (name) { case "Decoupler": return(TexturesUnlimitedLoader.getTextureSet(currentTextureSet)); case "Engines": return(engineModels.textureSet); default: return(TexturesUnlimitedLoader.getTextureSet(currentTextureSet)); } }
private void initialize() { if (initialized) { return; } initialized = true; recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); string[] names = node.GetStringValues("textureSet"); string[] titles = SSTUUtils.getNames(TexturesUnlimitedLoader.getTextureSets(names), m => m.title); TextureSet t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); if (t == null) { currentTextureSet = names[0]; t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(t.maskColors); } this.updateUIChooseOptionControl(nameof(currentTextureSet), names, titles, true, currentTextureSet); Transform tr = part.transform.FindRecursive("model").FindOrCreate("PetalAdapterRoot"); fairingBase = new InterstageFairingContainer(tr.gameObject, cylinderSides, numberOfPanels, wallThickness); UVMap uvs = UVMap.GetUVMapGlobal(uvMap); fairingBase.outsideUV = uvs.getArea("outside"); fairingBase.insideUV = uvs.getArea("inside"); fairingBase.edgesUV = uvs.getArea("edges"); validateStraightHeight(); rebuildFairing(false);//will create fairing using default / previously saved fairing configuration setPanelRotations(currentRotation); if (state == InterstageFairingState.JETTISONED) { fairingBase.destroyFairing(); } updateGuiState(); }
private void updateTextureSet(bool useDefaults) { TextureSet s = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); RecoloringData[] colors = useDefaults ? s.maskColors : getSectionColors(string.Empty); int len = fairingParts.Length; for (int i = 0; i < len; i++) { fairingParts[i].fairingBase.enableTextureSet(currentTextureSet, colors); } if (useDefaults) { recolorHandler.setColorData(colors); } updateOpacity(); ROTModInterop.onPartTextureUpdated(part); }
private void loadConfigData() { recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); ConfigNode node = SSTUConfigNodeUtils.parseConfigNode(configNodeData); string[] names = node.GetStringValues("textureSet"); string[] titles = SSTUUtils.getNames(TexturesUnlimitedLoader.getTextureSets(names), m => m.title); TextureSet currentTextureSetData = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); if (currentTextureSetData == null) { currentTextureSet = names[0]; currentTextureSetData = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(currentTextureSetData.maskColors); } Fields["currentTextureSet"].guiActiveEditor = names.Length > 1; this.updateUIChooseOptionControl("currentTextureSet", names, titles, true, currentTextureSet); }
//IRecolorable override public TextureSet getSectionTexture(string section) { return(TexturesUnlimitedLoader.getTextureSet(currentTextureSet)); }
//creates/recreates FairingData instances from data from config node and any persistent node (if applicable) private void loadFairingData(ConfigNode node) { recolorHandler = new RecoloringHandler(Fields[nameof(customColorData)]); ConfigNode[] fairingNodes = node.GetNodes("FAIRING"); fairingParts = new ROTNodeFairingData[fairingNodes.Length]; Transform modelBase = part.transform.FindRecursive("model"); Transform parent; ModuleROTNodeFairing[] cs = part.GetComponents <ModuleROTNodeFairing>(); int l = Array.IndexOf(cs, this); int moduleIndex = l; for (int i = 0; i < fairingNodes.Length; i++) { parent = modelBase.FindOrCreate(fairingName + "-" + moduleIndex + "-" + i); fairingParts[i] = new ROTNodeFairingData(); fairingParts[i].load(fairingNodes[i], parent.gameObject); if (fairingParts[i].canAdjustTop) { enableTopDiameterControls = true; if (guiTopDiameter < 0) { guiTopDiameter = fairingParts[i].topRadius * 2f; } else { fairingParts[i].topRadius = guiTopDiameter * 0.5f; } } if (fairingParts[i].canAdjustBottom) { enableBottomDiameterControls = true; if (guiBottomDiameter < 0) { guiBottomDiameter = fairingParts[i].bottomRadius * 2f; } else { fairingParts[i].bottomRadius = guiBottomDiameter * 0.5f; } } } //reload fairing data from persistence; //it -should- already match the guiTopDiameter/guiBottomDiameter (or else was already corrupted/invalid when saved out). if (!String.IsNullOrEmpty(persistentDataString)) { String[] datas = ROTUtils.parseCSV(persistentDataString, ":"); int length = datas.Length; for (int i = 0; i < length; i++) { fairingParts[i].loadPersistence(datas[i]); } } string[] names = node.GetStringValues("textureSet"); string[] titles = ROTUtils.getNames(TexturesUnlimitedLoader.getTextureSets(names), m => m.title); TextureSet t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); if (t == null) { currentTextureSet = names[0]; t = TexturesUnlimitedLoader.getTextureSet(currentTextureSet); initializedColors = false; } if (!initializedColors) { initializedColors = true; recolorHandler.setColorData(t.maskColors); } this.updateUIChooseOptionControl(nameof(currentTextureSet), names, titles, true, currentTextureSet); }
/// <summary> /// Construct the model definition from the data in the input ConfigNode.<para/> /// All data constructs MUST conform to the expected format (see documentation), or things will not load properly and the model will likely not work as expected. /// </summary> /// <param name="node"></param> public ROLModelDefinition(ConfigNode node) { //load basic model definition values -- data that pertains to every model definition regardless of end-use. configNode = node; name = node.ROLGetStringValue("name", String.Empty); if (string.IsNullOrEmpty(name)) { ROLLog.error("ERROR: Cannot load ROLModelDefinition with null or empty name. Full config:\n" + node.ToString()); } title = node.ROLGetStringValue("title", name); description = node.ROLGetStringValue("description", title); modelName = node.ROLGetStringValue("modelName", string.Empty); upgradeUnlock = node.ROLGetStringValue("upgradeUnlock", upgradeUnlock); height = node.ROLGetFloatValue("height", height); actualHeight = node.ROLGetFloatValue("actualHeight", actualHeight); volume = node.ROLGetFloatValue("volume", volume); mass = node.ROLGetFloatValue("mass", mass); cost = node.ROLGetFloatValue("cost", cost); diameter = node.ROLGetFloatValue("diameter", diameter); minVerticalScale = node.ROLGetFloatValue("minVerticalScale", minVerticalScale); maxVerticalScale = node.ROLGetFloatValue("maxVerticalScale", maxVerticalScale); upperDiameter = node.ROLGetFloatValue("upperDiameter", diameter); lowerDiameter = node.ROLGetFloatValue("lowerDiameter", diameter); panelLength = node.ROLGetFloatValue("panelLength", panelLength); panelWidth = node.ROLGetFloatValue("panelWidth", panelWidth); panelArea = node.ROLGetFloatValue("panelArea", panelArea); panelScale = node.ROLGetFloatValue("panelScale", panelScale); secondaryTransformName = node.ROLGetStringValue("secondaryTransformName", secondaryTransformName); pivotName = node.ROLGetStringValue("pivotName", pivotName); animationName = node.ROLGetStringValue("animationName", animationName); lengthWidth = node.ROLGetBoolValue("lengthWidth", lengthWidth); isTracking = node.ROLGetBoolValue("isTracking", isTracking); effectiveLength = node.ROLGetFloatValue("effectiveLength", effectiveLength); additionalVolume = node.ROLGetFloatValue("additionalVolume", additionalVolume); if (node.HasValue("verticalOffset")) { positionOffset = new Vector3(0, node.ROLGetFloatValue("verticalOffset"), 0); } else { positionOffset = node.ROLGetVector3("positionOffset", Vector3.zero); } rotationOffset = node.ROLGetVector3("rotationOffset", rotationOffset); scaleOffset = node.ROLGetVector3("scaleOffset", Vector3.one); orientation = (ModelOrientation)Enum.Parse(typeof(ModelOrientation), node.ROLGetStringValue("orientation", ModelOrientation.TOP.ToString())); invertAxis = node.ROLGetVector3("invertAxis", invertAxis); //load sub-model definitions ConfigNode[] subModelNodes = node.GetNodes("SUBMODEL"); int len = subModelNodes.Length; if (len == 0)//no defined submodel data, check for regular single model definition, if present, build a submodel definition for it. { if (!string.IsNullOrEmpty(modelName)) { SubModelData smd = new SubModelData(modelName, new string[0], string.Empty, positionOffset, rotationOffset, scaleOffset); subModelData = new SubModelData[] { smd }; } else//is an empty proxy model with no meshes { subModelData = new SubModelData[0]; } } else { subModelData = new SubModelData[len]; for (int i = 0; i < len; i++) { subModelData[i] = new SubModelData(subModelNodes[i]); } } if (node.HasNode("MERGEDMODELS")) { ConfigNode[] mergeNodes = node.GetNodes("MERGEDMODELS"); len = mergeNodes.Length; mergeData = new MeshMergeData[len]; for (int i = 0; i < len; i++) { mergeData[i] = new MeshMergeData(mergeNodes[i]); } } else { mergeData = new MeshMergeData[0]; } //Load texture set definitions. List <TextureSet> textureSetList = new List <TextureSet>(); foreach (string tsName in node.ROLGetStringValues("textureSet")) { if (TexturesUnlimitedLoader.getTextureSet(tsName) is TextureSet ts) { textureSetList.Add(ts); } } //then load any of the model-specific sets foreach (ConfigNode tsNode in node.GetNodes("KSP_TEXTURE_SET")) { textureSetList.Add(new TextureSet(tsNode)); } textureSets = textureSetList.ToArray(); //Load the default texture set specification defaultTextureSet = node.ROLGetStringValue("defaultTextureSet"); //if none is defined in the model def, but texture sets are present, set it to the name of the first defined texture set if (string.IsNullOrEmpty(defaultTextureSet) && textureSets.Length > 0) { defaultTextureSet = textureSets[0].name; } if (node.HasValue("topNode")) { topNodeData = new AttachNodeBaseData(node.ROLGetStringValue("topNode")); } else { float y = height; if (orientation == ModelOrientation.CENTRAL) { y *= 0.5f; } else if (orientation == ModelOrientation.BOTTOM) { y = 0; } topNodeData = new AttachNodeBaseData(0, y, 0, 0, 1, 0, diameter / 1.25f); } if (node.HasValue("bottomNode")) { bottomNodeData = new AttachNodeBaseData(node.ROLGetStringValue("bottomNode")); } else { float y = -height; if (orientation == ModelOrientation.CENTRAL) { y *= 0.5f; } else if (orientation == ModelOrientation.TOP) { y = 0; } bottomNodeData = new AttachNodeBaseData(0, y, 0, 0, -1, 0, diameter / 1.25f); } if (node.HasValue("bodyNode")) { string[] nodeData = node.ROLGetStringValues("bodyNode"); len = nodeData.Length; bodyNodeData = new AttachNodeBaseData[len]; for (int i = 0; i < len; i++) { bodyNodeData[i] = new AttachNodeBaseData(nodeData[i]); } } //load the surface attach node specifications, or create default if none are defined. if (node.HasValue("surface")) { surfaceNode = new AttachNodeBaseData(node.ROLGetStringValue("surface")); } else { surfaceNode = new AttachNodeBaseData($"{diameter / 2},0,0,1,0,0,2"); } if (node.HasNode("COMPOUNDMODEL")) { compoundModelData = new CompoundModelData(node.GetNode("COMPOUNDMODEL")); } if (node.HasNode("CONSTRAINT")) { constraintData = new ModelConstraintData(node.GetNode("CONSTRAINT")); } if (node.HasNode("RCSDATA")) { rcsModuleData = new ModelRCSModuleData(node.GetNode("RCSDATA")); } if (node.HasNode("RCSPOSITION")) { ConfigNode[] pns = node.GetNodes("RCSPOSITION"); len = pns.Length; rcsPositionData = new ModelAttachablePositionData[len]; for (int i = 0; i < len; i++) { rcsPositionData[i] = new ModelAttachablePositionData(pns[i]); } } if (node.HasNode("ENGINE_THRUST")) { engineThrustData = new ModelEngineThrustData(node.GetNode("ENGINE_THRUST")); } if (node.HasNode("ENGINE_TRANSFORM")) { engineTransformData = new ModelEngineTransformData(node.GetNode("ENGINE_TRANSFORM")); } }