Add question mark texture (and "model") for unknown blocks.

This commit is contained in:
David Vierra 2015-01-25 21:00:13 -10:00
parent e9f18b10dc
commit 673689fc7c
5 changed files with 48 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

View File

@ -14,6 +14,7 @@ from cpython cimport array
from array import array from array import array
from mceditlib import faces from mceditlib import faces
from mceditlib.blocktypes import BlockType
from mceditlib.geometry import Vector from mceditlib.geometry import Vector
from mceditlib.selection import FloatBox from mceditlib.selection import FloatBox
@ -33,6 +34,13 @@ cdef struct ModelQuadList:
cdef class BlockModels(object): cdef class BlockModels(object):
def _getBlockModel(self, modelName): def _getBlockModel(self, modelName):
if modelName == "block/MCEDIT_UNKNOWN":
return {
"parent": "block/cube_all",
"textures": {
"all": "MCEDIT_UNKNOWN"
}
}
model = self.modelBlockJsons.get(modelName) model = self.modelBlockJsons.get(modelName)
if model is None: if model is None:
model = json.load(self.resourceLoader.openStream("models/%s.json" % modelName)) model = json.load(self.resourceLoader.openStream("models/%s.json" % modelName))
@ -40,6 +48,14 @@ cdef class BlockModels(object):
return model return model
def _getBlockState(self, stateName): def _getBlockState(self, stateName):
if stateName == "MCEDIT_UNKNOWN":
return {
"variants": {
"MCEDIT_UNKNOWN": {
"model": "MCEDIT_UNKNOWN",
}
}
}
state = self.modelStateJsons.get(stateName) state = self.modelStateJsons.get(stateName)
if state is None: if state is None:
state = json.load(self.resourceLoader.openStream("blockstates/%s.json" % stateName)) state = json.load(self.resourceLoader.openStream("blockstates/%s.json" % stateName))
@ -69,7 +85,15 @@ cdef class BlockModels(object):
memset(self.cookedModelsByID, 0, sizeof(self.cookedModelsByID)) memset(self.cookedModelsByID, 0, sizeof(self.cookedModelsByID))
self.cooked = False self.cooked = False
for i, block in enumerate(blocktypes): missingnoProxy = BlockType(-1, -1, blocktypes)
missingnoProxy.internalName = "MCEDIT_UNKNOWN"
missingnoProxy.blockState = ""
missingnoProxy.renderType = 3
missingnoProxy.resourcePath = "MCEDIT_UNKNOWN"
missingnoProxy.resourceVariant = "MCEDIT_UNKNOWN"
missingnoProxy.color = 0xFFFFFF
for i, block in enumerate(list(blocktypes) + [missingnoProxy]):
if i % 100 == 0: if i % 100 == 0:
log.info("Loading block models %s/%s", i, len(blocktypes)) log.info("Loading block models %s/%s", i, len(blocktypes))
@ -196,6 +220,7 @@ cdef class BlockModels(object):
allElements, textureVars) allElements, textureVars)
raise raise
def buildBoxQuads(self, element, nameAndState, textureVars, variantXrot, variantYrot, variantZrot, blockColor): def buildBoxQuads(self, element, nameAndState, textureVars, variantXrot, variantYrot, variantZrot, blockColor):
quads = [] quads = []
shade = element.get("shade", True) shade = element.get("shade", True)
@ -253,6 +278,7 @@ cdef class BlockModels(object):
cdef int u1, u2, v1, v2 cdef int u1, u2, v1, v2
cdef int uw, vh cdef int uw, vh
cdef list cookedQuads cdef list cookedQuads
for nameAndState, allQuads in self.modelQuads.iteritems(): for nameAndState, allQuads in self.modelQuads.iteritems():
cookedQuads = [] cookedQuads = []
for (box, face, texture, uv, cullface, shade, rotation, textureRotation, for (box, face, texture, uv, cullface, shade, rotation, textureRotation,
@ -307,8 +333,18 @@ cdef class BlockModels(object):
cookedQuads.append((xyzuvc, cullface)) cookedQuads.append((xyzuvc, cullface))
cookedModels[nameAndState] = cookedQuads cookedModels[nameAndState] = cookedQuads
ID, meta = self.blocktypes.IDsByState[nameAndState] try:
self.storeQuads(cookedQuads, ID, meta) ID, meta = self.blocktypes.IDsByState[nameAndState]
except KeyError:
pass
else:
self.storeQuads(cookedQuads, ID, meta)
stoneModels = cookedModels['MCEDIT_UNKNOWN']
for ID in range(4096):
for meta in range(16):
if self.cookedModelsByID[ID][meta].count == 0:
self.storeQuads(stoneModels, ID, meta)
self.cookedModels = cookedModels self.cookedModels = cookedModels
self.cooked = True self.cooked = True

View File

@ -12,6 +12,7 @@ from mcedit2.util.load_png import loadPNGData
from mcedit2.rendering.lightmap import generateLightmap from mcedit2.rendering.lightmap import generateLightmap
from mcedit2.resourceloader import ResourceLoader from mcedit2.resourceloader import ResourceLoader
from mcedit2.util import glutils from mcedit2.util import glutils
from mcedit2.util.resources import resourcePath
from mceditlib import util from mceditlib import util
@ -87,22 +88,16 @@ class TextureAtlas(object):
self._terrainTexture = None self._terrainTexture = None
self._maxLOD = maxLOD self._maxLOD = maxLOD
missingno = numpy.empty((16, 16, 4), 'uint8')
missingno[:] = [[[0xff, 0x00, 0xff, 0xff]]]
missingnoTexture = 16, 16, missingno
names = set() names = set()
self._rawTextures = rawTextures = [] self._rawTextures = rawTextures = []
assert "MCEDIT_UNKNOWN" in blockModels.getTextureNames()
for filename in blockModels.getTextureNames(): for filename in blockModels.getTextureNames():
if filename in names: if filename in names:
continue continue
try: try:
if filename == "missingno": f = self._openImageStream(filename)
rawTextures.append((filename,) + missingnoTexture) rawTextures.append((filename,) + loadPNGData(f.read()))
else:
f = self._openImageStream(filename)
rawTextures.append((filename,) + loadPNGData(f.read()))
names.add(filename) names.add(filename)
log.debug("Loaded texture %s", filename) log.debug("Loaded texture %s", filename)
except KeyError as e: except KeyError as e:
@ -115,6 +110,7 @@ class TextureAtlas(object):
log.info("Preloaded %d textures for world %s (%i kB)", log.info("Preloaded %d textures for world %s (%i kB)",
len(self._rawTextures), util.displayName(self._filename), rawSize/1024) len(self._rawTextures), util.displayName(self._filename), rawSize/1024)
def load(self): def load(self):
if self._terrainTexture: if self._terrainTexture:
return return
@ -211,8 +207,9 @@ class TextureAtlas(object):
#raise SystemExit #raise SystemExit
def _openImageStream(self, name): def _openImageStream(self, name):
if name == "missingno": if name == "MCEDIT_UNKNOWN":
name = "stone" block_unknown = resourcePath("mcedit2/assets/mcedit2/block_unknown.png")
return file(block_unknown, "rb")
return self._resourceLoader.openStream("textures/" + name + ".png") return self._resourceLoader.openStream("textures/" + name + ".png")
def bindTerrain(self): def bindTerrain(self):

View File

@ -92,7 +92,7 @@ class BlockTypeSet(object):
'blockState': '[UNKNOWN_STATE]', 'blockState': '[UNKNOWN_STATE]',
'unlocalizedName': 'name.unknown', 'unlocalizedName': 'name.unknown',
'opaqueCube': True, 'opaqueCube': True,
'renderType': -1, #xxx unknowns 'renderType': 3, # Model block - defaults to stone(?)
} }
self.aka = defaultdict(lambda: "") self.aka = defaultdict(lambda: "")