All MREA cooker sections initial integration

This commit is contained in:
Jack Andersen 2016-08-11 09:52:22 -10:00
parent bc8daa1d50
commit e14bbeb368
16 changed files with 548 additions and 157 deletions

View File

@ -3,6 +3,8 @@
namespace DataSpec
{
#define AROT_MAX_LEVEL 11 /* These go to 11 */
static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
size_t AROTBuilder::BitmapPool::addIndices(const std::set<int>& indices)
@ -14,12 +16,12 @@ size_t AROTBuilder::BitmapPool::addIndices(const std::set<int>& indices)
return m_pool.size() - 1;
}
bool AROTBuilder::Node::addChild(const zeus::CAABox& curAabb, const zeus::CAABox& childAabb, int idx)
bool AROTBuilder::Node::addChild(int level, const zeus::CAABox& curAabb, const zeus::CAABox& childAabb, int idx)
{
if (childAabb.intersects(curAabb))
{
childIndices.insert(idx);
if (!curAabb.inside(childAabb))
if (!curAabb.inside(childAabb) && level < AROT_MAX_LEVEL)
{
childNodes.resize(8);
zeus::CAABox X[2];
@ -35,8 +37,8 @@ bool AROTBuilder::Node::addChild(const zeus::CAABox& curAabb, const zeus::CAABox
zeus::CAABox Z[2];
Y[j].splitZ(Z[0], Z[1]);
bool inZ[2] = {};
inZ[0] = childNodes[i*4 + j*2].addChild(Z[0], childAabb, idx);
inZ[1] = childNodes[i*4 + j*2 + 1].addChild(Z[1], childAabb, idx);
inZ[0] = childNodes[i*4 + j*2].addChild(level + 1, Z[0], childAabb, idx);
inZ[1] = childNodes[i*4 + j*2 + 1].addChild(level + 1, Z[1], childAabb, idx);
if (inZ[0] ^ inZ[1])
flags |= 0x4;
if (inZ[0] | inZ[1])
@ -164,13 +166,131 @@ void AROTBuilder::Node::advanceIndex(int& nodeIdx)
}
}
void AROTBuilder::Node::colSize(size_t& totalSz)
{
if (childIndices.size())
{
nodeOff = totalSz;
if (childNodes.empty())
{
totalSz += 26 + childIndices.size() * 2;
}
else
{
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
{
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
{
for (int k=0 ; k < 1 + ((flags & 0x4) != 0) ; ++k)
{
childNodes[i*4 + j*2 + k].colSize(totalSz);
}
}
}
}
}
}
void AROTBuilder::Node::writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB)
{
if (childIndices.size())
{
if (childNodes.empty())
{
*reinterpret_cast<zeus::CVector3f*>(ptr) = curAABB.min;
*reinterpret_cast<zeus::CVector3f*>(ptr + 12) = curAABB.max;
athena::io::MemoryWriter w(ptr + 24, INT32_MAX);
w.writeUint16Big(childIndices.size());
for (int idx : childIndices)
w.writeUint16Big(idx);
ptr += 26 + childIndices.size() * 2;
}
else
{
uint16_t* pflags = reinterpret_cast<uint16_t*>(ptr);
uint32_t* offsets = reinterpret_cast<uint32_t*>(ptr + 4);
*pflags = 0;
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
{
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
{
for (int k=0 ; k < 1 + ((flags & 0x4) != 0) ; ++k)
{
int idx = i*4 + j*2 + k;
uint32_t thisOffset;
uint16_t thisFlags = childNodes[idx].getColRef(thisOffset);
if (thisFlags)
{
*pflags |= thisFlags << (idx * 2);
offsets[idx] = thisOffset - nodeOff;
}
}
}
}
ptr += 36;
zeus::CAABox X[2];
if (flags & 0x1)
curAABB.splitX(X[0], X[1]);
else
{
X[0] = curAABB;
X[1] = curAABB;
}
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
{
zeus::CAABox Y[2];
if (flags & 0x2)
X[i].splitY(Y[0], Y[1]);
else
{
Y[0] = X[i];
Y[1] = X[i];
}
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
{
zeus::CAABox Z[2];
if (flags & 0x4)
Y[j].splitZ(Z[0], Z[1]);
else
{
Z[0] = Y[j];
Z[1] = Y[j];
}
for (int k=0 ; k < 1 + ((flags & 0x4) != 0) ; ++k)
{
int idx = i*4 + j*2 + k;
childNodes[idx].writeColNodes(ptr, Z[k]);
}
}
}
}
}
}
uint16_t AROTBuilder::Node::getColRef(uint32_t& offset)
{
if (childIndices.size())
{
offset = nodeOff;
if (childNodes.empty())
return 2;
else
return 1;
}
return 0;
}
void AROTBuilder::build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb,
const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes)
{
for (int i=0 ; i<meshAabbs.size() ; ++i)
{
const zeus::CAABox& aabb = meshAabbs[i];
rootNode.addChild(fullAabb, aabb, i);
rootNode.addChild(0, fullAabb, aabb, i);
}
size_t totalNodeCount = 0;
@ -228,4 +348,36 @@ void AROTBuilder::build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAA
rootNode.writeNodes(w, 0);
}
std::pair<std::unique_ptr<uint8_t[]>, uint32_t> AROTBuilder::buildCol(const ColMesh& mesh, BspNodeType& rootOut)
{
zeus::CAABox fullAabb(zeus::CVector3f(mesh.aabbMin), zeus::CVector3f(mesh.aabbMax));
int t = 0;
for (const ColMesh::Triangle& tri : mesh.trianges)
{
zeus::CAABox aabb;
for (int e=0 ; e<3 ; ++e)
{
const ColMesh::Edge& edge = mesh.edges[tri.edges[e]];
for (int v=0 ; v<2 ; ++v)
{
const auto& vert = mesh.verts[edge.verts[v]];
aabb.accumulateBounds(zeus::CVector3f(vert));
}
}
rootNode.addChild(0, fullAabb, aabb, t);
++t;
}
size_t totalSize = 0;
rootNode.colSize(totalSize);
std::unique_ptr<uint8_t[]> ret(new uint8_t[totalSize]);
uint32_t dummy;
rootOut = BspNodeType(rootNode.getColRef(dummy));
uint8_t* ptr = ret.get();
rootNode.writeColNodes(ptr, fullAabb);
return {std::move(ret), totalSize};
}
}

