Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

unity3d - Listen for changes to Mesh class for rebuilding metadata in Unity?

I need to detect when the Mesh class's vertex arrays get updated, so that I can update metadata (normals, tangents and similar) for my shader. The idea being that people could use my shader effect globally, or add it as a component on a model with no additional code required.

This is very similar to the Mesh.RecalculateNormals() concept, but for my own metadata. I believe that I'm trying to replicate the OnMeshChanged delegate from Unreal Engine:

https://docs.unrealengine.com/en-US...DynamicMeshComponent/OnMeshChanged/index.html

Here is another example for a "transform changed" listener in Java:

Listen for transformation changes

Evidently this can be done in Unity by NOT passing MeshUpdateFlags.DontNotifyMeshUsers (MeshUpdateFlags.Default) to methods like Mesh.SetVertexBufferData() and then intercepting the "mesh users" notification in a Renderer, MeshRenderer or ShapeModule.

But unfortunately using Mesh.MarkModified() and detecting that event in a Renderer appears to be undocumented.

Does someone have an example of detecting Mesh-modified events in something like a MeshRenderer?

This is related to the general concept of reactive programming, which currently appears to be impossible for sealed classes like GameObject and Mesh in Unity. I've posted lengthy questions with full details here and here and am mostly looking for any solution at all that doesn't require users of my library to manually call Mesh.MarkModified() everywhere.

question from:https://stackoverflow.com/questions/65852139/listen-for-changes-to-mesh-class-for-rebuilding-metadata-in-unity

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...