mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
simplify opacity cutoff and wear by using material properties
This commit is contained in:
parent
be3b7f791a
commit
03d2e66543
Binary file not shown.
@ -280,20 +280,6 @@ namespace ConformalDecals.MaterialProperties {
|
||||
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() {
|
||||
foreach (var material in Materials) {
|
||||
UpdateMaterial(material);
|
||||
|
@ -71,14 +71,17 @@ namespace ConformalDecals {
|
||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-opacity", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
||||
UI_FloatRange()]
|
||||
public float opacity = 1.0f;
|
||||
private MaterialFloatProperty _opacityProperty;
|
||||
|
||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-cutoff", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "P0"),
|
||||
UI_FloatRange()]
|
||||
public float cutoff = 0.5f;
|
||||
private MaterialFloatProperty _cutoffProperty;
|
||||
|
||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-wear", guiActive = false, guiActiveEditor = true, isPersistant = true, guiFormat = "F0"),
|
||||
UI_FloatRange()]
|
||||
public float wear = 100;
|
||||
private MaterialFloatProperty _wearProperty;
|
||||
|
||||
[KSPField(guiName = "#LOC_ConformalDecals_gui-multiproject", guiActive = false, guiActiveEditor = true, isPersistant = true),
|
||||
UI_Toggle()]
|
||||
@ -131,6 +134,10 @@ namespace ConformalDecals {
|
||||
else {
|
||||
materialProperties = ScriptableObject.Instantiate(materialProperties);
|
||||
}
|
||||
|
||||
_opacityProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_DecalOpacity");
|
||||
_cutoffProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Cutoff");
|
||||
_wearProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_EdgeWearStrength");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -227,30 +234,20 @@ namespace ConformalDecals {
|
||||
// scale or depth values have been changed, so update scale
|
||||
// and update projection matrices if attached
|
||||
UpdateProjection();
|
||||
UpdateTargets();
|
||||
|
||||
foreach (var counterpart in part.symmetryCounterparts) {
|
||||
var decal = counterpart.GetComponent<ModuleConformalDecal>();
|
||||
decal.UpdateProjection();
|
||||
decal.UpdateTargets();
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when the decal's material is modified through a tweakable
|
||||
protected void OnMaterialTweakEvent(BaseField field, object obj) {
|
||||
materialProperties.SetOpacity(opacity);
|
||||
materialProperties.SetCutoff(cutoff);
|
||||
if (useBaseNormal) {
|
||||
materialProperties.SetWear(wear);
|
||||
}
|
||||
UpdateMaterials();
|
||||
|
||||
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);
|
||||
}
|
||||
decal.UpdateMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +255,7 @@ namespace ConformalDecals {
|
||||
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
|
||||
if (_isAttached && eventPart != null && (!projectMultiple || eventPart == part.parent)) {
|
||||
_targets.Remove(eventPart);
|
||||
UpdateTargets();
|
||||
UpdateProjection();
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,7 +279,6 @@ namespace ConformalDecals {
|
||||
protected void OnPartTransformed(Part eventPart) {
|
||||
if (this.part == eventPart) {
|
||||
UpdateProjection();
|
||||
UpdateTargets();
|
||||
}
|
||||
else if (_isAttached && projectMultiple) {
|
||||
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
|
||||
@ -354,7 +350,6 @@ namespace ConformalDecals {
|
||||
|
||||
UpdateMaterials();
|
||||
UpdateProjection();
|
||||
UpdateTargets();
|
||||
}
|
||||
|
||||
/// Called when decal is detached from its parent part
|
||||
@ -542,7 +537,6 @@ namespace ConformalDecals {
|
||||
UpdateTextures();
|
||||
UpdateMaterials();
|
||||
UpdateProjection();
|
||||
UpdateTargets();
|
||||
}
|
||||
|
||||
/// Update decal textures
|
||||
@ -550,12 +544,11 @@ namespace ConformalDecals {
|
||||
|
||||
/// Update decal materials
|
||||
protected virtual void UpdateMaterials() {
|
||||
_opacityProperty.value = opacity;
|
||||
_cutoffProperty.value = cutoff;
|
||||
_wearProperty.value = wear;
|
||||
|
||||
materialProperties.UpdateMaterials();
|
||||
materialProperties.SetOpacity(opacity);
|
||||
materialProperties.SetCutoff(cutoff);
|
||||
if (useBaseNormal) {
|
||||
materialProperties.SetWear(wear);
|
||||
}
|
||||
|
||||
_decalMaterial = materialProperties.DecalMaterial;
|
||||
_previewMaterial = materialProperties.PreviewMaterial;
|
||||
@ -606,6 +599,26 @@ namespace ConformalDecals {
|
||||
_orthoMatrix[1, 3] = 0.5f;
|
||||
|
||||
decalProjectorTransform.localScale = new Vector3(size.x, size.y, depth);
|
||||
|
||||
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
|
||||
@ -618,30 +631,6 @@ namespace ConformalDecals {
|
||||
}
|
||||
}
|
||||
|
||||
/// Called when updating decal targets
|
||||
protected void UpdateTargets() {
|
||||
if (!_isAttached) return;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdatePartTarget(Part targetPart, Bounds projectionBounds) {
|
||||
if (targetPart.GetComponent<ModuleConformalDecal>() != null) return; // skip other decals
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user