View File

@ -2,6 +2,7 @@
#define _DNACOMMON_AROTBUILDER_HPP_
#include "DNACommon.hpp"
#include "DeafBabe.hpp"
#include "zeus/CAABox.hpp"
#include "CMDL.hpp"
#include <set>
@ -27,15 +28,21 @@ struct AROTBuilder
size_t nodeOff = 0;
size_t nodeSz = 4;
bool addChild(const zeus::CAABox& curAabb, const zeus::CAABox& childAabb, int idx);
bool addChild(int level, const zeus::CAABox& curAabb, const zeus::CAABox& childAabb, int idx);
void nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPool, size_t& curOff);
void writeIndirectionTable(athena::io::MemoryWriter& w);
void writeNodes(athena::io::MemoryWriter& w, int nodeIdx);
void advanceIndex(int& nodeIdx);
void colSize(size_t& totalSz);
void writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB);
uint16_t getColRef(uint32_t& offset);
} rootNode;
void build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb,
const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes);
using ColMesh = hecl::BlenderConnection::DataStream::ColMesh;
std::pair<std::unique_ptr<uint8_t[]>, uint32_t> buildCol(const ColMesh& mesh, BspNodeType& rootOut);
};
}

View File

@ -0,0 +1,154 @@
#include "BabeDead.hpp"
#include "DataSpec/DNAMP1/MREA.hpp"
#include "DataSpec/DNAMP3/MREA.hpp"
#include "zeus/CTransform.hpp"
namespace DataSpec
{
template<class BabeDeadLight>
void ReadBabeDeadLightToBlender(hecl::BlenderConnection::PyOutStream& os,
const BabeDeadLight& light, unsigned s, unsigned l)
{
switch (light.lightType)
{
case BabeDeadLight::LightType::LocalAmbient:
case BabeDeadLight::LightType::LocalAmbient2:
os.format("bg_node.inputs[0].default_value = (%f,%f,%f,1.0)\n"
"bg_node.inputs[1].default_value = %f\n",
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.q / 8.0);
return;
case BabeDeadLight::LightType::Directional:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"lamp.shadow_method = %s\n"
"\n", s, l,
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
return;
case BabeDeadLight::LightType::Custom:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'POINT')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp.shadow_method = %s\n"
"\n", s, l, light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
break;
case BabeDeadLight::LightType::Spot:
case BabeDeadLight::LightType::Spot2:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SPOT')\n"
"lamp.spot_size = %.6g\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"lamp.shadow_method = %s\n"
"\n", s, l,
zeus::degToRad(light.spotCutoff),
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2],
light.castShadows ? "RAY_SHADOW" : "NOSHADOW");
break;
default: return;
}
os.format("lamp.retro_layer = %u\n"
"lamp.retro_origtype = %u\n"
"lamp.falloff_type = 'INVERSE_COEFFICIENTS'\n"
"lamp.constant_coefficient = 0\n"
"lamp.use_nodes = True\n"
"falloff_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\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.inputs[1].default_value = 1.25\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_obj.location = (%f,%f,%f)\n"
"bpy.context.scene.objects.link(lamp_obj)\n"
"\n", s, light.lightType, light.q / 8.0,
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.position.vec[0], light.position.vec[1], light.position.vec[2]);
switch (light.falloff)
{
case BabeDeadLight::Falloff::Constant:
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";
if (light.q > FLT_EPSILON)
os.format("lamp.constant_coefficient = 2.0 / %f\n", light.q);
break;
case BabeDeadLight::Falloff::Linear:
os << "lamp.node_tree.links.new(falloff_node.outputs[1], lamp.node_tree.nodes['Emission'].inputs[1])\n";
if (light.q > FLT_EPSILON)
os.format("lamp.linear_coefficient = 250 / %f\n", light.q);
break;
case BabeDeadLight::Falloff::Quadratic:
os << "lamp.node_tree.links.new(falloff_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n";
if (light.q > FLT_EPSILON)
os.format("lamp.quadratic_coefficient = 25000 / %f\n", light.q);
break;
default: break;
}
}
template void ReadBabeDeadLightToBlender<DNAMP1::MREA::BabeDeadLight>
(hecl::BlenderConnection::PyOutStream& os, const DNAMP1::MREA::BabeDeadLight& light, unsigned s, unsigned l);
template void ReadBabeDeadLightToBlender<DNAMP3::MREA::BabeDeadLight>
(hecl::BlenderConnection::PyOutStream& os, const DNAMP3::MREA::BabeDeadLight& light, unsigned s, unsigned l);
template<class BabeDeadLight>
void WriteBabeDeadLightFromBlender(BabeDeadLight& lightOut, const hecl::BlenderConnection::DataStream::Light& lightIn)
{
using InterType = hecl::BlenderConnection::DataStream::Light::Type;
switch (lightIn.type)
{
case InterType::Ambient:
lightOut.lightType = BabeDeadLight::LightType::LocalAmbient;
break;
case InterType::Directional:
lightOut.lightType = BabeDeadLight::LightType::Directional;
break;
case InterType::Custom:
default:
lightOut.lightType = BabeDeadLight::LightType::Custom;
break;
case InterType::Spot:
lightOut.lightType = BabeDeadLight::LightType::Spot;
break;
}
if (lightIn.linear > lightIn.constant &&
lightIn.linear > lightIn.quadratic)
{
lightOut.falloff = BabeDeadLight::Falloff::Linear;
lightOut.q = 1.f / (lightIn.linear / 250.f);
}
else if (lightIn.quadratic > lightIn.constant &&
lightIn.quadratic > lightIn.linear)
{
lightOut.falloff = BabeDeadLight::Falloff::Quadratic;
lightOut.q = 1.f / (lightIn.quadratic / 25000.f);
}
else
{
lightOut.falloff = BabeDeadLight::Falloff::Constant;
lightOut.q = 1.f / (lightIn.constant / 2.f);
}
lightOut.color = lightIn.color;
lightOut.spotCutoff = lightIn.spotCutoff;
lightOut.castShadows = lightIn.shadow;
lightOut.position.vec[0] = lightIn.sceneXf[0].vec[3];
lightOut.position.vec[1] = lightIn.sceneXf[1].vec[3];
lightOut.position.vec[2] = lightIn.sceneXf[2].vec[3];
zeus::CTransform lightXf(&lightIn.sceneXf[0]);
lightOut.direction = lightXf * zeus::CVector3f(0.f, 0.f, -1.f);
}
template void WriteBabeDeadLightFromBlender<DNAMP1::MREA::BabeDeadLight>
(DNAMP1::MREA::BabeDeadLight& lightOut, const hecl::BlenderConnection::DataStream::Light& lightIn);
template void WriteBabeDeadLightFromBlender<DNAMP3::MREA::BabeDeadLight>
(DNAMP3::MREA::BabeDeadLight& lightOut, const hecl::BlenderConnection::DataStream::Light& lightIn);
}

