void UpdatePaintCanMaterial() { PaintMaterial material = PaintPreviewMaterial ?? OwnerInfo.GetPaintMaterial(); MyDefinitionManager.MyAssetModifiers skinRender = default(MyDefinitionManager.MyAssetModifiers); Vector3?skinColorOverride = null; if (material.Skin.HasValue) { skinRender = MyDefinitionManager.Static.GetAssetModifierDefinitionForRender(material.Skin.Value); MyAssetModifierDefinition skinDef = MyDefinitionManager.Static.GetAssetModifierDefinition(new MyDefinitionId(typeof(MyObjectBuilder_AssetModifierDefinition), material.Skin.Value)); if (skinDef != null && skinDef.DefaultColor.HasValue) { skinColorOverride = skinDef.DefaultColor.Value.ColorToHSVDX11(); } } Vector3 colorMask = skinColorOverride ?? material.ColorMask ?? Main.Palette.DefaultColorMask; IMyEntity paintEntity = (MagazineSubpart as IMyEntity) ?? Rifle; paintEntity.Render.MetalnessColorable = skinRender.MetalnessColorable; paintEntity.Render.TextureChanges = skinRender.SkinTextureChanges; // required to properly update skin (like glamour not being recolorable paintEntity.Render.RemoveRenderObjects(); paintEntity.Render.AddRenderObjects(); if (!paintEntity.Render.EnableColorMaskHsv) { paintEntity.Render.EnableColorMaskHsv = true; } paintEntity.Render.ColorMaskHsv = colorMask; ParticleColor = Utils.ColorMaskToRGB(colorMask); }
void FixModTexturePaths(MyAssetModifierDefinition assetDef) { try { if (assetDef.Textures == null || assetDef.Textures.Count <= 0) { Log.Error($"Skin '{assetDef.Id.SubtypeName}' has no textures!"); return; } if (TextureChanges == null) { TextureChanges = new Dictionary <string, DoTextureChange>(); } else { TextureChanges.Clear(); } for (int i = 0; i < assetDef.Textures.Count; i++) { MyObjectBuilder_AssetModifierDefinition.MyAssetTexture texture = assetDef.Textures[i]; if (string.IsNullOrEmpty(texture.Filepath)) { continue; } if (texture.Filepath.StartsWith("..")) { continue; // some fix already applied } string fixedPath = Path.Combine(assetDef.Context.ModPath, texture.Filepath); //fixedPath = Path.GetFullPath(fixedPath); if (!MyAPIGateway.Utilities.FileExistsInModLocation(fixedPath, assetDef.Context.ModItem)) { continue; } //Log.Info($"Fixed paths for mod '{assetDef.Context.ModName}' --- {texture.Location}: '{texture.Filepath}' to '{fixedPath}'"); // has no direct effect on the skin, the render thing after does, but this is for consistency texture.Filepath = fixedPath; assetDef.Textures[i] = texture; DoTextureChange texChange = TextureChanges.GetValueOrDefault(texture.Location); switch ((TextureType)texture.Type) { case TextureType.ColorMetal: texChange.ColorMetalFileName = fixedPath; break; case TextureType.NormalGloss: texChange.NormalGlossFileName = fixedPath; break; case TextureType.Extensions: texChange.ExtensionsFileName = fixedPath; break; case TextureType.Alphamask: texChange.AlphamaskFileName = fixedPath; break; } TextureChanges[texture.Location] = texChange; } if (TextureChanges.Count == 0) { return; } MyDefinitionManager.MyAssetModifiers assetModifierForRender = MyDefinitionManager.Static.GetAssetModifierDefinitionForRender(assetDef.Id.SubtypeId); foreach (var kv in TextureChanges) { // HACK: generating the prohibited MyTextureChange object from XML with similar data string xml = MyAPIGateway.Utilities.SerializeToXML(kv.Value); xml = xml.Replace(nameof(DoTextureChange), "MyTextureChange"); assetModifierForRender.SkinTextureChanges[kv.Key] = DeserializeAs(xml, assetModifierForRender.SkinTextureChanges); } Log.Info($"Fixed mod-relative paths for skin '{assetDef.Id.SubtypeName}' from mod '{assetDef.Context.ModName}'"); } catch (Exception e) { Log.Error($"Error in IsSkinAsset() for asset={assetDef.Id.ToString()}\n{e}"); } }