Game Development Community

T2DShape3D Layer issue

by David A Young · in Torque X 2D · 07/20/2009 (8:09 am) · 11 replies

For the most part I've resolved a lot of the issues using T2DShape3D assets except for their layer order.

I'm having the same issue as originally posted here.
www.garagegames.com/community/forums/viewthread/75538

For the most part it seems that the T2DShape3D objects ignore whatever their layer setting is.

Any help would greatly be appreciated.

- David

#1
07/20/2009 (10:05 am)
My guess is that it stems from the way that things are rendered in TX2D. Even though it is designed for 2D, it still technically renders in 3D, using depth to simulate drawing order. Because it is orthographic, you don't notice a difference no matter how close or far from the camera an object is.

The layers that are used simply guarantee that things in a lower (numerically) layer will be in front of things in higher number layers. Then the things which are in the same layer are sorted relative to each other according to x or y, depending on what is selected. Finally you have a complete definition of the order in which all objects should appear, front to back. At that point, they are assigned a depth based on that order, i.e. the first one is at a depth of 1.0, the second is at 2.0, etc. That is why the camera depth must be greater than the number of objects on screen, else the "lineup" in the z dimension would go past the camera depth.

Still, consecutive objects will only be separated by 1 unit in depth, which is fine when they are truly 2D: they have no depth. But with 3D objects, they do have depth, which may well be greater than 1, perhaps a lot greater. So even though its center point is behind something else, its depth may cause it to poke forward towards the camera and thus cover something else up.

Furthermore, putting one thing in layer 4, for instance, and another in layer 8 does not mean they will be 4 units apart; It simply means the 4-object will be in front of the 8-object (and anything in 5, 6, or 7). But if there is nothing in between, they will still be consecutive in the overall order, and thus only one unit apart in depth.

Since this is the built-in way that TorqueX2D ensures that 2D things are drawn in the right "order" front-to-back, I don't know if there is a fix (short of radically changing the rendering source code). Perhaps you could find a way to set the z coordinate of the 3D thing, but it would need to be after the sorting. Or, try to manually render the 3D, using straight XNA separate from the Torque rendering. It would no doubt require some kind of hack.

***EDIT***
One more crazy thing that might work: if you have enough objects in between the foreground thing and the 3D thing, that might push the 3D back enough. You could theoretically use a bunch of blank scene objects (which could be created as plain T2DSceneObjects in code) that would take up space in the z dimension, but not appear on screen. But that, of course, is a pretty ugly hack.
#2
07/20/2009 (10:28 am)
Thanks Scott this helps a lot.

Do you happen to know if you can go past the 31 Layers predefined by the 2D builder?
#3
07/20/2009 (10:44 am)
No, I believe that's a hard limit, though I could be wrong.
#4
07/20/2009 (11:09 am)
Although not for TorqueX2D I believe something like this probably exists in TorqueX2D, but since I don't have the source code ...

www.garagegames.com/community/forums/viewthread/27658

It would make sense of the masking limitations when going past 32 layers total.
#5
07/20/2009 (11:29 am)
Uh oh. this could be a major problem when I get to the meat of my game.

I was going to put all of my T2DShape3D objects on one single layer and then use the Y coordinate determine order.

Is that going to be problematic?
#6
07/20/2009 (3:12 pm)
Quote:One more crazy thing that might work: if you have enough objects in between the foreground thing and the 3D thing, that might push the 3D back enough. You could theoretically use a bunch of blank scene objects (which could be created as plain T2DSceneObjects in code) that would take up space in the z dimension, but not appear on screen. But that, of course, is a pretty ugly hack.

lol that's what I ended up doing. Transparent spacer images save the day.

I may have to dynamically modify the Layer property of the t2dshape3d objects to eventually get what I want.

Understanding why that bug exists though really helped a lot. Thanks again Scott.
#7
07/20/2009 (8:48 pm)
So, David, to my point.

If I wanted the Y coordinate to affect which character is in front, I would have to change the layer property via code? instead of the WYSIWYG way in TXB?
#8
07/21/2009 (2:00 am)
Well the T2DShape3D objects have their own Layer property which needs to be set. It does seem that the sort points work with the T2DShape3D objects.

The way I handle this is by making a T2DShape3D component which contains all the necessary info about the 3D shapes. That way I can edit it in the builder.
#9
07/23/2009 (7:10 am)
Is there any resource you found that makes a T2DShape3D component you could share with me, or did you code it from scratch?

Cause that would bre really helpful.
#10
07/23/2009 (8:21 am)
I made my own component from scratch, it basically ties a T2DShape3D object created within the component to the owner of the component.

It allows for altering all the settings of the T2DShape3D object within the builder and uses a memory manager to help create the T2DShape3D objects. This was to fix the delay time if you spawn off T2DShape3D objects.

You still can't see the 3D objects within the builder but it's a lot more flexible for me to create them.
#11
07/23/2009 (9:15 am)
care to sell it? lol