2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-06-07 01:53:29 +00:00

Added lights and collision to MP3 MREA

This commit is contained in:
Jack Andersen 2015-09-22 15:15:11 -10:00
parent bb89194157
commit 7f5eebdaeb
4 changed files with 99 additions and 142 deletions

View File

@ -23,9 +23,6 @@ void DeafBabeSendToBlender(HECL::BlenderConnection::PyOutStream& os, const DEAFB
os << "col_bm.verts.ensure_lookup_table()\n"; os << "col_bm.verts.ensure_lookup_table()\n";
int triIdx = 0; int triIdx = 0;
#define TEST 0
#if TEST == 0
for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections) for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections)
{ {
const typename DEAFBABE::Material& triMat = db.materials[db.triMats[triIdx++]]; const typename DEAFBABE::Material& triMat = db.materials[db.triMats[triIdx++]];
@ -52,68 +49,8 @@ void DeafBabeSendToBlender(HECL::BlenderConnection::PyOutStream& os, const DEAFB
"\n", "\n",
triMat.material); triMat.material);
} }
#elif TEST == 1
for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections2) db.insertNoClimb(os);
{
if (tri.edges[0] != 65535)
{
const typename DEAFBABE::Edge& edge0 = db.edgeVertConnections[tri.edges[0]];
os.format("edge_verts = [col_bm.verts[%u], col_bm.verts[%u]]\n",
edge0.verts[0], edge0.verts[1]);
os << "edge = col_bm.edges.get(edge_verts)\n"
"if edge is None:\n"
" edge = col_bm.edges.new(edge_verts)\n"
"\n";
}
if (tri.edges[1] != 65535)
{
const typename DEAFBABE::Edge& edge1 = db.edgeVertConnections[tri.edges[1]];
os.format("edge_verts = [col_bm.verts[%u], col_bm.verts[%u]]\n",
edge1.verts[0], edge1.verts[1]);
os << "edge = col_bm.edges.get(edge_verts)\n"
"if edge is None:\n"
" edge = col_bm.edges.new(edge_verts)\n"
"\n";
}
if (tri.edges[2] != 65535)
{
const typename DEAFBABE::Edge& edge2 = db.edgeVertConnections[tri.edges[2]];
os.format("edge_verts = [col_bm.verts[%u], col_bm.verts[%u]]\n",
edge2.verts[0], edge2.verts[1]);
os << "edge = col_bm.edges.get(edge_verts)\n"
"if edge is None:\n"
" edge = col_bm.edges.new(edge_verts)\n"
"\n";
}
}
#elif TEST == 2
int max = 0;
for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections2)
{
for (int e=0 ; e<3 ; ++e)
{
if (tri.edges[e] == 65535)
continue;
const typename DEAFBABE::Edge& edge = db.edgeVertConnections.at(tri.edges[e]);
if (edge.verts[0] > max)
max = edge.verts[0];
if (edge.verts[1] > max)
max = edge.verts[1];
}
}
printf("MAX: %d\n", max);
#endif
os << "col_mesh = bpy.data.meshes.new('CMESH')\n" os << "col_mesh = bpy.data.meshes.new('CMESH')\n"
"col_bm.to_mesh(col_mesh)\n" "col_bm.to_mesh(col_mesh)\n"
@ -209,7 +146,7 @@ struct DeafBabe : BigDNA
Vector<atVec3f, DNA_COUNT(vertCount)> verts; Vector<atVec3f, DNA_COUNT(vertCount)> verts;
/* Dummy MP2 member */ /* Dummy MP2 member */
std::vector<Triangle> triangleEdgeConnections2; void insertNoClimb(HECL::BlenderConnection::PyOutStream&) const {}
static void BlenderInit(HECL::BlenderConnection::PyOutStream& os); static void BlenderInit(HECL::BlenderConnection::PyOutStream& os);
void sendToBlender(HECL::BlenderConnection::PyOutStream& os) const void sendToBlender(HECL::BlenderConnection::PyOutStream& os) const

View File

