Game Development Community

Loading dsq question

by David Horn · in Torque X 2D · 11/14/2009 (8:53 pm) · 5 replies

I'm loading a lot of animations into my 3d object.
It is REALLY slowing the loading process down per character and I'm not even close to the number of animations I'm going to have.

Here is how I load my T2DShape3D:

public static void CreateNewWrestler(Wrestler w)
        {

            T2DShape3D shape = new T2DShape3D();
            w.pname = w.myName + Game.inc.ToString();
            Game.inc += 1;
            shape.Name = w.pname;
            String _shapeFile = @"data/shapes/testguy.dts";

            if (File.Exists(_shapeFile))
            {
                FileStream fs = new FileStream(_shapeFile, FileMode.Open, FileAccess.Read);
                ShapeReader reader = new ShapeReader();
                Shape dtsshape = reader.ReadShape(fs);
                fs.Close();
                fs = new FileStream(@"data/animations/stand.dsq", FileMode.Open, FileAccess.Read);
                Shape dsq = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/walk.dsq", FileMode.Open, FileAccess.Read);
                Shape dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/walkb.dsq", FileMode.Open, FileAccess.Read);
                dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/punch.dsq", FileMode.Open, FileAccess.Read);
                dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/punchhit.dsq", FileMode.Open, FileAccess.Read);
                dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/duck.dsq", FileMode.Open, FileAccess.Read);
                dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/grapple.dsq", FileMode.Open, FileAccess.Read);
                dsq2 = reader.ImportSequence(fs);
                fs = new FileStream(@"data/animations/grapplerec.dsq", FileMode.Open, FileAccess.Read);
dsq2 = reader.ImportSequence(fs);
                
//MANY MANY MANY MORE ANIMATIONS GO HERE (Edited for the forum post)


                FileInfo fi = new FileInfo(_shapeFile);
                dtsshape.FilePath = fi.DirectoryName;


                // remove executable directory so that path is relative to it   
                dtsshape.FilePath = dtsshape.FilePath.Replace(TorqueEngineComponent.Instance.ExecutableDirectory + @"", string.Empty);
                shape.Shape = dtsshape;

            }
            else
            {
                Assert.Fatal(false, string.Format("Specified shape file not found: {0}", _shapeFile));
            }

            //set the size of the model in the scene       
            shape.ShapeScale = new Microsoft.Xna.Framework.Vector3(3.5f);


            //the the rotation of the model      
            shape.Rotation2 = new Vector3((float)(Math.PI * 50) / 180, (float)(Math.PI * 90) / 180, (float)(Math.PI * 90) / 180);
            Vector2 p = new Vector2(21.0f, 20.0f);
            shape.Position = p;
            shape.Components.AddComponent(new T2DPhysicsComponent());
            

            shape.AddThread("default", null, true);
            
            TorqueObjectDatabase.Instance.Register(shape);
            //shape.SetSequence("stand", "stand", 0.0f);
            
            ApplyAttributesToWrestler(w);

        }

Is there a better way to load in multiple animations into the character? it takes almost a minute per character.

Please - any help would be appreciated.

#1
11/18/2009 (10:24 am)
Sorry to bump, but this is really starting to put a fatal blow to my project.

It takes well over a minute on the Xbox to load all of my dsq animations. And that's probably half the animations I want to have.

I've looked in the importsequence function, but haven't found anything I can trim.

Is there anyway for me to clone a T2DShape3D? So I can at least only load in the animations to 1 shape, then clone it?

Please help.
#2
11/18/2009 (11:13 am)
I guess there just aren't many of us working with 3D in TX 2D. Dig into the engine source though and I'm sure you'll be able to sort out cloning T2DShape3D with all it's anims.

You'll probably also want to preload all your anims too.
#3
11/18/2009 (11:15 am)
How do I preload them? according to the source code, each shape has to load in all of the animations individually.

That's kind of what I'm looking for. If I could just preload all of the animations somewhere, then anytime I create a shape, I can tell it to use that collection. But the importsequence funciton appears to tie the animations directly into one particular shape.
#4
11/18/2009 (6:23 pm)
ok, so basically what I've done was created a "Master" T2DShape3D.
Then when I want a new wrestler, I clone him out of that T2DShape3D.

T2DShape3D shape = Game.gameShape.Clone() as T2DShape3D;

However, when I do that, I get an exact clone. Meaning that when I animate it or apply texture changes, all of them change in the same way. I think it's because when I clone the T2DShape3D, every clone has the same reference to the T2DShape3D.Shape property. And unfortunately, it appears that al of the anims are imported into that Shape. I can't seem to be able to clone that shape.
#5
11/18/2009 (10:02 pm)
That would be a 'shallow' copy of T2DShape3D then. What you need is a deep copy. I would modify T2DShape3D to add a DeepCopy() method that will get me a copy of the object and also make copies of the anims - do whatever is required to make them separate copies. I've not looked at the code, but it does sound like you'll need to mod the engine on this one.