BlockModelMesh -> modelmesh.py

This commit is contained in:
David Vierra 2015-01-01 05:11:02 -10:00
parent 8ce6571f88
commit bcf904c548
3 changed files with 85 additions and 75 deletions

View File

@ -69,13 +69,13 @@ class BlockModels(object):
# 'parent' will be the name of a model # 'parent' will be the name of a model
# following 'parent' keys will eventually lead to a model with 'elements' # following 'parent' keys will eventually lead to a model with 'elements'
# #
# 'elements' is a list of dicts each describing a cube that makes up the model. # 'elements' is a list of dicts each describing a box that makes up the model.
# each cube dict has 'from' and 'to' keys, which are lists of 3 float coordinates. # each box dict has 'from' and 'to' keys, which are lists of 3 float coordinates.
# #
# the 'crossed squares' model demonstrates most of the keys found in a cube element # the 'crossed squares' model demonstrates most of the keys found in a box element
# #
# { "from": [ 0.8, 0, 8 ], # { "from": [ 0.8, 0, 8 ],
# "to": [ 15.2, 16, 8 ], # "to": [ 15.2, 16, 8 ],
# "rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true }, # "rotation": { "origin": [ 8, 8, 8 ], "axis": "y", "angle": 45, "rescale": true },
# "shade": false, # "shade": false,
# "faces": { # "faces": {
@ -87,9 +87,9 @@ class BlockModels(object):
# model may also have a 'textures' dict which assigns a texture file to a texture variable, # model may also have a 'textures' dict which assigns a texture file to a texture variable,
# or a texture variable to another texture variable. # or a texture variable to another texture variable.
# #
# the result of loading a model should be a list of quads, with four vertexes and four pairs of texture # the result of loading a model should be a list of quads, each with four vertexes, four pairs of
# coordinates each, plus a Face telling which adjacent block when present causes that quad to be # texture coordinates, four RGBA values for shading, plus a Face telling which adjacent block when
# culled. # present causes that quad to be culled.
textureVars = {} textureVars = {}
allElements = [] allElements = []

View File

@ -3,17 +3,15 @@
""" """
from __future__ import absolute_import, division, print_function, unicode_literals from __future__ import absolute_import, division, print_function, unicode_literals
import logging import logging
import itertools
import pprint
import numpy import numpy
from mcedit2.rendering import layers, renderstates from mcedit2.rendering import layers
from mcedit2.rendering.chunkmeshes.entitymesh import TileEntityMesh, MonsterRenderer, ItemRenderer from mcedit2.rendering.chunkmeshes.entitymesh import TileEntityMesh, MonsterRenderer, ItemRenderer
from mcedit2.rendering.chunkmeshes.lowdetail import LowDetailBlockMesh, OverheadBlockMesh from mcedit2.rendering.chunkmeshes.lowdetail import LowDetailBlockMesh, OverheadBlockMesh
from mcedit2.rendering.chunkmeshes.terrainpop import TerrainPopulatedRenderer from mcedit2.rendering.chunkmeshes.terrainpop import TerrainPopulatedRenderer
from mcedit2.rendering.chunkmeshes.tileticks import TileTicksRenderer from mcedit2.rendering.chunkmeshes.tileticks import TileTicksRenderer
from mcedit2.rendering.vertexarraybuffer import VertexArrayBuffer from mcedit2.rendering.modelmesh import BlockModelMesh
from mcedit2.util import profiler from mcedit2.util import profiler
from mcedit2.util.lazyprop import lazyprop from mcedit2.util.lazyprop import lazyprop
from mceditlib import faces from mceditlib import faces
@ -404,67 +402,3 @@ class SectionUpdate(object):
self.blockMeshes.append(modelMesh) self.blockMeshes.append(modelMesh)
yield yield
class BlockModelMesh(object):
renderstate = renderstates.RenderstateAlphaTestNode
def __init__(self, sectionUpdate):
"""
:param sectionUpdate:
:type sectionUpdate: SectionUpdate
:return:
:rtype:
"""
self.sectionUpdate = sectionUpdate
self.vertexArrays = []
def createVertexArrays(self):
chunk = self.sectionUpdate.chunkUpdate.chunk
cx, cz = chunk.chunkPosition
cy = self.sectionUpdate.cy
section = chunk.getSection(cy)
if section is None:
return
blockModels = self.sectionUpdate.chunkUpdate.updateTask.textureAtlas.blockModels
blocktypes = self.sectionUpdate.blocktypes
areaBlocks = self.sectionUpdate.areaBlocks
faceQuadVerts = []
for y in xrange(1, 17):
yield
for z, x in itertools.product(xrange(1, 17), xrange(1, 17)):
ID = areaBlocks[y, z, x]
if ID == 0:
continue
meta = section.Data[y-1, z-1, x-1]
block = blocktypes[ID, meta]
if block.renderType != 3: # only model blocks for now
continue
nameAndState = block.internalName + block.blockState
quads = blockModels.cookedModels[nameAndState]
for face, xyzuvc, cullface in quads:
if cullface is not None:
dx, dy, dz = cullface.vector
nx = x + dx
ny = y + dy
nz = z + dz
nID = areaBlocks[ny, nz, nx]
if nID != 0:
nBlock = blocktypes[nID]
if nBlock.opaqueCube:
continue
verts = numpy.array(xyzuvc)
verts.shape = 1, 4, 6
verts[..., :3] += (x - 1, y - 1 + (cy << 4), z - 1)
faceQuadVerts.append(verts)
# log.info("Block %s:\nVertices: %s", (x-1, y-1, z-1), verts)
# raise SystemExit
if len(faceQuadVerts):
vertexArray = VertexArrayBuffer(len(faceQuadVerts), lights=False)
vertexArray.buffer[..., :6] = numpy.vstack(faceQuadVerts)
self.vertexArrays = [vertexArray]

