Game Development Community

3D Lighting DTS models [solved!]

by Mathias Kahl · in Torque X 3D · 07/29/2009 (6:11 am) · 23 replies

Hello!

I just started trying to work with Torque X a few days ago.
Currently my only valuable source of information is John's book.

Currently I'm trying to get lighting to work with my DTS models.
I'm loading the player model as described in the book. At first I create a template:

private static void CreateTemplate()
        {
            Template = new TorqueObject();

            Template.Name = "Basic Creep Template";
            Template.IsTemplate = true;

            // Die Repräsentation im 3D-Raum erstellen 
            T3DSceneComponent scene = new T3DSceneComponent();
            scene.SceneGroup = Template.Name;
            scene.Position = new Vector3(1020, 1020, 350);
            Template.Components.AddComponent(scene);

            T3DTSRenderComponent dts = new T3DTSRenderComponent();
            dts.ShapeName = @"data/Static Models/Player/Ork/ork2.dts";

            dts.SceneGroupName = Template.Name;
            Template.Components.AddComponent(dts);           
            
            // Physikalische Eigenschaften            
            RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");
            T3DRigidComponent physics = new T3DRigidComponent();
            physics.SceneGroupName = Template.Name;
            physics.GravityScale = 1.0f;
            physics.Mass = 30.0f;

            physics.RigidManager = rigidManager;
            physics.CollisionBody.AddCollisionShape(new CollisionBoxShape());
            Template.Components.AddComponent(physics);

            // Den Objekttypen registrieren
            TorqueObjectType typeCreep = TorqueObjectDatabase.Instance.GetObjectType("Creep");
            Template.ObjectType += typeCreep;

            // Das Template ins W&ouml;rterbuch eintragen
            TorqueObjectDatabase.Instance.Dictionary.SetValue<TorqueObject>(Template, Template.Name, null);            
        }

Secondly I spawn it into my scene:
TorqueObject torqueObject = (TorqueObject)Template.CloneT();
            torqueObject.Components.FindComponent<T3DSceneComponent>().Position = pos;
            TorqueObjectDatabase.Instance.Register(torqueObject);

That works. However the model isn't lit (using my own Model created in Milkshape 3D):
bunkernetz.de/~bc/screenshots/erstes-level-2.jpg
Also an other model, which came with Torque Constructor isn't lit (also not the DTS terrain model below):
bunkernetz.de/~bc/screenshots/erstes-level.jpg
That's how I add the light to the scene (according to John's book):
// Beleuchtung
            TorqueObject lightSceneObject = new TorqueObject();
            T3DSceneComponent componentScene = new T3DSceneComponent();
            componentScene.Position = new Vector3(1050, 1050, 400);
            componentScene.SceneGroup = "LightObject";
            lightSceneObject.Components.AddComponent(componentScene);

            DirectionalLight light = new DirectionalLight();
            light.ConstantAttenuation = 1.0f;
            light.LinearAttenuation = 0.0f;
            light.AmbientColor = new Vector3(0.5f, 0.4f, 0.4f);
            light.DiffuseColor = new Vector3(0.75f, 0.75f, 0.75f);
            light.Direction = new Vector3(0, -1, -1);

            T3DLightComponent componentLight = new T3DLightComponent();
            componentLight.SceneGroupName = "LightObject";
            componentLight.IsEnabled = true;
            componentLight.LightList.Add(light);
            lightSceneObject.Components.AddComponent(componentLight);

            TorqueObjectDatabase.Instance.Register(lightSceneObject);

Can someone tell me how to do it right, please? Help would be much appreciated.

About the author

I'm a student of Computer Science (Freie Universität in Berlin, Germany). Currently I'm working on a multiplayer strategy/action game based on Torque X.

Page«First 1 2 Next»
#21
09/13/2009 (7:18 am)
thanks mathias
this is my code
public void light(Vector3 position)
{
TorqueObject lightscene = new TorqueObject();
T3DSceneComponent componentscene = new T3DSceneComponent();
componentscene.Position = position;
componentscene.SceneGroup = "LightObject";
lightscene.Components.AddComponent(componentscene);


DirectionalLight drlight = new DirectionalLight();
drlight.ConstantAttenuation = 1;
drlight.AmbientColor = Vector3.Forward;
drlight.DiffuseColor = Vector3.Backward;
drlight.Direction = Vector3.Down;





T3DLightComponent componentlight = new T3DLightComponent();
componentlight.SceneGroupName = "LightObject";
componentlight.IsEnabled = true;
componentlight.LightList.Add(drlight);


lightscene.Components.AddComponent(componentlight);

TorqueObjectDatabase.Instance.Register(lightscene);
}
private void cube()
{
RigidCollisionManager rigidmanager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager");

TorqueObject cube = new TorqueObject();
cube.Name = "cube";


T3DSceneComponent componentScene = new T3DSceneComponent();
componentScene.Position = new Vector3(1024, 1020, 295);
componentScene.SceneGroup = "cubegroup";
cube.Components.AddComponent(componentScene);

T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
componentRender.ShapeName = @"data/static models/cube/box.dts";
componentRender.SceneGroupName = "cubegroup";
cube.Components.AddComponent(componentRender);




TorqueObjectDatabase.Instance.Register(cube);

}
protected override void Update(GameTime gameTime)
{
FreeCameraComponent camera = TorqueObjectDatabase.Instance.FindObject<FreeCameraComponent>("CameraComponent");
sun(camera.Transform.Translation);
Window.Title = camera.Transform.Translation.ToString();

base.Update(gameTime);
}


<cubebumpMaterial type="GarageGames.Torque.Materials.LightingMaterial" name="cubebumpMaterial">
<NameMapping>data/static models/cube/general text</NameMapping>
<TextureFilename>data/static models/cube/general text</TextureFilename>
<NormalMapFilename>data/static models/cube/nm1.png</NormalMapFilename>
<SpecularPower>35.0</SpecularPower>
<SpecularIntensity>0.75</SpecularIntensity>
<LightingMode>PerVertex</LightingMode>
<EffectFilename>LightingEffect3D</EffectFilename>

</cubebumpMaterial>



#22
09/14/2009 (2:54 pm)
is this code enough or not?
#23
09/18/2009 (2:12 pm)
tanks
my problem solved
Page«First 1 2 Next»