b /oRe: Adding models at runtime

Hello!

My application reads information from an OPC server. Each model is a cylinder (Standard Primitives)

I have made 1 basemodel of the cylinder that i change the height and radius in runtime by scaling it.

My problem is that when the application first time gets information from the OPC server it contains only one cylinder, 2min later it could be 30cylinders. The number of cylinders will change under runtime.

In the startup i load one model of the cylinder:

protectedoverridevoid LoadGraphicsContent(bool loadAllContent)

{

if (loadAllContent)

{

Model modelRulle = content.Load<Model>("Content\\Models\\Rulle");

}

Can i resuse this model to clone or copy it in runtime ?

Or can content.Load be used in runtime as well ?

I could create an array of the model at startup i guess but since the numbers of cylinders (model) will change under runtime ireally would like to get some opinions on to approach this before i continue.

Any help would be really great.

BJ

[1919 byte] By [BJohansson] at [2007-12-28]
# 1
I believe technically you can do content.Load during runtime towards a file that has been properly built by an MSBuild operation. I am doing this with some code I am constructing. But instead of loading a unknown number of models, that from what I gather in your comment is basically the same model loaded in a number of times, I would just track the cylinders coordinates, scale, pitch, yaw and roll and render the same model for each different position/rotation.
remorse at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2

The Cylinder model is loaded at startup 1 time and i guess then it is build in a proper way right ? I use C$ Express and builds everything from there except for the actual models that i build in 3dmax and export as *.fbx.

It is the same model i want to be able to use dynamicly at runtime.

How can i render the same loaded model at several places ?

BJ

BJohansson at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 3

Draw your model multiple times at different positions. This just means changing the world matrix you are using to position the model.

Cheers,
Leaf.

Leaf. at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 4

A Suggestion:

Encapsulate your cylinder model into a class so it becomes an object.

Make the 3d cylinder model a static member of the class so there is only one copy in heap memory, which all the instances of the class will use.

Use class varibles to store the size & current position of each instance.

use class methods to update position & size as appropriate & to draw

In the game class use a collection to hold instances of the cylinder class. Then you can add more cylinders to it with ease.

In the main update method, use the foreach technique to loop through all the items in the collection, calling the cyylinder class update method to upate their position.

In the draw method, use the foreach technique again to call the class draw method to display them on the screen.

If you're new to object oriented coding, this would be a good way to start learning about it.

Chris

Ceej100 at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 5

Thanks everyone!

I have made a class for the static models and another class for the dynamic cylinders.

In the main application Update, Draw sequense i call the diffrent classes objects and so the dynamic cylinders can have routines to check on how many they are at the update moment and loop with a foreach on draw.

Works perfectly so I Thank you all for the great help!

BJ

BJohansson at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...