osgDB::ReaderWriter::ReadResult ReaderWriterPaths::readObject(std::istream& fin, const osgDB::Options* options) const { OSG_INFO<<"ReaderWriterPaths::readObject(std::istream& fin"<<std::endl; if (!options) return ReadResult::FILE_NOT_HANDLED; if (!fin) return ReadResult::ERROR_IN_READING_FILE; std::string filename = options->getPluginStringData("filename"); std::string ext = osgDB::getLowerCaseFileExtension(filename); OSG_INFO<<" filename found in options: "<<filename<<" extension="<<ext<<std::endl; if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; if (ext=="path") return read_path(fin, options); else if (ext=="material") return read_material(fin, options); else if (ext=="pivot_path") return read_pivot_path(fin, options); else if (ext=="rotation_path") return read_rotation_path(fin, options); return ReadResult::FILE_NOT_HANDLED; }
Item::Item(DFInstance *df, ItemDefUniform *u, QObject *parent) : QObject(parent) , m_df(df) , m_addr(0x0) , m_iType(u->item_type()) , m_wear(0) , m_mat_type(u->mat_type()) , m_mat_idx(u->mat_index()) , m_quality(-1) , m_id(u->id()) , m_affection(0) , m_stack_size(u->get_stack_size()) , m_size_prefix("") , m_maker_race(-1) { //set the color to the missing uniform color, since we passed in a uniform itemdef m_color_display = Item::color_missing(); if(m_id > 0){ //find the actual item's address m_addr = m_df->get_item_address(m_iType,m_id); if(m_addr){ read_data(); return; } } if(u->mat_flag() != MAT_NONE){ mat_flags().set_flag(u->mat_flag(),true); } read_material(); if(u->mat_flag() != MAT_NONE){ m_material_name = u->generic_mat_name(); } short subtype = u->item_subtype(); QVector<VIRTADDR> item_defs = m_df->get_itemdef_vector(m_iType); if(!item_defs.empty() && (subtype >=0 && subtype < item_defs.count())){ //get sub-type name m_item_name = m_df->read_string(item_defs.at(subtype) + m_df->memory_layout()->item_subtype_offset("name")); }else{ //get base item name m_item_name = Item::get_item_name(m_iType); //check skill type if(!u->indv_choice() && u->job_skill() >= 0){ m_item_name.append(QObject::tr(" of %1 skill type").arg(GameDataReader::ptr()->get_skill_name(u->job_skill()))); } if(m_id > 0){ //couldn't find the item, it's been claimed by another unit or couldn't be equipped m_item_name.prepend(tr("Specific ")); } } }
void Item::read_data(){ if(m_addr){ VIRTADDR item_vtable = m_df->read_addr(m_addr); m_iType = static_cast<ITEM_TYPE>(m_df->read_int(m_df->read_addr(item_vtable) + m_df->VM_TYPE_OFFSET())); m_id = m_df->read_int(m_addr+m_df->memory_layout()->item_offset("id")); m_stack_size = m_df->read_int(m_addr+m_df->memory_layout()->item_offset("stack_size")); m_wear = m_df->read_short(m_addr+m_df->memory_layout()->item_offset("wear")); m_mat_type = m_df->read_short(m_addr+m_df->memory_layout()->item_offset("mat_type")); m_mat_idx = m_df->read_int(m_addr+m_df->memory_layout()->item_offset("mat_index")); m_maker_race = m_df->read_short(m_addr+m_df->memory_layout()->item_offset("maker_race")); m_quality = m_df->read_short(m_addr+m_df->memory_layout()->item_offset("quality")); read_material(); QVector<VIRTADDR> gen_refs = m_df->enumerate_vector(m_addr+m_df->memory_layout()->item_offset("general_refs")); foreach(VIRTADDR ref, gen_refs){ VIRTADDR gen_ref_vtable = m_df->read_addr(ref); int ref_type = m_df->read_int(m_df->read_addr(gen_ref_vtable+m_df->memory_layout()->general_ref_offset("ref_type")) + m_df->VM_TYPE_OFFSET()); if(ref_type == 0 || ref_type == 1){ LOGD << "reading type:" << ref_type << "(artifact name)"; int artifact_id = m_df->read_int(ref+m_df->memory_layout()->general_ref_offset("artifact_id")); if(artifact_id > 0){ m_artifact_name = m_df->get_artifact_name(ARTIFACTS,artifact_id); break; } }else if(ref_type == 10 && m_iType == QUIVER){ //type of container item, could be expanded to show food and drink LOGD << "reading type:" << ref_type << "(container)"; int item_id = m_df->read_int(ref+m_df->memory_layout()->general_ref_offset("item_id")); VIRTADDR ammo_addr = m_df->get_item_address(AMMO,item_id); if(ammo_addr > 0){ ItemAmmo *ia = new ItemAmmo(m_df,ammo_addr); bool appended = false; foreach(Item *i, m_contained_items){ if(i->equals(*ia)){ i->add_to_stack(ia->get_stack_size()); appended = true; break; } } if(!appended){ m_contained_items.append(ia); }else{ delete ia; } }else{
void Material::load_data() { if (!m_df || !m_df->memory_layout() || !m_df->memory_layout()->is_valid()) { LOGW << "load of materials called but we're not connected"; return; } // make sure our reference is up to date to the active memory layout m_mem = m_df->memory_layout(); //if passed in an inorganic material, we have to offset to the material.common first if(m_inorganic) m_address += m_mem->material_offset("inorganic_materials_vector"); m_flag_address = m_address + m_mem->material_offset("flags"); TRACE << "Starting refresh of material data at" << hexify(m_address); read_material(); }
void read_mesh(context_t* context, const reader_mesh_t* mesh) { hwgm_mesh_t* out = NULL; hwgm_vertices_t* vertices = NULL; hwgm_material_t* material = NULL; out = (hwgm_mesh_t*)(context->meshes + context->mesh_pos); hwgm_mesh_initialize(out); vertices = read_vertices(context, mesh); out->vertices = vertices; material = read_material(context, &mesh->material); out->material = material; context->mesh_pos += calc_size_mesh(mesh); return out; }
void FBXSceneImporter::read_mesh(FbxNode *pNode, FbxMesh* pMesh) { std::vector<Mesh::Vertex> vertices; std::vector<int> indices; //pMesh->GenerateTangentsDataForAllUVSets(); Mesh *new_mesh = new Mesh(); new_mesh->set_name(pNode->GetName()); int polygonCount = pMesh->GetPolygonCount(); FbxVector4* controlPoints = pMesh->GetControlPoints(); int controlPointCount = pMesh->GetControlPointsCount(); int vertexID = 0; for (int polygon = polygonCount - 1; polygon > -1; polygon--) { int polyVertCount = pMesh->GetPolygonSize(polygon); assert(polyVertCount == 3); for (int polyVert = 0; polyVert < polyVertCount; polyVert++) { Mesh::Vertex vertex; int cpIndex = pMesh->GetPolygonVertex(polygon, polyVert); // Grab our CP index as well our position information //uniqueVert.m_nControlPointIndex = cpIndex; vertex.position[0] = controlPoints[cpIndex].mData[0]; vertex.position[1] = controlPoints[cpIndex].mData[1]; vertex.position[2] = controlPoints[cpIndex].mData[2]; vertex.position[3] = 1; // Grab UVs int uvElementCount = pMesh->GetElementUVCount(); int ctrlPointIndex = pMesh->GetPolygonVertex(polygon, polyVert); for (int uvElement = 0; uvElement < uvElementCount; uvElement++) { FbxGeometryElementUV* geomElementUV = pMesh->GetElementUV(uvElement); FbxLayerElement::EMappingMode mapMode = geomElementUV->GetMappingMode(); FbxLayerElement::EReferenceMode refMode = geomElementUV->GetReferenceMode(); if (FbxGeometryElement::eByControlPoint == mapMode) { switch (geomElementUV->GetReferenceMode()) { case FbxGeometryElement::eDirect: { vertex.texture_coord.x = static_cast<float>(geomElementUV->GetDirectArray().GetAt(ctrlPointIndex).mData[0]); vertex.texture_coord.y = static_cast<float>(geomElementUV->GetDirectArray().GetAt(ctrlPointIndex).mData[1]); } break; case FbxGeometryElement::eIndexToDirect: { int index = geomElementUV->GetIndexArray().GetAt(ctrlPointIndex); vertex.texture_coord.x = static_cast<float>(geomElementUV->GetDirectArray().GetAt(index).mData[0]); vertex.texture_coord.y = static_cast<float>(geomElementUV->GetDirectArray().GetAt(index).mData[1]); } break; default: throw std::exception("Invalid Reference"); } } if (FbxGeometryElement::eByPolygonVertex == mapMode) { int directIndex = -1; if (FbxGeometryElement::eDirect == refMode) { directIndex = vertexID; } else if (FbxGeometryElement::eIndexToDirect == refMode) { directIndex = geomElementUV->GetIndexArray().GetAt(vertexID); } // If we got an index if (directIndex != -1) { FbxVector4 texture_coord = geomElementUV->GetDirectArray().GetAt(directIndex); vertex.texture_coord = D3DXVECTOR4((float)texture_coord.mData[0], (float)texture_coord.mData[1], 0, 0); } } } // Grab normals int normElementCount = pMesh->GetElementNormalCount(); for (int normalElement = 0; normalElement < normElementCount; normalElement++) { FbxGeometryElementNormal* geomElementNormal = pMesh->GetElementNormal(normalElement); FbxLayerElement::EMappingMode mapMode = geomElementNormal->GetMappingMode(); FbxLayerElement::EReferenceMode refMode = geomElementNormal->GetReferenceMode(); FbxVector4 fbxNormal; pMesh->GetPolygonVertexNormal(polygon, polyVert, fbxNormal); fbxNormal.Normalize(); vertex.normal = D3DXVECTOR4(fbxNormal.mData[0], fbxNormal.mData[1], fbxNormal.mData[2], 0); //if (FbxGeometryElement::eByControlPoint == mapMode) //{ // switch (geomElementNormal->GetReferenceMode()) // { // case FbxGeometryElement::eDirect: // { // vertex.normal.x = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[0]); // vertex.normal.y = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[1]); // vertex.normal.z = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(ctrlPointIndex).mData[2]); // D3DXVec4Normalize(&vertex.normal, &vertex.normal); // } // break; // // case FbxGeometryElement::eIndexToDirect: // { // int index = geomElementNormal->GetIndexArray().GetAt(ctrlPointIndex); // vertex.normal.x = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[0]); // vertex.normal.y = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[1]); // vertex.normal.z = static_cast<float>(geomElementNormal->GetDirectArray().GetAt(index).mData[2]); // D3DXVec4Normalize(&vertex.normal, &vertex.normal); // } // break; // // default: // throw std::exception("Invalid Reference"); // } //} //if (FbxGeometryElement::eByPolygonVertex == mapMode) //{ // int directIndex = -1; // if (FbxGeometryElement::eDirect == refMode) // { // directIndex = vertexID; // } // else if (FbxGeometryElement::eIndexToDirect == refMode) // { // directIndex = geomElementNormal->GetIndexArray().GetAt(vertexID); // } // // // If we got an index // if (directIndex != -1) // { // FbxVector4 norm = geomElementNormal->GetDirectArray().GetAt(directIndex); // // D3DXVECTOR4 normal_final((float)norm.mData[0], (float)norm.mData[1], (float)norm.mData[2], 0); // D3DXVec4Normalize(&vertex.normal, &normal_final); // } //} } // grab tangents int tangentElementCount = pMesh->GetElementTangentCount(); for (int normalElement = 0; normalElement < tangentElementCount; normalElement++) { FbxGeometryElementTangent* geomElementTangent = pMesh->GetElementTangent(normalElement); FbxLayerElement::EMappingMode mapMode = geomElementTangent->GetMappingMode(); FbxLayerElement::EReferenceMode refMode = geomElementTangent->GetReferenceMode(); int directIndex = -1; if (FbxGeometryElement::eByPolygonVertex == mapMode) { if (FbxGeometryElement::eDirect == refMode) { directIndex = vertexID; } else if (FbxGeometryElement::eIndexToDirect == refMode) { directIndex = geomElementTangent->GetIndexArray().GetAt(vertexID); } } // If we got an index if (directIndex != 1) { FbxVector4 tangent = geomElementTangent->GetDirectArray().GetAt(directIndex); vertex.tangent = D3DXVECTOR4((float)tangent.mData[0], (float)tangent.mData[1], (float)tangent.mData[2], 0); } } size_t size = vertices.size(); size_t i = size; //for (i = 0; i < size; i++) //{ // if (vertex == vertices[i]) // { // break; // } //} // if (i == size) { vertices.push_back(vertex); } indices.push_back(i); ++vertexID; } //int cur_size = indices.size(); //int temp = indices[cur_size - 3]; //indices[cur_size - 3] = indices[cur_size - 1]; //indices[cur_size - 1] = temp; } int materialCount = pNode->GetSrcObjectCount<FbxSurfaceMaterial>(); new_mesh->create_from_buffers(vertices, indices); scene_to_fill->add_mesh(new_mesh); if (materialCount > 0) { FbxSurfaceMaterial* material = (FbxSurfaceMaterial*)pNode->GetSrcObject<FbxSurfaceMaterial>(0); new_mesh->set_material(read_material(pNode, material)); } get_transformation_matrix(pNode, new_mesh); cout << "Read mesh : " << new_mesh->get_name() << "\n"; }
int read_one_obj( FILE *fp, Polygon *poly, Surface *surface) { char b[MWS]; int flag_material = 0; int flag_point = 0; int flag_index = 0; /* initialize surface */ surface->diff[0] = 1.0; surface->diff[1] = 1.0; surface->diff[2] = 1.0; surface->spec[0] = 0.0; surface->spec[1] = 0.0; surface->spec[2] = 0.0; surface->ambi = 0.0; surface->shine = 0.2; if ( getword(fp,b,MWS) <= 0) return 0; poly->vtx_num = 0; poly->idx_num = 0; while (flag_material==0 || flag_point==0 || flag_index==0) { if (strindex(b,"Material")>=0) { getword(fp,b,MWS); flag_material = 1; } else if (strindex(b,"point")>=0) { fprintf(stderr,"Counting... [point]\n"); poly->vtx_num = count_point(fp, b); flag_point = 1; } else if (strindex(b,"coordIndex")>=0) { fprintf(stderr,"Counting... [coordIndex]\n"); poly->idx_num = count_index(fp, b); flag_index = 1; } else if (getword(fp,b,MWS) <= 0) return 0; } flag_material = 0; flag_point = 0; flag_index = 0; fseek(fp, 0, SEEK_SET); poly->vtx = (double *)malloc(sizeof(double)*3*poly->vtx_num); poly->idx = (int *)malloc(sizeof(int)*3*poly->idx_num); while (flag_material==0 || flag_point==0 || flag_index==0) { if (strindex(b,"Material")>=0) { fprintf(stderr,"Reading... [Material]\n"); read_material(fp,surface,b); flag_material = 1; } else if (strindex(b,"point")>=0) { fprintf(stderr,"Reading... [point]\n"); read_point(fp,poly,b); flag_point = 1; } else if (strindex(b,"coordIndex")>=0) { fprintf(stderr,"Reading... [coordIndex]\n"); read_index(fp,poly,b); flag_index = 1; } else if (getword(fp,b,MWS) <= 0) return 0; } return 1; }