View File

@ -10,83 +10,10 @@ namespace DataSpec
template<class BabeDeadLight>
void ReadBabeDeadLightToBlender(hecl::BlenderConnection::PyOutStream& os,
const BabeDeadLight& light, unsigned s, unsigned l)
{
switch (light.lightType)
{
case BabeDeadLight::LightType::LocalAmbient:
case BabeDeadLight::LightType::LocalAmbient2:
os.format("bg_node.inputs[0].default_value = (%f,%f,%f,1.0)\n"
"bg_node.inputs[1].default_value = %f\n",
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.q / 8.0);
return;
case BabeDeadLight::LightType::Directional:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"\n", s, l,
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]);
return;
case BabeDeadLight::LightType::Custom:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'POINT')\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"\n", s, l);
break;
case BabeDeadLight::LightType::Spot:
case BabeDeadLight::LightType::Spot2:
os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SPOT')\n"
"lamp.spot_size = %.6g\n"
"lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n"
"lamp_obj.rotation_mode = 'QUATERNION'\n"
"lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n"
"\n", s, l,
zeus::degToRad(light.spotCutoff),
light.direction.vec[0], light.direction.vec[1], light.direction.vec[2]);
break;
default: return;
}
const BabeDeadLight& light, unsigned s, unsigned l);
os.format("lamp.retro_layer = %u\n"
"lamp.retro_origtype = %u\n"
"lamp.falloff_type = 'INVERSE_COEFFICIENTS'\n"
"lamp.constant_coefficient = 0\n"
"lamp.use_nodes = True\n"
"falloff_node = lamp.node_tree.nodes.new('ShaderNodeLightFalloff')\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.inputs[1].default_value = 1.25\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_obj.location = (%f,%f,%f)\n"
"bpy.context.scene.objects.link(lamp_obj)\n"
"\n", s, light.lightType, light.q / 8.0,
light.color.vec[0], light.color.vec[1], light.color.vec[2],
light.position.vec[0], light.position.vec[1], light.position.vec[2]);
switch (light.falloff)
{
case BabeDeadLight::Falloff::Constant:
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";
if (light.q > FLT_EPSILON)
os.format("lamp.constant_coefficient = 2.0 / %f\n", light.q);
break;
case BabeDeadLight::Falloff::Linear:
os << "lamp.node_tree.links.new(falloff_node.outputs[1], lamp.node_tree.nodes['Emission'].inputs[1])\n";
if (light.q > FLT_EPSILON)
os.format("lamp.linear_coefficient = 250 / %f\n", light.q);
break;
case BabeDeadLight::Falloff::Quadratic:
os << "lamp.node_tree.links.new(falloff_node.outputs[0], lamp.node_tree.nodes['Emission'].inputs[1])\n";
if (light.q > FLT_EPSILON)
os.format("lamp.quadratic_coefficient = 25000 / %f\n", light.q);
break;
default: break;
}
}
template<class BabeDeadLight>
void WriteBabeDeadLightFromBlender(BabeDeadLight& lightOut, const hecl::BlenderConnection::DataStream::Light& lightIn);
}

