Project Anarchy Tutorial: Entities, Static Meshes and Components

 

In the previous tutorial we looked at how to export a model from 3DS Max to vForge.  This time, we are going to look at exporting a mesh, then explore the difference between entities and static meshes.  As the title might suggest, components play a big part of the difference!

 

So in this tutorial we will cover:

  • Exporting a VMESH file from Max
  • Coordinate difference between systems
  • Creating a static mesh in vForge
  • Differences between Entities and Static Mesh Instances and when to use which

 

 

Exporting a VMESH file

 

 

First off, let’s look at how you export a VMESH file from 3D Studio Max.  We will be using the crate model we created earlier, but you can use whatever object you want.  Load it in 3ds Max and then select File->Export.

 

image

 

Once again I am saving the file in the root of our project ( MyFirstObject, see prior tutorial ) directory.  Make sure you set “Save as type” to VMESH then click Save.

 

 

Next you will be presented with a series of options:

image

 

I’ve highlighted two of the most important settings for you to be aware of.  First is scaling multiplier and this is pretty important.  The value of  1-unit can be defined in most modelling applications.  In vForge however, 1 == 1cm.  So if you’ve modelled your crate as 2x2x2, that means 2cm x 2cm x 2cm, also known as really really really tiny.  To make things even more confusing, in Havok Physics 1= 1 meter!   Therefore when exporting, we are scaling our dimensions by a factor of 100, so our 2x2x2 cube created in Max, with become a 2m x 2m x 2m cube when viewed in vForge.  Of course, you could always set up 3ds to work in cm’s if you wanted.  Finally, take note of the directory textures are being exported to.

 

Once ready, click OK.

 

Your newly exported model will be shown in the model viewer.  You can navigate using the WASD keys and look around using the mouse.  Chances are the camera will be extremely zoomed in when it loads.

 

image

 

Press ESC to close the viewer.  If you dont want it to show up in the viewer, simply uncheck Preview after Export.  Having an option to quickly see how your object will look in engine can be incredibly advantageous, but it can also get annoying.

 

Creating a Static Mesh Instance

 

 

You now have a VMESH file to work with, lets create one in our scene.  In your project, drag a Static Mesh Instance onto the Engine View:

image

 

Now go to the properties and locate MeshFileName:

image

 

 

Select our newly created Mesh object:

image

 

 

So, now your scene should have an entity and static mesh in it, assuming you are working from the previous project that is, like so:

image

 

But there might be a bit of an issue in your scene…

 

image

 

See, when exporting our static mesh, we applied a conversion from cm to m, while when we exported our model we didn’t.  This can be easily rectified in vForge however.  With your entity crate selected, go to properties and locate Scaling and set Uniform Scaling to 100:

image

 

And…

 

image

 

 

… that’s more like it!

 

So, now we have two crates, one is a MODEL attached to an entity, while the other is a vMESH attached to a static mesh.  So, what’s the difference?  Good question!

 

Meshes vs Models, what’s the difference?

 

In a word, weight.  This has nothing to do with mass either.  A static mesh is a much more computationally light weight object than a model.  A static mesh is basically just displayed in the scene.  Physics can respond to it ( so for example, you can run into it ), but it does not respond to physics… it is exactly what it’s name suggests… static.  It doesn’t move, it isn’t animated, it simply is there and you can run into it… that’s about it.  On the bright side, a static mesh takes a great deal less processing power to deal with and because it is static, there are a number of optimizations the engine can perform.

 

A model on the other hand is a great deal more complex than a vmesh.  A model can contain a great deal more information, including of course animations.  An entity is also a great deal more capable than a static mesh instance.  Plus of course there’s components… we will come to that in a moment.  Components are a huge difference though!

 

So, when do you use which?   If it is part of the world and doesn’t move or require an additional component, use a static mesh.  Otherwise use a model.  For the sake of performance, prefer a static mesh whenever you get the chance.

 

 

Components

 

Components are where a great deal of Project Anarchy’s functionality lies and the difference in options between a static mesh and an entity is pretty severe, see:

 

Components available to a static mesh:

image

 

Components available to an entity:

image

 

So, if you want to hook your 3D object up for more advanced physics, as a character controller, to Havok Behavior, etc…  you need to go with an Entity.

 

There is one final mildly confusing point, that you can completely disregard for now if you want.  Up until now I have used the terms VMesh –> Static Mesh Instance and MODEL –> Entity.  It is however possibly for an Entity to reference a static mesh, but not the reverse.  Again, if that is confusing… forgetaboutit!

 

From the code side of things, a static mesh is actually a VStaticMeshInstance_cl, while an entity is VisBaseEntity_cl.  As you can see from their prospective inheritance diagrams, VStaticMeshInstance is “simpler”.

 

VStaticMeshInstance_cl Inheritance diagram:

image

 

VisBaseEntity_cl inheritance diagram:

image

 

It’s the inheritance from VisObject3D_cl that is absolutely critical.  That class itself contains the functions critical to movement such as GetPosition(), IncOrientation() etc…  basically the code you need to position and move an object in 3D space.  It is also what enables the more advanced parenting options and linking available to an Entity and other VisObject3D_cl derived classes.

 

 

TL;DR version… got a 3D object that doesn’t move and doesn’t change?  You probably want to export it as a VMESH and make it a Static Mesh Instance.  Otherwise, you probably want to export it as a MODEL and implement it as an entity. 

Programming Project Anarchy


Scroll to Top