XNA Game Development Forums
2012/05/21 19:18:24 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Loading a model in runtime?  (Read 3311 times)
XNASorcerer
Newbie
*
Offline Offline

Posts: 25



View Profile
« on: 2007/05/04 02:11:05 »

Is it possible to load a model in runtime with XNA? How?
Thanks.
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #1 on: 2007/05/04 02:58:59 »

Are you saying you want to dynamically load models into the scene at run time that you have no knowledge about at compile time?

If you are then the first thing you need to think about is how you are going to let your engine know that there is an object available to be loaded... You could have the engine watch a folder and when a .x or fbx file lands there it is picked up and loaded and used, but what shader should be used, what coords should the model be drawn at etc... I would use something like an XML file with the model file that describes these sort of things.

It is easy to do once you have decided on your mechanism.
Logged
XNASorcerer
Newbie
*
Offline Offline

Posts: 25



View Profile
« Reply #2 on: 2007/05/04 05:39:14 »

Are you saying you want to dynamically load models into the scene at run time that you have no knowledge about at compile time?

If you are then the first thing you need to think about is how you are going to let your engine know that there is an object available to be loaded... You could have the engine watch a folder and when a .x or fbx file lands there it is picked up and loaded and used, but what shader should be used, what coords should the model be drawn at etc... I would use something like an XML file with the model file that describes these sort of things.

It is easy to do once you have decided on your mechanism.

I am making ( trying and error system ) a scene editor and I would like to be able to drag and drop a model from the models folder inside the treeview into the scene and then saving all models and its positions into a txt file or something. But as far as i know models need to be first loaded into the programming solution before they can be loaded through the content manager, isn't?

 
« Last Edit: 2007/05/04 05:50:54 by XNASorcerer » Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #3 on: 2007/05/04 05:48:59 »

Well, they have to be compiled yes. I imagine you can invoke the pipeline code to do this in some way. I will have a look Smiley
Logged
XNASorcerer
Newbie
*
Offline Offline

Posts: 25



View Profile
« Reply #4 on: 2007/05/04 05:51:12 »

Thanks.
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #5 on: 2007/05/04 06:13:12 »

Take a look at this http://blogs.msdn.com/shawnhar/archive/2006/11/07/build-it-ahead-of-time.aspx It explains how to use the pipeline assemblies at runtime.

Hope this helps.
Logged
muchrejoicing
Newbie
*
Offline Offline

Posts: 46


View Profile
« Reply #6 on: 2007/05/04 08:11:05 »

Is that a GUI plugin for XNA? It looks really nice.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #7 on: 2007/05/04 17:09:08 »

If you have the time and knowledge of the file format, you can write your own model loader to load a .fbx/.x/.dae model at runtime. Benjamin Nitschke (Rocket Commander/XNA Racer), released a demo a while back about skinning with Collada Models in XNA.
He loads the model at runtime because he didnt like the limits of a precompiled model and the Content Pipeline. Collada seems pretty good because its XML, so you dont have to do any binary reading, but you need to know the file format.

If you really want to build it ahead of time, and not write the msbuild task yourself, XNADev.ru has greated a GUI ContentBuilder which gives you the same options as you would get in GSE, but seperately.
http://www.codeplex.com/xnadevru/Wiki/View.aspx?title=XNA%20Content%20Builder%20(XCB)&version=8
Logged

XNASorcerer
Newbie
*
Offline Offline

Posts: 25



View Profile
« Reply #8 on: 2007/05/05 14:44:43 »

I was trying that code from XNADev.ru and it only gives Building FAILED.

Can someone give a working example of how to implement it inside a project?
Logged
nicknz
Newbie
*
Offline Offline

Posts: 6


View Profile
« Reply #9 on: 2007/05/05 16:35:45 »

Hello!

Maybe this link can help you:
http://www.ziggyware.com/readarticle.php?article_id=67

Can you give me some hints about how to run the engine inside a windows form? I had been able to run the engine on a window and then have a separate WinForm running at the same time, but I would like to do something like your screenshot.
Logged
XNASorcerer
Newbie
*
Offline Offline