View File

@ -27,8 +27,8 @@ add_library(DNACommon
ParticleCommon.cpp
FONT.hpp FONT.cpp
DGRP.hpp DGRP.cpp
DeafBabe.hpp
BabeDead.hpp
DeafBabe.hpp DeafBabe.cpp
BabeDead.hpp BabeDead.cpp
RigInverter.hpp RigInverter.cpp
AROTBuilder.hpp AROTBuilder.cpp
Tweaks/ITweakGame.hpp

View File

@ -0,0 +1,140 @@
#include "DeafBabe.hpp"
#include "AROTBuilder.hpp"
#include "DataSpec/DNAMP1/DeafBabe.hpp"
#include "DataSpec/DNAMP2/DeafBabe.hpp"
namespace DataSpec
{
template<class DEAFBABE>
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db)
{
os << "material_index = []\n"
"col_bm = bmesh.new()\n";
for (const atVec3f& vert : db.verts)
os.format("col_bm.verts.new((%f,%f,%f))\n",
vert.vec[0],
vert.vec[1],
vert.vec[2]);
os << "col_bm.verts.ensure_lookup_table()\n";
int triIdx = 0;
for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections)
{
const typename DEAFBABE::Material& triMat = db.materials[db.triMats[triIdx++]];
const typename DEAFBABE::Edge& edge0 = db.edgeVertConnections[tri.edges[0]];
const typename DEAFBABE::Edge& edge1 = db.edgeVertConnections[tri.edges[1]];
const typename DEAFBABE::Edge& edge2 = db.edgeVertConnections[tri.edges[2]];
if (!edge0.verts[0] && !edge1.verts[0] && !edge2.verts[0])
break;
os << "tri_verts = []\n";
os.format("tri_verts.append(col_bm.verts[%u])\n", edge0.findCommon(edge1));
os.format("tri_verts.append(col_bm.verts[%u])\n", edge1.findCommon(edge2));
os.format("tri_verts.append(col_bm.verts[%u])\n", edge2.findCommon(edge0));
os.format("face = col_bm.faces.get(tri_verts)\n"
"if face is None:\n"
" face = col_bm.faces.new(tri_verts)\n"
"else:\n"
" face = face.copy()\n"
" for i in range(3):\n"
" face.verts[i].co = tri_verts[i].co\n"
" col_bm.verts.ensure_lookup_table()\n"
"face.material_index = select_material(0x%08X)\n"
"face.smooth = False\n"
"\n",
atUint32(triMat.material));
}
db.insertNoClimb(os);
os << "col_mesh = bpy.data.meshes.new('CMESH')\n"
"col_bm.to_mesh(col_mesh)\n"
"col_mesh_obj = bpy.data.objects.new(col_mesh.name, col_mesh)\n"
"\n"
"for mat_name in material_index:\n"
" mat = material_dict[mat_name]\n"
" col_mesh.materials.append(mat)\n"
"\n"
"bpy.context.scene.objects.link(col_mesh_obj)\n"
"col_mesh_obj.layers[1] = True\n"
"col_mesh_obj.layers[0] = False\n"
"col_mesh_obj.draw_type = 'SOLID'\n"
"col_mesh_obj.game.physics_type = 'STATIC'\n"
"\n";
}
template void DeafBabeSendToBlender<DNAMP1::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP1::DeafBabe& db);
template void DeafBabeSendToBlender<DNAMP2::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP2::DeafBabe& db);
template<class DEAFBABE>
void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh)
{
{
AROTBuilder builder;
auto octree = builder.buildCol(colMesh, db.rootNodeType);
static_cast<std::unique_ptr<atUint8[]>&>(db.bspTree) = std::move(octree.first);
db.bspSize = octree.second;
}
db.materials.reserve(colMesh.materials.size());
for (const auto& mat : colMesh.materials)
{
db.materials.emplace_back();
db.materials.back().setFireThrough(mat.fireThrough);
db.materials.back().setType(typename DEAFBABE::Material::Type(mat.type));
}
db.materialCount = colMesh.materials.size();
db.verts.reserve(colMesh.verts.size());
db.vertMats.resize(colMesh.verts.size());
for (const auto& vert : colMesh.verts)
db.verts.push_back(vert);
db.vertMatsCount = colMesh.verts.size();
db.vertCount = colMesh.verts.size();
db.edgeVertConnections.reserve(colMesh.edges.size());
db.edgeMats.resize(colMesh.edges.size());
for (const auto& edge : colMesh.edges)
{
db.edgeVertConnections.emplace_back();
db.edgeVertConnections.back().verts[0] = edge.verts[0];
db.edgeVertConnections.back().verts[1] = edge.verts[1];
}
db.edgeMatsCount = colMesh.edges.size();
db.edgeVertsCount = colMesh.edges.size();
db.triMats.reserve(colMesh.trianges.size());
db.triangleEdgeConnections.reserve(colMesh.trianges.size());
for (const auto& tri : colMesh.trianges)
{
db.triMats.push_back(tri.matIdx);
db.triangleEdgeConnections.emplace_back();
db.triangleEdgeConnections.back().edges[0] = tri.edges[0];
db.triangleEdgeConnections.back().edges[1] = tri.edges[1];
db.triangleEdgeConnections.back().edges[2] = tri.edges[2];
for (int e=0 ; e<3 ; ++e)
{
db.edgeMats[tri.edges[e]] = tri.matIdx;
for (int v=0 ; v<2 ; ++v)
db.vertMats[colMesh.edges[e].verts[v]] = tri.matIdx;
}
}
db.triMatsCount = colMesh.trianges.size();
db.triangleEdgesCount = colMesh.trianges.size() * 3;
db.unk1 = 0;
db.length = db.binarySize(0) - 8;
db.magic = 0xDEAFBABE;
db.version = 0;
db.aabb[0] = colMesh.aabbMin;
db.aabb[1] = colMesh.aabbMax;
}
template void DeafBabeBuildFromBlender<DNAMP1::DeafBabe>(DNAMP1::DeafBabe& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh);
template void DeafBabeBuildFromBlender<DNAMP2::DeafBabe>(DNAMP2::DeafBabe& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh);
}

