mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Use bounds to choose projection targets
This commit is contained in:
parent
23c309fa9a
commit
b09695d602
Binary file not shown.
@ -142,6 +142,7 @@ namespace ConformalDecals {
|
||||
|
||||
private Material _decalMaterial;
|
||||
private Material _previewMaterial;
|
||||
private BoxCollider _boundsCollider;
|
||||
|
||||
internal bool _shouldRender;
|
||||
|
||||
@ -320,6 +321,8 @@ namespace ConformalDecals {
|
||||
var boundsBehaviour = decalBoundsTransform.gameObject.AddComponent<DecalBoundsBehaviour>();
|
||||
boundsBehaviour.decalRenderer = this;
|
||||
|
||||
_boundsCollider = decalBoundsTransform.GetComponent<BoxCollider>();
|
||||
|
||||
UpdateMaterials();
|
||||
|
||||
if (HighLogic.LoadedSceneIsGame) {
|
||||
@ -481,7 +484,7 @@ namespace ConformalDecals {
|
||||
|
||||
// update projection
|
||||
foreach (var target in _targets) {
|
||||
target.Project(_orthoMatrix, decalProjectorTransform, useBaseNormal);
|
||||
target.Project(_orthoMatrix, decalProjectorTransform, _boundsCollider.bounds, useBaseNormal);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -20,9 +20,10 @@ namespace ConformalDecals {
|
||||
_decalMPB = new MaterialPropertyBlock();
|
||||
}
|
||||
|
||||
public void Project(Matrix4x4 orthoMatrix, Transform projector, bool useBaseNormal) {
|
||||
_projectionEnabled = true;
|
||||
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;
|
||||
|
||||
@ -46,6 +47,10 @@ namespace ConformalDecals {
|
||||
_decalMPB.SetTexture(DecalPropertyIDs._BumpMap, DecalConfig.BlankNormal);
|
||||
}
|
||||
}
|
||||
else {
|
||||
_projectionEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Render(Material decalMaterial, MaterialPropertyBlock partMPB, Camera camera) {
|
||||
if (_projectionEnabled) {
|
||||
|
Loading…
Reference in New Issue
Block a user