Game Development Community

BOOK clarification: T2DShape3D

by David Horn · in Torque X 2D · 07/04/2009 (5:16 pm) · 8 replies

Brian (or anyone),

In chapter 11, you have the example of the T2DShape3D. I also have downloaded the files off of ytour Web site and added them to a new TX2D project.

Unfortunately, I don't see the dts. only the gg logo. I have all of the files added from your shaped folder, and I have set the build action of the dts files to "content" like I've read in another forum post.

1. [SOLVED] Do you know of any reason why I can't see my dts model (datashapesorange_player.dts)?

2. Does the T2DShape3D give you options for animation (.dsq files), mounting, changing textures?
3. is there any reference that I could look at with the properties/methods of a T2DShape3D object?

This could really be the answer to a lot of my future games.

Thank you.


EDIT: I can see the model now (I didn't set the dts to "Copy Always")

I just can't seem the get the movement component to work - the keys don't move the model

#1
07/04/2009 (9:41 pm)
2) T2DShape3D does support animation with the

public bool SetSequence(string threadName, string sequenceName, float pos);

Just modify the chapter 11 code to this and you'll see animation.

public void CreatePlayer()
        {
            // enables mouse cursor.
            TorqueEngineComponent.Instance.Game.IsMouseVisible = true;

            T2DShape3D shape = new T2DShape3D();
            shape.Name = "Player";
            shape.SetShape(@"datashapesboombotorange_player.dts");

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

            //set the position of the model in the scene    
            shape.SetPosition(Vector2.Zero, true);

            //the the rotation of the model   
            //must be in radians NOT DEGREES
            shape.Rotation2 = new Vector3((float)(Math.PI * 0) / 180, (float)(Math.PI * 45) / 180, (float)(Math.PI * 90) / 180);

            //set the layer     
            shape.Layer = 0;
            shape.Components.AddComponent(new MovementComponent());
            shape.Components.AddComponent(new T2DPhysicsComponent());
            shape.AddThread("Main", "run", true);
            shape.AddThread("Look", "look", false);
            shape.AddThread("HeadSide", "headside", false);
            shape.OnAnimationTrigger = OnAnimationTrigger;
            shape.OnAnimateShape = OnAnimateShape;

            TorqueObjectDatabase.Instance.Register(shape);
        }

        public void OnAnimationTrigger(int channel)
        {
            switch (channel)
            {
                case 1:
                    // left foot down ... 
                    // add foot puff
                    // add foot step sound
                    // apply force
                    break;
                case 2:
                    // right foot down
                    // add foot puff
                    // add foot step sound
                    // apply force
                    break;
            }
        }

        public void OnAnimateShape(float dt)
        {

            T2DShape3D shape =
                TorqueObjectDatabase.Instance.FindObject<T2DShape3D>("Player");

            // moves the head right to left, then left to right
            if (toggleHead)
            {
                if (headside < 1.0f)
                {
                    headside += 0.01f;
                }
                else
                {
                    toggleHead = false;
                }
            }
            else
            {
                if (headside > 0.0f)
                {
                    headside -= 0.01f;
                }
                else
                {
                    toggleHead = true;
                }
            }

            shape.SetSequence("HeadSide", "headside", headside);
        }

Not sure if DSQ files are supported and I couldn't seem to get mounting to 2d objects to work but it looks like 3d mount to 3d objects work.

Also it seems that lighting a T2DShape3D object isn't supported.

3) Just take a look at the definition of the T2DShape3D object and you'll see a lot of the functionality.
#2
07/04/2009 (10:11 pm)
nvm it looks like you can load up DSQ files using

public bool LoadSequence(string dsqFilePath, string sequenceName);
#3
07/04/2009 (11:12 pm)
fantastic - thank you

2 quick follow up questions?


1 Any idea if you can change or swap out textures via code?

2 Is there any way to change the visibility of a mesh within the T2DShape3D model?
#4
07/04/2009 (11:39 pm)
You can grab the Shape from the T2DShape3D
public Shape Shape { get; set; }

But a look at the GarageGames.Torque.TS.Shape and it looks like you may be in for a world of hurt trying to mess with it.

Might be a lot easier to switch out multiple T2DShape3D models instead?
#5
07/05/2009 (11:13 am)
Well, I really wanted to try to use the texture swap because I wanted to do some character customization. But I guess I can't.
#6
07/05/2009 (3:06 pm)
Actually I'm half way there.

You can change the texture of it with the following...
String t = shape.Shape.MaterialList[0].Name;
Material m = new Material();
m.Name = "newtexture.jpg";
shape.Shape.MaterialList[0] = m;

where shape is your T2DShape3D

now I just want to see if you can hide and/or show a mesh.

I can drill down to the meshes

shape.Shape.Meshes[46]

It just doesn't have a visible or alpha property.

It'd be really cool to change the texture of a mesh (not a model) but I guess I'm getting greedy :)

more research...


EDIT:
I think I found a workaround. See if there's any failed logic.
So basically if you would want to have a custom character, you could use different materials for each part of the character (head, chest, etc.) Then you could change the texture of each of those to a different thing (change the face while separately changing the chest). If you wanted a hat, could you not simply add the hat in the dts, assign it to its own texture, and then if you wanted it to be invisible, just change the texture to a transparent png?
#7
07/05/2009 (7:56 pm)
I'm thinking you could do that, but why not mount another T2DShape3D object to it? or create your object out of multiple T2DShape3D Objects
#8
07/06/2009 (1:28 pm)
Because it's part of a character with a Skin modifier so that it will bend and shape itself with the biped.