Question about scene object creation and lighting

rated by 0 users
This post has 6 Replies | 2 Followers

Top 75 Contributor
Posts 40
SunBurn_Community_Licensee
SunBurn_Pro_Licensee
Epidemi Posted: 12-01-2010 1:44 PM

Hi,

I am trying to dynamically add scene objects to a scene but I am experiencing some issues with this. If anyone could answer the following questions, that would be great.

1. How do I load scene objects from model files?

I have the following code, which seems to work:

Model model = contentRepository.Load<Model>(@"Path\Model");

However, I had to add the model file to the content project, even though it's already added to the content repository. I thought I had read somewhere that adding models to the content repository and to the content project were mutually exclusive. Is this code correct?

2. How do I make sure the model is actually correctly affected by lighting?

I am adding the model to an existing scene, loaded from a scene file. The scene is created as:

Scene scene = ScreenManager.Game.Content.Load<Scene>("Scenes/Scene");

sceneInterface.LightManager.Submit(scene);
sceneInterface.ObjectManager.Submit(scene);

The new scene object is created and added to the scene as:

SceneObject obj = new SceneObject(model);               
obj.Visibility = ObjectVisibility.RenderedAndCastShadows;
obj.ObjectType = ObjectType.Static;
Matrix world = Matrix.CreateTranslation(objPos);
obj.World = world;
sceneInterface.ObjectManager.Submit(obj);

The new object is indeed added to the scene and rendered by the engine, but the new object is not lit. There is a light near the object, but the object seems unaffected by the light. See the following picture. Please note that the object has no texture, but I am loading the same object in code as in the scene file (which was created using the editor).

Thanks in advance!

Top 75 Contributor
Posts 40
SunBurn_Community_Licensee
SunBurn_Pro_Licensee

Oops, I forgot to add: I am using the Indie version of SunBurn 2.0, forward rendering :)

Top 10 Contributor
Posts 1,214
SunBurn_Community_Licensee
SunBurn_Contributor
SunBurn_Pro_Licensee

Is the light ShadowType set to All?

Top 75 Contributor
Posts 40
SunBurn_Community_Licensee
SunBurn_Pro_Licensee

Nope, it was set to None. I set it to all, and now I do see shadows being cast onto the terrain, even for the scene objects that are created through code. But still, the objects themselves are not lit. Thanks for the tip though, eventually I had to fix the shadowing too :)

Top 10 Contributor
Posts 4,854
Employee
SunBurn_Studio_Licensee

Hi Epidemi,

Make sure the model is using a SunBurn Model processor and not the default XNA processor.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 75 Contributor
Posts 40
SunBurn_Community_Licensee
SunBurn_Pro_Licensee

John, that works! I had to set the Content Processor to "Model - SunBurn Lighting System". Thanks a lot!

Just one more question: does adding the same model to the content project and the content repository at the same time bite each other? Thanks in advance :)

 

Top 10 Contributor
Posts 4,854
Employee
SunBurn_Studio_Licensee

Hi Epidemi,

Manually loading the same model won't affect the instance loaded by the content repository, but it will load two unique copies of the model (geometry only, the textures are still shared).  This is a little wasteful, however it shouldn't be noticeable unless loading large complex models.

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Page 1 of 1 (7 items) | RSS