Archive for July, 2009

Material system, the madness!

Wednesday, July 22nd, 2009

Well, it seems a centralized material library is not so good, because when you export a COLLADA mesh, that mesh should be already skinned with the texture files, and in case of many submeshes this gets complicated, so the best is to have scattered *.material.xml files for each submesh of the model, already generated by the COLLADA Nytro Importer tool from NytroStudio, so when you import, you get the mesh ready with textures and shader (the shader name will be taken from COLLADA hint text, or if you set up a Phong material, it will fallback to the engine’s generic blinn-phong shader. Below is an example of a complex mesh exported from 3DSMAX as a COLLADA file, and imported as .mesh, .material.xml and .model.xml files into the engine. Furthermore, a model file can be set up in the editor, dragging custom made materials onto the submeshes.

Big mesh with submesh materials, right from 3DSMAX

Big mesh with submesh materials, right from 3DSMAX

A video of that, here: http://www.youtube.com/watch?v=SxGsuLTLQno

Entity viewport icons and entity selection

Sunday, July 12th, 2009

The entities can render an icon when the engine is in editor mode. The entity must override the schematicRender() method of the base Entity class (this method is called only in editor, not when the engine is in game mode). The selected icons will blink in-out so they can be more visible. When selected, if there is one entity selected, there will be drawn a wire yellow box for the local entity bounding box, a transparent wire white box for the world bounding box of the entity, else if more entities are selected, the world box will be blue and where it cant be seen (in the back of meshes) will appear as red. Selecting is made with left click, Ctrl +LeftClick = multiple selection, Shift + moving/rotate/scale = clone selection, with Ctrl on any scale axis will scale uniformly, Delete = delete the selection, Ctrl+Z = undo, Ctrl+Shift+Z = redo. Also the entity icons have the following modes: show icons with fixed/constant size, independent of distance from camera, or show icons with world size, they will shrink if distance grows, enable/disable depth check to show or hide the icons behind entities. To pick an entity click on it or on its icon (if visible or available), the entity must handle the traceRay(..) virtual method to check for hit with the selection ray from mouse, there are two levels of checking for intersection, ACCURATE and BRUTE, the traceRay will be called first with BRUTE, if it passes then will be called with ACCURATE, depends on each entity type how it checks its intersection; by default there will be an implementation for the entity icon picking.

Selection and entity icons

Selection and entity icons

Material system decision(s)

Wednesday, July 8th, 2009

Today I was in deep-thinking mode about the material system in the engine, the flow goes like this:

At the root of all evil lies the shader program (pixel & vertex & other, like compute shader), then for a shader you have a shader preset which is basically a set of shader constants values, as an example: for a ‘Plastic’ shader, you have ‘ShinyRedPlastic’, ‘BluePlastic’, ‘GreenPlastic’ shader presets with their specific shader constant values. All the presets are kept in a ‘*.shader.xml’ file, and the HLSL or GLSL code is linked from that xml. Then we have a higher layer for surface materials, kept in a centralised Material Library, a material being composed of info about: shader, shader preset, hit sounds, physical material (for physics computations). Until here all good, but when I for example create a mesh in 3D Studio Max, I will export it to COLLADA file format, and from there it will be loaded into the editor’s Model tool, naked, without shaders or materials, and from there, you will drag and drop materials (with shader/sounds/physics set) onto the mesh’s submeshes, dressing up the model. It is a natural flow, for example you make a soldier, bring it into the ModelEditor, and start dropping materials onto its component parts, ‘TheSoldier/Helmet’ material goes on its helmet, the ‘TheSoldier/Head’ goes on its head, ‘TheSoldier/Pants’ goes on its pants, until you dress it all up and save it as a *.model.xml file, which is referencing the *.mesh (binary file produced from the COLLADA file, containing only the geometry), and the materials assigned to each submesh, the model being ready to be used. The problem is when the mesh is modified in 3D Studio Max, maybe you add more submeshes (elements) or delete some, export it in COLLADA format, and reload it into the ModelEditor, the material assignments to the submeshes will not match anymore, you’ll have to reassign some materials to their submeshes, but I think this is not such a big issue, the mesh file will not be changed so often in many cases. So, this way you can use whatever modelling package (which supports COLLADA export, and most of them do) you want to create your ‘clay’ mesh and dress it up in the engine’s editor. Maybe I could find a way to assign materials in the 3D Studio Max directly, but it is not a priority, model the mesh there, texture it there for testing how it looks, and export the raw mesh, to be dressed up in the engine, using the materials authored in the NytroStudio, with the MaterialEditor.

Some monster using the material central library

Some monster using the material central library

Resource browser drag and drop

Monday, July 6th, 2009

Added resource browser capability to drag and drop a resource file directly into the scene, for some types of resources only of course, so this way you can drop a model into the scene and the editor will create a ModelEntity and set the ModelFile property with the resource file name being dropped into the scene, same thing with SoundSourceEntity, ParticleSystemEntity and other “droppable” resource types. This will help speed up things when creating a scene.

Drag a resource to create a specific entity with that resource set

Drag a resource to create a specific entity with that resource set

Manipulate gizmo

Saturday, July 4th, 2009

In the past engine versions, the world editor had 3 buttons on the toolbar for move, rotate and scale the selection, but after testing I have tought that an unified control will suit a world builder better than going back to the toolbar, choosing another mode, coming back into scene and so on, after all a world editor is not a modelling program, at least NytroStudio, it has to be simple and fast, create entities, set properties, events and behavior, and save, that’s all; even with keyboard shortcuts would take longer than having a simple 3 operation gizmo on screen. The manipulator gizmo is designed to easily move rotate and scale the current selection, the arrows and the planes formed by the arrows move the object, the small cubes scale the object on their axes (Ctrl hold down to uniform scale) and the discs on top of axes rotates the selection, each element will be highlighted on hover over it, I’ll post later on some videos about editing in NytroStudio. Maybe as a final touch I’ll make some shortcuts to hide or show the 3 elements of the gizmo, so you can have 3, 2 or one mode at a given time, maybe you’re incomfortable with all three operations at once, but trust me after a while it will become a great tool, no more setting the current mode in toolbar or keyboard shortcut. Here is how it looks:

Manipulate gizmo

Manipulate gizmo

Resource browser

Thursday, July 2nd, 2009

Working on the resource browser in the editor, which is done with .NET DevExpress controls, in C++/CLI, which links directly with the engine code, without the need of a wrapper in the case of C#. Here is a little shot, not the final one:

Thumbs browser

Thumbs browser

I’m using a traditional ListView control from standard .NET classes, tuned a little the colors and font. The thumbs are generated at on-sight time in the list, or they are already generated from the model editor or particle editor; for the textures, are generated on the fly, if thumb is already on the disk, then the generation will be skipped, and the thumb will be loaded instead, so its a cache system. I will add a context menu on click on the thumb, which will contain regenerate thumb and edit resource (also double click on thumb). Otherwise, the thing looks good and simple, if prefabs will be shown in the thumb list, they can be dragged into the scene viewport to be created there. More on the resource browser soon!

It had to start

Thursday, July 2nd, 2009

I had to start this blog so I can be forced to keep working on the engine on a constant basis, also this blog will be a window in the past, for mistakes and successes… The blog is about the Nytro Game Engine Development process, a framework comprised of core engine, level editor, documentation. More on http://7thfactor.ro