I create an animation manually, but it said "No animation" .

I want to manually create an animation, and then to export the animation script writing.

This is middlechest02Anim.egg of part:

...
...
...
<Polygon>  {
<VertexRef> { 370   372   373
<Ref> { b'animNonAccum'b'1'  } 
  }
}
<Joint> b'animNonAccum' {
  <Transform> {
        <Matrix4> {
          1.00 0.00 0.00 0.00 
          0.00 1.00 0.00 0.00 
          0.00 0.00 1.00 0.00 
          0.00 0.00 0.00 1.00 
        }
      } <VertexRef> {
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 <Ref> { b'animNonAccum'b'1' } } }
<VertexPool> b'animNonAccum'b'2'  { 

<Vertex> 0 {
30.296537399291992
-1.682546615600586
...
...
...
<Polygon>  {
<VertexRef> { 45   41   59
<Ref> { b'animNonAccum'b'2'  } 
  }
}
<Joint> b'animNonAccum' {
  <Transform> {
        <Matrix4> {
          1.00 0.00 0.00 0.00 
          0.00 1.00 0.00 0.00 
          0.00 0.00 1.00 0.00 
          0.00 0.00 0.00 1.00 
        }
      } <VertexRef> {
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 <Ref> { b'animNonAccum'b'2' } } }
}

and this is middlechest02Anim-Open.egg:

<CoordinateSystem> { Z-up } 
<Table> animation {
  <Bundle> b'animNonAccum' {
    <Table> "<skeleton>" {
      <Table> b'animNonAccum'b'2' {
        <Xfm$Anim> xform {
          <Scalar> order { sprht }
          <Scalar> fps { 30 }
          <Scalar> contents { prh }
          <V> {
            107.064 -12.251 0.000
            107.064 -12.134 0.000
            107.064 -11.772 0.000
            107.064 -11.155 0.000
            107.064 -10.288 0.000
            107.064 -9.192 0.000 
            107.064 -7.914 0.000 
            107.064 -6.518 0.000 
            107.064 -5.077 0.000 
          }
        }
      }
    }
  }
}

It’s that I write manually, and I made reference to another anim file.

When I run

pview middlechest02Anim.egg middlechest02Anim-Open.egg

, it work without error. When I push A-key, it display “No animation”.

should point to the with { 1 }

which contain animation should point to the particular joint

You still bind to the vertex pool instead of the joint. Should be

b'animNonAccum' {

btw, strange naming b’animNonAccum’b’2’ may be better to name animNonAccum_2 or “animNonAccum 2” or so.

Ah, sorry - your Group and Joint has the same name. You should rename one.

I rename one, I do not know what to do next step.

ubuntuone.com/3sQln6VjIOMGlelp2EWiN6

It’s animation file content

<Table>  {
  <Bundle> animNonAccum {
    <Table> "<skeleton>" {
      <Table> Joint_animNonAccum {
        <Xfm$Anim> xform {
          <Scalar> order { sprht }
          <Scalar> fps { 30 }
          <Scalar> contents { prh }
          <V> {
            0 0 0.000
            -10 0 0.000
            -20 0 0.000
            -30 0 0.000
            -40 0 0.000
            -50 0 0.000 
            -60 0 0.000 
            -70 0 0.000 
            -80 0 0.000 
            -90 0 0.000 
            -100 0 0.000 
          }
        }
      }
    }
  }
}

You have two bones with the same name - you also should rename one or remove it and attach all vertices to another

#The code need python3 and install pyffi.
#pyffi URL: http://pyffi.sourceforge.net/
#If you use "python3 nif2egg.py filename", it will open filename.nif and create filename.egg.

from pyffi.formats.nif import NifFormat
from argparse import ArgumentParser
import os
import sys

def recursive(parent, joint, file_object, s="", verName=""):
	"""Recursive build bones, only used when generating the character models."""
	for bone in parent.children:
		if bone is parent:
			continue
		if bone is data.roots[0]:
			continue
		if not isinstance(bone, NifFormat.NiNode):
			continue
		n = str(bone.name)
		n = n.replace("b'NPC R ","")
		n = n.replace("b'NPC L ","")
		n = n.replace("b'Bip01 ","")
		n = n.replace("'","")
		n = n.replace(" ","")
		n = n.replace("[","")
		n = n.replace("]","")
		print(s,"<Joint>", file=file_object)
		print(s,n, file=file_object)
		print(s,"'"+n+"'")
		print(s,"{", file=file_object)
		#print(joint.keys())
		if n in joint:
			print("权值",joint[n])
			# 写入具体权值
			for w in joint[n]:
				print(s,"<VertexRef> {", file=file_object,end=' ')
				for i in joint[n][w]:
					print(i, file=file_object,end=' ')
				print("\n", s,"<Scalar> membership {", file=file_object,end=' ')
				print(w, file=file_object,end=' ')
				print("} <Ref> {", file=file_object,end=' ')
				print(verName, file=file_object,end=' ')
				print("}", file=file_object)
				print(s,"}", file=file_object)
		recursive(bone, joint, file_object, s=s+"  ", verName=verName)
		print(s,"}", file=file_object)

# 写入顶点池
def writeVertex(block, file_object, groupName="", group=None):
	"""Write vertices"""
	print("<VertexPool>", str(groupName)+str(block.name)," { \n", file=file_object)
	vnum = 0
	# write vertex and normal
	dc = block.data.center
	if 'uv_sets' in dir(block.data):
		#不知到为什么,uv_sets 是二维数组,对应多个 uv 坐标吗?
		for v,n,u in zip(block.data.vertices, block.data.normals, block.data.uv_sets[0]):
			print("<Vertex>",vnum,"{", file=file_object)
			print(v.x+group.translation.x, file=file_object)
			print(v.y+group.translation.y, file=file_object)
			print(v.z+group.translation.z, file=file_object)
			print("<Normal> {", n.x, " ", n.y, " ", n.z, "} ", file=file_object)
			print("<UV> {", u.u, " ", -u.v, "} \n }", file=file_object)
			vnum += 1
	else:
		if block.data.has_vertex_colors:
			for v,n,c in zip(block.data.vertices, block.data.normals, block.data.vertex_colors):
				print("<Vertex>",vnum,"{", file=file_object)
				print(v.x+group.translation.x, file=file_object)
				print(v.y+group.translation.y, file=file_object)
				print(v.z+group.translation.z, file=file_object)
				print("<Normal> {", n.x, " ", n.y, " ", n.z, "}", file=file_object)
				print("<RGBA> {", c.r, " ", c.g, " ", c.b, " ", c.a, "} \n }", file=file_object)
				vnum += 1
		else:
			for v,n in zip(block.data.vertices, block.data.normals):
				print("<Vertex>",vnum,"{", file=file_object)
				print(v.x+group.translation.x, file=file_object)
				print(v.y+group.translation.y, file=file_object)
				print(v.z+group.translation.z, file=file_object)
				print("<Normal> {", n.x, " ", n.y, " ", n.z, "} \n }", file=file_object)
				vnum += 1
	file_object.write("}")

# 写入多边形
def writePolygon(block, file_object, groupName=""):
	"""Write polygon"""
	if isinstance(block, NifFormat.NiTriShape):
		for tri in block.data.triangles:
			print("<Polygon>  {", file=file_object)
			for t in tRef:
				if t in str(groupName)+str(block.name):
					print("<TRef>", file=file_object)
					print("{", tRef[t], "}", file=file_object)
			print("<VertexRef> {", tri.v_1, " ", tri.v_2, " ", tri.v_3, file=file_object)
			print("<Ref> {", str(groupName)+str(block.name)," } \n  }", file=file_object)
			file_object.write("}\n")
	elif isinstance(block, NifFormat.NiTriStrips):
		print("<TriangleStrip>  {", file=file_object)
		for t in tRef:
			if t in str(groupName)+str(block.name):
				print("<TRef>", file=file_object)
				print("{", tRef[t], "}", file=file_object)
		print("<VertexRef> {", file=file_object)
		for p in block.data.points[0].iter_item():
			print(p, file=file_object)
		print("<Ref> {", str(groupName)+str(block.name)," } \n  }", file=file_object)
		if bface:
			print("<BFace> { 1 }", file=file_object)			
		file_object.write("}\n")

def writeTransform(block, file_object, groupName=""):
	print("  <Transform> {\n    <Matrix4> {", file=file_object)
	print("      ",1.0, 0.0, 0.0, 0.0, file=file_object)
	print("      ",0.0, 1.0, 0.0, 0.0, file=file_object)
	print("      ",0.0, 0.0, 1.0, 0.0, file=file_object)
	print("      ",block.translation.x, block.translation.y, block.translation.z, 1.0, "}\n  }", file=file_object)
	
# 写入一根骨骼
def writeSimpleJoint(block, file_object, groupName=""):
	for i in block.children:
		if len(block.children)==1:
			print("一个子节点")
			print("<Joint>", "Joint_"+groupName, "{", file=file_object)
		else:
			print(len(block.children), "个子节点")
			print("<Joint>", "Joint_"+groupName+str(i.name), "{", file=file_object)
		print("""  <Transform> {
        <Matrix4> {
          1.00 0.00 0.00 0.00 
          0.00 1.00 0.00 0.00 
          0.00 0.00 1.00 0.00 
          0.00 0.00 0.00 1.00 
        }
      }""", file=file_object)
		for v in i.tree(block_type=NifFormat.NiTriShape):
			print("<VertexRef> {", file=file_object)
			for j in range(0, v.data.num_vertices):
				print(j, file=file_object, end=' ')
			print("<Ref> {", str(groupName)+str(i.name)+str(v.name), "} }", file=file_object)

		for v in i.tree(block_type=NifFormat.NiTriStrips):
			print("<VertexRef> {", file=file_object)
			for j in range(0, v.data.num_vertices):
				print(j, file=file_object, end=' ')
			print("<Ref> {", str(groupName)+str(i.name)+str(v.name), "} }", file=file_object)

		print("}", file=file_object)

def createAnimFile(block, name, groupName="", joNaLi=[]):
	print(block.stop_time)
	file_object = open(filename+"-"+name+".egg", "w")
	print("""<Table> animNonAccum {
  <Bundle> animNonAccum {
    <Table> "<skeleton>" {""", file=file_object)
	for i, na in zip(block.tree(block_type=NifFormat.NiTransformData), joNaLi):
		fr = block.stop_time
		if len(joNaLi)==1:
			print("<Table> Joint_"+groupName, file=file_object)
		else:
			print("<Table> Joint_"+groupName+na, file=file_object)
		print(groupName, na)
		print(""" {
        <Xfm$Anim> xform {
          <Scalar> order { sprht }
          <Scalar> fps { 24 }
          <Scalar> contents { phrxyz }
          <V> {""", file=file_object)

		for t in range(0,int(24*fr)+1):
			t1 = t/24/fr*180/3.1415926
			t2 = (24*fr-t)/24/fr*180/3.1415926
			arr = [	[i.xyz_rotations[0],1],
					[i.xyz_rotations[1],1],
					[i.xyz_rotations[2],1]]
			for xyz, s in arr:
				if xyz.num_keys == 0:
					print(0, file=file_object, end="  ")
				else:
					print((t1*xyz.keys[1].value+(t2)*xyz.keys[0].value)*s, file=file_object, end="  ")
			if i.translations.num_keys==0:
				print(0,0,0, file=file_object)
			else:
				k = i.translations.keys
				b = 0
				t1 = t
				for j1,j2 in zip(k, range(0,len(k))):
					if t/24 > j1.time:
						b=j2
						t1 = t-j1.time*24
						fr = k[b+1].time - j1.time
				print(t1/24/fr*k[b+1].value.x+(24*fr-t1)/24/fr*k[b].value.x, file=file_object, end="  ")
				print(t1/24/fr*k[b+1].value.y+(24*fr-t1)/24/fr*k[b].value.y, file=file_object, end="  ")
				print(t1/24/fr*k[b+1].value.z+(24*fr-t1)/24/fr*k[b].value.z, file=file_object, end="  ")
				print(" ", file=file_object)

		print("""
          }
        }
      }""", file=file_object)
	print("""
    }
  }
}""", file=file_object)
	file_object.close()
	

#文件名
#Get file name
#parser = ArgumentParser(description='Nif 转 Egg 脚本')
parser = ArgumentParser(description='Nif to Egg script')
parser.add_argument("filename", help="要打开的文件名,省略扩展名和点。")
#parser.add_argument("-t", action="append", dest="texture", help="要添加的纹理")
parser.add_argument("-t", action="append", dest="texture", help="you will append texture filename")
#parser.add_argument("-tr", action="append", dest="TRef", help="纹理应用到哪个模型上")
parser.add_argument("-tr", action="append", dest="TRef", help="apply the texture. Not achieved")
parser.add_argument("-sk", dest="skeleton", help="纹理应用到哪个模型上")
parser.add_argument("-bface", dest="bface", help="启用双面显示", action='store_true')
args = parser.parse_args()
filename = args.filename
bface = args.bface
tRef = {}
if args.TRef:
	for tr in args.TRef:
		k,v = tr.split('=')
		tRef[k] = v

#建立文件
#Create output file
file_object = open(filename+".egg", "w")
try:
	# 如果有纹理,则将纹理写入。
	if args.texture:
		for texName in args.texture:
			print("<Texture>", file=file_object)
			print(os.path.split(texName)[1], file=file_object)
			print("{", file=file_object)
			print(texName, file=file_object)
			print("""<Scalar> envtype { MODULATE }
	  <Scalar> minfilter { LINEAR_MIPMAP_LINEAR }
	  <Scalar> magfilter { LINEAR_MIPMAP_LINEAR }
	  <Scalar> wrap { REPEAT }
	}""", file=file_object)
	if args.skeleton:
		print("<Dart> { 1 }", file=file_object)
		boneStream = open(args.skeleton, 'rb')
		boneData = NifFormat.Data()
		boneData.read(boneStream)
	stream = open(filename+".nif", 'rb')
	data = NifFormat.Data()
	print(stream.name) # stream.name is file name
	data.read(stream)
	print(hex(data.version)) # It talk our which game the mod belong in.
	for root in data.roots:
		print("global_display():",root.get_global_display())
		for block in root.children:
			if "name" in dir(block):
				bloname = str(block.name).replace(" ","")
				bloname = bloname.replace("b'","")
				bloname = bloname.replace("'","")
				print("<Group> ",bloname,"{", file=file_object)
				if bloname[:4]=="anim" or bloname[-8:]=="NonAccum":
					print("<Dart> { 1 }", file=file_object)
			writeTransform(block, file_object, bloname)
			jointNameList = []
			for i in block.children:
				print("    sub name:",i.name)
				jointNameList.append(str(i.name))
				for j in i.tree(block_type=NifFormat.NiTriShape):
					print("      NiTriShape name:",j.name)
					writeVertex(j, file_object, bloname+str(i.name), group=i)
					writePolygon(j, file_object, bloname+str(i.name))
				for j in i.tree(block_type=NifFormat.NiTriStrips):
					print("      NiTriStrips name:",j.name)
					writeVertex(j, file_object, bloname+str(i.name), group=i)
					writePolygon(j, file_object, bloname+str(i.name))
				# 判断是否加入骨骼
			if bloname[:4]=="anim" or bloname[-8:]=="NonAccum":
				print("writeSimpleJoint")
				writeSimpleJoint(block, file_object, bloname)
				for block in root.tree(block_type=NifFormat.NiControllerSequence):		
					print("Anim name:",block.name)
					n = str(block.name).replace("b'","")
					n = n.replace("'","")
					createAnimFile(block, n, bloname, jointNameList)
			if "name" in dir(block):
				print("}", file=file_object)
			# I try read skeleton, bone and weight.
			if isinstance(block, NifFormat.NiSkinInstance):
				for body in block.partitions:
					print("body part:", body)
			elif isinstance(block, NifFormat.NiSkinData):
				print("num bones:", block.num_bones)
		
				print(block.has_vertex_weights)
			elif isinstance(block, NifFormat.SkinData):
				print("Num Vertices:",dir(block))
				print("Num Vertices:",block.num_vertices)	
finally:
	file_object.close()

# 尝试使用树状结构列出骨骼
skelroot = data.roots[0]
for bone in skelroot.tree():
	if bone is skelroot:
		continue
	if not isinstance(bone, NifFormat.NiNode):
		continue
	if "b'Bip01 NonAccum'" == str(bone.name):
		skelroot = bone
		print('找到了 Bip01')
		break

#recursive(skelroot, "")

#for blocktype in data.header.block_types:
#	print(blocktype.decode("ascii"))

# Run pview automatically
#os.system("pview "+filename+".egg")

The code can make static model. About animation … Sometimes it works and sometimes does not work.




Perhaps if you post the egg files you generated, it will help us to understand what you mean about it sometimes not working, and it may also help us to guess what the problem is.

David

Sorry. I mean, I can’t transform some .nif file to .egg file, because I not fully understand .nif file.