Skip to content

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

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Tliks
Copy link

@Tliks Tliks commented May 25, 2025

closes #6

複数のRendererに対するデシメートを行うためのコンポーネントを追加します。

1245591 ではPreviewの処理を共通化するため 基底クラスを作り既存の処理を置き換えています。動作に変更はないはずです。
f61efa0 では不要と思われるproxy meshへのobserveを削除し、有効化されていないrendererを処理の対象から除外することで最適化をしています。
55f2550 ではOverallMeshiaMeshSimplifierを追加しています。コンポーネントを名前は仮のものです。また、一旦Draft PRを作るのを優先したため、CustomEditorは別パッケージのIMGUIのものをほぼそのまま移植しています。

@Tliks Tliks marked this pull request as draft May 25, 2025 02:36
}
}

public static void AssignMesh(Renderer renderer, Mesh mesh)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void AssignMesh(Renderer renderer, Mesh mesh)
public static void SetMesh(Renderer renderer, Mesh mesh)

C#、Unityでは普通にGetSetを使うのが一般的ですね

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 25 to 37
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;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.");

対象が見つからないのを単に無視するのはよくない
例外じゃないにしても警告とかは出したほうが良い

Copy link
Author

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

毎回trianglesが生成されます。

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に対しても使えるので、同様の方法でアロケートせずに三角形数を取得できます。

Copy link
Author

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static bool IsValidForTarget(Renderer renderer)
public static bool IsValidTarget(Renderer renderer)

現在の命名だとインスタンスメソッドと誤認しそうな気がする

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public bool Enabled() => State == OverallMeshiaMeshSimplifierTargetState.Enabled;
}

public enum OverallMeshiaMeshSimplifierTargetState
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public enum OverallMeshiaMeshSimplifierTargetState
public enum MeshiaCascadingMeshSimplifierTargetKind

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stateというより種別(Kind)では、という話

@Tliks Tliks changed the title feat: OverallMeshiaMeshSimplifier feat: MeshiaCascadingMeshSimplifier May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

複数のRendererに対する全体的な適用を行うコンポーネント
2 participants