View File

@ -0,0 +1,76 @@
"""
${NAME}
"""
from __future__ import absolute_import, division, print_function
import itertools
import logging
import numpy
from mcedit2.rendering import renderstates
from mcedit2.rendering.vertexarraybuffer import VertexArrayBuffer
log = logging.getLogger(__name__)
class BlockModelMesh(object):
renderstate = renderstates.RenderstateAlphaTestNode
def __init__(self, sectionUpdate):
"""
:param sectionUpdate:
:type sectionUpdate: SectionUpdate
:return:
:rtype:
"""
self.sectionUpdate = sectionUpdate
self.vertexArrays = []
def createVertexArrays(self):
chunk = self.sectionUpdate.chunkUpdate.chunk
cx, cz = chunk.chunkPosition
cy = self.sectionUpdate.cy
section = chunk.getSection(cy)
if section is None:
return
blockModels = self.sectionUpdate.chunkUpdate.updateTask.textureAtlas.blockModels
blocktypes = self.sectionUpdate.blocktypes
areaBlocks = self.sectionUpdate.areaBlocks
faceQuadVerts = []
for y in xrange(1, 17):
yield
for z, x in itertools.product(xrange(1, 17), xrange(1, 17)):
ID = areaBlocks[y, z, x]
if ID == 0:
continue
meta = section.Data[y-1, z-1, x-1]
block = blocktypes[ID, meta]
if block.renderType != 3: # only model blocks for now
continue
nameAndState = block.internalName + block.blockState
quads = blockModels.cookedModels[nameAndState]
for face, xyzuvc, cullface in quads:
if cullface is not None:
dx, dy, dz = cullface.vector
nx = x + dx
ny = y + dy
nz = z + dz
nID = areaBlocks[ny, nz, nx]
if nID != 0:
nBlock = blocktypes[nID]
if nBlock.opaqueCube:
continue
verts = numpy.array(xyzuvc)
verts.shape = 1, 4, 6
verts[..., :3] += (x - 1, y - 1 + (cy << 4), z - 1)
faceQuadVerts.append(verts)
# log.info("Block %s:\nVertices: %s", (x-1, y-1, z-1), verts)
# raise SystemExit
if len(faceQuadVerts):
vertexArray = VertexArrayBuffer(len(faceQuadVerts), lights=False)
vertexArray.buffer[..., :6] = numpy.vstack(faceQuadVerts)
self.vertexArrays = [vertexArray]