Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
struct TextureSlice(float w, float h) { static const float width = w; static const float height = h; static const float x_step = 1.0f/width; static const float y_step = 1.0f/height; byte x; byte y; alias texcoords this; this(byte lower_left_x, byte lower_left_y) { x = lower_left_x; y = lower_left_y; } @property byte[2][4] texcoords() { return [[cast(byte)x, cast(byte)y], [cast(byte)(x+1), cast(byte)y], [cast(byte)(x+1), cast(byte)(y-1)], [cast(byte)x, cast(byte)(y-1)]]; } @property byte[2][4] texcoords_90() { return [[cast(byte)(x+1), cast(byte)y], [cast(byte)(x+1), cast(byte)(y-1)], [cast(byte)x, cast(byte)(y-1)], [cast(byte)x, cast(byte)y]]; } @property byte[2][4] texcoords_180() { return [[cast(byte)(x+1), cast(byte)(y-1)], [cast(byte)x, cast(byte)(y-1)], [cast(byte)x, cast(byte)y], [cast(byte)(x+1), cast(byte)y]]; } @property byte[2][4] texcoords_270() { return [[cast(byte)x, cast(byte)(y-1)], [cast(byte)x, cast(byte)y], [cast(byte)(x+1), cast(byte)y], [cast(byte)(x+1), cast(byte)(y-1)]]; } } alias TextureSlice!(16, 16) MCTextureSlice; struct CubeSideData { float[3][4] positions; // 3*4, it's a cube! float[3] normal; } immutable CubeSideData[6] CUBE_VERTICES = [ { [[-0.5f, -0.5f, 0.5f], [0.5f, -0.5f, 0.5f], [0.5f, 0.5f, 0.5f], [-0.5f, 0.5f, 0.5f]], // front [0.0f, 0.0f, 1.0f] }, { [[-0.5f, -0.5f, -0.5f], [-0.5f, -0.5f, 0.5f], [-0.5f, 0.5f, 0.5f], [-0.5f, 0.5f, -0.5f]], // left [-1.0f, 0.0f, 0.0f] }, { [[0.5f, -0.5f, -0.5f], [-0.5f, -0.5f, -0.5f], [-0.5f, 0.5f, -0.5f], [0.5f, 0.5f, -0.5f]], // back [0.0f, 0.0f, -1.0f] }, { [[0.5f, -0.5f, 0.5f], [0.5f, -0.5f, -0.5f], [0.5f, 0.5f, -0.5f], [0.5f, 0.5f, 0.5f]], // right [1.0f, 0.0f, 0.0f] }, { [[-0.5f, 0.5f, 0.5f], [0.5f, 0.5f, 0.5f], [0.5f, 0.5f, -0.5f], [-0.5f, 0.5f, -0.5f]], // top [0.0f, 1.0f, 0.0f] }, { [[-0.5f, -0.5f, -0.5f], [0.5f, -0.5f, -0.5f], [0.5f, -0.5f, 0.5f], [-0.5f, -0.5f, 0.5f]], // bottom [0.0f, -1.0f, 0.0f] } ]; private const byte[2][4] nslice = MCTextureSlice(-1, -1).texcoords; Vertex[] simple_block(Side side, byte[2][4] texture_slice) pure { return simple_block(side, texture_slice, nslice); } Vertex[] simple_block(Side side, byte[2][4] texture_slice, byte[2][4] mask_slice) pure { CubeSideData cbsd = CUBE_VERTICES[side]; float[3][6] positions = to_triangles(cbsd.positions); byte[2][6] texcoords = to_triangles(texture_slice); byte[2][6] mask; if(mask_slice == nslice) { mask = texcoords; } else { mask = to_triangles(mask_slice); } Vertex[6] data; foreach(i; 0..6) { data[i] = Vertex(positions[i][0], positions[i][1], positions[i][2], cbsd.normal[0], cbsd.normal[1], cbsd.normal[2], texcoords[i][0], texcoords[i][1], mask[i][0], mask[i][1], 0, 0); } return data.dup; } template WoolPair(byte xi, byte yi) { enum x = xi; enum y = yi; } void wool_block(Side s)(const ref Block block, const ref BiomeData biome_data, float x_offset, float y_offset, float z_offset) { static string wool_vertices() { return `enum vertices = simple_block(s, MCTextureSlice(slice.x, slice.y).texcoords); add_template_vertices(vertices, x_offset, y_offset, z_offset, 0, 0);`; } alias WoolPair t; final switch(block.metadata) { foreach(i, slice; TypeTuple!(t!(0, 5), t!(2, 14), t!(2, 13), t!(2, 12), t!(2, 11), t!(2, 10), t!(2, 9), t!(2, 8), t!(1, 15), t!(1, 14), t!(1, 13), t!(1, 12), t!(1, 11), t!(1, 10), t!(1, 9), t!(1, 8))) { case i: mixin(wool_vertices()); break; } } }
Username
Message
Add comment
Paste info
Author:
dav1d
Views:
152
Private:
no
Expires:
Never
Uploaded:
17.08.12 18:21
Votes
:
0
Tweet
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason