ryancbaker

I've been experimenting with using meshes to imitate a 3D object in Spine, in order to save time developing some assets that would normally require 8 or more states for different directions in our top-down game. For example, our enemies typically face 8 directions in 45° increments (north, northeast, east, etc). I'm hoping to use my fake 3D system to create a single state that can then be rotated to the desired heading, rather than creating a unique animation state for all 8 directions.

My setup all works as expected, and I can create a totally convincing 3D rotation... except for when the mesh vertices wrap around to the "back" side of the object, I experience incorrect sorting. I understand that since Spine is purely 2D, it has no sense of Z buffering, the mesh doesn't know (and obviously cannot know) what I want to be in front and what I want to be in back. That's totally understandable, but I wonder if there could be a simple workaround.

For example: if we could turn on a setting (a checkbox) on any given mesh that causes any "inside-out" polygons (any polys that have been wrapped over other polys) to become invisible. This would be completely sufficient for the purposes of hiding the "back side" of a 3D-esque mesh. See the screenshot below for an example. The orange portion is the "outside" of the wheel in my example, and would be visible. But the blue area shows the "inside" of the model, aka polys that are "inside out". Ideally, the blue polys and the "inside out" portions of the orange polys would be invisible.

Screen Shot 2017-10-09 at 3.48.51 PM.jpg


This is an example showing some undesirable sorting of the polys:
Screen Shot 2017-10-09 at 3.49.23 PM.jpg


It might also be helpful to me if there is an explanation for which polys appear on top when rendered? It seems to be slightly random.

---

One other thing that I learned from this process:

I bound this mesh to about 48 bones to create the 3D cylinder effect — each of the 4 "rings" of the wheel has 12 vertices placed in a circle. Then each vertex of the mesh is bound 100% to a single bone. This was a pretty painful process, but I have a couple of suggestions for the binding process which could significantly speed things up:

1. Would it be hard to add an alphabetical sorting option to the list of bones the mesh is bound to? This would help me to find the bone I want more quickly. It is nice that the bones are manually sortable, but a quick alphabetizing option would be super handy.

2. I realize this next suggestion would be more difficult, but... I almost always prefer to select bones directly with the mouse rather than finding their names in the list / tree / etc. For a mesh like this, it would have been much easier for me to select a mesh vertex, then switch to a different tool (a bind tool?) via a shortcut key, and then select a bone to bind it to (100% binding). I realize there are about a million reasons why you may not want to add this, but it would save SO much time.

Thanks for your time and consideration!
—Ryan Baker
Creative Director at Pixelscopic
http://www.pixelscopic.com
Currently using Spine for Delver's Drop (http://www.delversdrop.com)
User avatar
ryancbaker
Posts: 25

Nate

Usually the angle a 2D mesh keeps it's 3D illusion is less than 360 degrees. It would be interesting to see how your mesh works.

Currently the only way to sort mesh triangles is by adjusting the bone order in the weights view:
Weights - Spine User Guide: Triangle order
Obviously this order is set once and can't be changed during animations. You might be able to workaround this by duplicating the mesh and changing the order, if that is acceptable.

If a mesh is not weighted, the triangle order is arbitrary. Binding bones solely to order mesh triangles is possible, though a bit unfortunate to have otherwise useless bones laying around.

Not drawing triangles which are facing away from the camera is called "back-face culling". This is something you can enable at runtime in your game toolkit. Eg, in Unity this can be done in your shader by deleting this line (or changing it to Cull Back, which is the default if omitted, or Cull Front if that is what you want).

---

Oops, I posted before your additions.

1) I don't think you want alpha sorting, since the sorting defines the triangle order.

2) The Weights tool allows both selecting vertices AND clicking a bone in the viewport to select it in the Weights view. Oh, I guess you are talking about binding, not assigning weights. We could use the current vertex selection and bind that 100% to the next bone you bind, though this may surprise people who didn't realize they still had a vertex selection. I would bind all the bones, then use the Weights tool: select vertices, click bone (in viewport or in Weights view), swipe with one of the weight modes to set it to 100%, then repeat. This should be pretty fast.
User avatar
Nate

Nate
Posts: 8365

ryancbaker

Great response Nate, thank you! I had looked around the documentation, but had not seen the Weights - Triangle order section you mentioned, so that is super helpful. That will probably get me at least halfway to making things look perfect. Maybe I can also get the programmers to enable back-face culling, and that would hopefully fix everything else. Thanks!
—Ryan Baker
Creative Director at Pixelscopic
http://www.pixelscopic.com
Currently using Spine for Delver's Drop (http://www.delversdrop.com)
User avatar
ryancbaker
Posts: 25

supersaiyansubtlety

Would it be possible to allow setting back face culling from within spine?
If an animation needs the culling, it's very difficult to make it look good if you don't see the culling in spine. Then you just have a value for each mesh that tells runtimes whether or not back-face-cull.

---

Also a note on if this were implemented:
This would make it useful to be able to have linked meshes in different slots. This would let you make images with 2 different side to them. Say you wanted to have a sign that rotated about the y-axis, one side says "front", the other side says "back". So you have one image for "front" and one for "back", you enable back face culling for both, transform the the "back" image to have -1 x-scale, and put them on top of each other. This would effectively give you a two-different-sided image.
Great for 3D illusions : )

--

Oh, and the "front" and "back" meshes would be linked so they always deform the same way, but would both be visible in there own slots.
supersaiyansubtlety
Posts: 72

Nate

It's an interesting idea to have a backface culling setting. It is simplest to make it an editor setting. Users would responsible for turning on backface culling in their game toolkit. There wouldn't be any affect on the Spine Runtime.

This wouldn't be enough for your two-sided mesh example though. If backface culling is on for all rendering, when any mesh is facing away the texture won't be drawn. The only way to make a double-sided mesh is for one attachment to be rendered with culling on and one with it off. This requires a per attachment setting or, more likely, a per slot setting. It would cause a batch flush, like changing the slot blend mode.

We'll discuss internally and see which we prefer. We've got a lot on our plates, so I'm leaning toward a simple editor setting, at least to start.
User avatar
Nate

Nate
Posts: 8365

supersaiyansubtlety

I was thinking of a per-slot setting, but I believe the 2-sided mesh would work with a global setting.
1) enable back face culling for all meshes
2) flip the "back" image of the sign 'backwards' so you can't see it in setup
3) align the "front" and "back" meshes and bind them to the same bone, with the same vertices and weights
4) wouldn't this act like a 2-sided mesh?
supersaiyansubtlety
Posts: 72

Nate

Ah, yes I think you are right and that would work.

Added a global setting in 3.7.20-beta! :party:



User avatar
Nate

Nate
Posts: 8365

supersaiyansubtlety

Yay : D thank you! 3D effects will reach a whole new level!
supersaiyansubtlety
Posts: 72

ryancbaker

This is probably a really dumb question (sorry).

Is there any way possible to enable backface culling for meshes, but still to flip some textures? Obviously, as it is now, any flipped textures all disappear with the setting on... but I need the setting turned on so that any 3D-ish effects don't show the meshes on the "back side" of the 3D-ish object. So I kind of need both back-face culling and texture flipping, which I realize is a contradiction.

Any way we could have a checkbox to mirror a texture/attachment without using negative scale? Or is there another solution?

Thanks.
—Ryan Baker
Creative Director at Pixelscopic
http://www.pixelscopic.com
Currently using Spine for Delver's Drop (http://www.delversdrop.com)
User avatar
ryancbaker
Posts: 25

Nate

The only way to flip things results in the back side of the texture being used, which won't be drawn if back face culling is enabled. I'm afraid we don't have short term plans to support a way to flip things without using the back side of the texture. Sorry! :S
User avatar
Nate

Nate
Posts: 8365


Return to Editor
cron