Add Chest and Large Chest models
This commit is contained in:
parent
f32c8b13bc
commit
5b963e6222
62
src/mcedit2/rendering/chunkmeshes/entity/chest.py
Normal file
62
src/mcedit2/rendering/chunkmeshes/entity/chest.py
Normal file
@ -0,0 +1,62 @@
|
||||
"""
|
||||
chest
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
import logging
|
||||
from mcedit2.rendering.chunkmeshes.entity.modelrenderer import ModelRenderer
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ModelChest(object):
|
||||
textureWidth = 64
|
||||
textureHeight = 64
|
||||
|
||||
tileEntityID = "Chest"
|
||||
|
||||
modelTexture = "assets/minecraft/textures/entity/chest/normal.png"
|
||||
|
||||
def __init__(self):
|
||||
self.chestLid = ModelRenderer(self, 0, 0)
|
||||
self.chestLid.addBox(0.0, -5.0, -14.0, 14, 5, 14, 0.0)
|
||||
self.chestLid.setCenterPoint(1., 7., 15.)
|
||||
|
||||
self.chestKnob = ModelRenderer(self, 0, 0)
|
||||
self.chestKnob.addBox(-1.0, -2.0, -15.0, 2, 4, 1, 0.0)
|
||||
self.chestKnob.setCenterPoint(8., 7., 15.)
|
||||
|
||||
self.chestBelow = ModelRenderer(self, 0, 19)
|
||||
self.chestBelow.addBox(0.0, 0.0, 0.0, 14, 10, 14, 0.0)
|
||||
self.chestBelow.setCenterPoint(1., 6., 1.)
|
||||
|
||||
|
||||
self.parts = [
|
||||
self.chestLid,
|
||||
self.chestKnob,
|
||||
self.chestBelow,
|
||||
]
|
||||
|
||||
class ModelLargeChest(object):
|
||||
textureWidth = 128
|
||||
textureHeight = 64
|
||||
|
||||
modelTexture = "assets/minecraft/textures/entity/chest/normal_double.png"
|
||||
tileEntityID = "MCEDIT_LargeChest" # gross
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.chestLid = ModelRenderer(self, 0, 0)
|
||||
self.chestLid.addBox(0.0, -5.0, -14.0, 30, 5, 14, 0.0)
|
||||
self.chestLid.setCenterPoint(1., 7., 15.)
|
||||
self.chestKnob = ModelRenderer(self, 0, 0)
|
||||
self.chestKnob.addBox(-1.0, -2.0, -15.0, 2, 4, 1, 0.0)
|
||||
self.chestKnob.setCenterPoint(16., 7., 15.)
|
||||
self.chestBelow = ModelRenderer(self, 0, 19)
|
||||
self.chestBelow.addBox(0.0, 0.0, 0.0, 30, 10, 14, 0.0)
|
||||
self.chestBelow.setCenterPoint(1., 6., 1.)
|
||||
|
||||
self.parts = [
|
||||
self.chestLid,
|
||||
self.chestKnob,
|
||||
self.chestBelow,
|
||||
]
|
@ -9,6 +9,7 @@ import numpy
|
||||
from mcedit2.rendering.chunkmeshes.entity.armorstand import ModelArmorStand
|
||||
from mcedit2.rendering.chunkmeshes.entity.biped import ModelZombie, ModelSkeleton, \
|
||||
ModelPigZombie
|
||||
from mcedit2.rendering.chunkmeshes.entity.chest import ModelChest, ModelLargeChest
|
||||
from mcedit2.rendering.chunkmeshes.entity.creeper import ModelCreeper
|
||||
from mcedit2.rendering.chunkmeshes.entity.quadruped import ModelPig, ModelCow, ModelSheep, \
|
||||
ModelSheepWool
|
||||
@ -111,7 +112,7 @@ def npRotate(axis, angle, rescale=False):
|
||||
# xxx rescale
|
||||
return rotate
|
||||
|
||||
CookedModel = collections.namedtuple('CookedModel', 'vertices texWidth texHeight')
|
||||
CookedModel = collections.namedtuple('CookedModel', 'vertices texWidth texHeight modelTexture')
|
||||
|
||||
def cookEntityModel(model):
|
||||
allVerts = []
|
||||
@ -136,14 +137,23 @@ def cookEntityModel(model):
|
||||
|
||||
allVerts.append((x+cx, y+cy, z+cz, u, v))
|
||||
|
||||
return CookedModel(allVerts, model.textureWidth, model.textureHeight)
|
||||
return CookedModel(allVerts, model.textureWidth, model.textureHeight, model.modelTexture)
|
||||
|
||||
cookedModels = {}
|
||||
models = {}
|
||||
|
||||
cookedTileEntityModels = {}
|
||||
tileEntityModels = {}
|
||||
|
||||
|
||||
def addModel(model):
|
||||
cookedModels[model.id] = cookEntityModel(model)
|
||||
models[model.id] = model
|
||||
if hasattr(model, 'id'):
|
||||
cookedModels[model.id] = cookEntityModel(model)
|
||||
models[model.id] = model
|
||||
else:
|
||||
cookedTileEntityModels[model.tileEntityID] = cookEntityModel(model)
|
||||
tileEntityModels[model.tileEntityID] = model
|
||||
|
||||
|
||||
def getModelTexture(entityRef):
|
||||
model = models.get(entityRef.id)
|
||||
@ -168,6 +178,8 @@ addModel(ModelSheep())
|
||||
addModel(ModelSheepWool())
|
||||
addModel(ModelVillager())
|
||||
addModel(ModelArmorStand())
|
||||
addModel(ModelChest())
|
||||
addModel(ModelLargeChest())
|
||||
|
||||
if __name__ == '__main__':
|
||||
from pprint import pprint
|
||||
|
@ -14,7 +14,7 @@ from mcedit2.rendering.blockmeshes import ChunkMeshBase
|
||||
from mcedit2.rendering.chunkmeshes.entity import models
|
||||
from mcedit2.rendering.layers import Layer
|
||||
from mcedit2.rendering.scenegraph.bind_texture import BindTextureNode
|
||||
from mcedit2.rendering.scenegraph.matrix import TranslateNode, RotateNode
|
||||
from mcedit2.rendering.scenegraph.matrix import TranslateNode, RotateNode, ScaleNode
|
||||
from mcedit2.rendering.scenegraph.misc import PolygonModeNode, LineWidthNode
|
||||
from mcedit2.rendering.scenegraph.depth_test import DepthFuncNode
|
||||
from mcedit2.rendering.scenegraph.scenenode import Node
|
||||
@ -441,6 +441,95 @@ class MonsterModelRenderer(ChunkMeshBase):
|
||||
self.sceneNode = sceneNode
|
||||
|
||||
|
||||
def chestEntityModelNode(ref, model, modelTex, chunk, facing, largeX, largeZ):
|
||||
modelVerts = numpy.array(model.vertices)
|
||||
modelVerts.shape = modelVerts.shape[0]/4, 4, modelVerts.shape[1]
|
||||
# scale down
|
||||
modelVerts[..., :3] *= 1/16.
|
||||
# modelVerts[..., 1] = -modelVerts[..., 1]
|
||||
# modelVerts[..., 0] = -modelVerts[..., 0]
|
||||
|
||||
vertexBuffer = QuadVertexArrayBuffer(len(modelVerts), lights=False, textures=True)
|
||||
vertexBuffer.vertex[:] = modelVerts[..., :3]
|
||||
vertexBuffer.texcoord[:] = modelVerts[..., 3:5]
|
||||
|
||||
node = VertexNode([vertexBuffer])
|
||||
rotations = {
|
||||
"north": 180,
|
||||
"east": 270,
|
||||
"south": 0,
|
||||
"west": 90
|
||||
}
|
||||
decenterTranslateNode = TranslateNode((-0.5, -0.5, -0.5))
|
||||
decenterTranslateNode.addChild(node)
|
||||
|
||||
rotateNode = RotateNode(rotations[facing], (0., 1., 0.))
|
||||
# rotateNode = RotateNode(0, (0., 1., 0.))
|
||||
rotateNode.addChild(decenterTranslateNode)
|
||||
dx = dz = 0
|
||||
if largeX and facing == "north":
|
||||
dx = 1.
|
||||
if largeZ and facing == "east":
|
||||
dz = -1.
|
||||
recenterTranslateNode = TranslateNode((0.5+dx, 0.5, 0.5+dz))
|
||||
recenterTranslateNode.addChild(rotateNode)
|
||||
x, y, z = (ref.Position - (chunk.cx << 4, 0, chunk.cz << 4))
|
||||
scaleNode = ScaleNode((1., -1., -1.))
|
||||
scaleNode.addChild(recenterTranslateNode)
|
||||
posTranslateNode = TranslateNode((x, y+1., z+1.))
|
||||
posTranslateNode.addChild(scaleNode)
|
||||
|
||||
textureNode = BindTextureNode(modelTex, (1./model.texWidth, 1./model.texHeight, 1))
|
||||
textureNode.addChild(posTranslateNode)
|
||||
return textureNode
|
||||
|
||||
class TileEntityModelRenderer(ChunkMeshBase):
|
||||
layer = Layer.TileEntities
|
||||
|
||||
def makeChunkVertices(self, chunk, limitBox):
|
||||
sceneNode = scenenode.Node()
|
||||
chests = {}
|
||||
for i, ref in enumerate(chunk.TileEntities):
|
||||
ID = ref.id
|
||||
if ID not in models.cookedTileEntityModels:
|
||||
continue
|
||||
if ID == "Chest":
|
||||
chests[ref.Position] = ref, {}
|
||||
continue
|
||||
|
||||
for (x, y, z), (ref, adj) in chests.iteritems():
|
||||
for dx, dz in ((-1, 0), (1, 0), (0, -1), (0, 1)):
|
||||
if (x+dx, y, z+dz) in chests:
|
||||
adj[dx, dz] = ref
|
||||
|
||||
for ref, adj in chests.itervalues():
|
||||
if (-1, 0) not in adj and (0, -1) not in adj:
|
||||
if (1, 0) not in adj and (0, 1) not in adj:
|
||||
model = models.cookedTileEntityModels[ref.id]
|
||||
else:
|
||||
model = models.cookedTileEntityModels["MCEDIT_LargeChest"]
|
||||
|
||||
texturePath = model.modelTexture
|
||||
if texturePath is None:
|
||||
modelTex = None
|
||||
else:
|
||||
modelTex = self.chunkUpdate.updateTask.getModelTexture(texturePath)
|
||||
|
||||
block = chunk.dimension.getBlock(*ref.Position)
|
||||
if block.internalName != "minecraft:chest":
|
||||
continue
|
||||
blockState = block.blockState[1:-1]
|
||||
facing = blockState.split("=")[1]
|
||||
|
||||
node = chestEntityModelNode(ref, model, modelTex, chunk, facing,
|
||||
(1, 0) in adj, (0, 1) in adj)
|
||||
sceneNode.addChild(node)
|
||||
|
||||
yield
|
||||
|
||||
self.sceneNode = sceneNode
|
||||
|
||||
|
||||
class MonsterLocationRenderer(EntityMeshBase):
|
||||
layer = Layer.MonsterLocations
|
||||
notMonsters = {"Item", "XPOrb", "Painting", "ItemFrame"}
|
||||
|
@ -10,7 +10,8 @@ from mcedit2.rendering.modelmesh import BlockModelMesh
|
||||
from mcedit2.rendering import layers
|
||||
from mcedit2.rendering.chunkmeshes.chunksections import ChunkSectionsRenderer
|
||||
from mcedit2.rendering.chunkmeshes.entitymesh import TileEntityLocationMesh, MonsterLocationRenderer, ItemRenderer, \
|
||||
ItemFrameMesh, MonsterModelRenderer, CommandBlockColorsMesh, CommandBlockLocationMesh
|
||||
ItemFrameMesh, MonsterModelRenderer, CommandBlockColorsMesh, CommandBlockLocationMesh, \
|
||||
TileEntityModelRenderer
|
||||
from mcedit2.rendering.chunkmeshes.lowdetail import LowDetailBlockMesh, OverheadBlockMesh
|
||||
from mcedit2.rendering.chunkmeshes.terrainpop import TerrainPopulatedRenderer
|
||||
from mcedit2.rendering.chunkmeshes.tileticks import TileTicksRenderer
|
||||
@ -125,6 +126,7 @@ class ChunkUpdate(object):
|
||||
CommandBlockLocationMesh,
|
||||
CommandBlockColorsMesh,
|
||||
TileEntityLocationMesh,
|
||||
TileEntityModelRenderer,
|
||||
ItemFrameMesh,
|
||||
MonsterLocationRenderer,
|
||||
MonsterModelRenderer,
|
||||
|
Reference in New Issue
Block a user