This is awesome! I'm doing a project where I needed to do exactly the same
thing for Collada. I started using a very dirty way to interpolate the
matrices, and now I'm almost finishing a nice way to interpolate using
slerps (as suggested per Rob). As soon as I get this done, I'll post here.
Also, I did something that *might* be useful for those who are using Collada
animation: since we can't export animation-only on .DAE files, it's kinda
hard to have separated files with different animations cycles (the geometry
will end up on every file). I did something really stupid, but that solves
the problem: a python script that gets only the <library_animations> info,
and a parser that receives the information and creates a new animation clip
on-the-fly for your Object3D. (attaching both python script and the class
here, the parser uses pretty much all the code from the away3d Collada
class).

Please give me feedback if you're using it or if there is a better way to do
it :)

On Tue, Jan 27, 2009 at 8:25 PM, ben <[email protected]> wrote:

>
> I'll can finally release my "snail fighter" game  ;-)




-- 
~Gabriel Laet

Attachment: ColladaAnimation.as
Description: Binary data

from xml.etree import ElementTree as ET
from xml.etree.ElementTree import Element
import os
import sys
import getopt

"""
@author Gabriel Laet (http://gabriellaet.com)
Requires Python 2.5
"""

def remove_namespace(doc, namespace):
    """Remove namespace in the passed document in place."""
    ns = u'{%s}' % namespace
    nsl = len(ns)
    for elem in doc.getiterator():
        if elem.tag.startswith(ns):
            elem.tag = elem.tag[nsl:]


def read_collada(file_path, output_path):
	try:
		xml = ET.parse(file_path)
	
	except Exception, error:
		print "Error when parsing the XML file %s" % error
		return
		
	default_namespace = "http://www.collada.org/2005/11/COLLADASchema";
	library_animations = xml.find("{%s}library_animations" % default_namespace)
	
	collada = Element("collada")
	collada.append(library_animations)
	remove_namespace(collada, default_namespace)

	ET.ElementTree(collada).write(output_path)
	
if __name__ == "__main__":
	opts, args = getopt.getopt(sys.argv[1:], "i:")
	for option, value in opts:
		if option == "-i":
			input_file = value
	
			
	if input_file and output_file:
		read_collada(input_file, output_file)
	else:
		print "please provide input/output files -i -o"

Reply via email to