Browse Source

Implement kBlendAlpha flag (and BlendSpans)

pull/6/head
Adam Johnson 10 years ago
parent
commit
eb323b30c3
  1. 18
      korman/exporter/material.py
  2. 25
      korman/exporter/mesh.py

18
korman/exporter/material.py

@ -110,15 +110,16 @@ class _Texture:
assert (texture or image) assert (texture or image)
if texture is not None: if texture is not None:
self.image = texture.image if image is None:
image = texture.image
self.calc_alpha = texture.use_calculate_alpha self.calc_alpha = texture.use_calculate_alpha
self.mipmap = texture.use_mipmap self.mipmap = texture.use_mipmap
self.use_alpha = texture.use_alpha else:
if image is not None:
self.image = image
self.calc_alpha = False self.calc_alpha = False
self.mipmap = False self.mipmap = False
self.use_alpha = image.use_alpha
self.image = image
self.use_alpha = (image.channels == 4 and image.use_alpha)
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, _Texture): if not isinstance(other, _Texture):
@ -222,10 +223,15 @@ class MaterialConverter:
def _export_texture_type_image(self, bo, hsgmat, layer, texture): def _export_texture_type_image(self, bo, hsgmat, layer, texture):
"""Exports a Blender ImageTexture to a plLayer""" """Exports a Blender ImageTexture to a plLayer"""
# Does the image have any alpha at all?
has_alpha = (texture.image.channels == 4 and texture.image.use_alpha) or texture.use_calculate_alpha
# First, let's apply any relevant flags # First, let's apply any relevant flags
state = layer.state state = layer.state
if texture.invert_alpha: if texture.invert_alpha and has_alpha:
state.blendFlags |= hsGMatState.kBlendInvertAlpha state.blendFlags |= hsGMatState.kBlendInvertAlpha
if texture.use_alpha and has_alpha:
state.blendFlags |= hsGMatState.kBlendAlpha
if texture.extension == "CLIP": if texture.extension == "CLIP":
state.clampFlags |= hsGMatState.kClampTexture state.clampFlags |= hsGMatState.kClampTexture

25
korman/exporter/mesh.py

@ -37,10 +37,13 @@ class _RenderLevel:
_MAJOR_SHIFT = 28 _MAJOR_SHIFT = 28
_MINOR_MASK = ((1 << _MAJOR_SHIFT) - 1) _MINOR_MASK = ((1 << _MAJOR_SHIFT) - 1)
def __init__(self, hsgmat, pass_index): def __init__(self, hsgmat, pass_index, blendSpan=False):
# TODO: Use hsGMaterial to determine major and minor
self.level = 0 self.level = 0
# Naive... BlendSpans (any blending on the first layer) are MAJOR_BLEND
if blendSpan:
self.major = self.MAJOR_BLEND
# We use the blender material's pass index (which we stashed in the hsGMaterial) to increment # We use the blender material's pass index (which we stashed in the hsGMaterial) to increment
# the render pass, just like it says... # the render pass, just like it says...
self.level += pass_index self.level += pass_index
@ -52,15 +55,15 @@ class _RenderLevel:
return hash(self.level) return hash(self.level)
def _get_major(self): def _get_major(self):
return self.level >> _MAJOR_SHIFT return self.level >> self._MAJOR_SHIFT
def _set_major(self, value): def _set_major(self, value):
self.level = ((value << _MAJOR_SHIFT) & 0xFFFFFFFF) | self.minor self.level = ((value << self._MAJOR_SHIFT) & 0xFFFFFFFF) | self.minor
major = property(_get_major, _set_major) major = property(_get_major, _set_major)
def _get_minor(self): def _get_minor(self):
return self.level & _MINOR_MASK return self.level & self._MINOR_MASK
def _set_minor(self, value): def _set_minor(self, value):
self.level = ((self.major << _MAJOR_SHIFT) & 0xFFFFFFFF) | value self.level = ((self.major << self._MAJOR_SHIFT) & 0xFFFFFFFF) | value
minor = property(_get_minor, _set_minor) minor = property(_get_minor, _set_minor)
@ -69,7 +72,7 @@ class _DrawableCriteria:
_layer = hsgmat.layers[0].object # better doggone well have a layer... _layer = hsgmat.layers[0].object # better doggone well have a layer...
self.blend_span = bool(_layer.state.blendFlags & hsGMatState.kBlendMask) self.blend_span = bool(_layer.state.blendFlags & hsGMatState.kBlendMask)
self.criteria = 0 # TODO self.criteria = 0 # TODO
self.render_level = _RenderLevel(hsgmat, pass_index) self.render_level = _RenderLevel(hsgmat, pass_index, self.blend_span)
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, _DrawableCriteria): if not isinstance(other, _DrawableCriteria):
@ -105,10 +108,10 @@ class MeshConverter:
self._dspans = {} self._dspans = {}
self._mesh_geospans = {} self._mesh_geospans = {}
def _create_geospan(self, bo, mesh, bm, hsgmat): def _create_geospan(self, bo, mesh, bm, hsgmatKey):
"""Initializes a plGeometrySpan from a Blender Object and an hsGMaterial""" """Initializes a plGeometrySpan from a Blender Object and an hsGMaterial"""
geospan = plGeometrySpan() geospan = plGeometrySpan()
geospan.material = hsgmat geospan.material = hsgmatKey
# GeometrySpan format # GeometrySpan format
# For now, we really only care about the number of UVW Channels # For now, we really only care about the number of UVW Channels
@ -289,8 +292,8 @@ class MeshConverter:
"""Exports all Materials and creates plGeometrySpans""" """Exports all Materials and creates plGeometrySpans"""
geospans = [None] * len(mesh.materials) geospans = [None] * len(mesh.materials)
for i, blmat in enumerate(mesh.materials): for i, blmat in enumerate(mesh.materials):
hsgmat = self.material.export_material(bo, blmat) matKey = self.material.export_material(bo, blmat)
geospans[i] = (self._create_geospan(bo, mesh, blmat, hsgmat), blmat.pass_index) geospans[i] = (self._create_geospan(bo, mesh, blmat, matKey), blmat.pass_index)
return geospans return geospans
def _export_static_lighting(self, bo): def _export_static_lighting(self, bo):

Loading…
Cancel
Save