Compare commits

..

No commits in common. "c33f5bacdd5ada7558f3f3e11fc922c5cf365fbe" and "be3b7f791a15b1ab437b681f39ea07426281c322" have entirely different histories.

3 changed files with 62 additions and 37 deletions

View File

@ -280,6 +280,20 @@ 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);

View File

@ -71,17 +71,14 @@ 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()]
@ -134,10 +131,6 @@ namespace ConformalDecals {
else {
materialProperties = ScriptableObject.Instantiate(materialProperties);
}
_opacityProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_DecalOpacity");
_cutoffProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_Cutoff");
_wearProperty = materialProperties.AddOrGetProperty<MaterialFloatProperty>("_EdgeWearStrength");
}
/// <inheritdoc />
@ -234,20 +227,30 @@ 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) {
UpdateMaterials();
materialProperties.SetOpacity(opacity);
materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
materialProperties.SetWear(wear);
}
foreach (var counterpart in part.symmetryCounterparts) {
var decal = counterpart.GetComponent<ModuleConformalDecal>();
decal.UpdateMaterials();
decal.materialProperties.SetOpacity(opacity);
decal.materialProperties.SetCutoff(cutoff);
if (useBaseNormal) {
decal.materialProperties.SetWear(wear);
}
}
}
@ -255,7 +258,7 @@ namespace ConformalDecals {
protected void OnVariantApplied(Part eventPart, PartVariant variant) {
if (_isAttached && eventPart != null && (!projectMultiple || eventPart == part.parent)) {
_targets.Remove(eventPart);
UpdateProjection();
UpdateTargets();
}
}
@ -277,8 +280,9 @@ namespace ConformalDecals {
/// Called when a part is transformed in the editor
protected void OnPartTransformed(Part eventPart) {
if (part == eventPart || part.symmetryCounterparts.Contains(eventPart)) {
if (this.part == eventPart) {
UpdateProjection();
UpdateTargets();
}
else if (_isAttached && projectMultiple) {
UpdatePartTarget(eventPart, _boundsRenderer.bounds);
@ -291,7 +295,7 @@ namespace ConformalDecals {
/// Called when a part is attached in the editor
protected void OnPartAttached(Part eventPart) {
if (part == eventPart || part.symmetryCounterparts.Contains(eventPart)) {
if (this.part == eventPart) {
OnAttach();
}
else if (_isAttached && projectMultiple) {
@ -305,7 +309,7 @@ namespace ConformalDecals {
/// Called when a part is detached in the editor
protected void OnPartDetached(Part eventPart) {
if (part == eventPart || part.symmetryCounterparts.Contains(eventPart)) {
if (this.part == eventPart) {
OnDetach();
}
else if (_isAttached && projectMultiple) {
@ -350,6 +354,7 @@ namespace ConformalDecals {
UpdateMaterials();
UpdateProjection();
UpdateTargets();
}
/// Called when decal is detached from its parent part
@ -537,6 +542,7 @@ namespace ConformalDecals {
UpdateTextures();
UpdateMaterials();
UpdateProjection();
UpdateTargets();
}
/// Update decal textures
@ -544,11 +550,12 @@ 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;
@ -599,26 +606,6 @@ 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
@ -631,6 +618,30 @@ 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