From 1e804604056ebd0d06715838b35fb7d63adde5aa Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sat, 3 Jan 2015 13:32:04 -1000 Subject: [PATCH] cdef several int/float variables --- src/mcedit2/rendering/blockmodels.pyx | 24 +++++++++++++++++------- src/mcedit2/rendering/modelmesh.pyx | 24 ++++++++++++++++-------- src/mceditlib/blocktypes/__init__.py | 2 +- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/mcedit2/rendering/blockmodels.pyx b/src/mcedit2/rendering/blockmodels.pyx index cbbd72b..9fdee64 100644 --- a/src/mcedit2/rendering/blockmodels.pyx +++ b/src/mcedit2/rendering/blockmodels.pyx @@ -1,12 +1,17 @@ """ blockmodels """ -from __future__ import absolute_import, division, print_function +from __future__ import absolute_import, print_function import json import logging import math import numpy +cimport numpy + +from cpython cimport array +from array import array + from mceditlib import faces from mceditlib.geometry import Vector, FloatBox @@ -211,6 +216,9 @@ class BlockModels(object): def cookQuads(self, textureAtlas): cookedModels = {} cookedModelsByID = {} + cdef int l, t, w, h + cdef int u1, u2, v1, v2 + cdef int uw, vh for nameAndState, allQuads in self.modelQuads.iteritems(): cookedQuads = [] for (box, face, texture, uv, cullface, shade, rotation, textureRotation, @@ -218,14 +226,14 @@ class BlockModels(object): l, t, w, h = textureAtlas.texCoordsByName[texture] u1, v1, u2, v2 = uv - uw = (u2 - u1) / 16 - vh = (v2 - v1) / 16 + uw = (w * (u2 - u1)) / 16 + vh = (h * (v2 - v1)) / 16 u1 += l - u2 = u1 + uw * w + u2 = u1 + uw # flip v axis - texcoords origin is top left but model uv origin is from bottom left v1 = t + h - v1 - v2 = v1 - vh * w + v2 = v1 - vh uv = (u1, v1, u2, v2) @@ -376,8 +384,10 @@ faceShades = { } -def getBlockFaceVertices(box, face, uv, textureRotation): - x1, y1, z1, = box.origin +cdef getBlockFaceVertices(box, face, tuple uv, textureRotation): + cdef float x1, y1, z1, x2, y2, z2, + cdef int u1, v1, u2, v2 + x1, y1, z1 = box.origin x2, y2, z2 = box.maximum u1, v1, u2, v2 = uv tc = [ diff --git a/src/mcedit2/rendering/modelmesh.pyx b/src/mcedit2/rendering/modelmesh.pyx index 98ffc77..91aaccf 100644 --- a/src/mcedit2/rendering/modelmesh.pyx +++ b/src/mcedit2/rendering/modelmesh.pyx @@ -2,9 +2,11 @@ ${NAME} """ from __future__ import absolute_import, division, print_function -import itertools import logging + import numpy +cimport numpy + from mcedit2.rendering import renderstates from mcedit2.rendering.vertexarraybuffer import VertexArrayBuffer @@ -25,6 +27,11 @@ class BlockModelMesh(object): self.vertexArrays = [] def createVertexArrays(self): + cdef numpy.ndarray[numpy.uint16_t, ndim=3] areaBlocks + #cdef numpy.ndarray[numpy.uint8_t, ndim=3] data + cdef numpy.ndarray[numpy.uint8_t, ndim=1] renderType + cdef numpy.ndarray[numpy.uint8_t, ndim=1] opaqueCube + chunk = self.sectionUpdate.chunkUpdate.chunk cx, cz = chunk.chunkPosition cy = self.sectionUpdate.cy @@ -35,6 +42,10 @@ class BlockModelMesh(object): blockModels = self.sectionUpdate.chunkUpdate.updateTask.textureAtlas.blockModels blocktypes = self.sectionUpdate.blocktypes areaBlocks = self.sectionUpdate.areaBlocks + data = section.Data + renderType = self.sectionUpdate.renderType + opaqueCube = blocktypes.opaqueCube + faceQuadVerts = [] cdef unsigned short y, z, x, ID, meta @@ -47,10 +58,9 @@ class BlockModelMesh(object): ID = areaBlocks[y, z, x] if ID == 0: continue - meta = section.Data[y-1, z-1, x-1] + meta = data[y-1, z-1, x-1] - block = blocktypes[ID, meta] - if block.renderType != 3: # only model blocks for now + if renderType[ID] != 3: # only model blocks for now continue quads = blockModels.cookedModelsByID.get((ID, meta)) if quads is None: @@ -63,10 +73,8 @@ class BlockModelMesh(object): ny = y + dy nz = z + dz nID = areaBlocks[ny, nz, nx] - if nID != 0: - nBlock = blocktypes[nID] - if nBlock.opaqueCube: - continue + if opaqueCube[nID]: + continue verts = numpy.array(xyzuvc) verts.shape = 1, 4, 6 diff --git a/src/mceditlib/blocktypes/__init__.py b/src/mceditlib/blocktypes/__init__.py index 6812b74..fafc6ba 100644 --- a/src/mceditlib/blocktypes/__init__.py +++ b/src/mceditlib/blocktypes/__init__.py @@ -108,7 +108,7 @@ class BlockTypeSet(object): self.mapColor = numpy.zeros((id_limit, 16, 3), dtype='uint8') self.mapColor[:] = 0xFF - self.opaqueCube = numpy.ones((id_limit, ), dtype='bool') + self.opaqueCube = numpy.ones((id_limit, ), dtype='uint8') self.opaqueCube[0] = 0 self.name = "Unnamed Set"