Skip to content

Commit d0161f1

Browse files
committed
使用源生成器生成属性绑定
1 parent 726eba3 commit d0161f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1550
-1718
lines changed

Coocoo3D/Components/VisualComponent.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
using Caprice.Display;
2-
using Coocoo3D.Present;
1+
using Coocoo3D.Present;
32

43
namespace Coocoo3D.Components;
54

65
public class VisualComponent
76
{
8-
public UIShowType UIShowType;
97
public RenderMaterial material = new RenderMaterial();
108
public Transform transform;
119
public int id;

Coocoo3D/Core/Scene.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void NewLighting()
9898
var gameObject = world.CreateEntity();
9999

100100
VisualComponent lightComponent = new VisualComponent();
101-
lightComponent.UIShowType = UIShowType.Light;
101+
lightComponent.material.Type = UIShowType.Light;
102102
gameObject.Set(lightComponent);
103103
gameObject.Set(new ObjectDescription
104104
{
@@ -114,7 +114,7 @@ public void NewDecal()
114114
var gameObject = world.CreateEntity();
115115

116116
VisualComponent decalComponent = new VisualComponent();
117-
decalComponent.UIShowType = UIShowType.Decal;
117+
decalComponent.material.Type = UIShowType.Decal;
118118
gameObject.Set(decalComponent);
119119
gameObject.Set(new ObjectDescription
120120
{

Coocoo3D/FileFormat/Coocoo3DScene.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CooSceneObject(Entity obj)
3131
}
3232
if (TryGetComponent<VisualComponent>(obj, out var visualComponent))
3333
{
34-
switch (visualComponent.UIShowType)
34+
switch (visualComponent.material.Type)
3535
{
3636
case UIShowType.Decal:
3737
type = "decal";
@@ -264,7 +264,7 @@ public void ToScene(Scene currentScene, MainCaches caches)
264264
continue;
265265
}
266266
VisualComponent component = new VisualComponent();
267-
component.UIShowType = uiShowType;
267+
component.material.Type = uiShowType;
268268
entity.Set(component);
269269
entity.Set(transform);
270270
if (obj.visual != null)

Coocoo3D/Present/RenderMaterial.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
using System.Collections.Generic;
1+
using Caprice.Display;
2+
using System.Collections.Generic;
23

34
namespace Coocoo3D.Present;
45

56
public class RenderMaterial
67
{
78
public string Name;
8-
9-
public RenderMaterial baseMaterial;
9+
public UIShowType Type;
10+
public Dictionary<string, object> Parameters = new Dictionary<string, object>();
1011

1112
public object GetObject(string key)
1213
{
1314
if (Parameters.TryGetValue(key, out object obj))
1415
return obj;
15-
return baseMaterial?.GetObject(key);
16+
17+
return null;
1618
}
1719

1820
public T GetObject<T>(string key)
@@ -21,15 +23,9 @@ public T GetObject<T>(string key)
2123
{
2224
return res;
2325
}
24-
if (baseMaterial == null)
25-
{
26-
return default;
27-
}
28-
return baseMaterial.GetObject<T>(key);
26+
return default;
2927
}
3028

31-
public Dictionary<string, object> Parameters = new Dictionary<string, object>();
32-
3329
public RenderMaterial GetClone()
3430
{
3531
var mat = (RenderMaterial)MemberwiseClone();

Coocoo3D/RenderPipeline/MainCaches.cs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class MainCaches : IDisposable
2828

2929
public VersionedDictionary<string, ModelPack> ModelPackCaches = new();
3030
public VersionedDictionary<string, MMDMotion> Motions = new();
31-
public VersionedDictionary<string, ComputeShader> ComputeShaders = new();
3231

3332
public VersionedDictionary<string, PSO> PipelineStateObjects = new();
3433
public VersionedDictionary<string, Assembly> Assemblies = new();
@@ -389,44 +388,6 @@ public static byte[] CompileScripts(string path)
389388
}
390389
}
391390

392-
public ComputeShader GetComputeShaderWithKeywords(IReadOnlyList<(string, string)> keywords, string path)
393-
{
394-
string xPath;
395-
if (keywords != null)
396-
{
397-
//keywords.Sort((x, y) => x.CompareTo(y));
398-
StringBuilder stringBuilder = new StringBuilder();
399-
stringBuilder.Append(path);
400-
foreach (var keyword in keywords)
401-
{
402-
stringBuilder.Append(keyword.Item1);
403-
stringBuilder.Append(keyword.Item2);
404-
}
405-
xPath = stringBuilder.ToString();
406-
}
407-
else
408-
{
409-
xPath = path;
410-
}
411-
if (string.IsNullOrEmpty(path)) return null;
412-
if (!Path.IsPathRooted(path)) path = Path.GetFullPath(path);
413-
return GetT(ComputeShaders, xPath, path, file =>
414-
{
415-
DxcDefine[] dxcDefines = null;
416-
if (keywords != null)
417-
{
418-
dxcDefines = new DxcDefine[keywords.Count];
419-
for (int i = 0; i < keywords.Count; i++)
420-
{
421-
dxcDefines[i] = new DxcDefine() { Name = keywords[i].Item1, Value = keywords[i].Item2 };
422-
}
423-
}
424-
var shaderCode = LoadShader(DxcShaderStage.Compute, File.ReadAllText(path), "csmain", path, dxcDefines, out var reflection);
425-
ComputeShader computeShader = new ComputeShader(shaderCode, reflection);
426-
return computeShader;
427-
});
428-
}
429-
430391
public PSO GetPSO(IReadOnlyList<(string, string)> keywords, string path)
431392
{
432393
string xPath;
@@ -497,22 +458,6 @@ static byte[] LoadShader(DxcShaderStage shaderStage, string shaderCode, string e
497458
return resultData;
498459
}
499460

500-
static byte[] LoadShader(DxcShaderStage shaderStage, string shaderCode, string entryPoint, string fileName, DxcDefine[] dxcDefines = null)
501-
{
502-
var shaderModel = shaderStage == DxcShaderStage.Library ? DxcShaderModel.Model6_3 : DxcShaderModel.Model6_0;
503-
var options = new DxcCompilerOptions() { ShaderModel = shaderModel };
504-
var result = DxcCompiler.Compile(shaderStage, shaderCode, entryPoint, options, fileName, dxcDefines, null);
505-
if (result.GetStatus() != SharpGen.Runtime.Result.Ok)
506-
{
507-
string err = result.GetErrors();
508-
result.Dispose();
509-
throw new Exception(err);
510-
}
511-
byte[] resultData = result.GetResult().AsBytes();
512-
result.Dispose();
513-
return resultData;
514-
}
515-
516461
public bool TryGetTexture(string path, out Texture2D tex)
517462
{
518463
bool result = TextureCaches.TryGetValue(path, out var tex1);
@@ -559,11 +504,7 @@ public void Dispose()
559504
t.Value?.Dispose();
560505
}
561506
TextureCaches.Clear();
562-
foreach (var t in ComputeShaders)
563-
{
564-
t.Value?.Dispose();
565-
}
566-
ComputeShaders.Clear();
507+
567508
foreach (var t in PipelineStateObjects)
568509
{
569510
t.Value?.Dispose();
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Caprice.Display;
2-
using System;
3-
using System.Collections.Generic;
1+
using Coocoo3D.Present;
42

53
namespace Coocoo3D.RenderPipeline;
64

@@ -12,10 +10,13 @@ public abstract class RenderPipeline
1210
public abstract void Render();
1311
public abstract void AfterRender();
1412

15-
public abstract IDictionary<UIShowType, ICloneable> materialTypes { get; }
16-
1713
public virtual void OnResourceInvald(string name)
1814
{
1915

2016
}
17+
18+
public virtual object UIMaterial(RenderMaterial material)
19+
{
20+
return null;
21+
}
2122
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy