[Monogame] couple questions

Discuss issues pertaining to the various game/web runtimes of Creature here.
Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

[Monogame] couple questions

Post by Kynes » Tue Oct 04, 2016 5:40 am

Hi, I'm new here, in the process of evaluating Creature. So far it looks like there is a lot of potential.
First of all, I'd like to mention that I was evaluating Spine just before, and the quality of the C# runtime wasn't good at all, the code is not elegant, neither clean, and I found a bug in the first few hours using it. So here I am, so far the c# code looks professional, the motor approach is simply awesome, so far I'm pleased :)

To evaluate properly I'm going to build a prototype using the monogame runtime with the samples available.
Here are my questions:

1/ I'd like to integrate a 2d physics engine (farseer) for collision detection. How to get a polygon out of a specific bone?

2/ Is there a way to attach events on specific frames from the editor (like foot steps) that I can listen to from code?

3/ Is there a convinient way to dynamicaly attach bones and replace an image (to change weapons?)

4/ I'd like to integrate facial expressions to my characters, that I can manipulate from code. Is there a way to set contextual image layers on top?

5/ How to manipulate the motors input parameters dynamically ?

6/ Is it possible to to render a mesh fragment separately, in order to assign a custom shader?


Quite a lot of questions I realize! But if most of these are possible, it would make this product simply incredible.
Thanks a lot!

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: [Monogame] couple questions

Post by chong » Tue Oct 04, 2016 7:01 am

Hello,

Thank you for your interest in Creature!
I will give you clear cut transparent answers ( I like to be straightforward about things ):

1) First, I will direct your attention to Meshbone.cs:
https://github.com/kestrelm/Creature_Mo ... eshBone.cs

This is the core of the skeletal posing engine for the Creature runtimes ( all runtimes share very similar structures, albeit C#, C++, JS, Java etc. )

There is a class called MeshRenderComposition. It has a list: public List<MeshRenderRegion> regions, this contains the regions data structures in the rest pose. All regions index into a global point pool. You will notice each region has a start and end index that determines its range in the global point pool. The reason to do this is to ensure efficient final rendering ( so only a single draw call is required to render the entire character )

What you want is probably the final posed points of the regions with the animated bones. Have a look at CreatureModule.cs:
https://github.com/kestrelm/Creature_Mo ... eModule.cs

In particular, look for the method PoseCreature() and the lines:

Code: Select all

			for(int j = 0; j < cur_regions.Count; j++) {
				MeshBoneUtil.MeshRenderRegion cur_region = cur_regions[j];
				
				int cur_pt_index = cur_region.getStartPtIndex();

				cur_region.poseFinalPts(ref target_pts,
				                        cur_pt_index * 3,
				                         ref cur_bones);

				// add in z offsets for different regions
				for(int k = cur_region.getStartPtIndex() * 3;
				    k <= cur_region.getEndPtIndex() * 3; 
				    k+=3)
				{
					target_pts[k + 2] = j * region_offsets_z;
				}

Notice how the loop goes through each region and writes into the global target_pts pool array. So you can follow the same pattern to extract points from target_pts for each region.

Take note however that because everything in Creature is a mesh and deforms, you might have deforming polygons per frame. You can probably fit a proxy polygon for those points if you want to and align it to the target region pts based on its closest rigid transform.

2) The ability to do event triggers was just added in the latest update of the Creature Editor. However, right now the currently supported engines are Unity and UE4 ( the 2 biggest users of Creature )

Having said that, it's not difficult to get the events code working in Monogame since the Unity and Monogame runtimes are quite similar.

There is a class in:
https://github.com/kestrelm/Creature_Un ... eModule.cs

called CreatureMetaData. This is a generic class ( just basic C# ) that stores layer ordering and events.
The method BuildCreatureMetaData() actually builds the required data for events based on an input JSON dictionary.

After that, the actual callback trigger mechanism exists in:
https://github.com/kestrelm/Creature_Un ... troller.cs

Again, a general C# class called CreatureFrameCallback handles the callback work.
There are additional functions BuildFrameCallbacks(), ResetFrameCallbacks() and ProcessFrameCallbacks() that handle the rest of the actual trigger mechanisms. The callbacks are just based off C# events and notifications.

3) Again there is but this is currently for the Unity C# runtimes:
http://www.kestrelmoon.com/creaturedocs ... times.html

There is a method called SetActiveItemSwap to do the swapping of sprites manually for a region.

4) Yes so layer ordering is the same thing as events, as in it is supported in the meta data structure in the unity runtimes.

5) Sorry, motors are authored in the editor but it bakes out raw keyframes ( to speed up processing ) in the actual runtimes. In the future we might consider real-time motor runtime support.

6) Actually yes if you don't mind writing your own renderer. As you mentioned before, the C# runtimes give you all the data structures needed to represent a fully deforming skinnable character.

It has a set of bones and regions that index into a global point pool. The default renderer in the name of efficiency renders the entire character in one single draw call.

