Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 29793e5

Browse files
authored
Misc fixes (#357)
* Fix for some invalid compounded csg operations on surfaces * Improved addition material data GUI in Chisel
1 parent 8724721 commit 29793e5

File tree

15 files changed

+9232
-5850
lines changed

15 files changed

+9232
-5850
lines changed

Assets/Sample Scene/sample scene.unity

Lines changed: 73 additions & 73 deletions
Large diffs are not rendered by default.

Assets/Test cases/test_case_21.unity

Lines changed: 8687 additions & 5514 deletions
Large diffs are not rendered by default.

Packages/com.chisel.core/Chisel/Core/1.Input/Nodes/CSGOperationType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Chisel.Core
66
/// <seealso cref="Chisel.Core.CSGTreeBrush"/>
77
/// <seealso cref="Chisel.Core.CSGTreeBranch"/>
88
[Serializable]
9-
public enum CSGOperationType : byte
9+
public enum CSGOperationType : byte // Note: DO NOT CHANGE THE ORDER OF THESE VALUES
1010
{
1111
/// <summary>The given <see cref="Chisel.Core.CSGTreeBrush"/> or <see cref="Chisel.Core.CSGTreeBranch"/> is added to the <see cref="Chisel.Core.CSGTree"/> and removes all the geometry inside it.</summary>
1212
Additive = 0,

Packages/com.chisel.core/Chisel/Core/1.Input/Surfaces/ChiselBrushMaterial.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

Packages/com.chisel.core/Chisel/Core/1.Input/Surfaces/ChiselBrushMaterial.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Packages/com.chisel.core/Chisel/Core/1.Input/Surfaces/ChiselSurface.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,38 @@ namespace Chisel.Core
1111
[Serializable]
1212
public struct ChiselMaterial
1313
{
14-
public const string kMaterialFieldName = nameof(material);
14+
public const string kMaterialFieldName = nameof(material);
1515
public const string kSurfaceMetadataFieldName = nameof(surfaceMetadata);
1616

1717
public Material material;
1818
public ChiselSurfaceMetadata surfaceMetadata;
19+
20+
public static ChiselMaterial Create(Material material)
21+
{
22+
ChiselMaterial chiselMaterial = new() { material = material };
23+
chiselMaterial.Update();
24+
return chiselMaterial;
25+
}
26+
27+
public bool Update()
28+
{
29+
if (material == null)
30+
{
31+
if (surfaceMetadata != null)
32+
{
33+
surfaceMetadata = null;
34+
return true;
35+
}
36+
return false;
37+
}
38+
var newSurfaceMetadata = material.GetMetadataOfType<ChiselSurfaceMetadata>();
39+
if (surfaceMetadata != newSurfaceMetadata)
40+
{
41+
surfaceMetadata = newSurfaceMetadata;
42+
return true;
43+
}
44+
return false;
45+
}
1946
}
2047

2148
/// <summary>Defines a surface on a <see cref="Chisel.Core.BrushMesh"/>.
@@ -44,19 +71,15 @@ public sealed class ChiselSurface
4471
public void SetMaterial(Material material)
4572
{
4673
chiselMaterial.material = material;
47-
chiselMaterial.surfaceMetadata = (material == null) ? null : chiselMaterial.material.GetMetadataOfType<ChiselSurfaceMetadata>();
74+
chiselMaterial.Update();
4875
}
4976

5077
public static ChiselSurface Create(Material material, SurfaceDetails details)
5178
{
5279
return new ChiselSurface
5380
{
54-
chiselMaterial = new ChiselMaterial
55-
{
56-
material = material,
57-
surfaceMetadata = (material == null) ? null : material.GetMetadataOfType<ChiselSurfaceMetadata>(),
58-
},
59-
surfaceDetails = details
81+
chiselMaterial = ChiselMaterial.Create(material),
82+
surfaceDetails = details
6083
};
6184
}
6285

Packages/com.chisel.core/Chisel/Core/1.Input/Surfaces/ChiselSurfaceMetadata.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,10 @@ public override int GetHashCode()
4242
return (int)hash;
4343
}
4444
}
45+
46+
public override void OnReset()
47+
{
48+
physicsMaterial = ChiselDefaultMaterials.DefaultPhysicsMaterial;
49+
}
4550
}
4651
}

