Vertex Morphing Details in Panda3D

Better way to impliment vertex morphing?

  • By having all morph targets in one mesh description
  • By having seperate mesh fo each morph target (may be even seperate egg files for each targets)

0 voters

Hi,
I require Vertex Morphing Animation.
Here is the present situation (I think) in Panda.

  1. .egg can contain multiple points for each vertex.
  2. No way to export morphing data from blender.
  3. No inbuild functionality in panda3d where user can set a new .egg file as target for vertex morphing.
    #note: Assuming that the vertex count and order are same as in original mesh and target mesh.
    #note: modeler blender with chicken 69 exporter.

To workaround we can:

  1. Add a functionality in Panda3d to work out the solution described in point(3) above.
  2. add additional vertexes by post-processing .egg file after export from blender.

I personally prefer first option but for immediate requirement second option (I am new to python and would write egg file handling better than making a separate functionality in Panda3d), so now the question is, how to do it?
If somebody can help me with few details:

  1. exactly where in the egg file are the vertexes of the target morphs?
  2. After processing the egg file how in code do we animate vertex morphing?
  3. Also if i go the first method way, can any friendly and experienced person guide me to stuffs as (in game vertex modification techniques in Panda3d)

Finally a bit of confirmation for blender:

  1. If we make a mesh and do object copy of it, then modify only by positioning of vertexes to new locations and finally exporting both separately using chicken 69 exporter. Are both export ‘vertex morphingly’ compatible???

thanks in advance for the above solution and thanks a lot for the wonderful Panda3d.

with regards,
Amit

Vertex morphing has complex internal set-up requirements, so it is necessary for Panda to know that the vertices involved in an egg file will be part of a deformable mesh at the time that the egg file is loaded. This makes solution (1) difficult to achieve, because at the time the first egg file is loaded, Panda has no way to know that you plan to add a morph target to it later, and thus will load it inappropriately for vertex morphing.

Solution (2) is relatively easy to achieve, though. You can write a Python program that reads two or more egg files and outputs a resulting egg file, which contains all of the original egg files as separate morph targets that you can switch between at runtime. There are some requirements, of course: you need to be sure that all of the vertices between the different models correspond one-to-one. There must be the same number of vertices in each morph target, and you must have some way to match them up to each other.

You can use the egg API to read and write egg files (there are examples in the manual, in the forum, and the full API is described in the API reference). To represent morph targets within the egg file, you store a delta with each vertex. Note that a morph target is not a new vertex, just a new position for an existing vertex. This is why you need to be able to match up the vertices one-to-one.

So, to build your morphable egg file, you will load up the two source egg files, choose one to be the base model, and for each vertex in the secondary model you will compute its delta vector from the corresponding vertex in the base model, and store that in the output egg file.

The deltas appear in the egg file with the syntax. The manual describes the syntax. With the egg API, they are added with the EggMorphVertexList, which, oops!, I’ve just realized isn’t exposed to Python.

That’s unfortunate. It means you can use the egg API to add morphs in C++, but you can’t (at the moment) use the egg API to add morphs in Python. You can still write a Python program that generates an egg file as a text stream, but this is harder.

I’ll see about exposing this API to Python for the future.

David

Thanks for the info.

So the syntax in egg file, for morph targets, contains difference between the base and target vertexes and not absolute coordinates.

Assuming that chicken exporter does not do any optimization on meshes while exporting and we have two ‘vertex to vertex compatible’ egg files.

  1. Does python optimizes(ie a new optimized runtime mesh) mesh while loading it from egg/x or any other file? because if it ‘does not’ then a routine to vertex morphing from separate meshes does not seem as difficult!

Also after making the final egg file how do I start/enable vertex morphing in panda python programming.

Also does panda works with morphing details in .x files also? Or does .X files contains any morphing details?

If you have many shape keys, the blender models will become very difficult to manage.

It would be much easier to just add shape key support to chicken. Look into the source and you should figure it out quickly.