However, you can easily change this to not do it and assign a shader per region if you want to.
Have a look at the default monogame C# Renderer:
https://github.com/kestrelm/Creature_Mo ... enderer.cs

You should follow the same pattern of iterating through each region, and render a mesh with indices pointing into that region. You can assign a different shader for every region you care about.

Cheers

Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

Re: [Monogame] couple questions

Post by Kynes » Tue Oct 04, 2016 7:54 am

This was a quick and complete answer, thank you so much!

It's interesting most users are using UE and unity, because these are fat engines for 2d.
Would it be a good idea in the future to implement an abstraction to share a common codebase for Unity and Monogame?

About building a collision polygon, I guess I'll have to filter vertices that are outlining the region myself. Is it a good idea to determine the polygon outline by looking for vertices that are used only once in the Index buffer?

About the event triggers, is this availlable in the demo version as well (I've downloaded few hours ago) ?

Thanks again, I'm getting very excited :)

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: [Monogame] couple questions

Post by chong » Tue Oct 04, 2016 3:39 pm

Hello,

Yes it would be a good idea to make them share an abstraction when I get the time to do it.

You can look for the polygon outline but remember that the outline changes if it undergoes mesh deformation per frame ( depending on how your animation is done of course. You can also not make the meshes deform if you want and just have rigid transforms. This just means in the authoring phase you have one bone affecting one region only, which is what other traditional 2D puppet/cutout animation software do. If you have 2 or more bones affecting one region, then it will do mesh deformation ) The other way is to first grab the outline of the region at the first frame of animation and its closest associated bone. Then as it animates, you use the outline you stored and transform it based on the animated bone. That should work quite well as long as the deformation doesn't stretch the mesh too much.

Yes the event triggers ( currently for Unity and UE4 ) have been added in the demo version, the tutorial and docs haven't been done yet. They will be published either this or next week so stay tuned.

Cheers

Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

Re: [Monogame] couple questions

Post by Kynes » Tue Oct 04, 2016 4:25 pm

I've spent the day on it.
Right now I have an algorythm that finds the outer vertices, now I almost got them reordered by walking the edges, and this is computed during initialization in MeshRenderRegion constructor.

Then on each frame I'll build the final polygon inside PoseCreature() as you mentionned, quickly walking the vertex buffer from the precomputed indices.

But this will work only if the final vertice array always will always have the same order as the one submited during initialization, I need confimation on this.

Once I'll be at this point, there is one last case that I haven't resolved yet: Motors that are bending meshes will lead to shapes with segments crossing each other:

Image

But I'm not there yet. Does this sounds good ?

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: [Monogame] couple questions

Post by chong » Tue Oct 04, 2016 4:38 pm

Hello,

This is just a suggestion but it might help you out.
For each MeshRenderRegion, it has a Dictionary called normal_weight_map that is indexed by the name of the bone.

The values for each bone key are lists of floats determining the weight on that region for mesh skinning/deformation. In other words, if the list of floats are all 0, then the bone has no influence on that mesh region.

This means you can easily determine using code which bones affect which regions ( without going through the Creature editor ). So here is something you can try:

1) First grab the outline from the first frame

2) Determine which bones affect which regions based on their weight values.

3) When the bones animate, for each mesh region, you find all the bones that affect it, get their average transformation and apply that transformation to the outline from 1). Essentially the outline does not deform but just rotates and translates rigidly.

Cheers

Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

Re: [Monogame] couple questions

Post by Kynes » Tue Oct 04, 2016 4:56 pm

I think I'm starting to realize the kind of mess I got into lol

Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

Re: [Monogame] couple questions

Post by Kynes » Wed Oct 05, 2016 7:59 pm

well... kinda progressing. still very buggy

Image

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: [Monogame] couple questions

Post by chong » Wed Oct 05, 2016 9:57 pm

Looks pretty cool! One thing you can do is to put some code to "shrink" the boundary vertices of the mesh if you think it is too thick. You can do that via the indices/connectivity information.

For this particular character animation, you can turn off the collision generation for the flames. The body itself fits quite well.

Also in Creature itself, you can craft the meshes to suit your collision scheme better.
There are also other sample animation files you can try on this page here:
http://creature.kestrelmoon.com/more_info_3.html

Cheers

Kynes
Posts: 14
Joined: Tue Oct 04, 2016 5:13 am

Re: [Monogame] couple questions

Post by Kynes » Wed Oct 05, 2016 10:28 pm

good evening,

This is indeed something I have in mind, selecting the inner level vertices. But here it's mostly the blue fire image that are too large.
My main concern currenly, besides fixing the outline finder algorytm, is to reduce the number of sides per polygon, because so far this is not suited for a physic engine, this will be way too expensive to process.

btw I just saw the event trigger video you posted, thats awesome =)

My next priority is to investigate how to dynamicaly add/remove bones/images, and see what kind of workflow may work on the editor side. Ideally, I'd like to build a generic skeleton and attach different weapons/equiment.

I still have tons of questions but right now my body is begging me to go to bed =)

Have a good day

Post Reply