@ -62,8 +62,8 @@ struct DeafBabe : BigDNA
Vector<Edge, DNA_COUNT(edgeVertsCount)> edgeVertConnections; Vector<Edge, DNA_COUNT(edgeVertsCount)> edgeVertConnections;
Value<atUint32> triangleEdgesCount; Value<atUint32> triangleEdgesCount;
Vector<Triangle, DNA_COUNT(triangleEdgesCount / 3)> triangleEdgeConnections; Vector<Triangle, DNA_COUNT(triangleEdgesCount / 3)> triangleEdgeConnections;
Value<atUint32> triangleEdges2Count; Value<atUint32> noClimbEdgeCount;
Vector<Triangle, DNA_COUNT(triangleEdges2Count / 3)> triangleEdgeConnections2; Vector<atInt16, DNA_COUNT(noClimbEdgeCount)> noClimbEdges;
Value<atUint32> vertCount; Value<atUint32> vertCount;
Vector<atVec3f, DNA_COUNT(vertCount)> verts; Vector<atVec3f, DNA_COUNT(vertCount)> verts;
@ -71,6 +71,19 @@ struct DeafBabe : BigDNA
{ {
DNAMP1::DeafBabe::BlenderInit(os); DNAMP1::DeafBabe::BlenderInit(os);
} }
void insertNoClimb(HECL::BlenderConnection::PyOutStream& os) const
{
for (atInt16 edgeIdx : noClimbEdges)
{
if (edgeIdx == -1)
continue;
const Edge& edge = edgeVertConnections[edgeIdx];
os.format("edge = col_bm.edges.get((col_bm.verts[%u], col_bm.verts[%u]))\n"
"if edge:\n"
" edge.seam = True\n",
edge.verts[0], edge.verts[1]);
}
}
void sendToBlender(HECL::BlenderConnection::PyOutStream& os) const void sendToBlender(HECL::BlenderConnection::PyOutStream& os) const
{ {
DNAMP1::DeafBabeSendToBlender(os, *this); DNAMP1::DeafBabeSendToBlender(os, *this);

View File

@ -60,14 +60,13 @@ void MREA::ReadBabeDeadToBlender_3(HECL::BlenderConnection::PyOutStream& os,
{ {
BabeDeadLight light; BabeDeadLight light;
light.read(rs); light.read(rs);
#if 0
switch (light.lightType) switch (light.lightType)
{ {
case BabeDeadLight::LightLocalAmbient: case BabeDeadLight::LightLocalAmbient:
os.format("bg_node.inputs[0].default_value = (%f,%f,%f,1.0)\n" os.format("bg_node.inputs[0].default_value = (%f,%f,%f,1.0)\n"
"bg_node.inputs[1].default_value = %f\n", "bg_node.inputs[1].default_value = %f\n",
light.color.vec[0], light.color.vec[1], light.color.vec[2], light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.q / 8.0); light.unk6 / 8.0);
continue; continue;
case BabeDeadLight::LightDirectional: case BabeDeadLight::LightDirectional:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n" os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n"
@ -89,7 +88,7 @@ void MREA::ReadBabeDeadToBlender_3(HECL::BlenderConnection::PyOutStream& os,
"lamp_obj.rotation_mode = 'QUATERNION'\n" "lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n" "lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"\n", s, l, "\n", s, l,
light.spotCutoff * M_PI / 180.f, light.spotCutoff / 2.f,
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]); light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]);
break; break;
default: continue; default: continue;
@ -97,34 +96,36 @@ void MREA::ReadBabeDeadToBlender_3(HECL::BlenderConnection::PyOutStream& os,
os.format("lamp.retro_layer = %u\n" os.format("lamp.retro_layer = %u\n"
"lamp.use_nodes = True\n" "lamp.use_nodes = True\n"
"falloff_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\n" "quadratic_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\n"
"quadratic_node.inputs[0].default_value = %f\n"
"quadratic_node.location = (-600, 0)\n"
"linear_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\n"
"linear_node.inputs[0].default_value = %f\n"
"linear_node.location = (-400, 0)\n"
"constant_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\n"
"constant_node.inputs[0].default_value = %f\n"
"constant_node.location = (-200, 0)\n"
"add1 = lamp.node_tree.nodes.new('ShaderNodeMath')\n"
"add1.operation = 'ADD'\n"
"add1.location = (-400, -300)\n"
"add2 = lamp.node_tree.nodes.new('ShaderNodeMath')\n"
"add2.operation = 'ADD'\n"
"add2.location = (-200, -300)\n"
"lamp.node_tree.links.new(quadratic_node.outputs[0], add1.inputs[0])\n"
"lamp.node_tree.links.new(linear_node.outputs[1], add1.inputs[1])\n"
"lamp.node_tree.links.new(add1.outputs[0], add2.inputs[0])\n"
"lamp.node_tree.links.new(constant_node.outputs[2], add2.inputs[1])\n"
"lamp.node_tree.links.new(add2.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n"
"lamp.energy = 0.0\n" "lamp.energy = 0.0\n"
"falloff_node.inputs[0].default_value = %f\n"
"hue_sat_node = lamp.node_tree.nodes.new('ShaderNodeHueSaturation')\n" "hue_sat_node = lamp.node_tree.nodes.new('ShaderNodeHueSaturation')\n"
"hue_sat_node.inputs[1].default_value = 1.25\n" "hue_sat_node.inputs[1].default_value = 1.25\n"
"hue_sat_node.inputs[4].default_value = (%f,%f,%f,1.0)\n" "hue_sat_node.inputs[4].default_value = (%f,%f,%f,1.0)\n"
"lamp.node_tree.links.new(hue_sat_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[0])\n" "lamp.node_tree.links.new(hue_sat_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[0])\n"
"lamp_obj.location = (%f,%f,%f)\n" "lamp_obj.location = (%f,%f,%f)\n"
"bpy.context.scene.objects.link(lamp_obj)\n" "bpy.context.scene.objects.link(lamp_obj)\n"
"\n", s, light.q / 8.0, "\n", s, light.unk5, light.unk6, light.unk7,
light.color.vec[0], light.color.vec[1], light.color.vec[2], light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.position.vec[0], light.position.vec[1], light.position.vec[2]); light.position.vec[0], light.position.vec[1], light.position.vec[2]);
switch (light.falloff)
{
case BabeDeadLight::FalloffConstant:
os << "falloff_node.inputs[0].default_value *= 75.0\n"
"lamp.node_tree.links.new(falloff_node.outputs[2], lamp.node_tree.nodes['Emission'].inputs[1])\n";
break;
case BabeDeadLight::FalloffLinear:
os << "lamp.node_tree.links.new(falloff_node.outputs[1], lamp.node_tree.nodes['Emission'].inputs[1])\n";
break;
case BabeDeadLight::FalloffQuadratic:
os << "lamp.node_tree.links.new(falloff_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n";
break;
default: break;
}
#endif
} }
} }
} }
@ -197,31 +198,31 @@ bool MREA::Extract(const SpecBase& dataSpec,
/* Read mesh info */ /* Read mesh info */
atUint32 curSec = 1; atUint32 curSec = 1;
auto secIdxIt = drs.beginSecIdxs();
std::vector<atUint32> surfaceCounts; std::vector<atUint32> surfaceCounts;
surfaceCounts.reserve(head.meshCount); surfaceCounts.reserve(head.meshCount);
for (int m=0 ; m<head.meshCount ; ++m) for (int m=0 ; m<head.meshCount ; ++m)
{ {
if (secIdxIt->first == FOURCC('WOBJ')) /* Mesh header */
{ MeshHeader mHeader;
/* Mesh header */ secStart = drs.position();
MeshHeader mHeader; mHeader.read(drs);
secStart = drs.position(); drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
mHeader.read(drs);
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
/* Surface count from here */ /* Surface count from here */
secStart = drs.position(); secStart = drs.position();
surfaceCounts.push_back(drs.readUint32Big()); surfaceCounts.push_back(drs.readUint32Big());
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin); drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
/* Seek through AROT-relation sections */ /* Seek through AROT-relation sections */
drs.seek(head.secSizes[curSec++], Athena::Current); drs.seek(head.secSizes[curSec++], Athena::Current);
drs.seek(head.secSizes[curSec++], Athena::Current); drs.seek(head.secSizes[curSec++], Athena::Current);
++secIdxIt;
}
} }
/* Skip though WOBJs */
auto secIdxIt = drs.beginSecIdxs();
while (secIdxIt->first == FOURCC('WOBJ'))
++secIdxIt;
/* Skip AROT */ /* Skip AROT */
if (secIdxIt->first == FOURCC('ROCT')) if (secIdxIt->first == FOURCC('ROCT'))
{ {
@ -248,41 +249,48 @@ bool MREA::Extract(const SpecBase& dataSpec,
++secIdxIt; ++secIdxIt;
} }
#if 0 /* Skip DEPS */
if (secIdxIt->first == FOURCC('DEPS'))
{
/* Skip AROT */
drs.seek(head.secSizes[curSec++], Athena::Current);
/* Skip BVH */
drs.seek(head.secSizes[curSec++], Athena::Current);
/* Skip Bitmap */
drs.seek(head.secSizes[curSec++], Athena::Current);
/* Skip SCLY (for now) */
for (atUint32 l=0 ; l<head.sclyLayerCount ; ++l)
drs.seek(head.secSizes[curSec++], Athena::Current); drs.seek(head.secSizes[curSec++], Athena::Current);
++secIdxIt;
}
/* Skip SCGN (for now) */ /* Skip SOBJ (SCLY) */
drs.seek(head.secSizes[curSec++], Athena::Current); if (secIdxIt->first == FOURCC('SOBJ'))
{
for (int l=0 ; l<head.sclyLayerCount ; ++l)
drs.seek(head.secSizes[curSec++], Athena::Current);
++secIdxIt;
}
/* Read collision meshes */ /* Skip SGEN */
DNAMP2::DeafBabe collision; if (secIdxIt->first == FOURCC('SGEN'))
secStart = drs.position(); {
collision.read(drs); drs.seek(head.secSizes[curSec++], Athena::Current);
DNAMP2::DeafBabe::BlenderInit(os); ++secIdxIt;
collision.sendToBlender(os); }
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
/* Skip unknown section */ /* Read Collision Meshes */
drs.seek(head.secSizes[curSec++], Athena::Current); if (secIdxIt->first == FOURCC('COLI'))
{
DNAMP2::DeafBabe collision;
secStart = drs.position();
collision.read(drs);
DNAMP2::DeafBabe::BlenderInit(os);
collision.sendToBlender(os);
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
++secIdxIt;
}
/* Read BABEDEAD Lights as Cycles emissives */ /* Read BABEDEAD Lights as Cycles emissives */
secStart = drs.position(); if (secIdxIt->first == FOURCC('LITE'))
ReadBabeDeadToBlender_3(os, drs); {
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin); secStart = drs.position();
#endif ReadBabeDeadToBlender_3(os, drs);
drs.seek(secStart + head.secSizes[curSec++], Athena::Begin);
++secIdxIt;
}
/* Origins to center of mass */ /* Origins to center of mass */
os << "bpy.context.scene.layers[1] = True\n" os << "bpy.context.scene.layers[1] = True\n"

View File

@ -66,16 +66,15 @@ struct MREA
Value<LightType> lightType; Value<LightType> lightType;
Value<atVec4f> color; Value<atVec4f> color;
Value<atVec3f> position; Value<atVec3f> position;
Value<atVec4f> unk3; Value<atVec3f> direction;
Value<float> power; Value<atVec3f> codirection;
Value<float> unk4;
Value<float> unk5; Value<float> unk5;
Value<float> unk6; Value<float> unk6;
Value<atUint8> unk7; Value<float> unk7;
Value<atUint32> unk8; Value<atUint8> unk8;
Value<atUint32> unk9; Value<atUint32> unk9;
Value<float> unk10; Value<atUint32> unk10;
Value<atUint32> unk11; Value<float> spotCutoff;
Value<atVec4f> unk12; Value<atVec4f> unk12;
Value<atUint32> unk13; Value<atUint32> unk13;
}; };