Has anyone tried John"s terrain example?
by Henry Shilling · in Torque X 3D · 06/04/2009 (4:25 pm) · 33 replies
I Tried Johns Terrain example, http://www.garagegames.com/community/blogs/view/17277 , and it would not compile for me. It hangs on the line:
The TerrainDetailMaterial is defined in the xml level file, however I really do not understand enough to debug what the issue is. And then on top of that how do I bring in the really cool texture that was created with L3DT.
terrainData.DetailMaterial = "TerrainDetailMaterial";
The TerrainDetailMaterial is defined in the xml level file, however I really do not understand enough to debug what the issue is. And then on top of that how do I bring in the really cool texture that was created with L3DT.
About the author
http://twitter.com/theBigDaddio
#2
http://www.garagegames.com/community/forums/viewthread/78749
I tried all the examples, it's also in the book, but not as an example and if you DL the book code the terrain stuff is in there, but not as an example. I can't make it work.
06/14/2009 (10:44 am)
If you look at this thread you can grab a terrain editor and just replace the terrain.http://www.garagegames.com/community/forums/viewthread/78749
I tried all the examples, it's also in the book, but not as an example and if you DL the book code the terrain stuff is in there, but not as an example. I can't make it work.
#3
06/15/2009 (11:20 am)
has l3dt been confirmed to work with tx3d?
#4
06/15/2009 (12:05 pm)
well supposedly L3DT works, however I cannot get the example to work.
#5
I changed the code to look like this:
07/01/2009 (6:08 pm)
I created a DetailMaterial object in code to get this to work. I changed the code to look like this:
DetailMaterial detailMaterial = new DetailMaterial();
detailMaterial.TextureFilename = "data/terrains/SandDetail01";
detailMaterial.DetailTextureRepeat = 256;
/// SPECIFY A TERRAIN DATA TYPE
TGETerrainData terrainData = new TGETerrainData();
terrainData.TerrainFilename = "data/terrains/terrain.ter";
terrainData.LightMapFilename = "data/terarins/lightmap.png";
terrainData.TexturePathSubstitution = "data/terrains";
// terrainData.DetailMaterial = "TerrainDetailMaterial";
terrainData.DetailMaterial = detailMaterial;
#6
Here is my code using 512x512.raw file that was made L3DT.
09/15/2009 (1:18 am)
Has anyone got this to work based on this article and this one www.garagegames.com/community/blogs/view/17277Here is my code using 512x512.raw file that was made L3DT.
protected void CreateTerrain()
{
// Find the collision manger
RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");
XTerrain objTerrain = new XTerrain();
objTerrain.Name = "Terrain";
objTerrain.HorizontalScale = 8;
objTerrain.VerticalScale = 1;
objTerrain.LevelZeroError = 0;
objTerrain.ViewError = 2;
objTerrain.LODLevels = 4;
objTerrain.LODError = 0.5f;
objTerrain.Repeat = true;
objTerrain.Visible = true;
T3DSceneComponent componentScene = new T3DSceneComponent();
componentScene.Position = new Vector3(0, 0, 0);
componentScene.SceneGroup = "Terrain";
objTerrain.Components.AddComponent(componentScene);
RigidMaterial materialRigid = new RigidMaterial();
materialRigid.Restitution = 0f;
materialRigid.KineticFriction = 1f;
materialRigid.StaticFriction = 1f;
// Give terrain some physics attributes
T3DRigidComponent componentPhysics = new T3DRigidComponent();
componentPhysics.SceneGroupName = "Terrain";
componentPhysics.GravityScale = 0f;
componentPhysics.RigidManager = rigidManager;
componentPhysics.RigidMaterial = materialRigid;
componentPhysics.Immovable = true;
CollisionXTerrainShape shape = new CollisionXTerrainShape();
componentPhysics.CollisionBody.AddCollisionShape(shape);
objTerrain.Components.AddComponent(componentPhysics);
DetailMaterial detailMaterial = new DetailMaterial();
detailMaterial.TextureFilename = "data/terrains/SandDetail01";
detailMaterial.DetailTextureRepeat = 256;
/// SPECIFY A TERRAIN DATA TYPE
RAWTerrainData terrainData = new RAWTerrainData();
terrainData.TerrainFilename = "data/terrains/512x512.raw";
terrainData.LightMapFilename = "data/terrains/512x512_LM.jpg";
terrainData.UniqueTextureFilename = "data/terrains/512x512_TX.jpg";
//terrainData.DetailMaterial = "TerrainDetailMaterial";
terrainData.DetailMaterial = detailMaterial;
objTerrain.Data = terrainData;
TorqueObjectDatabase.Instance.Register(objTerrain);
// This needs to be called after registering, normaly its called when XML is onLoaded
shape.OnLoaded(objTerrain);
componentPhysics.CollisionBody.UpdateShapes();
}right now all I get is an object not instance of an object, or the game starts debugging and stops.
#7
In the XTerrain.cs file the lines:
Give an error. The image is null event though the file exists. Weird.
09/15/2009 (10:47 am)
I tried it a number of different ways. It will not load the texture file nnn_TX.jpg. The file is null. I tried the old example and the example from the book and same deal. In the XTerrain.cs file the lines:
// preload the image to get the width
Bitmap image = null;
if (File.Exists(UniqueTextureFilename))
image = (Bitmap)Bitmap.FromFile(UniqueTextureFilename);Give an error. The image is null event though the file exists. Weird.
#8
I just want to render my own terrain for my RTS game with out using the torque x builder any ideas how i can do this?
09/15/2009 (10:52 am)
Thank you for your respone, Does torque x support .raw files anymore with there LM, TX etc images? Also I'm using png for those files if that matters any sure it does not.I just want to render my own terrain for my RTS game with out using the torque x builder any ideas how i can do this?
#9
I also tried raw with png and jpg and no dice.
09/15/2009 (11:42 am)
I did it with TGE terrain before. Read my post above, it links to where you can get TGE to build a terrain. I also tried raw with png and jpg and no dice.
#10
www.garagegames.com/community/forums/viewthread/80652
Just curious if it works or not.
09/15/2009 (11:51 am)
Thank you, I now have the TGE Terrain.zip file but I also found this post that I will try when I get home from work.www.garagegames.com/community/forums/viewthread/80652
Just curious if it works or not.
#11
I messed around with the HorizontalScale and the VerticalScale, making them smaller looks better.
09/15/2009 (11:56 am)
Yea IT WORKS! I guess it's the creating the new simple material from the texture file.I messed around with the HorizontalScale and the VerticalScale, making them smaller looks better.
#12
09/15/2009 (12:02 pm)
Would you be so kind to post your code please, I'm at work and I just want to see it... That is awesome it works.
#13
It has to be that part at the top, new SimpleMaterial();
That is the file it kept crashing on.
It will work for you tonight!
09/15/2009 (12:11 pm)
I literally copied the code from your link. the only thing I changed were the filenames to my filenames. Oh yea and then I messed with the Horizontal and Vertical scaling. protected void CreateTerrain()
{
//find the physics resolver
RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");
//SimpleMaterial
SimpleMaterial material = new SimpleMaterial();
material.TextureFilename = @"data\terrains\terrain_TX.jpg";
//Terrain Data
RAWTerrainData terrainData = new RAWTerrainData();
terrainData.TerrainFilename = @"data\terrains\terrain.raw";
terrainData.LightMapFilename = @"data\terrains\terrain_LM.jpg";
terrainData.UniqueTextureFilename = @"data\terrains\terrain_TX.jpg";
//create the terrain
XTerrain objTerrain = new XTerrain();
objTerrain.Name = "Terrain";
objTerrain.Position = new Vector3(0, 0, 0);
objTerrain.HorizontalScale = 1;
objTerrain.VerticalScale = 0.1f;
objTerrain.Repeat = true;
objTerrain.RepeatX = true;
objTerrain.RepeatY = true;
objTerrain.Visible = true;
objTerrain.Material = material;
objTerrain.LevelZeroError = 0;
objTerrain.ViewError = 2;
objTerrain.LODError = 0.5f;
objTerrain.LevelZeroError = 0;
objTerrain.Pool = false;
objTerrain.PoolWithComponents = false;
objTerrain.IsTemplate = false;
objTerrain.IsPersistent = false;
objTerrain.Notched = false;
objTerrain.Data = terrainData;
//Component Scene Component
T3DSceneComponent componentScene = new T3DSceneComponent();
componentScene.Position = new Vector3(1024, 1036, 300);
componentScene.SceneGroup = "Terrain";
objTerrain.Components.AddComponent(componentScene);
//give the Terrain
T3DRigidComponent componentPhysics = new T3DRigidComponent();
componentPhysics.SceneGroupName = "Terrain";
componentPhysics.GravityScale = 1.5f;
componentPhysics.Mass = 10.0f;
componentPhysics.RigidManager = rigidManager;
componentPhysics.CollisionBody.AddCollisionShape(new CollisionBoxShape());
objTerrain.Components.AddComponent(componentPhysics);
//Register
TorqueObjectDatabase.Instance.Register(objTerrain);
}It has to be that part at the top, new SimpleMaterial();
That is the file it kept crashing on.
It will work for you tonight!
#14
09/15/2009 (12:37 pm)
Great News Thank You for your help.
#15
10/31/2009 (4:39 pm)
Can someone post a finished C# project with this? I can make the code above complile and run but my scene still loads my default "sand terrain" from the XML. Do I have to empty out the XML file? How do I load the new terrain into the GUISceneview?
#16
Just checking, did you add your new content files to your project and then change the code to load them? If your hard coding it then for example, this is the part of code you need to change.
`//Terrain Data
RAWTerrainData terrainData = new RAWTerrainData();
terrainData.TerrainFilename = @"dataterrainsterrain.raw";
terrainData.LightMapFilename = @"dataterrainsterrain_LM.jpg";
terrainData.UniqueTextureFilename = @"dataterrainsterrain_TX.jpg"`
Add your .raw file, your lightmap file and your texture file into your project and then make sure you change the code to load your files.
As John points out in his blog, you need to set the .raw files build action property to “Content” and the copy to output directory property should be set to “Copy if newer”.
Check Johns blog at:
http://www.garagegames.com/community/blogs/view/17277
Hope it helps,
10/31/2009 (6:59 pm)
Hey Eric,Just checking, did you add your new content files to your project and then change the code to load them? If your hard coding it then for example, this is the part of code you need to change.
`//Terrain Data
RAWTerrainData terrainData = new RAWTerrainData();
terrainData.TerrainFilename = @"dataterrainsterrain.raw";
terrainData.LightMapFilename = @"dataterrainsterrain_LM.jpg";
terrainData.UniqueTextureFilename = @"dataterrainsterrain_TX.jpg"`
Add your .raw file, your lightmap file and your texture file into your project and then make sure you change the code to load your files.
As John points out in his blog, you need to set the .raw files build action property to “Content” and the copy to output directory property should be set to “Copy if newer”.
Check Johns blog at:
http://www.garagegames.com/community/blogs/view/17277
Hope it helps,
#17
10/31/2009 (11:17 pm)
Give me your email address and I will email you the project I have created using L3DT Standard 2.7
#18
http://smokinskull.com/terrainTest.zip
10/31/2009 (11:45 pm)
Hey I put the file up on my site for whoever needs one. It includes my map file for L3DT. It's just a big flat terrain.http://smokinskull.com/terrainTest.zip
#19
Thanks guys for your help, I got it working. It is good to see fellow developers on the forums and your feedback is greatly appreciated. It seems you guys are scattered all over this forum (along with John), keep up the good work.
I created a new terrain with L3DT Pro for Torque X and loaded it with no problems. Well, one problem. It doesn't look near as detailed as the default sand terrain. Kind of ugly actually.
11/03/2009 (12:47 pm)
Tim, Henry, JamesThanks guys for your help, I got it working. It is good to see fellow developers on the forums and your feedback is greatly appreciated. It seems you guys are scattered all over this forum (along with John), keep up the good work.
I created a new terrain with L3DT Pro for Torque X and loaded it with no problems. Well, one problem. It doesn't look near as detailed as the default sand terrain. Kind of ugly actually.
#20
04/19/2010 (1:39 am)
Henry, did you manage to make your character not free fall. In my attempt to use your code, my character still falls through the land. I copied and pasted your code.
Torque Owner Brian
Brian