mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Compare commits
38 Commits
0.2.9
...
feature-be
Author | SHA1 | Date | |
---|---|---|---|
5a7f101155 | |||
39555d92d1 | |||
7a909c18bc | |||
d714c498fb | |||
fa4b799788 | |||
970a69be11 | |||
dddb7f09f3 | |||
3cd229bc23 | |||
4948818065 | |||
036b084d34 | |||
1e3addeb4d | |||
47c70d3071 | |||
9955b9ce30 | |||
f20119565f | |||
6ee52ac18e | |||
67ccaa1dae | |||
c33f5bacdd | |||
03d2e66543 | |||
be3b7f791a | |||
3effae6ecd | |||
7406fa613b | |||
7b9ed99325 | |||
e069f85e56 | |||
2f2b6fb692 | |||
169f2e9bf1 | |||
eb033113b3 | |||
227c259e51 | |||
fc6820d73b | |||
9dc98a6f9d | |||
35fce78616 | |||
84611a26e8 | |||
a61a2b81a1 | |||
e37cf03f7b | |||
e6288942ea | |||
62bdd151e1 | |||
f5af8a4d53 | |||
df95601416 | |||
596675ad8d |
7
.github/workflows/ff-release.yml
vendored
7
.github/workflows/ff-release.yml
vendored
@ -1,5 +1,7 @@
|
|||||||
name: Fast-Forward Release Branch
|
name: Fast-Forward Release Branch
|
||||||
on: [ release ]
|
on:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
fast-forward:
|
fast-forward:
|
||||||
@ -12,8 +14,7 @@ jobs:
|
|||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Merge into Release
|
- name: Merge into Release
|
||||||
run: |
|
run: git merge ${{github.ref_name}} --ff-only
|
||||||
git merge ${{github.ref_name}} --ff-only
|
|
||||||
|
|
||||||
- name: Push Changes
|
- name: Push Changes
|
||||||
uses: ad-m/github-push-action@master
|
uses: ad-m/github-push-action@master
|
||||||
|
4
.github/workflows/ksp-publish.yml
vendored
4
.github/workflows/ksp-publish.yml
vendored
@ -37,7 +37,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
wget --user drewcassidy --password ${{ secrets.PILE_OF_ROCKS_PASS }} https://pileof.rocks/Secret/conformal-decals-dependencies-1.zip
|
wget --user drewcassidy --password ${{ secrets.PILE_OF_ROCKS_PASS }} https://pileof.rocks/Secret/conformal-decals-dependencies-1.zip
|
||||||
unzip conformal-decals-dependencies-*.zip -d ConformalDecals/dlls
|
unzip conformal-decals-dependencies-*.zip -d ConformalDecals/dlls
|
||||||
dotnet build --configuration Release ConformalDecals.sln
|
|
||||||
|
|
||||||
- name: Build DLL
|
- name: Build DLL
|
||||||
working-directory: Source
|
working-directory: Source
|
||||||
@ -50,11 +49,14 @@ jobs:
|
|||||||
wget http://pileof.rocks/KSP/Shabby_v0.2.0.zip
|
wget http://pileof.rocks/KSP/Shabby_v0.2.0.zip
|
||||||
wget https://ksp.sarbian.com/jenkins/job/ModuleManager/161/artifact/ModuleManager.4.2.1.dll
|
wget https://ksp.sarbian.com/jenkins/job/ModuleManager/161/artifact/ModuleManager.4.2.1.dll
|
||||||
wget https://github.com/blowfishpro/B9PartSwitch/releases/download/v2.19.0/B9PartSwitch_v2.19.0.zip
|
wget https://github.com/blowfishpro/B9PartSwitch/releases/download/v2.19.0/B9PartSwitch_v2.19.0.zip
|
||||||
|
wget https://github.com/KSPModdingLibs/HarmonyKSP/releases/download/2.0.4.0/HarmonyKSP_2.0.4.0_for_KSP1.8+.zip
|
||||||
unzip -d Shabby Shabby*.zip
|
unzip -d Shabby Shabby*.zip
|
||||||
unzip -d B9PartSwitch B9PartSwitch*.zip
|
unzip -d B9PartSwitch B9PartSwitch*.zip
|
||||||
|
unzip -d HarmonyKSP HarmonyKSP*.zip
|
||||||
mv Shabby/GameData/Shabby GameData/
|
mv Shabby/GameData/Shabby GameData/
|
||||||
mv ModuleManager*.dll GameData/
|
mv ModuleManager*.dll GameData/
|
||||||
mv B9PartSwitch/GameData/B9PartSwitch GameData/
|
mv B9PartSwitch/GameData/B9PartSwitch GameData/
|
||||||
|
mv HarmonyKSP/GameData/000_Harmony GameData/
|
||||||
|
|
||||||
- name: Upload Unbundled Build
|
- name: Upload Unbundled Build
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -52,6 +52,7 @@ Source/ConformalDecals/bin
|
|||||||
.ds_store
|
.ds_store
|
||||||
*.sublime*
|
*.sublime*
|
||||||
.idea
|
.idea
|
||||||
|
.vs
|
||||||
obj
|
obj
|
||||||
*.swp
|
*.swp
|
||||||
@thumbs
|
@thumbs
|
||||||
|
@ -30,8 +30,6 @@ public class TextRenderTest : MonoBehaviour {
|
|||||||
Debug.Log("starting...");
|
Debug.Log("starting...");
|
||||||
|
|
||||||
StartCoroutine(OnRender());
|
StartCoroutine(OnRender());
|
||||||
var thing = new GameObject();
|
|
||||||
thing.AddComponent<TextMeshPro>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
BIN
Assets/Textures/Decal-Back.afdesign
Normal file
BIN
Assets/Textures/Decal-Back.afdesign
Normal file
Binary file not shown.
BIN
Assets/Textures/Icons Generic.afdesign
Normal file
BIN
Assets/Textures/Icons Generic.afdesign
Normal file
Binary file not shown.
BIN
Assets/Textures/Munar.afdesign
Normal file
BIN
Assets/Textures/Munar.afdesign
Normal file
Binary file not shown.
BIN
Assets/Textures/Semiotic.afdesign
Normal file
BIN
Assets/Textures/Semiotic.afdesign
Normal file
Binary file not shown.
16
CHANGELOG.md
16
CHANGELOG.md
@ -8,6 +8,22 @@ All notable changes to this project will be documented in this file
|
|||||||
| website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals |
|
| website | https://forum.kerbalspaceprogram.com/index.php?/topic/194802-18-111-conformal-decals |
|
||||||
| author | Andrew Cassidy |
|
| author | Andrew Cassidy |
|
||||||
|
|
||||||
|
## 0.2.10 - 2022-03-14
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed decals not projecting on loading prefabs
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Re-enabled projecting onto TransparentFX layer
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Allowed for regular expressions to be used when blacklisting shaders
|
||||||
|
- Added all Waterfall shaders to the shader blacklist when Waterfall is present
|
||||||
|
|
||||||
|
|
||||||
## 0.2.9 - 2022-03-12
|
## 0.2.9 - 2022-03-12
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -15,7 +15,7 @@ Localization
|
|||||||
#LOC_ConformalDecals_gui-opacity = Opacity
|
#LOC_ConformalDecals_gui-opacity = Opacity
|
||||||
#LOC_ConformalDecals_gui-cutoff = Cutoff
|
#LOC_ConformalDecals_gui-cutoff = Cutoff
|
||||||
#LOC_ConformalDecals_gui-wear = Edge Wear
|
#LOC_ConformalDecals_gui-wear = Edge Wear
|
||||||
#LOC_ConformalDecals_gui-aspectratio = Aspect Ratio
|
#LOC_ConformalDecals_gui-multiproject = Project onto Multiple
|
||||||
#LOC_ConformalDecals_gui-select-flag = Select Flag
|
#LOC_ConformalDecals_gui-select-flag = Select Flag
|
||||||
#LOC_ConformalDecals_gui-reset-flag = Reset Flag
|
#LOC_ConformalDecals_gui-reset-flag = Reset Flag
|
||||||
#LOC_ConformalDecals_gui-set-text = Set Text
|
#LOC_ConformalDecals_gui-set-text = Set Text
|
||||||
|
@ -98,7 +98,7 @@ PART
|
|||||||
MODULE {
|
MODULE {
|
||||||
IDENTIFIER { name = ModuleConformalDecal }
|
IDENTIFIER { name = ModuleConformalDecal }
|
||||||
DATA {
|
DATA {
|
||||||
shader = ConformalDecals/Paint/DiffuseSDF
|
KEYWORD { name = DECAL_SDF_ALPHA }
|
||||||
tile = 0, 2, 128, 112
|
tile = 0, 2, 128, 112
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
GameData/ConformalDecals/Patches/Waterfall.cfg
Normal file
7
GameData/ConformalDecals/Patches/Waterfall.cfg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Prevent projection onto Waterfall plumes
|
||||||
|
|
||||||
|
CONFORMALDECALS:NEEDS[Waterfall] {
|
||||||
|
SHADERBLACKLIST {
|
||||||
|
shaderRegex = Waterfall/.*
|
||||||
|
}
|
||||||
|
}
|
@ -4,21 +4,13 @@ CONFORMALDECALS {
|
|||||||
|
|
||||||
SHADERBLACKLIST {
|
SHADERBLACKLIST {
|
||||||
shader = DepthMask
|
shader = DepthMask
|
||||||
shader = KSP/Alpha/Cutoff
|
|
||||||
shader = KSP/Alpha/Cutoff Bumped
|
|
||||||
shader = KSP/Alpha/Translucent
|
|
||||||
shader = KSP/Alpha/Translucent Additive
|
|
||||||
shader = KSP/Alpha/Translucent Specular
|
|
||||||
shader = KSP/Alpha/Unlit Transparent
|
|
||||||
shader = KSP/Bumped Specular (Transparent)
|
shader = KSP/Bumped Specular (Transparent)
|
||||||
shader = KSP/FX/ScrollingUnlit
|
shader = KSP/FX/ScrollingUnlit
|
||||||
shader = KSP/Particles/Additive
|
|
||||||
shader = KSP/Particles/Additive (Soft)
|
|
||||||
shader = KSP/Particles/Alpha Blended
|
|
||||||
shader = KSP/Particles/Alpha Blended Emissive Cutout
|
|
||||||
shader = KSP/Specular (Cutoff)
|
shader = KSP/Specular (Cutoff)
|
||||||
shader = KSP/Specular (Transparent)
|
shader = KSP/Specular (Transparent)
|
||||||
shader = Solid Color (Alpha)
|
shader = Solid Color (Alpha)
|
||||||
|
shaderRegex = KSP/Alpha/.*
|
||||||
|
shaderRegex = KSP/Particles/.*
|
||||||
}
|
}
|
||||||
|
|
||||||
FONT {
|
FONT {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"NAME": "ConformalDecals",
|
"NAME": "ConformalDecals",
|
||||||
"URL": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest/download/ConformalDecals.version.txt",
|
"URL": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest/download/ConformalDecals.version",
|
||||||
"DOWNLOAD": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest",
|
"DOWNLOAD": "https://github.com/drewcassidy/KSP-Conformal-Decals/releases/latest",
|
||||||
"CHANGE_LOG_URL": "https://raw.githubusercontent.com/drewcassidy/KSP-Conformal-Decals/release/CHANGELOG.md",
|
"CHANGE_LOG_URL": "https://raw.githubusercontent.com/drewcassidy/KSP-Conformal-Decals/release/CHANGELOG.md",
|
||||||
"VERSION": {
|
"VERSION": {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Conformal Decals v0.2.8
|
# Conformal Decals
|
||||||
[](https://travis-ci.com/drewcassidy/KSP-Conformal-Decals) [](https://creativecommons.org/licenses/by-sa/4.0/) [](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://creativecommons.org/licenses/by-sa/4.0/) [](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals/ConformalDecals.csproj", "{1EA983F9-42E5-494E-9683-FDAC9C9121F4}"
|
# Visual Studio Version 16
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConformalDecals", "ConformalDecals\ConformalDecals.csproj", "{1EA983F9-42E5-494E-9683-FDAC9C9121F4}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C2564402-B081-479B-B723-D5C065BC884E}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.editorconfig = .editorconfig
|
||||||
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -13,4 +19,28 @@ Global
|
|||||||
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1EA983F9-42E5-494E-9683-FDAC9C9121F4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(MonoDevelopProperties) = preSolution
|
||||||
|
Policies = $0
|
||||||
|
$0.DotNetNamingPolicy = $1
|
||||||
|
$1.DirectoryNamespaceAssociation = PrefixedHierarchical
|
||||||
|
$0.TextStylePolicy = $2
|
||||||
|
$2.FileWidth = 80
|
||||||
|
$2.TabsToSpaces = True
|
||||||
|
$2.scope = text/x-csharp
|
||||||
|
$2.NoTabsAfterNonTabs = True
|
||||||
|
$2.EolMarker = Unix
|
||||||
|
$0.CSharpFormattingPolicy = $3
|
||||||
|
$3.NewLinesForBracesInTypes = False
|
||||||
|
$3.NewLinesForBracesInMethods = False
|
||||||
|
$3.NewLinesForBracesInProperties = False
|
||||||
|
$3.NewLinesForBracesInAccessors = False
|
||||||
|
$3.NewLinesForBracesInAnonymousMethods = False
|
||||||
|
$3.NewLinesForBracesInControlBlocks = False
|
||||||
|
$3.NewLinesForBracesInAnonymousTypes = False
|
||||||
|
$3.NewLinesForBracesInObjectCollectionArrayInitializers = False
|
||||||
|
$3.NewLinesForBracesInLambdaExpressionBody = False
|
||||||
|
$3.scope = text/x-csharp
|
||||||
|
$3.SpaceAfterCast = True
|
||||||
|
$0.StandardHeader = $4
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" ?><Project Sdk="Microsoft.NET.Sdk">
|
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net48</TargetFramework>
|
<TargetFramework>net48</TargetFramework>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
@ -36,20 +36,23 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="dlls\**"/>
|
<Compile Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Remove="dlls\**"/>
|
<EmbeddedResource Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="dlls\**"/>
|
<None Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\.editorconfig" />
|
||||||
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins/ConformalDecals.dll'" IgnoreExitCode="true"/>
|
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins/ConformalDecals.dll'" IgnoreExitCode="true" />
|
||||||
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
|
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using ConformalDecals.Text;
|
using ConformalDecals.Text;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UniLinq;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
public static class DecalConfig {
|
public static class DecalConfig {
|
||||||
private static Texture2D _blankNormal;
|
private static Texture2D _blankNormal;
|
||||||
private static List<string> _shaderBlacklist;
|
private static List<string> _shaderBlacklist;
|
||||||
|
private static List<Regex> _shaderRegexBlacklist;
|
||||||
private static Dictionary<string, DecalFont> _fontList;
|
private static Dictionary<string, DecalFont> _fontList;
|
||||||
private static int _decalLayer = 31;
|
private static int _decalLayer = 31;
|
||||||
private static bool _selectableInFlight;
|
private static bool _selectableInFlight;
|
||||||
@ -50,15 +51,23 @@ namespace ConformalDecals {
|
|||||||
public static bool SelectableInFlight => _selectableInFlight;
|
public static bool SelectableInFlight => _selectableInFlight;
|
||||||
|
|
||||||
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
|
public static IEnumerable<DecalFont> Fonts => _fontList.Values;
|
||||||
|
|
||||||
public static DecalFont FallbackFont { get; private set; }
|
|
||||||
|
|
||||||
public static bool IsBlacklisted(Shader shader) {
|
public static bool IsBlacklisted(Shader shader) {
|
||||||
return IsBlacklisted(shader.name);
|
return IsBlacklisted(shader.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsBlacklisted(string shaderName) {
|
public static bool IsBlacklisted(string shaderName) {
|
||||||
return _shaderBlacklist.Contains(shaderName);
|
if (_shaderBlacklist.Contains(shaderName)) return true;
|
||||||
|
|
||||||
|
foreach (var regex in _shaderRegexBlacklist) {
|
||||||
|
if (regex.IsMatch(shaderName)) {
|
||||||
|
_shaderBlacklist.Add(shaderName);
|
||||||
|
Logging.Log($"Caching blacklisted shader name '{shaderName}' which matches '{regex}'");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsLegacy(string shaderName, out string newShader, out string[] keywords) {
|
public static bool IsLegacy(string shaderName, out string newShader, out string[] keywords) {
|
||||||
@ -91,13 +100,17 @@ namespace ConformalDecals {
|
|||||||
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
foreach (var shaderName in blacklist.GetValuesList("shader")) {
|
||||||
_shaderBlacklist.Add(shaderName);
|
_shaderBlacklist.Add(shaderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var shaderRegex in blacklist.GetValuesList("shaderRegex")) {
|
||||||
|
_shaderRegexBlacklist.Add(new Regex(shaderRegex));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
|
var allFonts = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
|
||||||
|
|
||||||
foreach (var fontNode in node.GetNodes("FONT")) {
|
foreach (var fontNode in node.GetNodes("FONT")) {
|
||||||
try {
|
try {
|
||||||
var font = new DecalFont(fontNode, allFonts);
|
var font = DecalFont.Parse(fontNode, allFonts);
|
||||||
_fontList.Add(font.Name, font);
|
_fontList.Add(font.Name, font);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -114,12 +127,8 @@ namespace ConformalDecals {
|
|||||||
var colors = new[] {color, color, color, color};
|
var colors = new[] {color, color, color, color};
|
||||||
|
|
||||||
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
|
var tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
|
||||||
for (var x = 0; x <= width; x++) {
|
|
||||||
for (var y = 0; y < height; y++) {
|
|
||||||
tex.SetPixels32(colors);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
tex.SetPixels32(colors);
|
||||||
tex.Apply();
|
tex.Apply();
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
@ -128,13 +137,14 @@ namespace ConformalDecals {
|
|||||||
// ReSharper disable once UnusedMember.Global
|
// ReSharper disable once UnusedMember.Global
|
||||||
public static void ModuleManagerPostLoad() {
|
public static void ModuleManagerPostLoad() {
|
||||||
_shaderBlacklist = new List<string>();
|
_shaderBlacklist = new List<string>();
|
||||||
|
_shaderRegexBlacklist = new List<Regex>();
|
||||||
_fontList = new Dictionary<string, DecalFont>();
|
_fontList = new Dictionary<string, DecalFont>();
|
||||||
|
|
||||||
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
var configs = GameDatabase.Instance.GetConfigs("CONFORMALDECALS");
|
||||||
|
|
||||||
if (configs.Length > 0) {
|
if (configs.Length > 0) {
|
||||||
Logging.Log("loading config");
|
|
||||||
foreach (var config in configs) {
|
foreach (var config in configs) {
|
||||||
|
Logging.Log($"loading config node '{config.url}'");
|
||||||
ParseConfig(config.config);
|
ParseConfig(config.config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,4 +160,4 @@ namespace ConformalDecals {
|
|||||||
_blankNormal = MakeBlankNormal();
|
_blankNormal = MakeBlankNormal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
public override void ParseNode(ConfigNode node) {
|
public override void ParseNode(ConfigNode node) {
|
||||||
base.ParseNode(node);
|
base.ParseNode(node);
|
||||||
|
|
||||||
ParseUtil.ParseBoolIndirect(ref value, node, "value");
|
value = ParseUtil.ParseBool(node, "value", true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Modify(Material material) {
|
public override void Modify(Material material) {
|
||||||
|
@ -95,7 +95,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
var property = MaterialProperty.Instantiate(_serializedProperties[i]);
|
var property = MaterialProperty.Instantiate(_serializedProperties[i]);
|
||||||
_materialProperties.Add(_serializedNames[i], property);
|
_materialProperties.Add(_serializedNames[i], property);
|
||||||
|
|
||||||
if (property is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
if (property is MaterialTextureProperty {isMain: true} textureProperty) {
|
||||||
_mainTexture = textureProperty;
|
_mainTexture = textureProperty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,6 +105,28 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
_materialProperties ??= new Dictionary<string, MaterialProperty>();
|
_materialProperties ??= new Dictionary<string, MaterialProperty>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Load(ConfigNode node) {
|
||||||
|
// add keyword nodes
|
||||||
|
foreach (var keywordNode in node.GetNodes("KEYWORD")) {
|
||||||
|
ParseProperty<MaterialKeywordProperty>(keywordNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add texture nodes
|
||||||
|
foreach (var textureNode in node.GetNodes("TEXTURE")) {
|
||||||
|
ParseProperty<MaterialTextureProperty>(textureNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add float nodes
|
||||||
|
foreach (var floatNode in node.GetNodes("FLOAT")) {
|
||||||
|
ParseProperty<MaterialTextureProperty>(floatNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add color nodes
|
||||||
|
foreach (var colorNode in node.GetNodes("COLOR")) {
|
||||||
|
ParseProperty<MaterialColorProperty>(colorNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnDestroy() {
|
public void OnDestroy() {
|
||||||
if (_decalMaterial != null) Destroy(_decalMaterial);
|
if (_decalMaterial != null) Destroy(_decalMaterial);
|
||||||
if (_previewMaterial != null) Destroy(_previewMaterial);
|
if (_previewMaterial != null) Destroy(_previewMaterial);
|
||||||
@ -192,7 +214,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
var newProperty = AddOrGetProperty<T>(propertyName);
|
var newProperty = AddOrGetProperty<T>(propertyName);
|
||||||
newProperty.ParseNode(node);
|
newProperty.ParseNode(node);
|
||||||
|
|
||||||
if (newProperty is MaterialTextureProperty textureProperty && textureProperty.isMain) {
|
if (newProperty is MaterialTextureProperty {isMain: true} textureProperty) {
|
||||||
_mainTexture = textureProperty;
|
_mainTexture = textureProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +252,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
|
|
||||||
public void UpdateScale(Vector2 scale) {
|
public void UpdateScale(Vector2 scale) {
|
||||||
foreach (var entry in _materialProperties) {
|
foreach (var entry in _materialProperties) {
|
||||||
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoScale) {
|
if (entry.Value is MaterialTextureProperty {autoScale: true} textureProperty) {
|
||||||
textureProperty.SetScale(scale);
|
textureProperty.SetScale(scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,7 +263,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
var mainTexSize = _mainTexture.Dimensions;
|
var mainTexSize = _mainTexture.Dimensions;
|
||||||
|
|
||||||
foreach (var entry in _materialProperties) {
|
foreach (var entry in _materialProperties) {
|
||||||
if (entry.Value is MaterialTextureProperty textureProperty && textureProperty.autoTile) {
|
if (entry.Value is MaterialTextureProperty {autoTile: true} textureProperty) {
|
||||||
textureProperty.SetTile(tile, mainTexSize);
|
textureProperty.SetTile(tile, mainTexSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,20 +280,6 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
UpdateTile(tile);
|
UpdateTile(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetOpacity(float opacity) {
|
|
||||||
DecalMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
|
|
||||||
PreviewMaterial.SetFloat(DecalPropertyIDs._DecalOpacity, opacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetCutoff(float cutoff) {
|
|
||||||
DecalMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff);
|
|
||||||
PreviewMaterial.SetFloat(DecalPropertyIDs._Cutoff, cutoff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetWear(float wear) {
|
|
||||||
DecalMaterial.SetFloat(DecalPropertyIDs._EdgeWearStrength, wear);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateMaterials() {
|
public void UpdateMaterials() {
|
||||||
foreach (var material in Materials) {
|
foreach (var material in Materials) {
|
||||||
UpdateMaterial(material);
|
UpdateMaterial(material);
|
||||||
|
@ -27,6 +27,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
public string TextureUrl {
|
public string TextureUrl {
|
||||||
get => _textureUrl;
|
get => _textureUrl;
|
||||||
set {
|
set {
|
||||||
|
if (_textureUrl == value) return; // URL hasnt changed
|
||||||
_texture = LoadTexture(value, isNormal);
|
_texture = LoadTexture(value, isNormal);
|
||||||
_textureUrl = value;
|
_textureUrl = value;
|
||||||
}
|
}
|
||||||
@ -44,7 +45,7 @@ namespace ConformalDecals.MaterialProperties {
|
|||||||
public float AspectRatio {
|
public float AspectRatio {
|
||||||
get {
|
get {
|
||||||
if (_texture == null) return 1;
|
if (_texture == null) return 1;
|
||||||
if (_textureUrl?.Contains("Squad/Flags") == true) return 0.625f;
|
if (_textureUrl?.Contains("Squad/Flags") == true) return 0.625f; // squad flags are slightly stretched, so unstretch them
|
||||||
return MaskedHeight / (float) MaskedWidth;
|
return MaskedHeight / (float) MaskedWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,9 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using ConformalDecals.MaterialProperties;
|
using ConformalDecals.MaterialProperties;
|
||||||
|
using ConformalDecals.Targets;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
|
using UniLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
@ -71,15 +73,23 @@ namespace ConformalDecals {
|
|||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float opacity = 1.0f;
|
public float opacity = 1.0f;
|
||||||
|
|
||||||
|
private MaterialFloatProperty _opacityProperty;
|
||||||
|
|
||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float cutoff = 0.5f;
|
public float cutoff = 0.5f;
|
||||||
|
|
||||||
|
private MaterialFloatProperty _cutoffProperty;
|
||||||
|
|
||||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
|
||||||
UI_FloatRange()]
|
UI_FloatRange()]
|
||||||
public float wear = 100;
|
public float wear = 100;
|
||||||
|
|
||||||
[KSPField(isPersistant = true)] public bool projectMultiple; // reserved for future features. do not modify
|
private MaterialFloatProperty _wearProperty;
|
||||||
|
|
||||||
|
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
|
||||||
|
UI_Toggle()]
|
||||||
|
public bool projectMultiple = true;
|
||||||
|
|
||||||
[KSPField] public MaterialPropertyCollection materialProperties;
|
[KSPField] public MaterialPropertyCollection materialProperties;
|
||||||
|
|
||||||
@ -96,7 +106,7 @@ namespace ConformalDecals {
|
|||||||
private const int DecalQueueMax = 2400;
|
private const int DecalQueueMax = 2400;
|
||||||
private static int _decalQueueCounter = -1;
|
private static int _decalQueueCounter = -1;
|
||||||
|
|
||||||
private List<ProjectionTarget> _targets;
|
private readonly Dictionary<Part, ProjectionPartTarget> _targets = new Dictionary<Part, ProjectionPartTarget>();
|
||||||
|
|
||||||
private bool _isAttached;
|
private bool _isAttached;
|
||||||
private Matrix4x4 _orthoMatrix;
|
private Matrix4x4 _orthoMatrix;
|
||||||
@ -116,22 +126,255 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EVENTS
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnAwake() {
|
public override void OnAwake() {
|
||||||
base.OnAwake();
|
base.OnAwake();
|
||||||
|
|
||||||
if (materialProperties == null) {
|
if (materialProperties == null) {
|
||||||
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_opacityProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_DecalOpacity");
|
||||||
|
_cutoffProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Cutoff");
|
||||||
|
_wearProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_EdgeWearStrength");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
|
// Load
|
||||||
try {
|
try {
|
||||||
// SETUP TRANSFORMS
|
LoadDecal(node);
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.LogException("Error loading decal", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
try {
|
||||||
|
SetupDecal();
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.LogException("Error setting up decal", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnIconCreate() {
|
||||||
|
UpdateAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnStart(StartState state) {
|
||||||
|
materialProperties.RenderQueue = DecalQueue;
|
||||||
|
|
||||||
|
_boundsRenderer = decalProjectorTransform.GetComponent<MeshRenderer>();
|
||||||
|
|
||||||
|
// handle tweakables
|
||||||
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
GameEvents.onEditorPartEvent.Add(OnEditorEvent);
|
||||||
|
GameEvents.onVariantApplied.Add(OnVariantApplied);
|
||||||
|
|
||||||
|
UpdateTweakables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called after OnStart is finished for all parts
|
||||||
|
/// This is mostly used to make sure all B9 variants are already in place for the rest of the vessel
|
||||||
|
public override void OnStartFinished(StartState state) {
|
||||||
|
// handle game events
|
||||||
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
|
// set initial attachment state
|
||||||
|
if (part.parent == null) {
|
||||||
|
OnDetach();
|
||||||
|
} else {
|
||||||
|
OnAttach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle flight events
|
||||||
|
if (HighLogic.LoadedSceneIsFlight) {
|
||||||
|
GameEvents.onPartWillDie.Add(OnPartWillDie);
|
||||||
|
|
||||||
|
if (part.parent == null) part.explode();
|
||||||
|
|
||||||
|
Part.layerMask |= 1 << DecalConfig.DecalLayer;
|
||||||
|
decalColliderTransform.gameObject.layer = DecalConfig.DecalLayer;
|
||||||
|
|
||||||
|
if (!selectableInFlight || !DecalConfig.SelectableInFlight) {
|
||||||
|
decalColliderTransform.GetComponent<Collider>().enabled = false;
|
||||||
|
_boundsRenderer.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called by Unity when the decal is destroyed
|
||||||
|
public virtual void OnDestroy() {
|
||||||
|
// remove GameEvents
|
||||||
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
GameEvents.onEditorPartEvent.Remove(OnEditorEvent);
|
||||||
|
GameEvents.onVariantApplied.Remove(OnVariantApplied);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HighLogic.LoadedSceneIsFlight) {
|
||||||
|
GameEvents.onPartWillDie.Remove(OnPartWillDie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove from preCull delegate
|
||||||
|
Camera.onPreCull -= Render;
|
||||||
|
|
||||||
|
// destroy material properties object
|
||||||
|
Destroy(materialProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when the decal's projection and scale is modified through a tweakable
|
||||||
|
protected void OnProjectionTweakEvent(BaseField field, object obj) {
|
||||||
|
// scale or depth values have been changed, so update scale
|
||||||
|
// and update projection matrices if attached
|
||||||
|
UpdateProjection();
|
||||||
|
|
||||||
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
|
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
||||||
|
decal.UpdateProjection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when the decal's material is modified through a tweakable
|
||||||
|
protected void OnMaterialTweakEvent(BaseField field, object obj) {
|
||||||
|
UpdateMaterials();
|
||||||
|
|
||||||
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
|
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
||||||
|
decal.UpdateMaterials();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called by KSP when a new variant is applied in the editor
|
||||||
|
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
||||||
|
if (_isAttached && eventPart != null && (projectMultiple || eventPart == part.parent)) {
|
||||||
|
_targets.Remove(eventPart);
|
||||||
|
UpdateProjection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called by KSP when an editor event occurs
|
||||||
|
protected void OnEditorEvent(ConstructionEventType eventType, Part eventPart) {
|
||||||
|
switch (eventType) {
|
||||||
|
case ConstructionEventType.PartAttached:
|
||||||
|
OnPartAttached(eventPart);
|
||||||
|
break;
|
||||||
|
case ConstructionEventType.PartDetached:
|
||||||
|
OnPartDetached(eventPart);
|
||||||
|
break;
|
||||||
|
case ConstructionEventType.PartOffsetting:
|
||||||
|
case ConstructionEventType.PartRotating:
|
||||||
|
OnPartTransformed(eventPart);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when a part is transformed in the editor
|
||||||
|
protected void OnPartTransformed(Part eventPart, bool firstcall = true) {
|
||||||
|
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
|
||||||
|
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
|
||||||
|
UpdateProjection();
|
||||||
|
} else if (_isAttached) {
|
||||||
|
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
|
||||||
|
// recursively call for child parts
|
||||||
|
foreach (var child in eventPart.children) {
|
||||||
|
OnPartTransformed(child, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when a part is attached in the editor
|
||||||
|
protected void OnPartAttached(Part eventPart, bool firstcall = true) {
|
||||||
|
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
|
||||||
|
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
|
||||||
|
OnAttach();
|
||||||
|
} else {
|
||||||
|
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
|
||||||
|
// recursively call for child parts
|
||||||
|
foreach (var child in eventPart.children) {
|
||||||
|
OnPartAttached(child, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when a part is detached in the editor
|
||||||
|
protected void OnPartDetached(Part eventPart, bool firstcall = true) {
|
||||||
|
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
|
||||||
|
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
|
||||||
|
OnDetach();
|
||||||
|
} else if (_isAttached) {
|
||||||
|
_targets.Remove(eventPart);
|
||||||
|
// recursively call for child parts
|
||||||
|
foreach (var child in eventPart.children) {
|
||||||
|
OnPartDetached(child, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when part `willDie` will be destroyed
|
||||||
|
protected void OnPartWillDie(Part willDie) {
|
||||||
|
if (willDie == part.parent && willDie != null) {
|
||||||
|
this.Log("Parent part about to be destroyed! Killing decal part.");
|
||||||
|
part.Die();
|
||||||
|
} else if (_isAttached && projectMultiple) {
|
||||||
|
_targets.Remove(willDie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when decal is attached to a new part
|
||||||
|
protected virtual void OnAttach() {
|
||||||
|
if (_isAttached) return;
|
||||||
|
if (part.parent == null) {
|
||||||
|
this.LogError("Attach function called but part has no parent!");
|
||||||
|
_isAttached = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isAttached = true;
|
||||||
|
_targets.Clear();
|
||||||
|
|
||||||
|
// hide model
|
||||||
|
decalModelTransform.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
// unhide projector
|
||||||
|
decalProjectorTransform.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
// add to preCull delegate
|
||||||
|
Camera.onPreCull += Render;
|
||||||
|
|
||||||
|
UpdateMaterials();
|
||||||
|
UpdateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when decal is detached from its parent part
|
||||||
|
protected virtual void OnDetach() {
|
||||||
|
if (!_isAttached) return;
|
||||||
|
_isAttached = false;
|
||||||
|
|
||||||
|
// unhide model
|
||||||
|
decalModelTransform.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
// hide projector
|
||||||
|
decalProjectorTransform.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
// remove from preCull delegate
|
||||||
|
Camera.onPreCull -= Render;
|
||||||
|
|
||||||
|
UpdateMaterials();
|
||||||
|
UpdateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FUNCTIONS
|
||||||
|
|
||||||
|
/// Load any settings from the decal config
|
||||||
|
protected virtual void LoadDecal(ConfigNode node) {
|
||||||
|
// PARSE TRANSFORMS
|
||||||
|
if (!HighLogic.LoadedSceneIsGame) {
|
||||||
decalFrontTransform = part.FindModelTransform(decalFront);
|
decalFrontTransform = part.FindModelTransform(decalFront);
|
||||||
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
|
if (decalFrontTransform == null) throw new FormatException($"Could not find decalFront transform: '{decalFront}'.");
|
||||||
|
|
||||||
@ -153,354 +396,62 @@ namespace ConformalDecals {
|
|||||||
if (backRenderer == null) {
|
if (backRenderer == null) {
|
||||||
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
|
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
|
||||||
updateBackScale = false;
|
updateBackScale = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
backMaterial = backRenderer.material;
|
backMaterial = backRenderer.material;
|
||||||
if (backMaterial == null) {
|
if (backMaterial == null) {
|
||||||
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
|
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
|
||||||
updateBackScale = false;
|
updateBackScale = false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
|
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PARSE MATERIAL PROPERTIES
|
|
||||||
|
|
||||||
// set shader
|
|
||||||
materialProperties.SetShader(shader);
|
|
||||||
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_BASE_NORMAL").value = useBaseNormal;
|
|
||||||
|
|
||||||
// add keyword nodes
|
|
||||||
foreach (var keywordNode in node.GetNodes("KEYWORD")) {
|
|
||||||
materialProperties.ParseProperty<MaterialKeywordProperty>(keywordNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add texture nodes
|
|
||||||
foreach (var textureNode in node.GetNodes("TEXTURE")) {
|
|
||||||
materialProperties.ParseProperty<MaterialTextureProperty>(textureNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add float nodes
|
|
||||||
foreach (var floatNode in node.GetNodes("FLOAT")) {
|
|
||||||
materialProperties.ParseProperty<MaterialTextureProperty>(floatNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add color nodes
|
|
||||||
foreach (var colorNode in node.GetNodes("COLOR")) {
|
|
||||||
materialProperties.ParseProperty<MaterialColorProperty>(colorNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle texture tiling parameters
|
|
||||||
var tileString = node.GetValue("tile");
|
|
||||||
if (!string.IsNullOrEmpty(tileString)) {
|
|
||||||
var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect);
|
|
||||||
if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tileRect.x >= 0) {
|
|
||||||
materialProperties.UpdateTile(tileRect);
|
|
||||||
}
|
|
||||||
else if (tileIndex >= 0) {
|
|
||||||
materialProperties.UpdateTile(tileIndex, tileSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
this.LogException("Exception parsing partmodule", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMaterials();
|
// PARSE MATERIAL PROPERTIES
|
||||||
|
// set shader
|
||||||
|
materialProperties.SetShader(shader);
|
||||||
|
materialProperties.AddOrGetProperty<MaterialKeywordProperty>("DECAL_BASE_NORMAL").value = useBaseNormal;
|
||||||
|
materialProperties.Load(node);
|
||||||
|
|
||||||
foreach (var keyword in _decalMaterial.shaderKeywords) {
|
// handle texture tiling parameters
|
||||||
this.Log($"keyword: {keyword}");
|
var tileString = node.GetValue("tile");
|
||||||
|
if (!string.IsNullOrEmpty(tileString)) {
|
||||||
|
var tileValid = ParseExtensions.TryParseRect(tileString, out tileRect);
|
||||||
|
if (!tileValid) throw new FormatException($"Invalid rect value for tile '{tileString}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tileRect.x >= 0) {
|
||||||
|
materialProperties.UpdateTile(tileRect);
|
||||||
|
} else if (tileIndex >= 0) {
|
||||||
|
materialProperties.UpdateTile(tileIndex, tileSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setup decal by calling update functions relevent for the current situation
|
||||||
|
protected virtual void SetupDecal() {
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
// Update tweakables in editor mode
|
||||||
UpdateTweakables();
|
UpdateTweakables();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
UpdateScale();
|
UpdateAll();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
scale = defaultScale;
|
scale = defaultScale;
|
||||||
depth = defaultDepth;
|
depth = defaultDepth;
|
||||||
opacity = defaultOpacity;
|
opacity = defaultOpacity;
|
||||||
cutoff = defaultCutoff;
|
cutoff = defaultCutoff;
|
||||||
wear = defaultWear;
|
wear = defaultWear;
|
||||||
|
|
||||||
|
UpdateAll();
|
||||||
|
|
||||||
// QUEUE PART FOR ICON FIXING IN VAB
|
// QUEUE PART FOR ICON FIXING IN VAB
|
||||||
DecalIconFixer.QueuePart(part.name);
|
DecalIconFixer.QueuePart(part.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// Update decal editor tweakables
|
||||||
public override void OnIconCreate() {
|
|
||||||
UpdateScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void OnStart(StartState state) {
|
|
||||||
materialProperties.RenderQueue = DecalQueue;
|
|
||||||
|
|
||||||
_boundsRenderer = decalProjectorTransform.GetComponent<MeshRenderer>();
|
|
||||||
|
|
||||||
// handle tweakables
|
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
|
||||||
GameEvents.onEditorPartEvent.Add(OnEditorEvent);
|
|
||||||
GameEvents.onVariantApplied.Add(OnVariantApplied);
|
|
||||||
|
|
||||||
UpdateTweakables();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnStartFinished(StartState state) {
|
|
||||||
// handle game events
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
|
||||||
// set initial attachment state
|
|
||||||
if (part.parent == null) {
|
|
||||||
OnDetach();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
OnAttach();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle flight events
|
|
||||||
if (HighLogic.LoadedSceneIsFlight) {
|
|
||||||
GameEvents.onPartWillDie.Add(OnPartWillDie);
|
|
||||||
|
|
||||||
if (part.parent == null) part.explode();
|
|
||||||
|
|
||||||
Part.layerMask |= 1 << DecalConfig.DecalLayer;
|
|
||||||
decalColliderTransform.gameObject.layer = DecalConfig.DecalLayer;
|
|
||||||
|
|
||||||
if (!selectableInFlight || !DecalConfig.SelectableInFlight) {
|
|
||||||
decalColliderTransform.GetComponent<Collider>().enabled = false;
|
|
||||||
_boundsRenderer.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnDestroy() {
|
|
||||||
// remove GameEvents
|
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
|
||||||
GameEvents.onEditorPartEvent.Remove(OnEditorEvent);
|
|
||||||
GameEvents.onVariantApplied.Remove(OnVariantApplied);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsFlight) {
|
|
||||||
GameEvents.onPartWillDie.Remove(OnPartWillDie);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove from preCull delegate
|
|
||||||
Camera.onPreCull -= Render;
|
|
||||||
|
|
||||||
// destroy material properties object
|
|
||||||
Destroy(materialProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnSizeTweakEvent(BaseField field, object obj) {
|
|
||||||
// scale or depth values have been changed, so update scale
|
|
||||||
// and update projection matrices if attached
|
|
||||||
UpdateScale();
|
|
||||||
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
|
||||||
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
|
||||||
decal.UpdateScale();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnMaterialTweakEvent(BaseField field, object obj) {
|
|
||||||
materialProperties.SetOpacity(opacity);
|
|
||||||
materialProperties.SetCutoff(cutoff);
|
|
||||||
if (useBaseNormal) {
|
|
||||||
materialProperties.SetWear(wear);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
|
||||||
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
|
||||||
decal.materialProperties.SetOpacity(opacity);
|
|
||||||
decal.materialProperties.SetCutoff(cutoff);
|
|
||||||
if (useBaseNormal) {
|
|
||||||
decal.materialProperties.SetWear(wear);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
|
||||||
if (_isAttached && eventPart == part.parent) {
|
|
||||||
UpdateTargets();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnEditorEvent(ConstructionEventType eventType, Part eventPart) {
|
|
||||||
if (this.part != eventPart && !part.symmetryCounterparts.Contains(eventPart)) return;
|
|
||||||
switch (eventType) {
|
|
||||||
case ConstructionEventType.PartAttached:
|
|
||||||
OnAttach();
|
|
||||||
break;
|
|
||||||
case ConstructionEventType.PartDetached:
|
|
||||||
OnDetach();
|
|
||||||
break;
|
|
||||||
case ConstructionEventType.PartOffsetting:
|
|
||||||
case ConstructionEventType.PartRotating:
|
|
||||||
UpdateScale();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void OnPartWillDie(Part willDie) {
|
|
||||||
if (willDie == part.parent) {
|
|
||||||
this.Log("Parent part about to be destroyed! Killing decal part.");
|
|
||||||
part.Die();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnAttach() {
|
|
||||||
if (part.parent == null) {
|
|
||||||
this.LogError("Attach function called but part has no parent!");
|
|
||||||
_isAttached = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_isAttached = true;
|
|
||||||
|
|
||||||
// hide model
|
|
||||||
decalModelTransform.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
// unhide projector
|
|
||||||
decalProjectorTransform.gameObject.SetActive(true);
|
|
||||||
|
|
||||||
// add to preCull delegate
|
|
||||||
Camera.onPreCull += Render;
|
|
||||||
|
|
||||||
UpdateMaterials();
|
|
||||||
UpdateTargets();
|
|
||||||
UpdateScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnDetach() {
|
|
||||||
_isAttached = false;
|
|
||||||
|
|
||||||
// unhide model
|
|
||||||
decalModelTransform.gameObject.SetActive(true);
|
|
||||||
|
|
||||||
// hide projector
|
|
||||||
decalProjectorTransform.gameObject.SetActive(false);
|
|
||||||
|
|
||||||
// remove from preCull delegate
|
|
||||||
Camera.onPreCull -= Render;
|
|
||||||
|
|
||||||
UpdateMaterials();
|
|
||||||
UpdateScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateScale() {
|
|
||||||
scale = Mathf.Max(0.01f, scale);
|
|
||||||
depth = Mathf.Max(0.01f, depth);
|
|
||||||
var aspectRatio = Mathf.Max(0.01f, materialProperties.AspectRatio);
|
|
||||||
Vector2 size;
|
|
||||||
|
|
||||||
switch (scaleMode) {
|
|
||||||
default:
|
|
||||||
case DecalScaleMode.HEIGHT:
|
|
||||||
size = new Vector2(scale / aspectRatio, scale);
|
|
||||||
break;
|
|
||||||
case DecalScaleMode.WIDTH:
|
|
||||||
size = new Vector2(scale, scale * aspectRatio);
|
|
||||||
break;
|
|
||||||
case DecalScaleMode.AVERAGE:
|
|
||||||
var width1 = 2 * scale / (1 + aspectRatio);
|
|
||||||
size = new Vector2(width1, width1 * aspectRatio);
|
|
||||||
break;
|
|
||||||
case DecalScaleMode.AREA:
|
|
||||||
var width2 = Mathf.Sqrt(scale / aspectRatio);
|
|
||||||
size = new Vector2(width2, width2 * aspectRatio);
|
|
||||||
break;
|
|
||||||
case DecalScaleMode.MINIMUM:
|
|
||||||
if (aspectRatio > 1) goto case DecalScaleMode.WIDTH;
|
|
||||||
else goto case DecalScaleMode.HEIGHT;
|
|
||||||
case DecalScaleMode.MAXIMUM:
|
|
||||||
if (aspectRatio > 1) goto case DecalScaleMode.HEIGHT;
|
|
||||||
else goto case DecalScaleMode.WIDTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update material scale
|
|
||||||
materialProperties.UpdateScale(size);
|
|
||||||
|
|
||||||
if (_isAttached) {
|
|
||||||
// update orthogonal matrix
|
|
||||||
_orthoMatrix = Matrix4x4.identity;
|
|
||||||
_orthoMatrix[0, 3] = 0.5f;
|
|
||||||
_orthoMatrix[1, 3] = 0.5f;
|
|
||||||
|
|
||||||
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
|
|
||||||
|
|
||||||
// update projection
|
|
||||||
foreach (var target in _targets) {
|
|
||||||
target.Project(_orthoMatrix, decalProjectorTransform, _boundsRenderer.bounds, useBaseNormal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// rescale preview model
|
|
||||||
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
|
|
||||||
|
|
||||||
// update back material scale
|
|
||||||
if (updateBackScale) {
|
|
||||||
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void UpdateMaterials() {
|
|
||||||
materialProperties.UpdateMaterials();
|
|
||||||
materialProperties.SetOpacity(opacity);
|
|
||||||
materialProperties.SetCutoff(cutoff);
|
|
||||||
if (useBaseNormal) {
|
|
||||||
materialProperties.SetWear(wear);
|
|
||||||
}
|
|
||||||
|
|
||||||
_decalMaterial = materialProperties.DecalMaterial;
|
|
||||||
_previewMaterial = materialProperties.PreviewMaterial;
|
|
||||||
|
|
||||||
if (!_isAttached) decalFrontTransform.GetComponent<MeshRenderer>().material = _previewMaterial;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateTargets() {
|
|
||||||
if (_targets == null) {
|
|
||||||
_targets = new List<ProjectionTarget>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_targets.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// find all valid renderers
|
|
||||||
var renderers = part.parent.FindModelComponents<MeshRenderer>();
|
|
||||||
foreach (var renderer in renderers) {
|
|
||||||
// skip disabled renderers
|
|
||||||
if (renderer.gameObject.activeInHierarchy == false) continue;
|
|
||||||
|
|
||||||
// skip transparentFX layer, which causes issues with Waterfall
|
|
||||||
if (renderer.gameObject.layer == 1) continue;
|
|
||||||
|
|
||||||
// skip blacklisted shaders
|
|
||||||
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
|
|
||||||
|
|
||||||
var meshFilter = renderer.GetComponent<MeshFilter>();
|
|
||||||
if (meshFilter == null) continue; // object has a meshRenderer with no filter, invalid
|
|
||||||
var mesh = meshFilter.mesh;
|
|
||||||
if (mesh == null) continue; // object has a null mesh, invalid
|
|
||||||
|
|
||||||
// create new ProjectionTarget to represent the renderer
|
|
||||||
var target = new ProjectionTarget(renderer, mesh);
|
|
||||||
|
|
||||||
// add the target to the list
|
|
||||||
_targets.Add(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void UpdateTweakables() {
|
protected virtual void UpdateTweakables() {
|
||||||
// setup tweakable fields
|
// setup tweakable fields
|
||||||
var scaleField = Fields[nameof(scale)];
|
var scaleField = Fields[nameof(scale)];
|
||||||
@ -508,6 +459,7 @@ namespace ConformalDecals {
|
|||||||
var opacityField = Fields[nameof(opacity)];
|
var opacityField = Fields[nameof(opacity)];
|
||||||
var cutoffField = Fields[nameof(cutoff)];
|
var cutoffField = Fields[nameof(cutoff)];
|
||||||
var wearField = Fields[nameof(wear)];
|
var wearField = Fields[nameof(wear)];
|
||||||
|
var multiprojectField = Fields[nameof(projectMultiple)];
|
||||||
|
|
||||||
scaleField.guiActiveEditor = scaleAdjustable;
|
scaleField.guiActiveEditor = scaleAdjustable;
|
||||||
depthField.guiActiveEditor = depthAdjustable;
|
depthField.guiActiveEditor = depthAdjustable;
|
||||||
@ -525,7 +477,7 @@ namespace ConformalDecals {
|
|||||||
scaleEditor.minValue = minValue;
|
scaleEditor.minValue = minValue;
|
||||||
scaleEditor.maxValue = maxValue;
|
scaleEditor.maxValue = maxValue;
|
||||||
scaleEditor.stepIncrement = 0.01f; //1cm
|
scaleEditor.stepIncrement = 0.01f; //1cm
|
||||||
scaleEditor.onFieldChanged = OnSizeTweakEvent;
|
scaleEditor.onFieldChanged = OnProjectionTweakEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depthAdjustable) {
|
if (depthAdjustable) {
|
||||||
@ -536,7 +488,7 @@ namespace ConformalDecals {
|
|||||||
depthEditor.minValue = minValue;
|
depthEditor.minValue = minValue;
|
||||||
depthEditor.maxValue = maxValue;
|
depthEditor.maxValue = maxValue;
|
||||||
depthEditor.stepIncrement = 0.01f; //1cm
|
depthEditor.stepIncrement = 0.01f; //1cm
|
||||||
depthEditor.onFieldChanged = OnSizeTweakEvent;
|
depthEditor.onFieldChanged = OnProjectionTweakEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opacityAdjustable) {
|
if (opacityAdjustable) {
|
||||||
@ -573,13 +525,127 @@ namespace ConformalDecals {
|
|||||||
wearEditor.stepIncrement = (maxValue - minValue) / steps;
|
wearEditor.stepIncrement = (maxValue - minValue) / steps;
|
||||||
wearEditor.onFieldChanged = OnMaterialTweakEvent;
|
wearEditor.onFieldChanged = OnMaterialTweakEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var multiprojectEditor = (UI_Toggle) multiprojectField.uiControlEditor;
|
||||||
|
multiprojectEditor.onFieldChanged = OnProjectionTweakEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates materials, scale and targets
|
||||||
|
protected virtual void UpdateAll() {
|
||||||
|
UpdateMaterials();
|
||||||
|
UpdateProjection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update decal materials
|
||||||
|
protected virtual void UpdateMaterials() {
|
||||||
|
_opacityProperty.value = opacity;
|
||||||
|
_cutoffProperty.value = cutoff;
|
||||||
|
_wearProperty.value = wear;
|
||||||
|
|
||||||
|
materialProperties.UpdateMaterials();
|
||||||
|
|
||||||
|
_decalMaterial = materialProperties.DecalMaterial;
|
||||||
|
_previewMaterial = materialProperties.PreviewMaterial;
|
||||||
|
|
||||||
|
if (!_isAttached) decalFrontTransform.GetComponent<MeshRenderer>().material = _previewMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update decal scale and projection
|
||||||
|
protected void UpdateProjection() {
|
||||||
|
|
||||||
|
// Update scale and depth
|
||||||
|
scale = Mathf.Max(0.01f, scale);
|
||||||
|
depth = Mathf.Max(0.01f, depth);
|
||||||
|
var aspectRatio = Mathf.Max(0.01f, materialProperties.AspectRatio);
|
||||||
|
Vector2 size;
|
||||||
|
|
||||||
|
switch (scaleMode) {
|
||||||
|
default:
|
||||||
|
case DecalScaleMode.HEIGHT:
|
||||||
|
size = new Vector2(scale / aspectRatio, scale);
|
||||||
|
break;
|
||||||
|
case DecalScaleMode.WIDTH:
|
||||||
|
size = new Vector2(scale, scale * aspectRatio);
|
||||||
|
break;
|
||||||
|
case DecalScaleMode.AVERAGE:
|
||||||
|
var width1 = 2 * scale / (1 + aspectRatio);
|
||||||
|
size = new Vector2(width1, width1 * aspectRatio);
|
||||||
|
break;
|
||||||
|
case DecalScaleMode.AREA:
|
||||||
|
var width2 = Mathf.Sqrt(scale / aspectRatio);
|
||||||
|
size = new Vector2(width2, width2 * aspectRatio);
|
||||||
|
break;
|
||||||
|
case DecalScaleMode.MINIMUM:
|
||||||
|
if (aspectRatio > 1) goto case DecalScaleMode.WIDTH;
|
||||||
|
else goto case DecalScaleMode.HEIGHT;
|
||||||
|
case DecalScaleMode.MAXIMUM:
|
||||||
|
if (aspectRatio > 1) goto case DecalScaleMode.HEIGHT;
|
||||||
|
else goto case DecalScaleMode.WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update material scale
|
||||||
|
materialProperties.UpdateScale(size);
|
||||||
|
|
||||||
|
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
|
||||||
|
|
||||||
|
if (_isAttached) {
|
||||||
|
// update orthogonal matrix
|
||||||
|
_orthoMatrix = Matrix4x4.identity;
|
||||||
|
_orthoMatrix[0, 3] = 0.5f;
|
||||||
|
_orthoMatrix[1, 3] = 0.5f;
|
||||||
|
|
||||||
|
var projectionBounds = _boundsRenderer.bounds;
|
||||||
|
|
||||||
|
// disable all targets
|
||||||
|
foreach (var target in _targets.Values) {
|
||||||
|
target.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// collect list of potential targets
|
||||||
|
IEnumerable<Part> targetParts;
|
||||||
|
if (projectMultiple) {
|
||||||
|
targetParts = HighLogic.LoadedSceneIsFlight ? part.vessel.parts : EditorLogic.fetch.ship.parts;
|
||||||
|
} else {
|
||||||
|
targetParts = new[] {part.parent};
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var targetPart in targetParts) {
|
||||||
|
UpdatePartTarget(targetPart, projectionBounds);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// rescale preview model
|
||||||
|
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
|
||||||
|
|
||||||
|
// update back material scale
|
||||||
|
if (updateBackScale) {
|
||||||
|
backMaterial.SetTextureScale(PropertyIDs._MainTex, new Vector2(size.x * backTextureBaseScale.x, size.y * backTextureBaseScale.y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void UpdatePartTarget(Part targetPart, Bounds projectionBounds) {
|
||||||
|
if (targetPart.GetComponent<ModuleConformalDecal>() != null) return; // skip other decals
|
||||||
|
|
||||||
|
if (!_targets.TryGetValue(targetPart, out var target)) {
|
||||||
|
var rendererList = targetPart.FindModelComponents<MeshRenderer>();
|
||||||
|
|
||||||
|
if (rendererList.Any(o => projectionBounds.Intersects(o.bounds))) {
|
||||||
|
target = new ProjectionPartTarget(targetPart, useBaseNormal);
|
||||||
|
_targets.Add(targetPart, target);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.Project(_orthoMatrix, decalProjectorTransform, projectionBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render the decal
|
||||||
public void Render(Camera camera) {
|
public void Render(Camera camera) {
|
||||||
if (!_isAttached) return;
|
if (!_isAttached) return;
|
||||||
|
|
||||||
// render on each target object
|
// render on each target object
|
||||||
foreach (var target in _targets) {
|
foreach (var target in _targets.Values) {
|
||||||
target.Render(_decalMaterial, part.mpb, camera);
|
target.Render(_decalMaterial, part.mpb, camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
||||||
|
|
||||||
// The URL of the flag for the current mission or agency
|
|
||||||
public string MissionFlagUrl {
|
public string MissionFlagUrl {
|
||||||
get {
|
get {
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
@ -24,28 +23,16 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnLoad(ConfigNode node) {
|
|
||||||
base.OnLoad(node);
|
|
||||||
|
|
||||||
// Since OnLoad is called for all modules, we only need to update this module
|
|
||||||
// Updating symmetry counterparts would be redundent
|
|
||||||
UpdateFlag();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnStart(StartState state) {
|
public override void OnStart(StartState state) {
|
||||||
base.OnStart(state);
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
// Register flag change event
|
// Register flag change event
|
||||||
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
||||||
|
|
||||||
// Register reset button event
|
// Register reset button event
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = useCustomFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since OnStart is called for all modules, we only need to update this module
|
base.OnStart(state);
|
||||||
// Updating symmetry counterparts would be redundent
|
|
||||||
UpdateFlag();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy() {
|
public override void OnDestroy() {
|
||||||
@ -53,81 +40,81 @@ namespace ConformalDecals {
|
|||||||
// Unregister flag change event
|
// Unregister flag change event
|
||||||
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
|
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
||||||
public void SelectFlag() {
|
public void SelectFlagButton() {
|
||||||
// Button for selecting a flag
|
// Button for selecting a flag
|
||||||
// This is a bit of a hack to bring up the stock flag selection menu
|
// This is a bit of a hack to bring up the stock flag selection menu
|
||||||
// When its done, it calls OnCustomFlagSelected()
|
// When its done, it calls OnCustomFlagSelected()
|
||||||
|
|
||||||
// ReSharper disable once PossibleNullReferenceException
|
// ReSharper disable once PossibleNullReferenceException
|
||||||
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
|
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
|
||||||
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
|
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
|
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
|
||||||
public void ResetFlag() {
|
public void ResetFlagButton() {
|
||||||
|
|
||||||
// we are no longer using a custom flag, so instead use the mission or agency flag
|
// we are no longer using a custom flag, so instead use the mission or agency flag
|
||||||
useCustomFlag = false;
|
SetFlag("Mission", false, true);
|
||||||
flagUrl = "Mission";
|
|
||||||
UpdateFlag(true);
|
|
||||||
|
|
||||||
// disable the reset button, since it no longer makes sense
|
// disable the reset button, since it no longer makes sense
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = false;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
||||||
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
||||||
|
|
||||||
// we are now using a custom flag with the URL of the new flag entry
|
// we are now using a custom flag with the URL of the new flag entry
|
||||||
useCustomFlag = true;
|
SetFlag(newFlagEntry.textureInfo.name, true, true);
|
||||||
flagUrl = newFlagEntry.textureInfo.name;
|
|
||||||
UpdateFlag(true);
|
|
||||||
|
|
||||||
// make sure the reset button is now available
|
// make sure the reset button is now available
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = true;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEditorFlagSelected(string newFlagUrl) {
|
private void OnEditorFlagSelected(string newFlagUrl) {
|
||||||
|
// Callback for when a new mission flag is selected in the editor
|
||||||
|
// Since this callback is called for all modules, we only need to update this module
|
||||||
|
// Updating symmetry counterparts would be redundent
|
||||||
|
|
||||||
|
// if we are using the mission flag, update it. otherwise ignore the call
|
||||||
if (!useCustomFlag) {
|
if (!useCustomFlag) {
|
||||||
flagUrl = newFlagUrl;
|
SetFlag(newFlagUrl, false, false);
|
||||||
// Since this callback is called for all modules, we only need to update this module
|
|
||||||
// Updating symmetry counterparts would be redundent
|
|
||||||
UpdateFlag();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the displayed flag texture for this decal or optionally any symmetry counterparts
|
private void SetFlag(string newFlagUrl, bool isCustom, bool recursive) {
|
||||||
private void UpdateFlag(bool recursive = false) {
|
// Function to set the flag URL, the custom flag
|
||||||
// get the decal material property for the decal texture
|
|
||||||
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
|
||||||
|
|
||||||
if(useCustomFlag) {
|
// Set values
|
||||||
// set the texture to the custom flag
|
flagUrl = newFlagUrl;
|
||||||
textureProperty.TextureUrl = flagUrl;
|
useCustomFlag = isCustom;
|
||||||
}
|
|
||||||
else {
|
|
||||||
// set the texture to the mission flag
|
|
||||||
textureProperty.TextureUrl = MissionFlagUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateMaterials();
|
// Update material and projection
|
||||||
UpdateScale();
|
UpdateAll();
|
||||||
|
|
||||||
|
// Update symmetry counterparts if called to
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
// for each symmetry counterpart, copy this part's properties and update it in turn
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
||||||
|
decal.SetFlag(newFlagUrl, isCustom, false);
|
||||||
decal.useCustomFlag = useCustomFlag;
|
|
||||||
decal.flagUrl = flagUrl;
|
|
||||||
decal.UpdateFlag();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void UpdateMaterials() {
|
||||||
|
// get the decal material property for the decal texture
|
||||||
|
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||||
|
|
||||||
|
if (useCustomFlag) { // set the texture to the custom flag
|
||||||
|
textureProperty.TextureUrl = flagUrl;
|
||||||
|
} else { // set the texture to the mission flag
|
||||||
|
textureProperty.TextureUrl = MissionFlagUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.UpdateMaterials();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ using ConformalDecals.Text;
|
|||||||
using ConformalDecals.UI;
|
using ConformalDecals.UI;
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
|
using UniLinq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
@ -28,8 +29,7 @@ namespace ConformalDecals {
|
|||||||
public void SetText() {
|
public void SetText() {
|
||||||
if (_textEntryController == null) {
|
if (_textEntryController == null) {
|
||||||
_textEntryController = TextEntryController.Create(text, font, style, vertical, lineSpacing, charSpacing, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
_textEntryController = TextEntryController.Create(text, font, style, vertical, lineSpacing, charSpacing, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_textEntryController.Close();
|
_textEntryController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,8 +46,7 @@ namespace ConformalDecals {
|
|||||||
public void SetFillColor() {
|
public void SetFillColor() {
|
||||||
if (_fillColorPickerController == null) {
|
if (_fillColorPickerController == null) {
|
||||||
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_fillColorPickerController.Close();
|
_fillColorPickerController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,8 +68,7 @@ namespace ConformalDecals {
|
|||||||
public void SetOutlineColor() {
|
public void SetOutlineColor() {
|
||||||
if (_outlineColorPickerController == null) {
|
if (_outlineColorPickerController == null) {
|
||||||
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_outlineColorPickerController.Close();
|
_outlineColorPickerController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,41 +87,11 @@ namespace ConformalDecals {
|
|||||||
private MaterialColorProperty _outlineColorProperty;
|
private MaterialColorProperty _outlineColorProperty;
|
||||||
private MaterialFloatProperty _outlineWidthProperty;
|
private MaterialFloatProperty _outlineWidthProperty;
|
||||||
|
|
||||||
private DecalText _currentText;
|
private DecalText _currentText;
|
||||||
|
|
||||||
public override void OnLoad(ConfigNode node) {
|
// EVENTS
|
||||||
base.OnLoad(node);
|
|
||||||
|
|
||||||
string textRaw = "";
|
|
||||||
if (ParseUtil.ParseStringIndirect(ref textRaw, node, "text")) {
|
|
||||||
text = WebUtility.UrlDecode(textRaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
string fontName = "";
|
|
||||||
if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName")) {
|
|
||||||
font = DecalConfig.GetFont(fontName);
|
|
||||||
}
|
|
||||||
else if (font == null) font = DecalConfig.GetFont("Calibri SDF");
|
|
||||||
|
|
||||||
int styleInt = 0;
|
|
||||||
if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style")) {
|
|
||||||
style = (FontStyles) styleInt;
|
|
||||||
}
|
|
||||||
|
|
||||||
ParseUtil.ParseColor32Indirect(ref fillColor, node, "fillColor");
|
|
||||||
ParseUtil.ParseColor32Indirect(ref outlineColor, node, "outlineColor");
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
|
||||||
// For some reason, rendering doesnt work right on the first frame a scene is loaded
|
|
||||||
// So delay any rendering until the next frame when called in OnLoad
|
|
||||||
// This is probably a problem with Unity, not KSP
|
|
||||||
StartCoroutine(UpdateTextLate());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
UpdateText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public override void OnSave(ConfigNode node) {
|
public override void OnSave(ConfigNode node) {
|
||||||
node.AddValue("text", WebUtility.UrlEncode(text));
|
node.AddValue("text", WebUtility.UrlEncode(text));
|
||||||
node.AddValue("fontName", font.Name);
|
node.AddValue("fontName", font.Name);
|
||||||
@ -147,13 +115,23 @@ namespace ConformalDecals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnTextUpdate(string newText, DecalFont newFont, FontStyles newStyle, bool newVertical, float newLineSpacing, float newCharSpacing) {
|
public void OnTextUpdate(string newText, DecalFont newFont, FontStyles newStyle, bool newVertical, float newLineSpacing, float newCharSpacing) {
|
||||||
this.text = newText;
|
text = newText;
|
||||||
this.font = newFont;
|
font = newFont;
|
||||||
this.style = newStyle;
|
style = newStyle;
|
||||||
this.vertical = newVertical;
|
vertical = newVertical;
|
||||||
this.lineSpacing = newLineSpacing;
|
lineSpacing = newLineSpacing;
|
||||||
this.charSpacing = newCharSpacing;
|
charSpacing = newCharSpacing;
|
||||||
UpdateText(true);
|
UpdateAll();
|
||||||
|
|
||||||
|
foreach (var decal in part.symmetryCounterparts.Select(o => o.GetComponent<ModuleConformalText>())) {
|
||||||
|
decal.text = newText;
|
||||||
|
decal.font = newFont;
|
||||||
|
decal.style = newStyle;
|
||||||
|
decal.vertical = newVertical;
|
||||||
|
decal.lineSpacing = newLineSpacing;
|
||||||
|
decal.charSpacing = newCharSpacing;
|
||||||
|
decal.UpdateAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
||||||
@ -240,48 +218,58 @@ namespace ConformalDecals {
|
|||||||
base.OnDetach();
|
base.OnDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator UpdateTextLate() {
|
// FUNCTIONS
|
||||||
yield return null;
|
|
||||||
UpdateText();
|
protected override void LoadDecal(ConfigNode node) {
|
||||||
|
base.LoadDecal(node);
|
||||||
|
|
||||||
|
string textRaw = "";
|
||||||
|
if (ParseUtil.ParseStringIndirect(ref textRaw, node, "text")) {
|
||||||
|
text = WebUtility.UrlDecode(textRaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
string fontName = "";
|
||||||
|
if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName")) {
|
||||||
|
font = DecalConfig.GetFont(fontName);
|
||||||
|
} else if (font == null) font = DecalConfig.GetFont("Calibri SDF");
|
||||||
|
|
||||||
|
int styleInt = 0;
|
||||||
|
if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style")) {
|
||||||
|
style = (FontStyles) styleInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
ParseUtil.ParseColor32Indirect(ref fillColor, node, "fillColor");
|
||||||
|
ParseUtil.ParseColor32Indirect(ref outlineColor, node, "outlineColor");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateText(bool recursive = false) {
|
protected override void SetupDecal() {
|
||||||
// Render text
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
|
// For some reason text rendering fails on the first frame of a scene, so this is my workaround
|
||||||
var output = TextRenderer.UpdateText(_currentText, newText);
|
StartCoroutine(UpdateTextLate());
|
||||||
|
} else {
|
||||||
// update the _currentText state variable
|
base.SetupDecal();
|
||||||
// this is the ONLY place this variable should be set! otherwise the current state is lost
|
|
||||||
_currentText = newText;
|
|
||||||
|
|
||||||
// Update the texture with the new rendered output
|
|
||||||
UpdateTexture(output);
|
|
||||||
|
|
||||||
// If recursive, copy parameters to other parts and perform the same operation
|
|
||||||
if (recursive) {
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
|
||||||
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
||||||
decal.text = text;
|
|
||||||
decal.font = font;
|
|
||||||
decal.style = style;
|
|
||||||
decal.vertical = vertical;
|
|
||||||
decal.charSpacing = charSpacing;
|
|
||||||
decal.lineSpacing = lineSpacing;
|
|
||||||
|
|
||||||
decal.UpdateText();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTexture(TextRenderOutput output) {
|
private IEnumerator UpdateTextLate() {
|
||||||
_decalTextureProperty.Texture = output.Texture;
|
yield return null;
|
||||||
_decalTextureProperty.SetTile(output.Window);
|
UpdateAll();
|
||||||
|
|
||||||
UpdateMaterials();
|
|
||||||
UpdateScale();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateMaterials() {
|
protected override void UpdateMaterials() {
|
||||||
|
// Render text
|
||||||
|
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
|
||||||
|
if (newText != _currentText) {
|
||||||
|
var output = TextRenderer.UpdateText(_currentText, newText);
|
||||||
|
|
||||||
|
// update the _currentText state variable
|
||||||
|
// this is the ONLY place this variable should be set! otherwise the current state is lost
|
||||||
|
_currentText = newText;
|
||||||
|
|
||||||
|
_decalTextureProperty.Texture = output.Texture;
|
||||||
|
_decalTextureProperty.SetTile(output.Window);
|
||||||
|
}
|
||||||
|
|
||||||
_fillEnabledProperty.value = fillEnabled;
|
_fillEnabledProperty.value = fillEnabled;
|
||||||
_fillColorProperty.color = fillColor;
|
_fillColorProperty.color = fillColor;
|
||||||
|
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Rendering;
|
|
||||||
|
|
||||||
namespace ConformalDecals {
|
|
||||||
public class ProjectionTarget {
|
|
||||||
// Target object data
|
|
||||||
public readonly Transform target;
|
|
||||||
|
|
||||||
private readonly Renderer _targetRenderer;
|
|
||||||
private readonly Mesh _targetMesh;
|
|
||||||
private bool _projectionEnabled;
|
|
||||||
|
|
||||||
// property block
|
|
||||||
private readonly MaterialPropertyBlock _decalMPB;
|
|
||||||
|
|
||||||
public ProjectionTarget(MeshRenderer targetRenderer, Mesh targetMesh) {
|
|
||||||
target = targetRenderer.transform;
|
|
||||||
_targetRenderer = targetRenderer;
|
|
||||||
_targetMesh = targetMesh;
|
|
||||||
_decalMPB = new MaterialPropertyBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectorBounds, bool useBaseNormal) {
|
|
||||||
|
|
||||||
if (projectorBounds.Intersects(_targetRenderer.bounds)) {
|
|
||||||
_projectionEnabled = true;
|
|
||||||
var targetMaterial = _targetRenderer.sharedMaterial;
|
|
||||||
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
|
|
||||||
|
|
||||||
var projectionMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
|
|
||||||
var decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
|
|
||||||
var decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
|
|
||||||
|
|
||||||
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, projectionMatrix);
|
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, decalNormal);
|
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, decalTangent);
|
|
||||||
|
|
||||||
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
|
||||||
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
|
||||||
|
|
||||||
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
|
||||||
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
|
|
||||||
|
|
||||||
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_projectionEnabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
|
||||||
if (_projectionEnabled) {
|
|
||||||
_decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
|
|
||||||
_decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor));
|
|
||||||
|
|
||||||
Graphics.DrawMesh(_targetMesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
8
Source/ConformalDecals/Targets/IProjectionTarget.cs
Normal file
8
Source/ConformalDecals/Targets/IProjectionTarget.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Targets {
|
||||||
|
public interface IProjectionTarget {
|
||||||
|
bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds);
|
||||||
|
void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera);
|
||||||
|
}
|
||||||
|
}
|
93
Source/ConformalDecals/Targets/ProjectionMeshTarget.cs
Normal file
93
Source/ConformalDecals/Targets/ProjectionMeshTarget.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Targets {
|
||||||
|
public class ProjectionMeshTarget : IProjectionTarget {
|
||||||
|
public const string NodeName = "MESH_TARGET";
|
||||||
|
|
||||||
|
// enabled flag
|
||||||
|
public bool enabled;
|
||||||
|
|
||||||
|
// Target object data
|
||||||
|
public readonly Transform target;
|
||||||
|
public readonly Transform root;
|
||||||
|
public readonly Mesh mesh;
|
||||||
|
public readonly MeshRenderer renderer;
|
||||||
|
|
||||||
|
// Projection data
|
||||||
|
private Matrix4x4 _decalMatrix;
|
||||||
|
private Vector3 _decalNormal;
|
||||||
|
private Vector3 _decalTangent;
|
||||||
|
|
||||||
|
// property block
|
||||||
|
private readonly MaterialPropertyBlock _decalMPB;
|
||||||
|
|
||||||
|
public ProjectionMeshTarget(Transform target, Transform root, MeshRenderer renderer, Mesh mesh, bool useBaseNormal) {
|
||||||
|
this.root = root;
|
||||||
|
this.target = target;
|
||||||
|
this.renderer = renderer;
|
||||||
|
this.mesh = mesh;
|
||||||
|
_decalMPB = new MaterialPropertyBlock();
|
||||||
|
|
||||||
|
SetNormalMap(renderer.sharedMaterial, useBaseNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetNormalMap(Material targetMaterial, bool useBaseNormal) {
|
||||||
|
if (useBaseNormal && targetMaterial.HasProperty(DecalPropertyIDs._BumpMap)) {
|
||||||
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, targetMaterial.GetTexture(DecalPropertyIDs._BumpMap));
|
||||||
|
|
||||||
|
var normalScale = targetMaterial.GetTextureScale(DecalPropertyIDs._BumpMap);
|
||||||
|
var normalOffset = targetMaterial.GetTextureOffset(DecalPropertyIDs._BumpMap);
|
||||||
|
|
||||||
|
_decalMPB.SetVector(DecalPropertyIDs._BumpMap_ST, new Vector4(normalScale.x, normalScale.y, normalOffset.x, normalOffset.y));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds) {
|
||||||
|
if (projectionBounds.Intersects(renderer.bounds)) {
|
||||||
|
enabled = true;
|
||||||
|
|
||||||
|
var projectorToTargetMatrix = target.worldToLocalMatrix * projector.localToWorldMatrix;
|
||||||
|
|
||||||
|
_decalMatrix = orthoMatrix * projectorToTargetMatrix.inverse;
|
||||||
|
_decalNormal = projectorToTargetMatrix.MultiplyVector(Vector3.back).normalized;
|
||||||
|
_decalTangent = projectorToTargetMatrix.MultiplyVector(Vector3.right).normalized;
|
||||||
|
|
||||||
|
_decalMPB.SetMatrix(DecalPropertyIDs._ProjectionMatrix, _decalMatrix);
|
||||||
|
_decalMPB.SetVector(DecalPropertyIDs._DecalNormal, _decalNormal);
|
||||||
|
_decalMPB.SetVector(DecalPropertyIDs._DecalTangent, _decalTangent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
_decalMPB.SetFloat(PropertyIDs._RimFalloff, partMPB.GetFloat(PropertyIDs._RimFalloff));
|
||||||
|
_decalMPB.SetColor(PropertyIDs._RimColor, partMPB.GetColor(PropertyIDs._RimColor));
|
||||||
|
|
||||||
|
Graphics.DrawMesh(mesh, target.localToWorldMatrix, decalMaterial, 0, camera, 0, _decalMPB, ShadowCastingMode.Off, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ValidateTarget(Transform target, MeshRenderer renderer, MeshFilter filter) {
|
||||||
|
if (renderer == null) return false;
|
||||||
|
if (filter == null) return false;
|
||||||
|
if (!target.gameObject.activeInHierarchy) return false;
|
||||||
|
|
||||||
|
var material = renderer.material;
|
||||||
|
if (material == null) return false;
|
||||||
|
if (DecalConfig.IsBlacklisted(material.shader)) return false;
|
||||||
|
|
||||||
|
if (filter.sharedMesh == null) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
50
Source/ConformalDecals/Targets/ProjectionPartTarget.cs
Normal file
50
Source/ConformalDecals/Targets/ProjectionPartTarget.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Targets {
|
||||||
|
public class ProjectionPartTarget : IProjectionTarget {
|
||||||
|
public const string NodeName = "PART_TARGET";
|
||||||
|
|
||||||
|
// enabled flag
|
||||||
|
public bool enabled;
|
||||||
|
|
||||||
|
public readonly Part part;
|
||||||
|
public readonly List<ProjectionMeshTarget> meshTargets = new List<ProjectionMeshTarget>();
|
||||||
|
|
||||||
|
|
||||||
|
public ProjectionPartTarget(Part part, bool useBaseNormal) {
|
||||||
|
this.part = part;
|
||||||
|
|
||||||
|
foreach (var renderer in part.FindModelComponents<MeshRenderer>()) {
|
||||||
|
var target = renderer.transform;
|
||||||
|
var filter = target.GetComponent<MeshFilter>();
|
||||||
|
|
||||||
|
// check if the target has any missing data
|
||||||
|
if (!ProjectionMeshTarget.ValidateTarget(target, renderer, filter)) continue;
|
||||||
|
|
||||||
|
// create new ProjectionTarget to represent the renderer
|
||||||
|
var projectionTarget = new ProjectionMeshTarget(target, part.transform, renderer, filter.sharedMesh, useBaseNormal);
|
||||||
|
|
||||||
|
// add the target to the list
|
||||||
|
meshTargets.Add(projectionTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Project(Matrix4x4 orthoMatrix, Transform projector, Bounds projectionBounds) {
|
||||||
|
enabled = false;
|
||||||
|
foreach (var meshTarget in meshTargets) {
|
||||||
|
enabled |= meshTarget.Project(orthoMatrix, projector, projectionBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
||||||
|
if (!enabled) return;
|
||||||
|
|
||||||
|
foreach (var target in meshTargets) {
|
||||||
|
target.Render(decalMaterial, partMPB, camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -46,21 +46,25 @@ namespace ConformalDecals.Text {
|
|||||||
public bool SmallCapsMask => (_fontStyleMask & FontStyles.SmallCaps) != 0;
|
public bool SmallCapsMask => (_fontStyleMask & FontStyles.SmallCaps) != 0;
|
||||||
|
|
||||||
|
|
||||||
public DecalFont(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
|
public static DecalFont Parse(ConfigNode node, IEnumerable<TMP_FontAsset> fontAssets) {
|
||||||
if (node == null) throw new ArgumentNullException(nameof(node));
|
if (node == null) throw new ArgumentNullException(nameof(node));
|
||||||
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
|
if (fontAssets == null) throw new ArgumentNullException(nameof(fontAssets));
|
||||||
|
|
||||||
|
var font = ScriptableObject.CreateInstance<DecalFont>();
|
||||||
|
|
||||||
var name = ParseUtil.ParseString(node, "name");
|
var name = ParseUtil.ParseString(node, "name");
|
||||||
_fontAsset = fontAssets.First(o => o.name == name);
|
var fontAsset = fontAssets.First(o => o.name == name);
|
||||||
if (FontAsset == null) {
|
if (fontAsset == null) {
|
||||||
throw new FormatException($"Could not find font asset named {name}");
|
throw new FormatException($"Could not find font asset named {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_title = ParseUtil.ParseString(node, "title", true, name);
|
font._fontAsset = fontAsset;
|
||||||
_fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
|
font._title = ParseUtil.ParseString(node, "title", true, name);
|
||||||
_fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
|
font._fontStyle = (FontStyles) ParseUtil.ParseInt(node, "style", true);
|
||||||
}
|
font._fontStyleMask = (FontStyles) ParseUtil.ParseInt(node, "styleMask", true);
|
||||||
|
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetupSample(TMP_Text tmp) {
|
public void SetupSample(TMP_Text tmp) {
|
||||||
if (tmp == null) throw new ArgumentNullException(nameof(tmp));
|
if (tmp == null) throw new ArgumentNullException(nameof(tmp));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using ConformalDecals.Util;
|
using ConformalDecals.Util;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UniLinq;
|
using UniLinq;
|
||||||
|
33
Source/ConformalDecals/Tweakables/TweakableData.cs
Normal file
33
Source/ConformalDecals/Tweakables/TweakableData.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using ConformalDecals.Util;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Tweakables {
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public abstract class TweakableData : System.Attribute, ISerializationCallbackReceiver {
|
||||||
|
public string name;
|
||||||
|
|
||||||
|
public bool adjustable = true;
|
||||||
|
public string adjustableKey;
|
||||||
|
|
||||||
|
// public string fieldChangedCallback;
|
||||||
|
public bool useSymmetry = true;
|
||||||
|
|
||||||
|
protected TweakableData(string name) {
|
||||||
|
this.name = name;
|
||||||
|
adjustableKey = name + "Adjustable";
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Load(ConfigNode node) {
|
||||||
|
ParseUtil.ParseBoolIndirect(ref adjustable, node, adjustableKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Apply(BaseField baseField, PartModule module) {
|
||||||
|
baseField.guiActiveEditor = adjustable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnBeforeSerialize() { }
|
||||||
|
|
||||||
|
public void OnAfterDeserialize() { }
|
||||||
|
}
|
||||||
|
}
|
30
Source/ConformalDecals/Tweakables/TweakableDataCollection.cs
Normal file
30
Source/ConformalDecals/Tweakables/TweakableDataCollection.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UniLinq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Tweakables {
|
||||||
|
public class TweakableDataCollection : IEnumerable<TweakableData>, ISerializationCallbackReceiver {
|
||||||
|
public readonly Dictionary<string, TweakableData> tweakables = new Dictionary<string, TweakableData>();
|
||||||
|
|
||||||
|
[SerializeField] private TweakableData[] _serializedTweakables;
|
||||||
|
|
||||||
|
public IEnumerator<TweakableData> GetEnumerator() {
|
||||||
|
return tweakables.Values.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() {
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnBeforeSerialize() {
|
||||||
|
_serializedTweakables = tweakables.Values.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnAfterDeserialize() {
|
||||||
|
foreach (var tweakable in _serializedTweakables) {
|
||||||
|
tweakables.Add(tweakable.name, tweakable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
Source/ConformalDecals/Tweakables/TweakableSlider.cs
Normal file
56
Source/ConformalDecals/Tweakables/TweakableSlider.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using ConformalDecals.Util;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Tweakables {
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public class TweakableSlider : TweakableData {
|
||||||
|
// The default value for the slider
|
||||||
|
public float defaultValue;
|
||||||
|
public string defaultValueKey;
|
||||||
|
|
||||||
|
// The range of the slider as a vector of <min, max>
|
||||||
|
public float min = 0;
|
||||||
|
public float max = 1;
|
||||||
|
public string rangeKey;
|
||||||
|
|
||||||
|
// The step size of the slider
|
||||||
|
public float step;
|
||||||
|
public string stepKey;
|
||||||
|
|
||||||
|
public TweakableSlider(string name) : base(name) {
|
||||||
|
defaultValueKey = name + "Default";
|
||||||
|
rangeKey = name + "Range";
|
||||||
|
stepKey = name + "Step";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Load(ConfigNode node) {
|
||||||
|
base.Load(node);
|
||||||
|
|
||||||
|
var range = new Vector2(min, max);
|
||||||
|
ParseUtil.ParseVector2Indirect(ref range, node, rangeKey);
|
||||||
|
min = Mathf.Max(Mathf.Epsilon, range.x);
|
||||||
|
max = Mathf.Max(min, range.y);
|
||||||
|
|
||||||
|
ParseUtil.ParseFloatIndirect(ref step, node, stepKey);
|
||||||
|
|
||||||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||||||
|
ParseUtil.ParseFloatIndirect(ref defaultValue, node, defaultValueKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Apply(BaseField baseField, PartModule module) {
|
||||||
|
base.Apply(baseField, module);
|
||||||
|
var uiControlEditor = (UI_FloatRange) baseField.uiControlEditor;
|
||||||
|
|
||||||
|
uiControlEditor.minValue = min;
|
||||||
|
uiControlEditor.maxValue = max;
|
||||||
|
uiControlEditor.stepIncrement = step;
|
||||||
|
|
||||||
|
// Set the default value on first load
|
||||||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||||||
|
baseField.FieldInfo.SetValue(module, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
Source/ConformalDecals/Tweakables/TweakableToggle.cs
Normal file
34
Source/ConformalDecals/Tweakables/TweakableToggle.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using ConformalDecals.Util;
|
||||||
|
|
||||||
|
namespace ConformalDecals.Tweakables {
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public class TweakableToggle : TweakableData {
|
||||||
|
// The default value for the toggle
|
||||||
|
public bool defaultValue;
|
||||||
|
public string defaultValueKey;
|
||||||
|
|
||||||
|
public TweakableToggle(string name) : base(name) {
|
||||||
|
defaultValueKey = name + "Default";
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Load(ConfigNode node) {
|
||||||
|
base.Load(node);
|
||||||
|
|
||||||
|
// Set the default value on first load
|
||||||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||||||
|
ParseUtil.ParseBoolIndirect(ref defaultValue, node, defaultValueKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Apply(BaseField baseField, PartModule module) {
|
||||||
|
base.Apply(baseField, module);
|
||||||
|
|
||||||
|
// Set the default value on first load
|
||||||
|
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) {
|
||||||
|
baseField.FieldInfo.SetValue(module, defaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,7 @@ namespace ConformalDecals.Util {
|
|||||||
|
|
||||||
public static string ParseString(ConfigNode node, string valueName, bool isOptional = false, string defaultValue = "") {
|
public static string ParseString(ConfigNode node, string valueName, bool isOptional = false, string defaultValue = "") {
|
||||||
if (node.HasValue(valueName)) return node.GetValue(valueName);
|
if (node.HasValue(valueName)) return node.GetValue(valueName);
|
||||||
|
|
||||||
if (isOptional) {
|
if (isOptional) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
@ -74,6 +74,14 @@ namespace ConformalDecals.Util {
|
|||||||
return ParseValueIndirect(ref value, node, valueName, int.TryParse);
|
return ParseValueIndirect(ref value, node, valueName, int.TryParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static uint ParseUint(ConfigNode node, string valueName, bool isOptional = false, uint defaultValue = 0) {
|
||||||
|
return ParseValue(node, valueName, uint.TryParse, isOptional, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ParseUintIndirect(ref uint value, ConfigNode node, string valueName) {
|
||||||
|
return ParseValueIndirect(ref value, node, valueName, uint.TryParse);
|
||||||
|
}
|
||||||
|
|
||||||
public static Color32 ParseColor32(ConfigNode node, string valueName, bool isOptional = false, Color32 defaultValue = default) {
|
public static Color32 ParseColor32(ConfigNode node, string valueName, bool isOptional = false, Color32 defaultValue = default) {
|
||||||
return ParseValue(node, valueName, TryParseColor32, isOptional, defaultValue);
|
return ParseValue(node, valueName, TryParseColor32, isOptional, defaultValue);
|
||||||
}
|
}
|
||||||
@ -106,6 +114,14 @@ namespace ConformalDecals.Util {
|
|||||||
return ParseValueIndirect(ref value, node, valueName, ParseExtensions.TryParseVector3);
|
return ParseValueIndirect(ref value, node, valueName, ParseExtensions.TryParseVector3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Matrix4x4 ParseMatrix4x4(ConfigNode node, string valueName, bool isOptional = false, Matrix4x4 defaultValue = default) {
|
||||||
|
return ParseValue(node, valueName, ParseUtil.TryParseMatrix4x4, isOptional, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool ParseMatrix4x4Indirect(ref Matrix4x4 value, ConfigNode node, string valueName) {
|
||||||
|
return ParseValueIndirect(ref value, node, valueName, ParseUtil.TryParseMatrix4x4);
|
||||||
|
}
|
||||||
|
|
||||||
public static T ParseValue<T>(ConfigNode node, string valueName, TryParseDelegate<T> tryParse, bool isOptional = false, T defaultValue = default) {
|
public static T ParseValue<T>(ConfigNode node, string valueName, TryParseDelegate<T> tryParse, bool isOptional = false, T defaultValue = default) {
|
||||||
string valueString = node.GetValue(valueName);
|
string valueString = node.GetValue(valueName);
|
||||||
|
|
||||||
@ -145,6 +161,26 @@ namespace ConformalDecals.Util {
|
|||||||
throw new FormatException($"Improperly formatted {typeof(T)} value for {valueName} : '{valueString}");
|
throw new FormatException($"Improperly formatted {typeof(T)} value for {valueName} : '{valueString}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool TryParseMatrix4x4(string valueString, out Matrix4x4 value) {
|
||||||
|
value = new Matrix4x4();
|
||||||
|
|
||||||
|
var split = valueString.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
for (int i = 0; i < split.Length; i++) {
|
||||||
|
split[i] = split[i].Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split.Length != 16) return false;
|
||||||
|
int index = 0;
|
||||||
|
for (int row = 0; row < 4; row++) {
|
||||||
|
for (int col = 0; col < 4; col++) {
|
||||||
|
if (!float.TryParse(split[index], out float component)) return false;
|
||||||
|
value[row, col] = component;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool TryParseHexColor(string valueString, out Color32 value) {
|
public static bool TryParseHexColor(string valueString, out Color32 value) {
|
||||||
value = new Color32(0, 0, 0, byte.MaxValue);
|
value = new Color32(0, 0, 0, byte.MaxValue);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user