View File

@ -7,64 +7,18 @@
namespace DataSpec
{
template<class DEAFBABE>
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db)
enum class BspNodeType : atUint32
{
os << "material_index = []\n"
"col_bm = bmesh.new()\n";
for (const atVec3f& vert : db.verts)
os.format("col_bm.verts.new((%f,%f,%f))\n",
vert.vec[0],
vert.vec[1],
vert.vec[2]);
Invalid,
Branch,
Leaf
};
os << "col_bm.verts.ensure_lookup_table()\n";
template<class DEAFBABE>
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db);
int triIdx = 0;
for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections)
{
const typename DEAFBABE::Material& triMat = db.materials[db.triMats[triIdx++]];
const typename DEAFBABE::Edge& edge0 = db.edgeVertConnections[tri.edges[0]];
const typename DEAFBABE::Edge& edge1 = db.edgeVertConnections[tri.edges[1]];
const typename DEAFBABE::Edge& edge2 = db.edgeVertConnections[tri.edges[2]];
if (!edge0.verts[0] && !edge1.verts[0] && !edge2.verts[0])
break;
os << "tri_verts = []\n";
os.format("tri_verts.append(col_bm.verts[%u])\n", edge0.findCommon(edge1));
os.format("tri_verts.append(col_bm.verts[%u])\n", edge1.findCommon(edge2));
os.format("tri_verts.append(col_bm.verts[%u])\n", edge2.findCommon(edge0));
os.format("face = col_bm.faces.get(tri_verts)\n"
"if face is None:\n"
" face = col_bm.faces.new(tri_verts)\n"
"else:\n"
" face = face.copy()\n"
" for i in range(3):\n"
" face.verts[i].co = tri_verts[i].co\n"
" col_bm.verts.ensure_lookup_table()\n"
"face.material_index = select_material(0x%08X)\n"
"face.smooth = False\n"
"\n",
atUint32(triMat.material));
}
db.insertNoClimb(os);
os << "col_mesh = bpy.data.meshes.new('CMESH')\n"
"col_bm.to_mesh(col_mesh)\n"
"col_mesh_obj = bpy.data.objects.new(col_mesh.name, col_mesh)\n"
"\n"
"for mat_name in material_index:\n"
" mat = material_dict[mat_name]\n"
" col_mesh.materials.append(mat)\n"
"\n"
"bpy.context.scene.objects.link(col_mesh_obj)\n"
"col_mesh_obj.layers[1] = True\n"
"col_mesh_obj.layers[0] = False\n"
"col_mesh_obj.draw_type = 'SOLID'\n"
"col_mesh_obj.game.physics_type = 'STATIC'\n"
"\n";
}
template<class DEAFBABE>
void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh);
}

