Morph maker

Because few exporters/converters support morphs (blend keys, vertex animation, call it what you will), I needed to make a tool that takes two egg file and make a morph based on the difference in vertex position of both models.

Here it is.

morph_maker.py:

import os, sys

Egg2=file(sys.argv[1], 'r')
Egg1=file(sys.argv[2], 'r')
outFile=file(sys.argv[3], 'w')

vertData=[]
read=False
i=-1
for line in Egg1.readlines():
    if line.strip().startswith('<Vertex>'):  
        read=True
    elif read:
        vertData.append(map(float, line.split()))
        i=i+1
        read=False
i=0    
  
for line in Egg2.readlines():
    outFile.write(line)
    if line.strip().startswith('<Vertex>'): 
        read=True
    elif read:
        vert=map(float, line.split())
        if vert!=vertData[i]:
            morph=[vertData[i][0]-vert[0], vertData[i][1]-vert[1], vertData[i][2]-vert[2]]
            outFile.write("        <Dxyz> morph01 {"+str(morph[0])+" "+str(morph[1])+" "+str(morph[2])+" }\n")
        i=i+1
        read=False      
#else:    
#    del outFile
#    os.system('pview '+sys.argv[3])   

Usage:
morph_maker.py morph model out_file
where:
morph_maker.py is the name you saved the above python script
morph is a path to a egg file containing the ‘morph target’
model is a path to a egg file containing the model you want to morph
out_file is the name of the file you want the morphing model written to

The morph and the model should be based on the same model, the morph just needs to have its vertex moved (keeping the same order of the vertex in the file - but there’s a big chance if both are exported/converted with the same tool then the order is kept).

If nothing has changed and my memory is correct, then your model needs to have at least one bone.

To use the morph export a ‘pose’ (1 frame anim) or any animation and add to that egg file info about the morph.
Something like this:
original anim file:

<CoordinateSystem> { Z-Up }

<Table> {
  <Bundle> character {
    <Table> "<skeleton>" {
      <Table> Bip001 {
        <Xfm$Anim_S$> xform {
          <Scalar> fps { 30 }
          <Char*> order { srpht }
          <S$Anim> h { <V> { -89.9999 } }
          <S$Anim> z {
            <V> {
              7.52792 7.47407 7.43132 7.43438 7.49138 7.57633 7.67274
              7.76409 7.83391 7.86567 7.8518 7.80398 7.73461 7.6561
              7.58088 7.52134 7.47003 7.43183 7.43769 7.49491 7.57935
              7.6748 7.76507 7.83393 7.86519 7.85129 7.80366 7.73464
              7.65654 7.58168 7.52239
            }
          }
        }
        <Table> "Bip001 Footsteps" {
          <Xfm$Anim_S$> xform {
            <Scalar> fps { 30 }
            <Char*> order { srpht }
            <S$Anim> h { <V> { 89.9999 } }
            <S$Anim> z {
              <V> {
                -7.17656 -7.12271 -7.07996 -7.08302 -7.14002 -7.22497
                -7.32138 -7.41273 -7.48254 -7.51431 -7.50044 -7.45262
                .
                .
                .

with morph:


<CoordinateSystem> { Z-Up }

<Table> {
  <Bundle> character {
  <Table> morph {
      <S$Anim> morph01 {
        <Scalar> fps { 30 }
        <V> { 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 }
      }
    }
    <Table> "<skeleton>" {
      <Table> Bip001 {
        <Xfm$Anim_S$> xform {
          <Scalar> fps { 30 }
          <Char*> order { srpht }
          <S$Anim> h { <V> { -89.9999 } }
          <S$Anim> z {
            <V> {
              7.52792 7.47407 7.43132 7.43438 7.49138 7.57633 7.67274
              7.76409 7.83391 7.86567 7.8518 7.80398 7.73461 7.6561
              7.58088 7.52134 7.47003 7.43183 7.43769 7.49491 7.57935
              7.6748 7.76507 7.83393 7.86519 7.85129 7.80366 7.73464
              7.65654 7.58168 7.52239
            }
          }
        }
        <Table> "Bip001 Footsteps" {
          <Xfm$Anim_S$> xform {
            <Scalar> fps { 30 }
            <Char*> order { srpht }
            <S$Anim> h { <V> { 89.9999 } }
            <S$Anim> z {
              <V> {
                -7.17656 -7.12271 -7.07996 -7.08302 -7.14002 -7.22497
                -7.32138 -7.41273 -7.48254 -7.51431 -7.50044 -7.45262
                .
                .
                .