Minor cook fixes

This commit is contained in:
Jack Andersen 2018-04-03 22:28:13 -10:00
parent 94988eb9e5
commit b54dedb22b
3 changed files with 78 additions and 51 deletions

View File

@ -168,6 +168,50 @@ def animin_loop(globals):
pt.interpolation = 'LINEAR'
pt.co = (key_data[0], key_data[1])
def writelight(obj):
wmtx = obj.matrix_world
writepipebuf(struct.pack('ffffffffffffffff',
wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3],
wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3],
wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3],
wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3]))
writepipebuf(struct.pack('fff', obj.data.color[0], obj.data.color[1], obj.data.color[2]))
type = 2
spotCutoff = 0.0
hasFalloff = False
castShadow = False
if obj.data.type == 'POINT':
type = 2
hasFalloff = True
castShadow = obj.data.shadow_method != 'NOSHADOW'
elif obj.data.type == 'SPOT':
type = 3
hasFalloff = True
spotCutoff = obj.data.spot_size
castShadow = obj.data.shadow_method != 'NOSHADOW'
elif obj.data.type == 'SUN':
type = 1
castShadow = obj.data.shadow_method != 'NOSHADOW'
constant = 1.0
linear = 0.0
quadratic = 0.0
if hasFalloff:
if obj.data.falloff_type == 'INVERSE_COEFFICIENTS':
constant = obj.data.constant_coefficient
linear = obj.data.linear_coefficient
quadratic = obj.data.quadratic_coefficient
layer = 0
if 'retro_layer' in obj.data.keys():
layer = obj.data['retro_layer']
writepipebuf(struct.pack('IIfffffb', layer, type, obj.data.energy, spotCutoff, constant, linear, quadratic,
castShadow))
writepipestr(obj.name.encode())
# Command loop for reading data from blender
def dataout_loop():
writepipestr(b'READY')
@ -295,11 +339,15 @@ def dataout_loop():
elif cmdargs[0] == 'LIGHTCOMPILEALL':
writepipestr(b'OK')
lampCount = 0;
lampCount = 0
firstSpot = None
for obj in bpy.context.scene.objects:
if obj.type == 'LAMP':
lampCount += 1
if firstSpot is None and obj.data.type == 'SPOT':
firstSpot = obj
# Ambient
world = bpy.context.scene.world
ambient_energy = 0.0
ambient_color = None
@ -312,6 +360,9 @@ def dataout_loop():
writepipebuf(struct.pack('I', lampCount))
if firstSpot is not None:
writelight(firstSpot)
if ambient_energy:
writepipebuf(struct.pack('ffffffffffffffff',
1.0, 0.0, 0.0, 0.0,
@ -322,50 +373,10 @@ def dataout_loop():
writepipebuf(struct.pack('IIfffffb', 0, 0, ambient_energy, 0.0, 1.0, 0.0, 0.0, False))
writepipestr(b'AMBIENT')
# Lamp objects
for obj in bpy.context.scene.objects:
if obj.type == 'LAMP':
wmtx = obj.matrix_world
writepipebuf(struct.pack('ffffffffffffffff',
wmtx[0][0], wmtx[0][1], wmtx[0][2], wmtx[0][3],
wmtx[1][0], wmtx[1][1], wmtx[1][2], wmtx[1][3],
wmtx[2][0], wmtx[2][1], wmtx[2][2], wmtx[2][3],
wmtx[3][0], wmtx[3][1], wmtx[3][2], wmtx[3][3]))
writepipebuf(struct.pack('fff', obj.data.color[0], obj.data.color[1], obj.data.color[2]))
type = 2
spotCutoff = 0.0
hasFalloff = False
castShadow = False
if obj.data.type == 'POINT':
type = 2
hasFalloff = True
castShadow = obj.data.shadow_method != 'NOSHADOW'
elif obj.data.type == 'SPOT':
type = 3
hasFalloff = True
spotCutoff = obj.data.spot_size
castShadow = obj.data.shadow_method != 'NOSHADOW'
elif obj.data.type == 'SUN':
type = 1
castShadow = obj.data.shadow_method != 'NOSHADOW'
constant = 1.0
linear = 0.0
quadratic = 0.0
if hasFalloff:
if obj.data.falloff_type == 'INVERSE_COEFFICIENTS':
constant = obj.data.constant_coefficient
linear = obj.data.linear_coefficient
quadratic = obj.data.quadratic_coefficient
layer = 0
if 'retro_layer' in obj.data.keys():
layer = obj.data['retro_layer']
writepipebuf(struct.pack('IIfffffb', layer, type, obj.data.energy, spotCutoff, constant, linear, quadratic,
castShadow))
writepipestr(obj.name.encode())
if obj != firstSpot and obj.type == 'LAMP':
writelight(obj)
elif cmdargs[0] == 'GETTEXTURES':
writepipestr(b'OK')

View File

@ -188,6 +188,20 @@ struct GX : IBackend
TEV_KASEL_K3_A = 0x1F
};
enum ChannelID
{
GX_COLOR0,
GX_COLOR1,
GX_ALPHA0,
GX_ALPHA1,
GX_COLOR0A0,
GX_COLOR1A1,
GX_COLOR_ZERO,
GX_ALPHA_BUMP,
GX_ALPHA_BUMPN,
GX_COLOR_NULL = 0xff
};
enum TexGenSrc
{
TG_POS = 0,

View File

@ -50,7 +50,8 @@ unsigned GX::addTexCoordGen(Diagnostics& diag, const SourceLocation& loc,
for (unsigned i=0 ; i<m_tcgCount ; ++i)
{
TexCoordGen& tcg = m_tcgs[i];
if (tcg.m_src == src && tcg.m_mtx == mtx && tcg.m_norm && tcg.m_pmtx)
if (tcg.m_src == src && tcg.m_mtx == mtx &&
tcg.m_norm == norm && tcg.m_pmtx == pmtx)
return i;
}
if (m_tcgCount >= 8)
@ -112,8 +113,9 @@ unsigned GX::RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Ins
/* Otherwise treat as game-specific function */
const IR::Instruction& tcgSrcInst = inst.getChildInst(ir, 0);
bool doNorm = normalize || tcgName.back() == 'N';
unsigned idx = RecursiveTraceTexGen(ir, diag, tcgSrcInst, TexMtx(TEXMTX0 + m_texMtxCount * 3),
normalize || tcgName.back() == 'N', PTTexMtx(PTTEXMTX0 + m_texMtxCount * 3));
doNorm, doNorm ? PTTexMtx(PTTEXMTX0 + m_texMtxCount * 3) : PTIDENTITY);
GX::TexCoordGen& tcg = m_tcgs[idx];
m_texMtxRefs[m_texMtxCount] = &tcg;
++m_texMtxCount;
@ -201,11 +203,7 @@ GX::TraceResult GX::RecursiveTraceColor(const IR& ir, Diagnostics& diag, const I
if (aTrace.type == TraceResult::Type::TEVStage &&
bTrace.type == TraceResult::Type::TEVStage &&
getStageIdx(aTrace.tevStage) > getStageIdx(bTrace.tevStage))
{
TraceResult tmp = aTrace;
aTrace = bTrace;
bTrace = tmp;
}
std::swap(aTrace, bTrace);
TevKColorSel newKColor = TEV_KCSEL_1;
if (aTrace.type == TraceResult::Type::TEVKColorSel &&
@ -514,6 +512,10 @@ GX::TraceResult GX::RecursiveTraceAlpha(const IR& ir, Diagnostics& diag, const I
aTrace = RecursiveTraceAlpha(ir, diag, aInst);
bTrace = RecursiveTraceAlpha(ir, diag, bInst);
}
if (aTrace.type == TraceResult::Type::TEVStage &&
bTrace.type == TraceResult::Type::TEVStage &&
getStageIdx(aTrace.tevStage) > getStageIdx(bTrace.tevStage))
std::swap(aTrace, bTrace);
TevKAlphaSel newKAlpha = TEV_KASEL_1;
if (aTrace.type == TraceResult::Type::TEVKAlphaSel &&