Get flag module working

feature-multiSDF
Andrew Cassidy 4 years ago
parent 6a5604911d
commit 6c20675a99

@ -43,7 +43,7 @@ PART
MODULE
{
name = ModuleConformalDecal
name = ModuleConformalDecalGeneric
decalFront = Decal-Front
decalBack = Decal-Back
@ -61,7 +61,7 @@ PART
MODULE {
IDENTIFIER {
name = ModuleConformalDecal
name = ModuleConformalDecalGeneric
}
DATA {
decalShader = ConformalDecals/Feature/Bumped
@ -87,7 +87,7 @@ PART
MODULE {
IDENTIFIER {
name = ModuleConformalDecal
name = ModuleConformalDecalGeneric
}
DATA {
decalShader = ConformalDecals/Paint/Diffuse

@ -0,0 +1,53 @@
// ReStock+ 1.2.0
// 0.625m Radial Attachment Node
PART
{
name = decal-flag
module = Part
author = Andrew Cassidy
MODEL
{
model = ConformalDecals/Assets/decal-blank
scale = 1.0, 1.0, 1.0
}
scale = 1
rescaleFactor = 1
// Attachment
attachRules = 1,1,0,0,1
node_attach = 0.0, 0.0, 0.1, 0.0, 0.0, -1.0
// Tech
TechRequired = specializedConstruction
entryCost = 600
// Info
cost = 75
category = Structural
title = Blank Flag
manufacturer = #autoLOC_501648 // Maxo Construction Toys
description = foo
tags = foo
bulkheadProfiles = srf
// Parameters
mass = 0.015
dragModelType = default
maximum_drag = 0.1
minimum_drag = 0.05
angularDrag = 1.0
crashTolerance = 10
maxTemp = 2000
breakingForce = 350
breakingTorque = 150
MODULE
{
name = ModuleConformalDecalFlag
decalFront = Decal-Front
decalBack = Decal-Back
useBaseNormal = true
}
}

@ -60,12 +60,6 @@ namespace ConformalDecals {
private Bounds _decalBounds;
private Vector2 _backTextureBaseScale;
public ModuleConformalDecalBase() {
decalBackTransform = null;
decalModelTransform = null;
decalProjectorTransform = null;
}
private int DecalQueue {
get {
_decalQueueCounter++;
@ -83,36 +77,6 @@ namespace ConformalDecals {
if (HighLogic.LoadedSceneIsEditor) {
UpdateTweakables();
}
if (materialProperties == null) {
// materialProperties is null, so make a new one
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
materialProperties.Initialize();
}
else {
// materialProperties already exists, so make a copy
materialProperties = ScriptableObject.Instantiate(materialProperties);
}
// set shader
materialProperties.SetShader(decalShader);
// get back material if necessary
if (updateBackScale) {
this.Log("Getting material and base scale for back material");
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
updateBackScale = false;
}
else if ((backMaterial = backRenderer.material) == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false;
}
else {
_backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
}
}
// find front transform
decalFrontTransform = part.FindModelTransform(decalFront);
@ -148,6 +112,26 @@ namespace ConformalDecals {
decalProjectorTransform = part.FindModelTransform(decalProjector);
if (decalProjectorTransform == null) throw new FormatException($"Could not find decalProjector transform: '{decalProjector}'.");
}
// get back material if necessary
if (updateBackScale) {
this.Log("Getting material and base scale for back material");
var backRenderer = decalBackTransform.GetComponent<MeshRenderer>();
if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
updateBackScale = false;
}
else {
backMaterial = backRenderer.material;
if (backMaterial == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false;
}
else {
_backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
}
}
}
// update EVERYTHING if currently attached
if (_isAttached) {

@ -5,15 +5,24 @@ using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalDecalFlag : ModuleConformalDecalBase {
[KSPField]
private MaterialTextureProperty _flagTextureProperty;
[KSPField] public MaterialTextureProperty flagTextureProperty;
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
_flagTextureProperty = new MaterialTextureProperty("_MainTex", Texture2D.whiteTexture);
materialProperties.AddProperty(_flagTextureProperty);
if (materialProperties == null) {
// materialProperties is null, so make a new one
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
materialProperties.Initialize();
}
else {
// materialProperties already exists, so make a copy
materialProperties = ScriptableObject.Instantiate(materialProperties);
}
// set shader
materialProperties.SetShader(decalShader);
base.OnLoad(node);
}
public override void OnStart(StartState state) {
@ -24,7 +33,21 @@ namespace ConformalDecals {
}
private void UpdateFlag(string flagUrl) {
_flagTextureProperty.texture = GameDatabase.Instance.GetTexture(flagUrl, false);
this.Log($"Loading flag texture '{flagUrl}'.");
var flagTexture = GameDatabase.Instance.GetTexture(flagUrl, false);
if (flagTexture == null) {
this.LogWarning($"Unable to find flag texture '{flagUrl}'.");
return;
}
if (flagTextureProperty == null) {
this.Log("Initializing flag property");
flagTextureProperty = new MaterialTextureProperty("_Decal", flagTexture, isMain: true);
materialProperties.AddProperty(flagTextureProperty);
}
else {
flagTextureProperty.texture = flagTexture;
}
materialProperties.UpdateMaterials();
}

@ -5,8 +5,19 @@ using UnityEngine;
namespace ConformalDecals {
public class ModuleConformalDecalGeneric : ModuleConformalDecalBase {
public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
if (materialProperties == null) {
// materialProperties is null, so make a new one
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
materialProperties.Initialize();
}
else {
// materialProperties already exists, so make a copy
materialProperties = ScriptableObject.Instantiate(materialProperties);
}
// set shader
materialProperties.SetShader(decalShader);
// add texture nodes
foreach (var textureNode in node.GetNodes("TEXTURE")) {
materialProperties.AddProperty(new MaterialTextureProperty(textureNode));
@ -21,6 +32,8 @@ namespace ConformalDecals {
foreach (var colorNode in node.GetNodes("COLOR")) {
materialProperties.AddProperty(new MaterialColorProperty(colorNode));
}
base.OnLoad(node);
}
}
}
Loading…
Cancel
Save