Search Unity

BaseMeshEffect that removes elements.

Discussion in 'UGUI & TextMesh Pro' started by Pharan, Nov 4, 2015.

  1. Pharan

    Pharan

    Joined:
    Oct 28, 2013
    Posts:
    102
    I implemented a UnityEngine.UI.BaseMeshEffect (originally a BaseVertexEffect) that removes items instead of adding.
    My goal is still to remove (n) number of vertices (like the last letters on a UI.Text).

    This was simple back when it was BaseVertexEffect, and you overrode ModifyVertices. I had access to the List<UIVertex>. I just did some List mutations to remove the last (n) number of UIVertex elements of the list.

    Then the API was replaced with BaseMeshEffect, and you overrode ModifyMesh (Mesh). I at least had access to the Mesh. The logic was a bit different, but it wasn't too much work. You just had to remove the last few int items in the triangle index array and I got the same effect— those triangles wouldn't be drawn anymore.

    In 5.2.2, the API for ModifyMesh(Mesh) still exists but that was blamed in the Release Notes as one for the sources of the slowdowns in the UI system, and now, the recommended (and required) override is ModifyMesh(VertexHelper).

    My problem is, VertexHelper doesn't give access to its index array. It has all sorts of methods for adding, but not removing.

    Am I supposed to just keep using ModifyMesh(Mesh) and override ModifyMesh(VertexHelper) with an empty method?

    This doesn't seem to work.
    I'm really pissed now.
     
    Last edited: Nov 4, 2015
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Yes in 5.2.2 and above you are now supposed to use ModifyMesh(VertexHelper)

    VertexHelper does give you options for removing verticies. Although it's better to just extract the vertexStream to a List<UIVertex>, modify the list and then load the list back in to overwrite the mesh with AddUIVertexTriangleStream

    Hope this helps.
     
  3. Pharan

    Pharan

    Joined:
    Oct 28, 2013
    Posts:
    102
    I decided to push degenerate triangles (like what TextGenerator already does with richtext tags) using SetUIVertex for the time being. Had I been less experienced, I wouldn't have known I could do that.

    What are these options, exactly?

    From the looks of the internal structure of VertexHelper, it's actually not a List<UIVertex> internally but more like a mesh but with pooled internal arrays for tris, verts, normals, etc... getting and pushing UIVertex lists out of it is essentially "rehydration/dehydration" operations. That sounds kinda terrible.
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    You can check it for yourself here.
    https://bitbucket.org/Unity-Technol...ine.UI/UI/Core/Utility/VertexHelper.cs?at=5.2

    Internally, the VertexHelper receives the UI mesh. This can then be extracted through it's methods which results in a List<UIVertex>. However it doesn't manage anything itself internally, these are run by internal methods on the CanvasRenderer.

    The VertexHelper also lets you avoid pulling the full List<UIVertex> by setting / getting individual UIVertex elements with a bit of handwaving. (granted you end up pulling the list to just get the references.
     
  5. Pharan

    Pharan

    Joined:
    Oct 28, 2013
    Posts:
    102
    I think you're misunderstanding the code, and misunderstanding what I'm talking about.

    Internally, only the constructor uses Mesh. (The constructor used by the legacy fallback via
    DoLegacyMeshGeneration(). Not applicable to UI.Text. The Graphic class certainly doesn't use that constructor. But BaseMeshEffect does, but only in legacy mode, which UI.Text doesn't allow.)
    Internally, it's a bunch of Lists, just like a Mesh is a bunch of arrays.

    Yes, I know it lets you get and set IMPLIED UIVertex elements, but not remove them. How do you think I knew what the internals were? I checked the repo. VertexHelper is a bunch of private Lists. That was my problem in the first place.

    I want access to the internal lists so I can remove items from them. But I can't. That was the whole point of my post.

    My workaround was to force Vector3.zero verts down its throat so its triangles end up degenerate, because this is how the TextGenerator class also works when it ignores richtext tags.

    Why am I repeating myself in a forum post?