-
Notifications
You must be signed in to change notification settings - Fork 5
feat: MeshiaCascadingMeshSimplifier #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
} | ||
} | ||
|
||
public static void AssignMesh(Renderer renderer, Mesh mesh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void AssignMesh(Renderer renderer, Mesh mesh) | |
public static void SetMesh(Renderer renderer, Mesh mesh) |
C#、Unityでは普通にGetSetを使うのが一般的ですね
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (renderer) | ||
{ | ||
case MeshRenderer meshrenderer: | ||
var meshfilter = meshrenderer.GetComponent<MeshFilter>(); | ||
if (meshfilter == null) return; | ||
meshfilter.sharedMesh = mesh; | ||
break; | ||
case SkinnedMeshRenderer skinnedMeshRenderer: | ||
skinnedMeshRenderer.sharedMesh = mesh; | ||
break; | ||
default: | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (renderer) | |
{ | |
case MeshRenderer meshrenderer: | |
var meshfilter = meshrenderer.GetComponent<MeshFilter>(); | |
if (meshfilter == null) return; | |
meshfilter.sharedMesh = mesh; | |
break; | |
case SkinnedMeshRenderer skinnedMeshRenderer: | |
skinnedMeshRenderer.sharedMesh = mesh; | |
break; | |
default: | |
break; | |
} | |
switch (renderer) | |
{ | |
case MeshRenderer meshrenderer: | |
var meshfilter = meshrenderer.GetComponent<MeshFilter>(); | |
if (meshfilter == null) break; | |
meshfilter.sharedMesh = mesh; | |
break; | |
case SkinnedMeshRenderer skinnedMeshRenderer: | |
skinnedMeshRenderer.sharedMesh = mesh; | |
break; | |
default: | |
break; | |
} | |
throw new ArgumentException("Could not find target property to set mesh."); |
対象が見つからないのを単に無視するのはよくない
例外じゃないにしても警告とかは出したほうが良い
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (renderer is not SkinnedMeshRenderer and not MeshRenderer) return false; | ||
var mesh = RendererUtility.GetMesh(renderer); | ||
if (mesh == null) return false; | ||
if (mesh.triangles.Length == 0) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
毎回triangles
が生成されます。
Lines 20 to 32 in 545ef9b
public static int GetTriangleCount(this Mesh.MeshData mesh) | |
{ | |
var indexCount = 0; | |
for (int subMeshIndex = 0; subMeshIndex < mesh.subMeshCount; subMeshIndex++) | |
{ | |
var subMesh = mesh.GetSubMesh(subMeshIndex); | |
if (subMesh.topology == MeshTopology.Triangles) | |
{ | |
indexCount += subMesh.indexCount; | |
} | |
} | |
return indexCount / 3; | |
} |
GetSubMesh
は通常のMeshに対しても使えるので、同様の方法でアロケートせずに三角形数を取得できます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed = false; | ||
} | ||
|
||
public static bool IsValidForTarget(Renderer renderer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static bool IsValidForTarget(Renderer renderer) | |
public static bool IsValidTarget(Renderer renderer) |
現在の命名だとインスタンスメソッドと誤認しそうな気がする
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Packages/com.ramtype0.meshia.mesh-simplification/Ndmf/Runtime/OverallMeshiaMeshSimplifier.cs
Outdated
Show resolved
Hide resolved
public bool Enabled() => State == OverallMeshiaMeshSimplifierTargetState.Enabled; | ||
} | ||
|
||
public enum OverallMeshiaMeshSimplifierTargetState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public enum OverallMeshiaMeshSimplifierTargetState | |
public enum MeshiaCascadingMeshSimplifierTargetKind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stateというより種別(Kind)では、という話
closes #6
複数のRendererに対するデシメートを行うためのコンポーネントを追加します。
1245591 ではPreviewの処理を共通化するため 基底クラスを作り既存の処理を置き換えています。動作に変更はないはずです。
f61efa0 では不要と思われるproxy meshへのobserveを削除し、有効化されていないrendererを処理の対象から除外することで最適化をしています。
55f2550 ではOverallMeshiaMeshSimplifierを追加しています。コンポーネントを名前は仮のものです。また、一旦Draft PRを作るのを優先したため、CustomEditorは別パッケージのIMGUIのものをほぼそのまま移植しています。