View File

@ -11,12 +11,7 @@ namespace DNAMP1
struct DeafBabe : BigDNA
{
DECL_DNA
enum class BspNodeType : atUint32
{
Invalid,
Branch,
Leaf
};
using BspNodeType = DataSpec::BspNodeType;
struct Material : BigDNA
{

View File

@ -249,7 +249,8 @@ void MREA::MeshHeader::VisorFlags::setFromBlenderProps(const std::unordered_map<
bool MREA::Cook(const hecl::ProjectPath& outPath,
const hecl::ProjectPath& inPath,
const std::vector<DNACMDL::Mesh>& meshes,
const ColMesh& cMesh)
const ColMesh& cMesh,
const std::vector<Light>& lights)
{
return false;
}
@ -257,7 +258,8 @@ bool MREA::Cook(const hecl::ProjectPath& outPath,
bool MREA::PCCook(const hecl::ProjectPath& outPath,
const hecl::ProjectPath& inPath,
const std::vector<DNACMDL::Mesh>& meshes,
const ColMesh& cMesh)
const ColMesh& cMesh,
const std::vector<Light>& lights)
{
/* Discover area layers */
hecl::ProjectPath areaDirPath = inPath.getParentPath();
@ -370,15 +372,68 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
/* Collision */
{
DeafBabe collision;
DeafBabeBuildFromBlender(collision, cMesh);
secs.emplace_back(collision.binarySize(0), 0);
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
collision.write(w);
}
/* Unk */
{
secs.emplace_back(8, 0);
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
w.writeUint32Big(1);
}
/* Lights */
{
int actualCount = 0;
for (const Light& l : lights)
{
if (l.layer == 0 || l.layer == 1)
++actualCount;
}
secs.emplace_back(12 + 65 * actualCount, 0);
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
w.writeUint32Big(0xBABEDEAD);
for (int lay=0 ; lay<2 ; ++lay)
{
int lightCount = 0;
for (const Light& l : lights)
{
if (l.layer == lay)
++lightCount;
}
w.writeUint32Big(lightCount);
for (const Light& l : lights)
{
if (l.layer == lay)
{
BabeDeadLight light;
WriteBabeDeadLightFromBlender(light, l);
light.write(w);
}
}
}
}
/* VISI */
{
/* Empty (for now) */
secs.emplace_back(0, 0);
}
/* PATH */
{
secs.emplace_back(4, 0);
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
w.writeUint32Big(0xffffffff); /* Empty (for now) */
}
/* Assemble sizes and add padding */
{

View File

@ -123,16 +123,19 @@ struct MREA
PAK::Entry& entry);
using ColMesh = hecl::BlenderConnection::DataStream::ColMesh;
using Light = hecl::BlenderConnection::DataStream::Light;
static bool Cook(const hecl::ProjectPath& outPath,
const hecl::ProjectPath& inPath,
const std::vector<DNACMDL::Mesh>& meshes,
const ColMesh& cMesh);
const ColMesh& cMesh,
const std::vector<Light>& lights);
static bool PCCook(const hecl::ProjectPath& outPath,
const hecl::ProjectPath& inPath,
const std::vector<DNACMDL::Mesh>& meshes,
const ColMesh& cMesh);
const ColMesh& cMesh,
const std::vector<Light>& lights);
};
}

