User Tools

Site Tools


custom_block_models

Making custom block models

In ChunkStories, block models live in res/voxels/blockmodels and have the extension .model. The game automatically loads them all in at assets loading state and you can access them using <filenamewithout.model>.subtype when you need to specify their usage. Not putting .subtype at the end make the game assume it's .default.

These files are laid out as :

bottom
	# Top face
	#vert x,y,z tex t,s normal x,y,z 
	v 1.0,0.5,1.0 0.0,0.0 0.0,1.0,0.0
	v 0.0,0.5,1.0 1.0,0.0 0.0,1.0,0.0
	v 0.0,0.5,0.0 1.0,1.0 0.0,1.0,0.0

	v 0.0,0.5,0.0 1.0,1.0 0.0,1.0,0.0
	v 1.0,0.5,0.0 0.0,1.0 0.0,1.0,0.0
	v 1.0,0.5,1.0 0.0,0.0 0.0,1.0,0.0
	
	# Bottom
	cull bottom
	v 0.0,0.0,1.0 1.0,0.0 0.0,-1.0,0.0
	v 1.0,0.0,1.0 0.0,0.0 0.0,-1.0,0.0
	v 0.0,0.0,0.0 1.0,1.0 0.0,-1.0,0.0

	v 1.0,0.0,0.0 0.0,1.0 0.0,-1.0,0.0
	v 0.0,0.0,0.0 1.0,1.0 0.0,-1.0,0.0
	v 1.0,0.0,1.0 0.0,0.0 0.0,-1.0,0.0
	cull none
	# right face
	cull right

	# Adds a last tag to enable "wind" influence
	v 1.0,0.0,1.0 0.0,1.0 1.0,0.0,0.0 1
	v 1.0,0.5,1.0 0.0,0.5 1.0,0.0,0.0 1
	v 1.0,0.0,0.0 1.0,1.0 1.0,0.0,0.0 1
	
	v 1.0,0.5,0.0 1.0,0.5 1.0,0.0,0.0 1
	v 1.0,0.0,0.0 1.0,1.0 1.0,0.0,0.0 1
	v 1.0,0.5,1.0 0.0,0.5 1.0,0.0,0.0 1
	
	# left face
	cull left
	v 0.0,0.5,1.0 1.0,0.5 -1.0,0.0,0.0
	v 0.0,0.0,1.0 1.0,1.0 -1.0,0.0,0.0
	v 0.0,0.0,0.0 0.0,1.0 -1.0,0.0,0.0
	
	v 0.0,0.0,0.0 0.0,1.0 -1.0,0.0,0.0
	v 0.0,0.5,0.0 0.0,0.5 -1.0,0.0,0.0
	v 0.0,0.5,1.0 1.0,0.5 -1.0,0.0,0.0
	
	# Front
	cull front
	v 1.0,0.5,1.0 1.0,0.5 0.0,0.0,1.0
	v 1.0,0.0,1.0 1.0,1.0 0.0,0.0,1.0
	v 0.0,0.0,1.0 0.0,1.0 0.0,0.0,1.0
	
	v 0.0,0.0,1.0 0.0,1.0 0.0,0.0,1.0
	v 0.0,0.5,1.0 0.0,0.5 0.0,0.0,1.0
	v 1.0,0.5,1.0 1.0,0.5 0.0,0.0,1.0
	
	# Back
	cull back
	v 1.0,0.0,0.0 0.0,1.0 0.0,0.0,-1.0
	v 1.0,0.5,0.0 0.0,0.5 0.0,0.0,-1.0
	v 0.0,0.0,0.0 1.0,1.0 0.0,0.0,-1.0
	
	v 0.0,0.5,0.0 1.0,0.5 0.0,0.0,-1.0
	v 0.0,0.0,0.0 1.0,1.0 0.0,0.0,-1.0
	v 1.0,0.5,0.0 0.0,0.5 0.0,0.0,-1.0
end

anotherKind
	# Etc
end

The files contains 1+n subtypes, the default subtype is not mandatory but recommended to use. The subtypes definition begin with their name, n*3 vertices and various options and then the end tag.

Format

  • v X Y Z T S NX NY NZ Defines a vertice ( 3 needed to form a triangle ) with it's xyz coordinates, ts texture coordinates ( in normalized space inside whatever texture the model is using ) and normal direction data.
  • culling <face/none> Enables culling per face or disable it. If it's enabled on face X and the block touching this one's X face is either opaque or opaque on this side, the following vertices won't be rendered.
  • texture Tells the model to use another texture than the default one. Use ~ as the voxel name, _left, _top , _back and so on for the 'sides' textures defined in the voxels file.
  • #comments start with the hash character

Consider culling !

When specifying your vertices, you have to pay attention to respect a certain order because the game uses face culling. The best explanation of face culling I can write on the top of my head is that it's a process to reduce the load on the GPU by rejecting faces when they could not be seen anyway ( this implies one-sided faces ). It does this by looking at how the vertex end up on screen, in the mode Chunk Stories uses they have to be counter-clockwise specified when looking at their visible side.

Image stolen from Wikipedia to try making my point clear

custom_block_models.txt · Last modified: 2018/01/24 14:13 by gobrosse