Posts: 25



View Profile
« Reply #10 on: 2007/05/06 21:22:42 »

Hello!

Maybe this link can help you:
http://www.ziggyware.com/readarticle.php?article_id=67

Can you give me some hints about how to run the engine inside a windows form? I had been able to run the engine on a window and then have a separate WinForm running at the same time, but I would like to do something like your screenshot.

I saw that before, but it didn't help. Thanks anyway

Yes, of course. But I am having a problem. I can not use the keyboard to type anything inside any UserControl. Mouse input is working great, but whenever a try to type any text, it simple doesn't type anything. Perhaps someone else could help us with that.


Create your engine.
Then, add a UserControl into your project and design it the way you want it, with the controls you want. For example lets make a menu. Look at this example:

 

Now, inside our engine class, we have to create our UserControl Menu and initialize it. I am going to add a public backColor variable to change it by clicking on a menu.

Code:
public class Game1 : Microsoft.Xna.Framework.Game
{
      public UserControlMenu myUCMenu;
      public Color backColor = Color.Black;

      //Then inside the Initialize funtion:

      protected override void Initialize()
      {
                   // TODO: Add your initialization logic here
           
                   myUCMenu = new UserControlMenu(this);
                   Control gameWindow = Control.FromHandle(this.Window.Handle);
                   myUCMenu.Parent = gameWindow;
                   myUCMenu.Dock = DockStyle.Top;

                   base.Initialize();

      }

      protected override void Draw(GameTime gameTime)
      {
            graphics.GraphicsDevice.Clear(backColor);

               //The rest of your code
      }

      //The rest of your code
}


Now, we have to add the class of our engine into the UserControl Menu. If your engine class is called Game1, then before the constructor of your UserControl Menu, add this:

Code:
public partial class UserControlMenu : UserControl
{

      Game1 gameEngine;

      //Now, inside the contructor pass the same class again and pass it into "gameEngine". Like this:

      public UserControlMenu( Game1 game)
      {
                  gameEngine = game;
                  InitializeComponent();
      }

      //Now if you want to change the color of the backColor of the engine by clicking on a menu:

      private void showAllPanelsToolStripMenuItem_Click(object sender, EventArgs e)
      {
               gameEngine.backColor = Color.Orange;

               //If you want to change the Height of the UserControl Menu:

                gameEngine.myUCMenu.height = 100;
      }
}

And that is it, You can add as many UserControls as you want.

Now we need to figure out the solution for that problem.

« Last Edit: 2007/05/06 21:24:15 by XNASorcerer » Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tut 6: Model Class Hazy Mind XNA Engine MicahN 2 2258 Last post 2006/11/15 09:43:47
by MicahN
Tutorial 6 :: Getting a Model on Screen Tutorial Discussion mikeschuld 11 5587 Last post 2007/02/18 10:35:28
by Iarus
How To: Render a model with a texture?? Hazy Mind XNA Engine Quinn 6 2324 Last post 2007/01/07 00:33:58
by mikeschuld
Loading another project in runtime Hazy Mind 3D Engine LucianX 7 3031 Last post 2007/03/12 14:31:39
by Tiago
Detecting Model Collision...? General Discussion « 1 2 » DaphydTheBard 15 4291 Last post 2007/03/27 01:29:52
by Nemo Krad
Model exporters General Discussion EclipsE 13 3719 Last post 2007/04/26 12:25:03
by EclipsE
Question about loading textures General Discussion nicknz 2 1962 Last post 2007/04/23 05:36:17
by EclipsE
Tranforming a model's vertices Hazy Mind XNA Engine « 1 2 » DoomMarine 29 6879 Last post 2007/08/28 05:15:34
by DoomMarine
BSP/PAK LOADING General Discussion Mikeske 1 1966 Last post 2008/07/26 00:50:51
by Mikeske
Game-ready model shops General Discussion Balosh 0 1609 Last post 2009/07/10 02:37:54
by Balosh
Game- ready model shops Hazy Mind 3D Engine Tinlau 0 1183 Last post 2010/02/03 20:23:12
by Tinlau
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.554 seconds with 19 queries.