View File

@ -11,7 +11,7 @@ namespace DNAMP2
struct DeafBabe : BigDNA
{
DECL_DNA
using BspNodeType = DNAMP1::DeafBabe::BspNodeType;
using BspNodeType = DataSpec::BspNodeType;
struct Material : BigDNA
{

View File

@ -96,14 +96,15 @@ struct MREA
Quadratic
};
Value<LightType> lightType;
Value<atVec4f> color;
Value<atVec3f> color;
Value<float> alpha = 1.f;
Value<atVec3f> position;
Value<atVec3f> direction;
Value<atVec3f> codirection;
Value<float> q;
Value<float> spotCutoff;
Value<float> unk7;
Value<atUint8> unk8;
Value<bool> castShadows;
Value<float> unk9;
Value<Falloff> falloff;
Value<float> unk11;

View File

@ -55,6 +55,7 @@ struct SpecBase : hecl::Database::IDataSpec
using BlendStream = hecl::BlenderConnection::DataStream;
using Mesh = BlendStream::Mesh;
using ColMesh = BlendStream::ColMesh;
using Light = BlendStream::Light;
using Actor = BlendStream::Actor;
virtual void cookMesh(const hecl::ProjectPath& out, const hecl::ProjectPath& in,

View File

@ -410,10 +410,12 @@ struct SpecMP1 : SpecBase
if (!colMesh)
Log.report(logvisor::Fatal, _S("unable to find mesh named 'CMESH' in %s"), in.getAbsolutePath().c_str());
std::vector<Light> lights = ds.compileLights();
if (m_pc)
DNAMP1::MREA::PCCook(out, in, meshCompiles, *colMesh);
DNAMP1::MREA::PCCook(out, in, meshCompiles, *colMesh, lights);
else
DNAMP1::MREA::Cook(out, in, meshCompiles, *colMesh);
DNAMP1::MREA::Cook(out, in, meshCompiles, *colMesh, lights);
}
void cookYAML(const hecl::ProjectPath& out, const hecl::ProjectPath& in,

View File

@ -7,7 +7,7 @@ CAreaOctTree::Node CAreaOctTree::Node::GetChild(int idx) const
{
u16 flags = *reinterpret_cast<const u16*>(m_ptr);
const u32* offsets = reinterpret_cast<const u32*>(m_ptr + 4);
ETreeType type = ETreeType((flags << (2 * idx)) & 0x3);
ETreeType type = ETreeType((flags >> (2 * idx)) & 0x3);
if (type == ETreeType::Branch)
{
@ -76,7 +76,7 @@ void CAreaOctTree::SwapTreeNode(u8* ptr, Node::ETreeType type)
for (int i=0 ; i<8 ; ++i)
{
Node::ETreeType ctype = Node::ETreeType((*typeBits << (2 * i)) & 0x3);
Node::ETreeType ctype = Node::ETreeType((*typeBits >> (2 * i)) & 0x3);
u32* offsets = reinterpret_cast<u32*>(ptr + 4);
offsets[i] = hecl::SBig(offsets[i]);
SwapTreeNode(ptr + offsets[i] + 36, ctype);

2
hecl

@ -1 +1 @@
Subproject commit 6b9594a40c2f286db07b979b6d2e5c6db5c5283a
Subproject commit e7d37d7132a25506c19c27d78108b8ba7247af87