#ifndef _DNAMP1_DEAFBABE_HPP_ #define _DNAMP1_DEAFBABE_HPP_ #include "../DNACommon/DNACommon.hpp" #include "BlenderConnection.hpp" namespace Retro { namespace DNAMP1 { template 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; #define TEST 0 #if TEST == 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", triMat.material); } #elif TEST == 1 for (const typename DEAFBABE::Triangle& tri : db.triangleEdgeConnections2) { 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" "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"; } struct DeafBabe : BigDNA { DECL_DNA enum BspNodeType : atUint32 { BspNodeInvalid, BspNodeBranch, BspNodeLeaf }; struct Material : BigDNA { DECL_DNA Value material; bool fireThrough() const {return material >> 18 & 0x1;} void setFireThrough(bool v) {material &= 0x40000; material |= v << 18;} enum Type { Mat0, MatGround, Mat2, MatStone, MatHardStone, MatMetal, Mat6, Mat7, Mat8, MatLeaves }; Type type() const {return Type(material & 0xff);} void setType(Type t) {material &= 0xff; material |= t;} }; struct Edge : BigDNA { DECL_DNA Value verts[2]; atUint16 findCommon(const Edge& other) const { if (verts[0] == other.verts[0] || verts[0] == other.verts[1]) return verts[0]; if (verts[1] == other.verts[0] || verts[1] == other.verts[1]) return verts[1]; return -1; } }; struct Triangle : BigDNA { DECL_DNA Value edges[3]; }; Value unk1; Value length; Value magic; Value version; Value aabb[2]; Value rootNodeType; Value bspSize; Buffer bspTree; Value materialCount; Vector materials; Value vertMatsCount; Vector vertMats; Value edgeMatsCount; Vector edgeMats; Value triMatsCount; Vector triMats; Value edgeVertsCount; Vector edgeVertConnections; Value triangleEdgesCount; Vector triangleEdgeConnections; Value vertCount; Vector verts; /* Dummy MP2 member */ std::vector triangleEdgeConnections2; static void BlenderInit(HECL::BlenderConnection::PyOutStream& os); void sendToBlender(HECL::BlenderConnection::PyOutStream& os) const { DeafBabeSendToBlender(os, *this); } }; } } #endif // _DNAMP1_DEAFBABE_HPP_