Packages/com.chisel.core/Chisel/Core/2.Processing/Categorization/CategoryRoutingRow.cs

Lines changed: 216 additions & 144 deletions
Large diffs are not rendered by default.

Packages/com.chisel.core/Chisel/Core/2.Processing/Jobs/CreateRoutingTableJob.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#define HAVE_SELF_CATEGORIES
12
#define USE_OPTIMIZATIONS
23
//#define SHOW_DEBUG_MESSAGES
3-
#define HAVE_SELF_CATEGORIES
44
using System;
55
using System.Runtime.CompilerServices;
66
using System.Runtime.InteropServices;
@@ -263,7 +263,7 @@ static int GetStackNodes(CompactNodeID processedNodeID,
263263
output[outputLength] = new CategoryStackNode { NodeIDValue = currentNodeID.value, routingRow = CategoryRoutingRow.AllSelfAligned };
264264
outputLength++;
265265
break;
266-
}
266+
}
267267

268268
if (haveGoneBeyondSelf > 0)
269269
haveGoneBeyondSelf = 2; // We're now definitely beyond our brush
@@ -504,8 +504,9 @@ static void Combine([NoAlias] ref NativeArray<CategoryStackNode> leftStack, int
504504
#if HAVE_SELF_CATEGORIES
505505
var operationTableOffset = (int)operation;
506506
#else
507-
var operationTableOffset = (leftHaveGoneBeyondSelf >= 1 && rightStackLength == 1 ?
508-
CategoryRoutingRow.RemoveOverlappingOffset : 0) +
507+
var operationTableOffset = //(leftHaveGoneBeyondSelf >= 1 ?//&& rightStackLength == 1 ?
508+
//CategoryRoutingRow.RemoveOverlappingOffset : 0) +
509+
(leftHaveGoneBeyondSelf * CategoryRoutingRow.OperationCount) +
509510
(int)operation;
510511
#endif
511512

@@ -574,7 +575,7 @@ static void Combine([NoAlias] ref NativeArray<CategoryStackNode> leftStack, int
574575
{
575576
// Fix up output of last node to include operation between last left and last right.
576577
// We don't add a routingOffset here since this is last node & we don't have a destination beyond this point
577-
var routingRow = new CategoryRoutingRow(operationTableOffset, leftCategoryIndex, rightStack[rightStackRowIndex].routingRow); // applies operation
578+
var routingRow = new CategoryRoutingRow(operationTableOffset, leftCategoryIndex, rightStack[rightStackRowIndex].routingRow); // applies operation
578579
var skip = !combineUsedIndices.IsSet(vIndex);
579580
#if USE_OPTIMIZATIONS
580581
combineIndexRemap[vIndex] = skip ? (byte)0 :
@@ -626,7 +627,7 @@ static void Combine([NoAlias] ref NativeArray<CategoryStackNode> leftStack, int
626627
}
627628

628629

629-
[BurstDiscard]
630+
[BurstDiscard]
630631
static void FailureMessage()
631632
{
632633
Debug.LogError("Unity Burst Compiler is broken");
@@ -676,6 +677,7 @@ static void RemapIndices([NoAlias] NativeArray<CategoryStackNode> stack, [NoAlia
676677
if (key >= remap.Length || remap[key] == 0) { FailureMessage(); return; }
677678
}
678679

680+
#if HAVE_SELF_CATEGORIES
679681
{
680682
var key = (int)routingRow.selfAligned;
681683
if (key >= remap.Length || remap[key] == 0) { FailureMessage(); return; }
@@ -685,6 +687,7 @@ static void RemapIndices([NoAlias] NativeArray<CategoryStackNode> stack, [NoAlia
685687
var key = (int)routingRow.selfReverseAligned;
686688
if (key >= remap.Length || remap[key] == 0) { FailureMessage(); return; }
687689
}
690+
#endif
688691

689692
{
690693
var key = (int)routingRow.reverseAligned;
@@ -738,4 +741,4 @@ static void Dump(int processedNodeID, NativeArray<CategoryStackNode> stack, int
738741
}
739742
#endif
740743
}
741-
}
744+
}

0 commit comments

Comments
 (0)