Properly move an entity model's expected texture size to the models

Allows high res entity textures and also isn't completely disgusting.
This commit is contained in:
David Vierra 2015-07-12 17:37:43 -10:00
parent 32a09b555e
commit 2310a24468
7 changed files with 24 additions and 6 deletions

View File

@ -8,6 +8,9 @@ from mcedit2.rendering.chunkmeshes.entity.modelrenderer import ModelRenderer
log = logging.getLogger(__name__)
class ModelBiped(object):
textureWidth = 64
textureHeight = 32
def __init__(self, expandOffset=0.0, headOffset=0.0):
self.bipedHead = ModelRenderer(self, 0, 0)
self.bipedHead.addBox(-4.0, -8.0, -4.0, 8, 8, 8, expandOffset)
@ -48,11 +51,17 @@ class ModelBiped(object):
class ModelZombie(ModelBiped):
textureWidth = 64
textureHeight = 64
modelTexture = "assets/minecraft/textures/entity/zombie/zombie.png"
id = "Zombie"
class ModelPigZombie(ModelBiped):
textureWidth = 64
textureHeight = 64
modelTexture = "assets/minecraft/textures/entity/zombie_pigman.png"
id = "PigZombie"

View File

@ -9,6 +9,9 @@ log = logging.getLogger(__name__)
class ModelCreeper(object):
textureWidth = 64
textureHeight = 32
modelTexture = "assets/minecraft/textures/entity/creeper/creeper.png"
id = "Creeper"

View File

@ -2,6 +2,7 @@
models
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import collections
import logging
import math
import numpy
@ -107,6 +108,8 @@ def npRotate(axis, angle, rescale=False):
# xxx rescale
return rotate
CookedModel = collections.namedtuple('CookedModel', 'vertices texWidth texHeight')
def cookEntityModel(model):
allVerts = []
for part in model.parts:
@ -130,12 +133,11 @@ def cookEntityModel(model):
allVerts.append((x+cx, y+cy, z+cz, u, v))
return allVerts
return CookedModel(allVerts, model.textureWidth, model.textureHeight)
cookedModels = {}
textures = {}
def addModel(model):
cookedModels[model.id] = cookEntityModel(model)
textures[model.id] = model.modelTexture

View File

@ -9,6 +9,9 @@ from mcedit2.rendering.chunkmeshes.entity.modelrenderer import ModelRenderer
log = logging.getLogger(__name__)
class ModelQuadruped(object):
textureWidth = 64
textureHeight = 32
def __init__(self, height, expandOffset=0.0):
self.head = ModelRenderer(self, 0, 0)

View File

@ -9,6 +9,9 @@ from mcedit2.rendering.chunkmeshes.entity.modelrenderer import ModelRenderer
log = logging.getLogger(__name__)
class ModelSpider(object):
textureWidth = 64
textureHeight = 32
id = "Spider"
modelTexture = "assets/minecraft/textures/entity/spider/spider.png"

View File

@ -146,7 +146,7 @@ class MonsterModelRenderer(ChunkMeshBase):
model = models.cookedModels[ID]
modelVerts = numpy.array(model)
modelVerts = numpy.array(model.vertices)
modelVerts.shape = modelVerts.shape[0]/4, 4, modelVerts.shape[1]
# scale down
modelVerts[..., :3] *= 1/16.
@ -165,7 +165,7 @@ class MonsterModelRenderer(ChunkMeshBase):
modelTex = self.chunkUpdate.updateTask.getModelTexture(models.textures[ID])
textureNode = BindTextureNode(modelTex, (1./modelTex.w, 1./modelTex.h, 1))
textureNode = BindTextureNode(modelTex, (1./model.texWidth, 1./model.texHeight, 1))
textureNode.addChild(translateNode)
sceneNode.addChild(textureNode)

View File

@ -195,8 +195,6 @@ class SceneUpdateTask(object):
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, rgba[::-1])
modelTex = Texture(_load)
modelTex.w = w # ewwwww
modelTex.h = h
self.modelTextures[texturePath] = modelTex
return modelTex