|
Darwinia /
ShapeFilesSHAPE FILESIt is very possible to get your own models into Darwinia, and if you do, it gives your mods a touch of class. Most of the buildings and units you see in the game are meshes that are described in Darwinia's shp files. You can find all the shp files in the shapes folder in main.dat. You can also put a shapes folder in the root of your mod folder and Darwinia will use those shape files before the default ones in data/shapes ( from main.dat ). The quickest way to change the way a building or unit looks is to modify an existing shp file. However, this limits you to minor changes in position, orientation or scale, and you will find that if you try to make major changes by manipulating the shape file by hand, you will probably break it. To get your own unique models into the game, you will have to model them in a 3D modelling package and then convert them. I have written a simple perl script that will convert 3D Studio Max ASE files to Darwina shape files, but if you prefer another modelling package you can write your own conversion script if you feel up to it. I will go into the convertion process later, but first, lets have a look at the structure of the shape files and how you can make some simple modifications by hand. Syntax Fragment : fragment ParentName : ( SceneRoot || fragment ) Up : x y z Front : x y z Pos : x y z Positions : positions PosId : x y z [ PosId : x y z ] ... Normals : normals NormId : x y z [ NormId : x y z ] ... Colours : colours ColourId : R G B [ ColourId : R G B ] ... Vertices : vertices VertId : posId ColourId [ VertId : posId ColourId ] ... (Triangles : triangles posId posId PosId [ posId posId PosId ] ... || Strips : strips Strip : stripId Material : [ GunMetal ] Verts : verts vertId [ vertId ] ... [ Strip : stripId Material : [ GunMetal ] Verts : verts vertId [ vertId ] ... ] ... ) [ Fragment : fragment ... ] ... [ Marker : marker ParentName : ( SceneRoot || fragment ) Depth : depth Up : x y z Front : x y z Pos : x y z MarkerEnd ] ... Parameter Descriptions Fragment, string : Each shape file can include several fragments. The fragment name is used to uniquely identify a fragment. ParentName, string : The parent fragment. Sceneroot indicates the fragment has no parent. Fragment and ParentName work together to create a tree of parts. Sceneroot is always at the top of the tree, and a ParentName of sceneroot indicates the position and orientation is relative to the unit or buildings position on the map. If the ParentName is the name of another fragment, then the position and orientation is relative to the parent fragment. For example, if the parent fragment has a y ( vertical ) position offset of 10 and the child fragment also had an offset of 10, the effective offset of the child frgmant would be y + 20 from SceneRoot. Up x y z, float / Front x y z, float : The Up and front parameters work together to indicate the fragments orientation. They each have x, y and z assignments. The exact workings of these two parameters are obscured behind the particular matrix transformations used ingame. However, you can manipulate these values by following the orientation tutorial here Pos x y z, float : Pos indicates the relative x, y and z offsets of the fragments position ( not to be confused with individual positions ). Positions, integer : The number of positions in the fragment mesh. Positions are effectively vertices, and the number of positions and vertices should be identical. Position PosId , integer / Position x y z, float : Each position has a unique id and x y z offset. A position is like a point on the fragment mesh that has an x, y and z offset from the objects centre ( this doesnt have to be the exact centre, it is an arbitrary centrepoint chosen when modelling ) . You can scale a fragment by manipulating the positions ( Only staticshape objects can be directly scaled in the mission/map files ). If you double all the x, y and z offset parameters for each vertex, you will have scaled your model by a factor of two. You will only be able to do this by hand for a really simple shape, but it is easy to write a script that will do it for you. Here is a perl script that takes a shape file and a scale value as parameters and outputs a new scaled version of the shape file : scaleshp_pl.txt. You can also apply this technique to a single axis, i.e. doubling only the x offset for each position will make your fragment look 'fat'. Normals normID , integer / Normals x y z, float : Each normal has a unique id and x y z value indicating the normalised (length 1) normal for a particular face. The number of normals should equal the number of triangles. All default shapes have zero normals. Normals are only effective when smooth shading is enabled. DFPatch switches on smooth shading Colours colourId, integer / Colours R G B, integers: Each colour is assigned a unique id and RGB value. Vertices vertId , integer : Each vertex is assigned a position Id and colour. Vertices are effectively positions, and the number of positions and vertices should be identical ( although this is not a requirement, there is no reason why the two would be different ). Triangles, integer : Triangles describe each of the faces of the fragment mesh. Each triangle described by three vertices, indicating the three corners of the triangle. You can set the number of triangles ( or the number of verts if the shp file has strip parameters ) to zero. This will make your building invisible. Why would you do that ? Well, you can overlay staticshapes over invisible building, giving the impression that each instance of that building in a location has a different shape ( Leave your building markers visible for best effect ). Note that staticshapes, being static, will mean your building will not animate, so this trick is not much good for buildings like radardishes, unless you are clever with your staticshape design. You may also want to hide certain building from the player to enhance gameplay. Strips stripId, integer : Assigns each strip a unique stripId. Strips are an alternative method of rendering as opposed to triangles. To be honest, Im not sure quite how they work, but I suspect the define a series of triangles in a strip rather than a number of faces. Triangle strips are a particular rendering method in opengl and it seems reasonable that this is what is being defined here Strips Material, string : Either blank or GunMetal. Im not sure what this material parameter actually does. There have been some reports that it is to do with collision detection, but I dont think that is the case. Im not sure it actually does anything. Verts vertId, integer : Each strip is defined by a number of vertex ids. Marker, string : Each shape file can include several markers. The marker name is used to uniquely identify a marker. Marker Depth, integer : The depth parameter is always 1 greater than the position of the parent fragment in the fragment tree. For example, if the ParentName for a marker is sceneroot, the Depth will be 1. If the ParentName for a marker is the name of a fragment, the Depth will be 2, assuming that fragment in turn has a ParentName of sceneroot, of higher, if the ParentName of the parent fragment is the name of another fragment. Confused ? You may think that the depth parameter is redundant because its value is implied by the ParentName of the marker, and you would be right. However, you do have to supply the correct Depth parameter or the game will probably crash. Notes So, now you know a bit about the shp files, what can you do to change the shapes? Probably the simplest thing to do is to change the colour. You can simply change the RGB value for any of the colours in the colour section. If the colour has a value of 255 0 0, you can tell that any vertex assigned that colour will appear red in the game ( RGB value of 255 0 0 gives red ). To change all red vertices to blue, you would change the RGB values of that colour to 0 0 255 ( RGB value of 0 0 255 gives blue ). But before you go adding wierd and wonderful palletes to your shapes, note that Darwinia uses flat shading, and if you have two adjacent vertices with very different colours, the resulting effect will look clumsy. Another easy way to change a shape is by altering the Up/Front/Pos parameters. By changing the x, y and z values, you can turn a vertical fragment to a horizontal fragment, for example. Try changing the Up parameter from 0 1 0 to 0.707 0.707 0. The shape will move 45 degrees around the z axis. Changing the Front Parameter from 0 0 1 to 0 0.707 0.707 will rotate the shape 45 degrees around the x axis. Note these parameters are like vectors and have a value of between -1 and 1, representing a full 360 degree turn. Changing position is probably best constrained to the y axis. That way you can make shapes float above the ground, or give the impression they are embedded in the ground. There is nothing to stop you changing the x and z axes, but you probably wont notice much difference. There are other ways to alter the shp file manually. One easy thing to do is to remove whole fragments of even add whole fragments from another shp file. Unfortunatley, some units and building require certain fragments ( and markers ) to be there, so if the game crashes after you remove a fragment, you will need to restore it to the shp file. Page last modified on August 24, 2006, at 11:16 AM - Page generated in 0.242 seconds. |