soil_generator::soil_generator(world& w, const ptree& conf) : terrain_generator_i(w, conf) , surfacemap_(w.find_area_generator("surface")) , grass_(find_material("grass")) , dirt_(find_material("dirt")) , rock_(find_material("cobblestone")) , sand_(find_material("sand")) { if (surfacemap_ < 0) throw std::runtime_error("soil_generator requires a surface map"); }
material_type::material_type(std::string ident) { material_type* mat_type = find_material(ident); _id = mat_type->id(); _name = mat_type->name(); _bash_resist = mat_type->bash_resist(); _cut_resist = mat_type->cut_resist(); _acid_resist = mat_type->acid_resist(); _elec_resist = mat_type->elec_resist(); _fire_resist = mat_type->fire_resist(); }
struct mesh *find_mesh(struct model *model, char *matname) { struct material *material = find_material(model, matname); struct mesh *mesh; for (mesh = model->mesh; mesh; mesh = mesh->next) if (mesh->material == material) return mesh; mesh = malloc(sizeof(struct mesh)); mesh->material = material; mesh->len = mesh->cap = 0; mesh->tri = 0; mesh->next = model->mesh; mesh->vba = 0; mesh->vbo = 0; model->mesh = mesh; return mesh; }
material_type::material_type(std::string ident) { material_type* mat_type = find_material(ident); _ident = ident; _name = mat_type->name(); _bash_resist = mat_type->bash_resist(); _cut_resist = mat_type->cut_resist(); _bash_dmg_verb = mat_type->bash_dmg_verb(); _cut_dmg_verb = mat_type->bash_dmg_verb(); _dmg_adj[0] = mat_type->dmg_adj(1); _dmg_adj[1] = mat_type->dmg_adj(2); _dmg_adj[2] = mat_type->dmg_adj(3); _dmg_adj[3] = mat_type->dmg_adj(4); _acid_resist = mat_type->acid_resist(); _elec_resist = mat_type->elec_resist(); _fire_resist = mat_type->fire_resist(); _density = mat_type->density(); }
material_type::material_type( std::string ident ) { material_type *mat_type = find_material( ident ); _ident = ident; _name = mat_type->name(); _salvage_id = mat_type->salvage_id(); _salvage_multiplier = mat_type->salvage_multiplier(); _bash_resist = mat_type->bash_resist(); _cut_resist = mat_type->cut_resist(); _bash_dmg_verb = mat_type->bash_dmg_verb(); _cut_dmg_verb = mat_type->bash_dmg_verb(); _acid_resist = mat_type->acid_resist(); _elec_resist = mat_type->elec_resist(); _fire_resist = mat_type->fire_resist(); _chip_resist = mat_type->chip_resist(); _density = mat_type->density(); for( auto i = 0; i != MAX_ITEM_DAMAGE; ++i ) { _dmg_adj[i] = mat_type->dmg_adj( i + 1 ); } }
void export_node(FILE *out, const struct aiScene *scene, const struct aiNode *node, struct aiMatrix4x4 mat, char *clean_name) { struct aiMatrix3x3 mat3; int i, a, k, t; aiMultiplyMatrix4(&mat, &node->mTransformation); mat3.a1 = mat.a1; mat3.a2 = mat.a2; mat3.a3 = mat.a3; mat3.b1 = mat.b1; mat3.b2 = mat.b2; mat3.b3 = mat.b3; mat3.c1 = mat.c1; mat3.c2 = mat.c2; mat3.c3 = mat.c3; if (!strstr(node->mName.data, "$ColladaAutoName$")) clean_name = clean_node_name((char*)node->mName.data); if (only_one_node && strcmp(clean_name, only_one_node)) goto skip_mesh; for (i = 0; i < node->mNumMeshes; i++) { struct aiMesh *mesh = scene->mMeshes[node->mMeshes[i]]; struct aiMaterial *material = scene->mMaterials[mesh->mMaterialIndex]; if (mesh->mNumBones == 0 && dobone && !dorigid) { if (verbose) fprintf(stderr, "skipping rigid mesh %d in node %s (no bones)\n", i, clean_name); continue; } fprintf(stderr, "exporting mesh %s[%d]: %d vertices, %d faces\n", clean_name, i, mesh->mNumVertices, mesh->mNumFaces); fprintf(out, "\n"); fprintf(out, "mesh \"%s\"\n", clean_name); fprintf(out, "material \"%s\"\n", find_material(material)); struct vb *vb = (struct vb*) malloc(mesh->mNumVertices * sizeof(*vb)); memset(vb, 0, mesh->mNumVertices * sizeof(*vb)); // A rigidly animated node -- insert fake blend index/weights if (mesh->mNumBones == 0 && dobone) { a = find_bone((char*)node->mName.data); if (verbose) fprintf(stderr, "\trigid bone %d for mesh in node %s (no bones)\n", bonelist[a].number, node->mName.data); for (k = 0; k < mesh->mNumVertices; k++) { vb[k].b[0] = bonelist[a].number; vb[k].w[0] = 1; vb[k].n = 1; } } // Assemble blend index/weight array for (k = 0; k < mesh->mNumBones; k++) { struct aiBone *bone = mesh->mBones[k]; a = find_bone(bone->mName.data); for (t = 0; t < bone->mNumWeights; t++) { struct aiVertexWeight *w = mesh->mBones[k]->mWeights + t; int idx = w->mVertexId; if (vb[idx].n < MAXBLEND) { vb[idx].b[vb[idx].n] = bonelist[a].number; vb[idx].w[vb[idx].n] = w->mWeight; vb[idx].n++; } } } for (k = 0; k < mesh->mNumVertices; k++) { struct aiVector3D vp = mesh->mVertices[k]; if (!dobone) aiTransformVecByMatrix4(&vp, &mat); fprintf(out, "vp %.9g %.9g %.9g\n", vp.x, vp.y, vp.z); if (mesh->mNormals) { struct aiVector3D vn = mesh->mNormals[k]; if (!dobone) aiTransformVecByMatrix3(&vn, &mat3); fprintf(out, "vn %.9g %.9g %.9g\n", vn.x, vn.y, vn.z); } if (mesh->mTextureCoords[0]) { float u = mesh->mTextureCoords[0][k].x; float v = 1 - mesh->mTextureCoords[0][k].y; fprintf(out, "vt %.9g %.9g\n", u, v); } for (t = 1; t <= MAX_UVMAP; t++) { if (mesh->mTextureCoords[t]) { float u = mesh->mTextureCoords[t][k].x; float v = 1 - mesh->mTextureCoords[t][k].y; fprintf(out, "v%d %.9g %.9g\n", FIRST_UVMAP+t-1, u, v); } } if (mesh->mColors[0]) { float r = mesh->mColors[0][k].r; r = floorf(r * 255) / 255; float g = mesh->mColors[0][k].g; g = floorf(g * 255) / 255; float b = mesh->mColors[0][k].b; b = floorf(b * 255) / 255; float a = mesh->mColors[0][k].a; a = floorf(a * 255) / 255; fprintf(out, "vc %.9g %.9g %.9g %.9g\n", r, g, b, a); } for (t = 1; t <= MAX_COL; t++) { if (mesh->mColors[t]) { float r = mesh->mColors[t][k].r; r = floorf(r * 255) / 255; float g = mesh->mColors[t][k].g; g = floorf(g * 255) / 255; float b = mesh->mColors[t][k].b; b = floorf(b * 255) / 255; float a = mesh->mColors[t][k].a; a = floorf(a * 255) / 255; fprintf(out, "v%d %.9g %.9g %.9g %.9g\n", FIRST_COL+t-1, r, g, b, a); } } if (dobone) { fprintf(out, "vb"); for (t = 0; t < vb[k].n; t++) { fprintf(out, " %d %.9g", vb[k].b[t], vb[k].w[t]); } fprintf(out, "\n"); } } for (k = 0; k < mesh->mNumFaces; k++) { struct aiFace *face = mesh->mFaces + k; if (face->mNumIndices == 3) { if (doflip) fprintf(out, "fm %d %d %d\n", face->mIndices[2], face->mIndices[1], face->mIndices[0]); else fprintf(out, "fm %d %d %d\n", face->mIndices[0], face->mIndices[1], face->mIndices[2]); } else if (face->mNumIndices == 4) { if (doflip) fprintf(out, "fm %d %d %d %d\n", face->mIndices[3], face->mIndices[2], face->mIndices[1], face->mIndices[0]); else fprintf(out, "fm %d %d %d %d\n", face->mIndices[0], face->mIndices[1], face->mIndices[2], face->mIndices[3]); } else if (face->mNumIndices > 4) { fprintf(stderr, "n-gon (%d) in mesh!\n", face->mNumIndices); int i1 = face->mIndices[0]; int i2 = face->mIndices[1]; for (a = 2; a < face->mNumIndices; a++) { int i3 = face->mIndices[a]; if (doflip) fprintf(out, "fm %d %d %d\n", i3, i2, i1); else fprintf(out, "fm %d %d %d\n", i1, i2, i3); i2 = i3; } } else { fprintf(stderr, "skipping point/line primitive\n"); } } free(vb); } skip_mesh: for (i = 0; i < node->mNumChildren; i++) export_node(out, scene, node->mChildren[i], mat, clean_name); }