AlexStv

Texture index

For the past week or so I've been implementing a texture index to address some of the planned features for Voxelmetric. The texture index, much like the block index is meant to act as an abstraction layer between textures and things that use them. Block textures are now added to Voxelmetric as individual files placed in the Resources/Textures folder (Or wherever you define in the config) The texture index collects these on start and sorts them into TextureCollections. Texture collections are how textures are accessed now.

A texture collection is made for each file with a unique file name before any dash (-), so textureName-1.png is the same texture as textureName-2.png. If you add more than one file with the same name they will both be added to the texture collection and when you request a texture it will randomly choose one. This means that block controllers no longer store a tile position, they should store a texture collection which they request from the texture index at start up () and then whenever a a texture is needed call GetTexture on the collection to get a Rect with the texture position.

Connected textures are also added as part of this, connected textures are a collection of textures that connect on sides neighboring a block of the same type.

[centerimg]http://alexstv.com/images/connected_example.png[/centerimg]

48 textures are needed to support every possible connected texture type Voxelmetric needs 5 to generate the rest on load. Connected textures are loaded from the Resources/Connected Textures folder and named textureName-c0.png where 0 is the texture type as defined in the image below. These 5 textures are cut up and used to create the rest. Right now it's not possible to define all 48 types manually but it is planned. The 5 textures needed are outline here:

[centerimg]http://alexstv.com/images/5type.png[/centerimg]

Connected textures take a little more time to render, a little more time to load at the start of the game and a lot more ram and space in the texture atlas so use them sparingly especially with large textures.

Mesh blocks have also changed to support the new texture index and to support a better way to import meshes. Mesh blocks are now imported automatically from Resources/Meshes and are added as blocks with the name of the mesh. Bear in mind that Unity reads each submesh of a file individually and doesn't combine them into one, the mesh will be named after the mesh, not the file and you'll get a block for every block mesh. The texture your mesh uses can be added to the textures folder with the same name before the dash as your mesh. Mesh blocks can use random textures if more than one texture is defined but cannot use connected textures.

6th Jul, 2015
Alex