If you load the egg file via the egg API, there is no optimization: you are directly operating on the egg structures. If you load the egg file via loader.loadModel() or via the Actor interfaces, though, you are asking Panda to create a renderable model for you, which is altogether different. In that case you will end up with an optimized model which is not suitable for this operation.

Use the Actor interface. Each morph target has a unique name that appears in the egg file; you can access the morph target by this name with actor.controlJoint(), and dynamically adjust the slider in-game. Or you can bind static animation tables to the slider in a separate animation egg file.

.x files do not contain morphing details.

I think clcheung’s point is a good one.

David

Following clcheung’s advice saw chicken exporter.
the change to export part are easy in function “def write()”

but the trouble is to understand blender api for getting details of shape key. Think, have to work hard (Python, Python, everywhere, little jonny want to play).

So Integrating directly to the processed egg file seems to be faster option for now, unless i get to the blenders documentation for shapekeys.

Again in future I would try to develop an interface where the meshes and target meshes are loaded first, the morphing details are integrated second and then the optimization happens (Hm’mm should download panda source code and see the loadModel() and Actor interfaces)

Would keep updating of what I’ll do. Thanks

Again in future I would try to develop an interface where the meshes and target meshes are loaded first, the morphing details are integrated second and then the optimization happens (Hm'mm should download panda source code and see the loadModel() and Actor interfaces) 

It’s not really that simple. You’re talking about fundamentally restructuring the way Panda loads model files. It’s not just an “optimization”; it’s a translation of a scene in egg language, which describes a model from a high-level perspective, into another scene in Panda’s internal structures, which describes a model for the purposes of rendering quickly.

The right long-term solution really is to fix the blender converter. If that can’t be done, an egg pre-processor is a decent short-term solution. But making Panda load multiple egg files as morph targets is really not a viable idea.

David

Well, the shape key api is more simple comparing to what you want to do with panda. I have made a prototype exporter in a few days and create the talking head:
discourse.panda3d.org/viewtopic.php?t=6389
and also some examples in demomaster

Send me an email if you to test the exporter. It is not 100% tested and it is based on R66.

clcheung, if you send me your code I can always integrate it into the actual Chicken releases. I obviously prefer the least amount of effort on my part, so a diff off R71b is preferred, but anything that makes it easier to do is appreciated.

Sure. I just want to make sure it is working well first.

You are right drwr, abt the change in egg file.
Since Panda3d does not have a full fledged WYSIWYG editor and ide. Egg file more or less acts as a resource panel for us.

To just facilitate and giving better support for morphing technique, a flexible mechanism is to be devised.
My intention was doing processing on .egg ( adding target vertexes for morphing ) at runtime just before calling loadModel() and Actor interfaces.

Offcourse it would be better to one-time integrate, before even writing the main program. I would try making a tool for same.

I would certainly look forward to lethe integrating clcheung’s code.

Thanks a lot to all for the details.

Ok, moved a little bit forward.
Opened ripple.egg, and experimented with it, then tried with my own model and it worked.
Anyhow few doubt remains:

  1. As in ripple.egg, each vertex contained all the vertex, and morph vertex details as well as the details for normals.
  2. While exporting from blender the normals are embed in the polygon section. So where would be the normal of morphed vertexes store in this scenario.

I am using a hackish sort of programming for integration of two egg files but would like to make a more decent application.
Can someone help me in providing a basic template c++ program for using Egg API.

Hi amitpanda3d, you could try to apply a skin modifier on vertices you want morph on with a couple of bones and exporting your model to egg file you could load it in Panda3D as Actor and with function “controlJoint” you can retrieve the bones related with vertex and acting on them you can morph very well.
But, in 3DS for example, the exporter doesn’t export in a correct way the vertex where you applied on skin modifier… so you have to check if in blender the exporter gives any problem.
In your egg file must be tag on the head otherwise you couldn’t do that task.

The other way would be exporting the animation with the same method and acting on animation directly.