Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make textures clearly belong to blocks #37

Open
traverseda opened this issue Apr 19, 2016 · 3 comments
Open

Make textures clearly belong to blocks #37

traverseda opened this issue Apr 19, 2016 · 3 comments
Milestone

Comments

@traverseda
Copy link
Owner

traverseda commented Apr 19, 2016

Enhancement for #2

Right now, there are like 3 different places where we import/define textures.

It will involve some digging into pyglet, but we definitely need to de-duplicate that.

I'm imagining a "texture" object, that has textures for more then one block.

Blocks return coordinates and a reference to their texture in it.

I think heightmaps could lead to some very interesting effects, and in the future we might want to support dynamic textures (maps) or layered textures (signs).

But we don't need a perfect solution off the bat. Just a quick system for defining a texture in one place, and having the renderer read them.

@traverseda traverseda added this to the 0.1 milestone Apr 19, 2016
@PythonJedi
Copy link

Would it be useful to have blocks 'owning' their textures via having the textures split into separate files? I'm not sure what difficulties that could bring into the rendering setup logic, but I know minecraft uses separate files for each texture and allows blocks and items to 'inherit' the textures and models of other blocks/items.

I'm not suggesting we take the same organizational route minecraft has taken (in fact, I'd argue vehemently against it), but splitting textures into separate files seems like a win for modularity.

@r58Playz
Copy link

True.

@r58Playz
Copy link

This may be useful:

class Block(object):
    tex = []
    files = []
    colorizeable = False

    def get_tex(self,file):
        tex = pyglet.image.load(file).get_texture()
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
        return pyglet.graphics.TextureGroup(tex)

    def __init__(self):
        for nme in self.files:
            self.tex.append(self.get_tex(nme))
            
    def draw(self, position, batch):
        x, y, z = position
        return self.cuboid(*position, self.tex, batch)
    
    def cuboid(self, x, y, z, textures, batch):
        '''
        Draws a cuboid from x1,y1,z1 to x2,y2,z2 and covers each side with tex
        tex format:
            (side, top, bottom)
        Facing in the -z direction
        '''
        tex = textures
        front = tex[0]
        back = tex[0]
        left = tex[0]
        right = tex[0]
        top = tex[1]
        bottom = tex[2]

        tex_coords = ("t2f", (0, 0, 1, 0, 1, 1, 0, 1))
        x1, y1, z1 = x, y, z
        x2, y2, z2 = x + 1, y + 1, z + 1
        if self.colorizeable:
            color = self.colorizer.colorize(y)
        else:
            color = None
        if color:
            cube = (batch.add(4, GL_QUADS, right, ('v3f', (x1, y1, z1, x1, y1, z2, x1, y2, z2, x1, y2, z1)), tex_coords),
                batch.add(4, GL_QUADS, left, ('v3f', (x2, y1, z2, x2, y1, z1, x2, y2, z1, x2, y2, z2)), tex_coords),
                batch.add(4, GL_QUADS, bottom, ('v3f', (x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2)), tex_coords),
                batch.add(4, GL_QUADS, top, ('v3f', (x1, y2, z2, x2, y2, z2, x2, y2, z1, x1, y2, z1)), tex_coords, color),
                batch.add(4, GL_QUADS, back, ('v3f', (x2, y1, z1, x1, y1, z1, x1, y2, z1, x2, y2, z1)), tex_coords),
                batch.add(4, GL_QUADS, front, ('v3f', (x1, y1, z2, x2, y1, z2, x2, y2, z2, x1, y2, z2)), tex_coords))
        else:
            cube = (batch.add(4, GL_QUADS, right, ('v3f', (x1, y1, z1, x1, y1, z2, x1, y2, z2, x1, y2, z1)), tex_coords),
                batch.add(4, GL_QUADS, left, ('v3f', (x2, y1, z2, x2, y1, z1, x2, y2, z1, x2, y2, z2)), tex_coords),
                batch.add(4, GL_QUADS, bottom, ('v3f', (x1, y1, z1, x2, y1, z1, x2, y1, z2, x1, y1, z2)), tex_coords),
                batch.add(4, GL_QUADS, top, ('v3f', (x1, y2, z2, x2, y2, z2, x2, y2, z1, x1, y2, z1)), tex_coords),
                batch.add(4, GL_QUADS, back, ('v3f', (x2, y1, z1, x1, y1, z1, x1, y2, z1, x2, y2, z1)), tex_coords),
                batch.add(4, GL_QUADS, front, ('v3f', (x1, y1, z2, x2, y1, z2, x2, y2, z2, x1, y2, z2)), tex_coords))
        return cube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants