public void loadReciepeToEdtior(UMAReciepe reciepe) { isMale = reciepe.isMale; _skinGroup = reciepe.skinColor; foreach (var slot in _slotList) { var isEnable = reciepe.slots.ContainsKey(slot.Key); slot.Value.setEnabled(isEnable); if (isEnable == false) { foreach (var overlay in slot.Value.overlayList) { overlay.Value.setEnabled(isEnable); } } else { var reciepeSlot = reciepe.slots[slot.Key]; foreach (var overlay in slot.Value.overlayList) { var isOverlayEnabled = reciepeSlot.ContainsKey(overlay.Key); overlay.Value.setEnabled(isOverlayEnabled); if (isOverlayEnabled) { overlay.Value.setCurrentMaterial(reciepeSlot[overlay.Key].usedMaterial); overlay.Value.setAlbedoColor(reciepeSlot[overlay.Key].overlayAlbedoColor); } } } } }
/** * Clean up old surfacess **/ private ArrayMesh cleanOldSlots(ArrayMesh oldMesh, UMAReciepe reciepe) { List <string> oldSurfaces = new List <string>(); for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++) { oldSurfaces.Add(oldMesh.SurfaceGetName(surface)); } var allSlotNames = reciepe.slots.Select(tf => tf.Key).ToList(); //clean up current surface by new slots foreach (var oldSurface in oldSurfaces) { bool exist = false; foreach (var reicpeSlotName in allSlotNames) { if (oldSurface.Contains(reicpeSlotName)) { exist = true; } } if (!exist) { Console.WriteLine("[UMA] Delete surface " + oldSurface); oldMesh.SurfaceRemove(oldMesh.SurfaceFindByName(oldSurface)); changes++; } } return(oldMesh); }
/** * create overlay */ private ArrayMesh createOverlays(ArrayMesh oldMesh, UMAReciepe reciepe) { Dictionary <int, string> oldSurfaces = new Dictionary <int, string>(); for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++) { var name = oldMesh.SurfaceGetName(surface); oldSurfaces.Add(surface, name); } foreach (var slot in reciepe.slots) { var slotName = slot.Key; var path = System.IO.Path.Combine(reciepe.slotPath, slot.Key + ".tscn"); var restBones = extractBinds(path); foreach (var overlay in slot.Value) { var overlayName = slotName + "/Overlay_" + overlay.Key; if (!oldSurfaces.ContainsValue(overlayName)) { var overlayPath = System.IO.Path.Combine(overlay.Value.overlayPath, overlay.Key + ".tscn"); oldMesh = createSurfaceOverlay(oldMesh, slotName, overlayPath, overlayName, restBones); } } } return(oldMesh); }
protected ArrayMesh changeSkinColorSurface(ArrayMesh oldMesh, UMAReciepe reciepe) { var skinableSlots = new Dictionary <string, string>(); foreach (var slot in reciepe.slots) { var origSlot = _slotList[slot.Key]; var slotName = slot.Key; float glow = origSlot.Glow; if (origSlot.skinGroup.ToString() != "None") { skinableSlots.Add(slot.Key, origSlot.skinGroup.ToString()); } foreach (var overlay in slot.Value) { var overlayName = slotName + "/Overlay_" + overlay.Key; var origOverlay = origSlot.overlayList[overlay.Key]; if (origOverlay != null) { string materialPath = null; if (!String.IsNullOrEmpty(overlay.Value.usedMaterial) && origOverlay.isSkinable) { materialPath = System.IO.Path.Combine(origOverlay.fabricPath, overlay.Value.usedMaterial + ".tres"); } bool useAlbedoColor = origOverlay.useSkinColor; Color albedoColor = overlay.Value.overlayAlbedoColor; assignMaterialOverlay(oldMesh, overlayName, useAlbedoColor, albedoColor, materialPath, glow); } } } foreach (var skinableSlot in skinableSlots) { var color = reciepe.skinColor.FirstOrDefault(df => df.Key == skinableSlot.Value); if (color.Key == null) { continue; } var surface = oldMesh.SurfaceFindByName(skinableSlot.Key); if (surface >= 0) { var mat = oldMesh.SurfaceGetMaterial(surface); if (mat != null && mat is SpatialMaterial) { (mat as SpatialMaterial).AlbedoColor = color.Value; } } } return(oldMesh); }
public void setMainSkinColor(UMAReciepe reciepe = null) { if (meshin == null || meshin.Mesh == null) { return; } if (reciepe != null) { changeSkinColorSurface(meshin.Mesh as ArrayMesh, reciepe); } else { changeSkinColorSurface(meshin.Mesh as ArrayMesh, getReciepeFromEdtior()); } }
private ArrayMesh cleanOldOverlays(ArrayMesh oldMesh, UMAReciepe reciepe) { List <string> oldSurfaces = new List <string>(); for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++) { oldSurfaces.Add(oldMesh.SurfaceGetName(surface)); } foreach (var oldSurface in oldSurfaces) { bool exist = false; if (!oldSurface.Contains("Overlay_")) { continue; } foreach (var slot in reciepe.slots) { var slotName = slot.Key; foreach (var overlay in slot.Value) { var overlayName = slotName + "/Overlay_" + overlay.Key; if (oldSurface.Contains(overlayName)) { exist = true; } } } if (!exist) { Console.WriteLine("[UMA] Delete overlay " + oldSurface); oldMesh.SurfaceRemove(oldMesh.SurfaceFindByName(oldSurface)); changes++; } } return(oldMesh); }
/** * get all binds */ private List <UMAReciepeBindPose> getBinds(UMAReciepe reciepe) { var res = new List <UMAReciepeBindPose>(); foreach (var slot in reciepe.slots) { var slotPath = System.IO.Path.Combine(reciepe.slotPath, slot.Key + ".tscn"); res.AddRange(extractBinds(slotPath)); /* * foreach (var overlay in slot.Value) * { * var overlayPath = System.IO.Path.Combine(overlay.Value.overlayPath, overlay.Key + ".tscn"); * res.AddRange(extractBinds(overlayPath)); * } */ } return(res); }
public ArrayMesh generate(ArrayMesh oldMesh, Skin skin, UMAReciepe reciepe, List <string> boneNames) { //reset changes value changes = 0; //clean up slots oldMesh = cleanOldSlots(oldMesh, reciepe); //clean up overlay oldMesh = cleanOldOverlays(oldMesh, reciepe); //create new slots oldMesh = createNewSlots(oldMesh, reciepe); //create new overlay oldMesh = createOverlays(oldMesh, reciepe); //assign binds if (changes > 0) { var binds = getBinds(reciepe); binds = binds.DistinctBy(dt => dt.getSelector()).ToList(); skin.ClearBinds(); int i = 0; foreach (var bind in binds) { if (!boneNames.Contains(bind.boneName)) { continue; } skin.AddBind(0, bind.transform); skin.SetBindName(i, bind.boneName); i++; } } //set main color return(oldMesh); }
public UMAReciepe getReciepeFromEdtior() { var reciepe = new UMAReciepe(); try { foreach (var slot in slotList) { if (!slot.Value.isEnable) { continue; } var overlayList = new Dictionary <string, UMAReciepeOverlay>(); foreach (var overlay in slot.Value.overlayList) { if (overlay.Value.isEnable) { overlayList.Add(overlay.Key, new UMAReciepeOverlay { overlayAlbedoColor = overlay.Value.skinColor, usedMaterial = overlay.Value.currentMaterial }); } } reciepe.slots.Add(slot.Key, overlayList); } reciepe.skinColor = _skinGroup; reciepe.isMale = isMale; reciepe.dna = (UMADnaHumanoid)dna.Duplicate(); } catch (Exception e) { GD.PrintErr("[UMA] Fails: " + e.Message + ", " + e.StackTrace); } return(reciepe); }
/** * create slots */ private ArrayMesh createNewSlots(ArrayMesh oldMesh, UMAReciepe reciepe) { Dictionary <int, string> oldSurfaces = new Dictionary <int, string>(); for (int surface = 0; surface < oldMesh.GetSurfaceCount(); surface++) { var name = oldMesh.SurfaceGetName(surface); oldSurfaces.Add(surface, name); } foreach (var slot in reciepe.slots) { if (!oldSurfaces.ContainsValue(slot.Key)) { var path = System.IO.Path.Combine(reciepe.slotPath, slot.Key + ".tscn"); //create slot Console.WriteLine("[UMA] Create slot: " + path); oldMesh = createSurface(oldMesh, path, slot.Key); } } return(oldMesh); }
protected void renderMesh(UMAReciepe reciepe) { try { var timeStart = OS.GetUnixTime(); var generator = new UMAMeshGenerator(); reciepe.slotPath = _slotDir; foreach (var slot in reciepe.slots) { var origSlot = _slotList[slot.Key]; foreach (var overlay in slot.Value) { overlay.Value.overlayPath = origSlot.overlayDir; } } List <string> boneNames = new List <string>(); for (int bone = 0; bone < GetBoneCount(); bone++) { boneNames.Add(GetBoneName(bone)); } var newMesh = generator.generate((ArrayMesh)meshin.Mesh, meshin.Skin, reciepe, boneNames); newMesh = changeSkinColorSurface(newMesh, reciepe); CallDeferred("assignMesh", timeStart); //set reciepe to last reciepe _lastReciepe = reciepe; } catch (Exception e) { GD.PrintErr("[UMA] Fails: " + e.Message + ", " + e.StackTrace); } }
public void loadReciepe(UMAReciepe reciepe) { renderQueue.Enqueue(reciepe); }