bool WindowsManager::addMesh (const char* meshNameCorba, const char* meshPathCorba) { std::string meshName (meshNameCorba); std::string meshPath (meshPathCorba); if (nodes_.find (meshName) != nodes_.end ()) { std::cout << "You need to chose an other name, \"" << meshName << "\" already exist." << std::endl; return false; } else { try { mtx_.lock(); LeafNodeColladaPtr_t mesh = LeafNodeCollada::create (meshName, meshPath); WindowsManager::initParent (meshName, mesh); addNode (meshName, mesh); mtx_.unlock(); return true; } catch (const std::exception& exc) { std::cout << "Mesh \"" << meshPath << "\" not found." << std::endl; return false; } } }
void LuxRenderer::createAreaLightMesh(mtlu_MayaObject *obj) { MString meshName(""); MFnDependencyNode depFn(obj->mobject); MObject otherSideObj = getOtherSideNode(MString("mtlu_areaLight_geo"), obj->mobject); if( otherSideObj != MObject::kNullObj) { }else{ int indices[6] = {0,1,2,2,3,0}; float floatPointArray[12] = {-1, -1, 0, -1, 1, 0, 1, 1, 0, 1, -1, 0}; float floatNormalArray[12] = {0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1}; ParamSet triParams = CreateParamSet(); triParams->AddInt("indices", indices, 6); triParams->AddPoint("P", floatPointArray, 4); triParams->AddNormal("N", floatNormalArray, 4); lux->transformBegin(); float fm[16]; MMatrix tm = obj->transformMatrices[0]; setZUp(tm, fm); this->lux->transform(fm); this->lux->shape("trianglemesh", boost::get_pointer(triParams)); lux->transformEnd(); } }
std::string MeshManager::createHUDPanel(const Rectangle& bounds) { BasicMesh* result = new BasicMesh(); result->m_vertices = new float[12]; memset(result->m_vertices, 0, 12*sizeof(float)); result->m_vertices[0] = bounds.x; result->m_vertices[1] = bounds.y; result->m_vertices[3] = bounds.x + bounds.width; result->m_vertices[4] = bounds.y; result->m_vertices[6] = bounds.x + bounds.width; result->m_vertices[7] = bounds.y + bounds.height; result->m_vertices[9] = bounds.x; result->m_vertices[10]= bounds.y + bounds.height; result->m_uvs = new GLfloat[8]; memset(result->m_uvs, 0, 8 * sizeof(GLfloat)); if(!Game::getInstance().getHUD().flipUi()) { result->m_uvs[0] = 0; result->m_uvs[1] = 1; result->m_uvs[2] = 1; result->m_uvs[3] = 1; result->m_uvs[4] = 1; result->m_uvs[5] = 0; result->m_uvs[6] = 0; result->m_uvs[7] = 0; } else { result->m_uvs[0] = 0; result->m_uvs[1] = 0; result->m_uvs[2] = 0; result->m_uvs[3] = 1; result->m_uvs[4] = 1; result->m_uvs[5] = 1; result->m_uvs[6] = 1; result->m_uvs[7] = 0; } result->m_indices = new GLshort[6]; result->m_indices[0] = 0; result->m_indices[1] = 1; result->m_indices[2] = 2; result->m_indices[3] = 0; result->m_indices[4] = 2; result->m_indices[5] = 3; result->m_indicesCount = 6; result->m_verticesCount = 4; std::stringstream ss; ss << s_panelsCount++; std::string meshName(""); Log("Panels count: %d", s_panelsCount); ss >> meshName; meshName += "HUDPanel"; result->m_name = meshName; m_meshes[result->m_name] = result; return meshName; }
void avtFITSFileFormat::Initialize(avtDatabaseMetaData *md) { const char *mName = "avtFITSFileFormat::Initialize: "; if(fits == 0) { debug4 << mName << "Opening " << filename << endl; int status = 0; if(fits_open_file(&fits, filename, 0, &status)) { PrintError(status); EXCEPTION1(InvalidFilesException, filename); } char card[FLEN_CARD], tmp[100]; std::string fileComment; int hdutype = 0; // Iterate over the HDU's for(int hdu = 1; !(fits_movabs_hdu(fits, hdu, &hdutype, &status)); hdu++) { debug4 << mName << "Looking at HDU " << hdu << endl; // Get no. of keywords int nkeys = 0, keypos = 0; if(fits_get_hdrpos(fits, &nkeys, &keypos, &status)) PrintError(status); if(hdutype == IMAGE_HDU) { debug4 << mName << "HDU " << hdu << " contains an image" << endl; //int status2 = 0; char value[FLEN_VALUE]; std::string objname, bunit, xlabel, ylabel, zlabel; // Try and get the key value for BUNIT if(GetKeywordValue("BUNIT", value)) { bunit = std::string(value); debug4 << "\tBUNIT=" << value << endl; } // Try and get the key value for OBJECT if(GetKeywordValue("OBJECT", value)) { objname = std::string(value); debug4 << "\tOBJECT=" << value << endl; } #if 0 // // Re-enable these someday when we read the mesh coordinates from the file // and use them to construct a sensible mesh. // // Try and get the key value for CTYPE1 if(GetKeywordValue("CTYPE1", value)) { xlabel = std::string(value); debug4 << "\tCTYPE1=" << value << endl; } // Try and get the key value for CTYPE2 if(GetKeywordValue("CTYPE2", value)) { ylabel = std::string(value); debug4 << "\tCTYPE2=" << value << endl; } // Try and get the key value for CTYPE3 if(GetKeywordValue("CTYPE3", value)) { zlabel = std::string(value); debug4 << "\tCTYPE3=" << value << endl; } #endif // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); fileComment += tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); fileComment += cs; if(cs.size() > 0 && cs[cs.size()-1] != '\n') fileComment += "\n"; } fileComment += "\n\n"; // // Get the image's dimensions. // int ndims = 0; if(fits_get_img_dim(fits, &ndims, &status)) PrintError(status); debug4 << mName << "Num dimensions: " << ndims << ", status=" << status << endl; long *dims = new long[ndims]; if(fits_get_img_size(fits, ndims, dims, &status)) PrintError(status); if(ndims == 0) { debug4 << mName << "The image has no dimensions. Skip it." << endl; continue; } // // Create a mesh name for the image. // intVector mdims; std::string meshName("image"); debug4 << mName << "Image dimensions: "; bool dimensionsNonZero = false; for(int i = 0; i < ndims; ++i) { char num[20]; if(i > 0) SNPRINTF(num, 20, "x%d", (int)dims[i]); else SNPRINTF(num, 20, "%d", (int)dims[i]); meshName += num; mdims.push_back((int)dims[i]); dimensionsNonZero |= (dims[i] != 0); debug4 << dims[i] << ", "; } debug4 << endl; if(!dimensionsNonZero) { debug4 << mName << "All dimensions were zero. skip." << endl; continue; } if(ndims == 1 && objname != "") meshName = objname; if(meshDimensions.find(meshName) == meshDimensions.end()) { meshDimensions[meshName] = mdims; // Create metadata if necessary. if(md != 0) { if(ndims == 1) { debug4 << mName << "Adding a curve called " << meshName.c_str() << " for HDU " << hdu << endl; avtCurveMetaData *cmd = new avtCurveMetaData; cmd->name = meshName; if(xlabel != "") cmd->xLabel = xlabel; if(ylabel != "") cmd->yLabel = ylabel; md->Add(cmd); // Do this because we use GetVar to read the data // that we use to create the curve. varToHDU[meshName] = hdu; varToMesh[meshName] = meshName; } else { int sdims, tdims; int nrealdims = (ndims <= 3) ? ndims : 3; #define VECTOR_SUPPORT #ifdef VECTOR_SUPPORT if(nrealdims == 3 && dims[2] == 3) nrealdims = 2; #endif sdims = tdims = nrealdims; debug4 << mName << "Adding a " << sdims << " dimensional mesh called " << meshName.c_str() << " for HDU " << hdu << endl; avtMeshMetaData *mmd = new avtMeshMetaData( meshName, 1, 1, 1, 0, sdims, tdims, AVT_RECTILINEAR_MESH); if(xlabel != "") mmd->xLabel = xlabel; if(ylabel != "") mmd->yLabel = ylabel; if(zlabel != "") mmd->zLabel = zlabel; md->Add(mmd); } } } // // Create a name for the variable at this HDU // if(ndims > 1) { char varname[100]; SNPRINTF(varname, 100, "hdu%d", hdu); std::string vName(varname); if(objname != "") vName = objname; varToHDU[vName] = hdu; varToMesh[vName] = meshName; // Create metadata if necessary if(md != 0) { #ifdef VECTOR_SUPPORT // Limit the dimensions to 3. int ncomps = 1; int nrealdims = (ndims <= 3) ? ndims : 3; if(nrealdims == 3 && dims[2] == 3) ncomps = 3; if(ncomps == 1) { #endif debug4 << mName << "Adding a scalar called " << vName.c_str() << " for HDU " << hdu << endl; // Add the scalar metadata avtScalarMetaData *smd = new avtScalarMetaData( vName, meshName, AVT_ZONECENT); smd->hasUnits = bunit != ""; smd->units = bunit; md->Add(smd); #ifdef VECTOR_SUPPORT } else { debug4 << mName << "Adding a color vector called " << vName.c_str() << " for HDU " << hdu << endl; // Add the vector metadata avtVectorMetaData *vmd = new avtVectorMetaData( vName, meshName, AVT_ZONECENT, 4); // vmd->hasUnits = true; // vmd->units = md->Add(vmd); } #endif } } delete [] dims; } else if(hdutype == ASCII_TBL) { debug4 << mName << "HDU " << hdu << " contains an ascii table" << endl; } else if(hdutype == BINARY_TBL) { debug4 << mName << "HDU " << hdu << " contains a binary table" << endl; // Use the keywords to create a comment. SNPRINTF(tmp, 100, "Header listing for HDU #%d:\n", hdu); debug4 << tmp; for(int jj = 1; jj <= nkeys; jj++) { if(fits_read_record(fits, jj, card, &status)) PrintError(status); std::string cs(card); if(cs.size() > 0 && cs[cs.size()-1] != '\n') cs += "\n"; debug4 << "\t" << cs.c_str(); } } } if(md != 0) md->SetDatabaseComment(fileComment); } }
void avtVis5DFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState) { Initialize(); // Don't alphabetize the variables in the client menus. md->SetMustAlphabetizeVariables(false); if(v5dfile != 0) { #if 0 // Print the structure of the file. v5dPrintStruct(v5dfile); #endif // // Add the mesh // std::string meshName("grid"); avtMeshType mt; if(v5dfile->Projection == 0 || v5dfile->Projection == 1) mt = AVT_RECTILINEAR_MESH; else mt = AVT_CURVILINEAR_MESH; avtMeshMetaData *mmd = new avtMeshMetaData(meshName, 1, 1, 1, 0, 3, 3, mt); if(v5dfile->Projection == 1) { mmd->xUnits = "degrees"; mmd->yUnits = "degrees"; mmd->xLabel = "W Longitude"; mmd->yLabel = "N Latitude"; } else if(v5dfile->Projection != 0) { mmd->xUnits = "degrees"; mmd->yUnits = "degrees"; mmd->xLabel = "Longitude"; mmd->yLabel = "Latitude"; } mmd->zLabel = "Levels"; if(v5dfile->VerticalSystem == 1 || v5dfile->VerticalSystem == 2) mmd->zUnits = "km"; else if(v5dfile->VerticalSystem == 3) mmd->zUnits = "mb"; md->Add(mmd); // // Add the scalars // for(int i = 0; i < v5dfile->NumVars; ++i) { char varName[10], units[20], *cptr = 0; strcpy(varName, v5dfile->VarName[i]); strcpy(units, v5dfile->Units[i]); for(cptr = varName + 8; cptr >= varName; --cptr) { if(*cptr == ' ') *cptr = '\0'; else break; } for(cptr = units + 18; cptr >= varName; --cptr) { if(*cptr == ' ') *cptr = '\0'; else break; } if(varName[0] != '\0') { avtScalarMetaData *smd = new avtScalarMetaData( varName, meshName, AVT_NODECENT); smd->hasUnits = units[0] != '\0'; if(smd->hasUnits) smd->units = std::string(units); smd->hasDataExtents = true; smd->minDataExtents = v5dfile->MinVal[i]; smd->maxDataExtents = v5dfile->MaxVal[i]; md->Add(smd); } } } }
void akDemo::init(void) { m_camera->m_transform.identity(); m_camera->m_transform.loc = akVector3(7.4811316,-6.5076399,5.3436651); m_camera->m_transform.rot = akQuat(0.48170695,0.21292172,0.33425143,0.78159994); m_camera->m_fov = 49.134342; m_camera->m_clipStart = 0.1; m_camera->m_clipEnd = 100; akMesh* mesh = new akMesh(); m_canUseVbo = true; bool hasNormals= false; bool hasColors=false; int uvlayers=0; utArray<float> uvs; akSubMesh* subMesh = new akSubMesh(akSubMesh::ME_TRIANGLES,hasNormals,hasColors,uvlayers); akVector3 xyz[NUM_VERTS]={ akVector3(1.000000,1.000000,-1.000000), akVector3(1.000000,-1.000000,-1.000000), akVector3(-1.000000,-1.000000,-1.000000), akVector3(-1.000000,1.000000,-1.000000), akVector3(1.000000,1.000000,-1.000000), akVector3(1.000000,0.999999,1.000000), akVector3(1.000000,-1.000000,-1.000000), akVector3(0.999999,-1.000001,1.000000), akVector3(1.000000,-1.000000,-1.000000), akVector3(0.999999,-1.000001,1.000000), akVector3(-1.000000,-1.000000,-1.000000), akVector3(-1.000000,-1.000000,1.000000), akVector3(-1.000000,-1.000000,-1.000000), akVector3(-1.000000,-1.000000,1.000000), akVector3(-1.000000,1.000000,1.000000), akVector3(-1.000000,1.000000,-1.000000), akVector3(1.000000,0.999999,1.000000), akVector3(1.000000,1.000000,-1.000000), akVector3(-1.000000,1.000000,1.000000), akVector3(-1.000000,1.000000,-1.000000), akVector3(-1.000000,1.000000,1.000000), akVector3(-1.000000,1.000000,3.000000), akVector3(-1.000000,-1.000000,3.000000), akVector3(-1.000000,-1.000000,1.000000), akVector3(-1.000000,-1.000000,3.000000), akVector3(0.999999,-1.000001,3.000000), akVector3(-1.000000,1.000000,1.000000), akVector3(1.000000,0.999999,3.000000), akVector3(-1.000000,1.000000,3.000000), akVector3(0.999999,-1.000001,1.000000), akVector3(0.999999,-1.000001,3.000000), akVector3(1.000000,0.999999,3.000000), akVector3(0.999999,-1.000001,3.000000), akVector3(1.000000,0.999999,3.000000), akVector3(0.999999,-1.000001,5.000000), akVector3(1.000000,0.999999,5.000000), akVector3(1.000000,0.999999,3.000000), akVector3(-1.000000,1.000000,3.000000), akVector3(1.000000,0.999999,5.000000), akVector3(-1.000000,1.000000,5.000000), akVector3(-1.000000,-1.000000,3.000000), akVector3(0.999999,-1.000001,3.000000), akVector3(-1.000000,-1.000000,5.000000), akVector3(0.999999,-1.000001,5.000000), akVector3(-1.000000,1.000000,3.000000), akVector3(-1.000000,-1.000000,3.000000), akVector3(-1.000000,1.000000,5.000000), akVector3(-1.000000,-1.000000,5.000000), akVector3(1.000000,0.999999,5.000000), akVector3(-1.000000,1.000000,5.000000) }; int indices[NUM_TRIANGLES*3]={0,1,2,2,3,0,4,5,6,6,5,7,8,9,10,10,9,11,12,13,14,14,15,12,16,17,18,18,17,19,20,13 ,21,21,13,22,23,9,24,24,9,25,16,26,27,27,26,28,29,5,30,30,5,31,32,33,34,34,33,35 ,36,37,38,38,37,39,40,41,42,42,41,43,44,45,46,46,45,47,48,49,34,34,49,47 }; akVector3 normal(0,1,0);//s[NUM_VERTS]; unsigned int color = 0; int numIndices = sizeof(indices)/sizeof(int); for (int v=0;v<NUM_VERTS;v++) { subMesh->addVertex(xyz[v],normal,color,uvs); } for (int i=0;i<NUM_TRIANGLES*3;i++) { subMesh->addIndex(indices[i]); } mesh->addSubMesh(subMesh); int numTris = mesh->getTriangleCount(); utHashedString meshName("myMesh"); addMesh(meshName, mesh); akEntity* entity = new akEntity(); akTransformState trans = akTransformState::identity(); entity->setTransformState(trans); entity->setMesh(mesh); this->addEntity(utHashedString("MyEntity"),entity); utHashedString jointNames[NUM_JOINTS]={utHashedString("Bone"),utHashedString("Bone.001"),utHashedString("Bone.002")}; akSkeleton* skeleton = new akSkeleton(); int parent = skeleton->addJoint(jointNames[0],AK_JOINT_NO_PARENT); parent = skeleton->addJoint(jointNames[1],parent); parent = skeleton->addJoint(jointNames[2],parent); akSkeletonPose* bindPose = new akSkeletonPose(skeleton, akSkeletonPose::SP_MODEL_SPACE); akTransformState jointPoses[NUM_JOINTS] = { akTransformState(akVector3(0,0,0),akQuat(0.70710671, 0.00000000,0.00000000,0.70710677)), akTransformState(akVector3(0,0,1),akQuat(0.0,0.70710671,0.70710677,0.0)), akTransformState(akVector3(0,0,2),akQuat(0.0,0.70710671,0.70710677,0.f))}; for (int i=0;i<NUM_JOINTS;i++) { *bindPose->getJointPose(i) = jointPoses[i]; } skeleton->setBindingPose(bindPose); addSkeleton(utHashedString("MySkeleton"),skeleton); entity->setSkeleton(skeleton); for(int i=0;i<NUM_JOINTS; i++) { akVertexGroup* vg = new akVertexGroup(); vg->setName(jointNames[i].str()); mesh->getSubMesh(0)->addVertexGroup(vg); } int indices0[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,36,37,40,41,44,45}; int indices1[40]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,36,37,40,41,44,45}; int indices2[38]={5,7,9,11,13,14,16,18,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49}; float weights0[NUM_WEIGHTS0]={ 0.895997,0.895092,0.895997,0.895092,0.895997,0.496942,0.895092,0.496901,0.895092 ,0.496901,0.895997,0.496942,0.895997,0.496942,0.496901,0.895092,0.496942,0.895997, 0.496901,0.895092,0.496901,0.051515,0.051474,0.496942,0.051474,0.051515,0.496901, 0.051474,0.051515,0.496901,0.051515,0.051474,0.051515,0.051474,0.051474,0.051515, 0.051474,0.051515,0.051515,0.051474}; float weights1[NUM_WEIGHTS1]={0.093034,0.093843,0.093034,0.093843,0.093034,0.449999,0.093843,0.450039,0.093843, 0.450039,0.093034,0.449999,0.093034,0.449999,0.450039,0.093843,0.449999,0.093034, 0.450039,0.093843,0.450039,0.043311,0.043225,0.449999,0.043225,0.043311,0.450039, 0.043225,0.043311,0.450039,0.043311,0.043225,0.043311,0.043225,0.043225,0.043311, 0.043225,0.043311,0.043311,0.043225}; float weights2[NUM_WEIGHTS2]={0.053059,0.053060,0.053060,0.053059,0.053059,0.053060,0.053059,0.053060,0.053060, 0.901830,0.901914,0.053059,0.901914,0.901830,0.053060,0.901914,0.901830,0.053060, 0.901830,0.901914,0.901830,0.901914,0.964282,0.965462,0.901914,0.901830,0.965462, 0.964282,0.901914,0.901830,0.965462,0.964282,0.901830,0.901914,0.964282,0.965462, 0.965462,0.964282}; for (int i=0;i<NUM_WEIGHTS0;i++) { mesh->getSubMesh(0)->getVertexGroup(0)->add(indices0[i],weights0[i]); } for (int i=0;i<NUM_WEIGHTS1;i++) { mesh->getSubMesh(0)->getVertexGroup(1)->add(indices1[i],weights1[i]); } for (int i=0;i<NUM_WEIGHTS2;i++) { mesh->getSubMesh(0)->getVertexGroup(2)->add(indices2[i],weights2[i]); } mesh->generateBoneWeightsFromVertexGroups(skeleton, true); akAnimationClip* act = new akAnimationClip(); { akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[0]); akAnimationCurve* spline = 0; spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,1.0000000,-0.041666668,1.0000000,0.041666668 ,1.0000000); chan->addCurve(spline); spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000); chan->addCurve(spline); spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000); chan->addCurve(spline); spline = new akAnimationCurve(1, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,0.00000000,-0.041666668,0.00000000,0.041666668,0.00000000); chan->addCurve(spline); act->addChannel(chan); } { akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[1]); akAnimationCurve* spline = 0; spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,1.0000000,-0.89469218,1.0000000,0.89469218,1.0000000); spline->setSample(1,2.2916667,0.92387956,1.3969746,0.92387956,3.1863589,0.92387956); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000 ,0.00000000 ,-0.89467138 ,0.00000000 ,0.89467138 ,0.00000000 ); spline->setSample(1 ,2.2916667,0.38268343,1.3969953,0.38268343 ,3.1863382 ,0.38268343); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000,0.00000000,-0.89469308,0.00000000,0.89469308 ,0.00000000 ); spline->setSample(1,2.2916667 ,-3.8454296e-015 ,1.3969736 ,-3.8454296e-015 ,3.1863599 ,-3.8454296e-015 ); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000 ,0.00000000 ,-0.89469308 ,0.00000000 ,0.89469308 ,0.00000000); spline->setSample(1 ,2.2916667 ,5.7783591e-008 ,1.3969736 ,5.7783591e-008 ,3.1863599 ,5.7783591e-008 ); chan->addCurve(spline); act->addChannel(chan); } { akAnimationChannel* chan = new akAnimationChannel(akAnimationChannel::AC_BONE, jointNames[2]); akAnimationCurve* spline = 0; spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_W, akAnimationCurve::BEZ_CUBIC); spline->setSample(0 ,0.00000000 ,1.0000000 ,-0.40667677 ,1.0000000 ,0.40667677 ,1.0000000); spline->setSample(1,1.0416667 ,0.92387956 ,0.63498992 ,0.92387956 ,1.4483435 ,0.92387956 ); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_X, akAnimationCurve::BEZ_CUBIC); spline->setSample(0,0.00000000 ,0.00000000 ,-0.40663099 ,0.00000000 ,0.40663099 ,0.00000000 ); spline->setSample(1,1.0416667 ,0.38268343 ,0.63503569 ,0.38268343 ,1.4482977 ,0.38268343 ); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Y, akAnimationCurve::BEZ_CUBIC); spline->setSample(0 ,0.00000000 ,0.00000000 ,-0.40667865 ,0.00000000 ,0.40667865 ,0.00000000 ); spline->setSample( 1,1.0416667 ,-3.8454296e-015 ,0.63498801 ,-3.8454296e-015 ,1.4483454 ,-3.8454296e-015); chan->addCurve(spline); spline = new akAnimationCurve(2, akAnimationCurve::AC_CODE_ROT_QUAT_Z, akAnimationCurve::BEZ_CUBIC); spline->setSample( 0,0.00000000 ,0.00000000 ,-0.40667865 ,0.00000000 ,0.40667865 ,0.00000000 ); spline->setSample( 1,1.0416667 ,3.3455247e-008 ,0.63498801 ,3.3455247e-008 ,1.4483454 ,3.3455247e-008 ); chan->addCurve(spline); act->addChannel(chan); } float animfps = 24.f; float actionStart = 5.f; float actionEnd = 60.f; act->setLength( (actionEnd-actionStart )/animfps); addAnimation(utHashedString("MyActionClip"), act); akAnimationPlayer* play = entity->getAnimationPlayers()->addNewAnimationPlayer(act); }
//! Create 3DRep from a Lib3dsNode GLC_3DRep GLC_3dsToWorld::create3DRep(Lib3dsMesh* p3dsMesh) { QString meshName(p3dsMesh->name); if (m_LoadedMeshes.contains(meshName)) { // This mesh as been already loaded QList<GLC_3DViewInstance*> instancesList(m_pWorld->collection()->instancesHandle()); GLC_3DViewInstance* pCurrentInstance= NULL; int currentIndex= -1; do { pCurrentInstance= instancesList[++currentIndex]; } while (pCurrentInstance->name() != meshName); // return an instance. //qDebug() << "instance"; return pCurrentInstance->representation(); } GLC_Mesh * pMesh= new GLC_Mesh(); pMesh->setName(p3dsMesh->name); // The mesh normals const int normalsNumber= p3dsMesh->faces * 3; Lib3dsVector *normalL= new Lib3dsVector[normalsNumber]; lib3ds_mesh_calculate_normals(p3dsMesh, normalL); // Position vector QVector<float> position(normalsNumber * 3); // Normal Vector QVector<float> normal(normalsNumber * 3); memcpy((void*)normal.data(), normalL, normalsNumber * 3 * sizeof(float)); // Texel Vector QVector<float> texel; if (p3dsMesh->texels > 0) { texel.resize(normalsNumber * 2); } int normalIndex= 0; for (unsigned int i= 0; i < p3dsMesh->faces; ++i) { IndexList triangleIndex; Lib3dsFace *p3dsFace=&p3dsMesh->faceL[i]; for (int i=0; i < 3; ++i) { triangleIndex.append(normalIndex); // Add vertex coordinate memcpy((void*)&(position.data()[normalIndex * 3]), &p3dsMesh->pointL[p3dsFace->points[i]], 3 * sizeof(float)); // Add texel if (p3dsMesh->texels > 0) { memcpy((void*)&(texel.data()[normalIndex * 2]), &p3dsMesh->texelL[p3dsFace->points[i]], 2 * sizeof(float)); } ++normalIndex; } // Load the material // The material current face index GLC_Material* pCurMaterial= NULL; if (p3dsFace->material[0]) { Lib3dsMaterial* p3dsMat=lib3ds_file_material_by_name(m_pLib3dsFile, p3dsFace->material); if (NULL != p3dsMat) { // Check it this material as already been loaded const QString materialName(p3dsFace->material); if (!m_Materials.contains(materialName)) { // Material not already loaded, load it loadMaterial(p3dsMat); } pCurMaterial= m_Materials.value(materialName); } } pMesh->addTriangles(pCurMaterial, triangleIndex); } pMesh->addVertice(position); pMesh->addNormals(normal); if (p3dsMesh->texels > 0) { pMesh->addTexels(texel); } // free normal memmory delete[] normalL; // Compute loading progress ++m_CurrentMeshNumber; m_CurrentQuantumValue = static_cast<int>((static_cast<double>(m_CurrentMeshNumber) / m_NumberOfMeshes) * (100 - m_InitQuantumValue)) + m_InitQuantumValue; if (m_CurrentQuantumValue > m_PreviousQuantumValue) { emit currentQuantum(m_CurrentQuantumValue); } m_PreviousQuantumValue= m_CurrentQuantumValue; pMesh->finish(); return GLC_3DRep(pMesh); }
void AssetLoader::readModel(Ogre::SceneManager* sceneMgr, Ogre::SceneNode* scnNode, const aiScene* scene, aiNode* nd) { for (size_t n = 0; n < nd->mNumChildren; n++) { aiNode* cnd = nd->mChildren[n]; Ogre::SceneNode* cnode = createChildSceneNodeWithTransform(scnNode, cnd); for (size_t i = 0; i < cnd->mNumMeshes; i++) { aiMesh* m = scene->mMeshes[cnd->mMeshes[i]]; aiMaterial* mat = scene->mMaterials[m->mMaterialIndex]; std::string nodeName = getFullPathName(cnd); Ogre::MaterialPtr omat = createMaterial(Ogre::String(nodeName), m->mMaterialIndex, mat); aiVector3D* vec = m->mVertices; aiVector3D* norm = m->mNormals; aiVector3D* uv = m->mTextureCoords[0]; aiColor4D* vcol = NULL; if (m->HasVertexColors(0)) vcol = m->mColors[0]; // 頂点情報の読み込み Ogre::AxisAlignedBox aab; Ogre::ManualObject* mobj = new Ogre::ManualObject(nodeName+"_MObj"); mobj->begin(omat->getName()); //mobj->begin("Ogre/Skin"); for (size_t n = 0; n < m->mNumVertices; n ++) { Ogre::Vector3 position(vec->x, vec->y, vec->z); aab.merge(position); mobj->position(vec->x, vec->y, vec->z); vec++; mobj->normal(norm->x, norm->y, norm->z); norm++; if (uv) { mobj->textureCoord(uv->x, uv->y); uv++; } if (vcol) { mobj->colour(vcol->r, vcol->g, vcol->b, vcol->a); vcol++; } } // ポリゴンの構築 for (size_t n = 0; n < m->mNumFaces; n++) { aiFace* face = &m->mFaces[n]; for (size_t k = 0; k < face->mNumIndices; k++) { mobj->index(face->mIndices[k]); } } mobj->end(); mobj->setBoundingBox(aab); Ogre::String meshName(nodeName+"_Mesh"); mobj->convertToMesh(meshName); delete mobj; Ogre::String entityName(nodeName+"_Entity"); std::cout << "entity: " << entityName << std::endl; Ogre::Entity* ent = sceneMgr->createEntity(entityName, meshName); cnode->attachObject(ent); } readModel(sceneMgr, cnode, scene, cnd); } }
// Convert a Maya file into an OBJ file bool CMayaObjConverter::Convert(CFile* pOtherFile, CFile* pObjFile) { // Initialize MAYA -> OBJ m_pMayaFile = InitConversion<CMayaFile>(pOtherFile, pObjFile); OBJ_ASSERT(m_pMayaFile && m_pOptions); if(!m_pMayaFile || !m_pOptions) return false; MSG_INFO("Converting Maya file format into OBJ file format..."); // Get the Obj group vector CObjFile::GroupVector& groups = m_pObjFile->GetGroupVector(); // Get the Maya mesh vector CMayaFile::MeshVector& meshes = m_pMayaFile->GetMeshVector(); CMayaFile::MeshVector::iterator meshIt; CMayaFile::MeshVector::const_iterator meshEnd = meshes.end(); for(meshIt = meshes.begin(); meshIt != meshEnd; ++meshIt) // for each Maya mesh { std::string meshName(meshIt->GetMeshName()); // verify that it is a valid mesh if(meshIt->GetPolyFaceVector().size() <= 0 ) continue; MSG_DEBUG(meshName << "..."); // a group corresponds to a Maya mesh node CObjFile::CGroup group(meshName); // "Append" Vertex positions { Vector3DVector& mayaVertexVector = meshIt->GetVertexPositionVector(); Vector3DVector& objVertexVector = m_pObjFile->GetVertexPositionVector(); objVertexVector.reserve(mayaVertexVector.size()); objVertexVector.insert(objVertexVector.end(), mayaVertexVector.begin(), mayaVertexVector.end()); // Append new Vertices } // "Append" Texture coordinates { Vector3DVector& mayaUvVector = meshIt->GetTextureCoordVector(); Vector3DVector& objUvVector = m_pObjFile->GetTextureCoordVector(); objUvVector.reserve(mayaUvVector.size()); objUvVector.insert(objUvVector.end(), mayaUvVector.begin(), mayaUvVector.end()); // Append new UVs } // "Append" Normals { Vector3DVector& mayaNormalVector = meshIt->GetNormalVector(); Vector3DVector& objNormalVector = m_pObjFile->GetNormalVector(); objNormalVector.reserve(mayaNormalVector.size()); objNormalVector.insert(objNormalVector.end(), mayaNormalVector.begin(), mayaNormalVector.end()); // Append new Normals } // Faces { CMayaFile::CMesh::PolyFaceVector& polyFaces = meshIt->GetPolyFaceVector(); CMayaFile::CMesh::PolyFaceVector::iterator polyFaceIt; CMayaFile::CMesh::PolyFaceVector::const_iterator polyFaceEnd = polyFaces.end(); group.GetFaceVector().reserve(polyFaces.size()); // reserve face vector for(polyFaceIt = polyFaces.begin(); polyFaceIt != polyFaceEnd; ++polyFaceIt) // for each Maya face { CMayaFile::CMesh::CPolyFace::CFace mayaFace = polyFaceIt->GetFace(); CMayaFile::CMesh::CPolyFace::CMu mayaMu; if(polyFaceIt->HasTextureCoordinate()) mayaMu = polyFaceIt->GetMu(); CObjFile::CFace objFace; uint edgeCount = mayaFace.EdgeCount(); uint debugFace = polyFaceIt - polyFaces.begin(); int vIndex = 0; std::pair< bool, uint > uvIndex; std::pair< bool, uint > normalIndex; for(uint v=0; v < edgeCount; ++v ) // for each vertex in maya polyface { vIndex = 0; uvIndex = std::make_pair(false, 0); normalIndex = std::make_pair(false, 0); OBJ_ASSERT(v < mayaFace.GetEdgeVector().size()); int edgeIndex = mayaFace.GetEdgeVector()[v]; if(edgeIndex >= 0) // edge positive direction : take the first vertex of the edge { OBJ_ASSERT(edgeIndex < (int)meshIt->GetEdgeVector().size()); vIndex = (int)meshIt->GetEdgeVector()[edgeIndex][0] + 1; // OBJ is 1-based index } else // edge negative direction : make the edge index positive, decrement 1 and take the second vertex of the edge { OBJ_ASSERT(abs(edgeIndex)-1 <= (int)meshIt->GetEdgeVector().size()-1); vIndex = (int)meshIt->GetEdgeVector()[abs(edgeIndex)-1][1] + 1; // OBJ is 1-based index } // UVs if(polyFaceIt->HasTextureCoordinate()) uvIndex = std::make_pair(true, mayaMu.GetUvVector()[v] + 1); // absolute UV index, OBJ is 1-based index // Normals if(polyFaceIt->HasNormal()) { OBJ_ASSERT(v < mayaFace.GetNormalVector().size()); normalIndex = std::make_pair(true, mayaFace.GetNormalVector()[v] + 1); // OBJ is 1-based index } // Add vertex to OBJ face objFace.AddVertex( CObjFile::CVertex(vIndex, uvIndex, normalIndex) ); } group.AddFace(objFace); // Add face to OBJ group } } m_pObjFile->AddGroup(group); // Add group to OBJ file } // Materials { CMtlFile* pMtlFile = m_pObjFile->GetMaterialFile(); OBJ_ASSERT(pMtlFile); if(!pMtlFile) return true; // Retreive and set material properties here } return true; }
bool CMayaAsciiWriter::Write() { OBJ_ASSERT(m_pMayaFile); if(!m_pMayaFile) return false; std::string fileName(m_fileName.string()); // Extract native file path string // Verify here that we have something to actually write OBJ_ASSERT(m_pMayaFile->GetMeshVector().size() > 0); // Write Maya Ascii file version 6.0 OBJ_ASSERT(CheckStr(fileName)); if(!CheckStr(fileName)) return false; m_ofs.open(fileName.c_str()); MSG_INFO("Writing Maya Ascii file (.MA) : '" << fileName << "'."); if( !m_ofs.is_open() ) { MSG_ERROR("Couldn't write to Maya file '" << fileName << "'"); return false; } std::string fileNameOnly(fileName); if(m_fileName.has_leaf()) { fileNameOnly = m_fileName.leaf(); } // Write the Maya file header m_ofs << "//Maya ASCII 6.0 scene" << std::endl; m_ofs << "//Name: " << fileNameOnly << std::endl; // Windows System Time // TODO : abstract date&time to have it multiplatform { SYSTEMTIME st; GetSystemTime(&st); m_ofs << "//Last modified: " << st.wMonth << "/" << st.wDay << "/" << st.wYear << " " << st.wHour << ":" << st.wMinute << ":" << st.wSecond << std::endl; } // File information m_ofs << "requires maya \"7.0\";" << std::endl; m_ofs << "currentUnit -l centimeter -a degree -t film;" << std::endl; m_ofs << "fileInfo \"application\" \"ZConverter v1.0\";" << std::endl; m_ofs << "fileInfo \"product\" \"Maya Unlimited 7.0\";" << std::endl; m_ofs << "fileInfo \"version\" \"7.0\";" << std::endl; m_ofs << "fileInfo \"cutIdentifier\" \"200404092210-618567\";" << std::endl; m_ofs << "fileInfo \"osv\" \"Microsoft Windows XP Professional Service Pack 2 (Build 2600)\\n\";" << std::endl; /* // Read the maya_viewport file and write it { std::ifstream ifs("maya_viewport.txt"); if( !ifs ) { MSG_ERROR("Couldn't read the maya_viewport.txt file'"); return false; } const int maxline = 1000; char line[maxline]; while(ifs) { ifs.getline( line, maxline ); // get the curent line pointer m_ofs << line << std::endl; } } */ // Retreive the group vector CMayaFile::MeshVector& meshes = m_pMayaFile->GetMeshVector(); CMayaFile::MeshVector::iterator meshIt; CMayaFile::MeshVector::const_iterator meshEnd = meshes.end(); StringVector validNodeVector; // for every groups for(meshIt = meshes.begin(); meshIt != meshEnd; ++meshIt) // For each Maya mesh { std::string meshName(meshIt->GetMeshName()); // verify that it is a valid node if(meshIt->GetPolyFaceVector().size() <= 0 ) continue; validNodeVector.push_back(meshName); // Create the transform node { m_ofs << "createNode transform -n \"" << meshName << "\";" << std::endl; } // Create the shape node { m_ofs << "createNode mesh -n \"" << meshName << "Shape\" -p \"" << meshName << "\";" << std::endl; m_ofs << "\tsetAttr -k off \".v\";" << std::endl; // what is that ? //m_ofs << "\tsetAttr \".vir\" yes;" << std::endl; //m_ofs << "\tsetAttr \".vif\" yes;" << std::endl; } // Texture coordinates { Vector3DVector& textureCoords = meshIt->GetTextureCoordVector(); Vector3DVector::iterator textureCoordIt; Vector3DVector::const_iterator textureCoordEnd = textureCoords.end(); if(textureCoords.size() > 0) { uint lastFaceIndex = meshIt->GetPolyFaceVector().size() - 1; // Connection on the shading groups : instObjectGroups m_ofs << "\tsetAttr -s 2 \".iog[0].og\";" << std::endl; // I think the 2 is for the initialShadingGroup + assigned shadingGroup m_ofs << "\tsetAttr \".iog[0].og[0].gcl\" -type \"componentList\" 0;" << std::endl; m_ofs << "\tsetAttr \".iog[0].og[1].gcl\" -type \"componentList\" 1 \"f[0:" << lastFaceIndex << "]\";" << std::endl; // Texture coordinates m_ofs << "\tsetAttr \".uvst[0].uvsn\" -type \"string\" \"map1\";" << std::endl; // for a cube : 30 : 60 m_ofs << "\tsetAttr -s " << textureCoords.size() << " \".uvst[0].uvsp[0:" << textureCoords.size()-1 << "]\" -type \"float2\" "; int i = 0; for(textureCoordIt = textureCoords.begin(); textureCoordIt != textureCoordEnd; ++textureCoordIt) // for each UV coord { m_ofs << (*textureCoordIt)[0] << " " << (*textureCoordIt)[1] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; m_ofs << "\tsetAttr \".cuvs\" -type \"string\" \"map1\";" << std::endl; m_ofs << "\tsetAttr \".dcc\" -type \"string\" \"Ambient+Diffuse\";" << std::endl; } } //m_ofs.setf(std::ios::showpoint); //m_ofs.precision(6); // Vertex positions { Vector3DVector& vertices = meshIt->GetVertexPositionVector(); Vector3DVector::iterator vertexIt; Vector3DVector::const_iterator vertexEnd = vertices.end(); OBJ_ASSERT(vertices.size() > 0); if(vertices.size() > 0) // if vertex vector is not empty { m_ofs << "\tsetAttr -s " << vertices.size() << " \".vt[0:" << vertices.size()-1 << "]\" "; int i = 0; for(vertexIt = vertices.begin(); vertexIt != vertexEnd; ++vertexIt) // for each vertex position { m_ofs << (*vertexIt)[0] << " " << (*vertexIt)[1] << " " << (*vertexIt)[2] << " "; if(!(i++%2)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Edges { Vector3DVector& edgeVector = meshIt->GetEdgeVector(); Vector3DVector::iterator edgeIt; Vector3DVector::const_iterator edgeEnd = edgeVector.end(); OBJ_ASSERT(edgeVector.size() > 0); if(edgeVector.size() > 0) // if edge vector is not empty { m_ofs << "\tsetAttr -s " << edgeVector.size() << " \".ed[0:" << edgeVector.size()-1 << "]\" "; int i = 0; for(edgeIt = edgeVector.begin(); edgeIt != edgeEnd; ++edgeIt) // for each edge (2 index to vertex) { m_ofs << (*edgeIt)[0] << " " << (*edgeIt)[1] << " " << (*edgeIt)[2] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Normals (4 per face - 1 per vertex per face) { Vector3DVector& normals = meshIt->GetNormalVector(); Vector3DVector::iterator normalIt; Vector3DVector::const_iterator normalEnd = normals.end(); if(normals.size() > 0) { m_ofs << "\tsetAttr -s " << normals.size() << " \".n[0:" << normals.size()-1 << "]\" -type \"float3\" " << std::endl; int i = 0; for(normalIt = normals.begin(); normalIt != normalEnd; ++normalIt) // for each normal { m_ofs << (*normalIt)[0] << " " << (*normalIt)[1] << " " << (*normalIt)[2] << " "; if(!(i++%6)) m_ofs << std::endl << "\t\t"; } m_ofs << ";" << std::endl; } } // Faces { CMayaFile::CMesh::PolyFaceVector& polyFaces = meshIt->GetPolyFaceVector(); CMayaFile::CMesh::PolyFaceVector::iterator polyFaceIt; CMayaFile::CMesh::PolyFaceVector::const_iterator polyFaceEnd = polyFaces.end(); OBJ_ASSERT(polyFaces.size() > 0); m_ofs << "\tsetAttr -s " << polyFaces.size() << " \".fc[0:" << polyFaces.size()-1 << "]\" -type \"polyFaces\" " << std::endl; for(polyFaceIt = polyFaces.begin(); polyFaceIt != polyFaceEnd; ++polyFaceIt) // for each face { CMayaFile::CMesh::CPolyFace::CFace face = polyFaceIt->GetFace(); CMayaFile::CMesh::CPolyFace::CMu mu = polyFaceIt->GetMu(); uint edgeCount = face.EdgeCount(); uint uvCount = mu.UvCount(); // Face std::vector<int>& edgeVector = face.GetEdgeVector(); std::vector<int>::iterator edgeIt; std::vector<int>::const_iterator edgeEnd = edgeVector.end(); // Mu std::vector<uint>& uvVector = mu.GetUvVector(); std::vector<uint>::iterator uvIt; std::vector<uint>::const_iterator uvEnd = uvVector.end(); // if edge vector not empty if(edgeVector.size() > 0) { m_ofs << "\t\tf " << edgeCount; for(edgeIt = edgeVector.begin(); edgeIt != edgeEnd; ++edgeIt ) // for each indexed edge { m_ofs << " " << (*edgeIt); } if(polyFaceIt+1 == polyFaceEnd && uvVector.size() == 0) // last face and no "mu" m_ofs << " ;" << std::endl; else m_ofs << std::endl; } // if uv vector not empty if(uvVector.size() > 0) { m_ofs << "\t\tmu " << "0 " << uvCount; for(uvIt = uvVector.begin(); uvIt != uvEnd; ++uvIt ) // for each indexed UV coord { m_ofs << " " << (*uvIt); } if(polyFaceIt+1 == polyFaceEnd) // last face and no "mu" m_ofs << " ;" << std::endl; else m_ofs << std::endl; } } } } // Add shading groups / material / texture here CMtlFile* pMtlFile = m_pMayaFile->GetMaterialFile(); OBJ_ASSERT(pMtlFile); if(!pMtlFile) return true; CMtlFile::MaterialMap& materials = pMtlFile->GetMaterialMap(); CMtlFile::MaterialMap::iterator materialIt; CMtlFile::MaterialMap::const_iterator materialEnd = materials.end(); uint materialCount = materials.size(); uint textureCount = 0; uint materialID = 0; m_ofs << "createNode lightLinker -n \"lightLinker1\";" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".lnk\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "createNode displayLayerManager -n \"layerManager\";" << std::endl; m_ofs << "createNode displayLayer -n \"defaultLayer\";" << std::endl; m_ofs << "createNode renderLayerManager -n \"renderLayerManager\";" << std::endl; m_ofs << "createNode renderLayer -n \"defaultRenderLayer\";" << std::endl; m_ofs << "createNode renderLayer -s -n \"globalRender\";" << std::endl; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; OBJ_ASSERT(materialIt->first == pMaterial->GetMaterialName()); //MayaStringCheck(materialName); // TODO : look if we already created this material std::stringstream materialIDSS; materialIDSS << materialID; // Create the shading group m_ofs << "createNode shadingEngine -n \"" << shadingGroupName << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; // MaterialInfo, 1 per material (shading group) materialIDSS.str(""); materialIDSS << (materialID+1); // starts at 1, the first one is reserved ? m_ofs << "createNode materialInfo -n \"materialInfo" << materialIDSS.str() << "\";" << std::endl; // what is that ? 2 groupID per mesh materialIDSS.str(""); materialIDSS << (materialID*3+2); // starts at 2 m_ofs << "createNode groupId -n \"groupId" << materialIDSS.str() << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; materialIDSS.str(""); materialIDSS << (materialID*3+3); m_ofs << "createNode groupId -n \"groupId" << materialIDSS.str() << "\";" << std::endl; m_ofs << "\tsetAttr \".ihi\" 0;" << std::endl; int number = 1; // TODO : increment std::string materialName(shadingGroupName + "1"); // TODO : support more type of material : phong, blinn, etc // Create the material m_ofs << "createNode phong -n \"" << materialName << "\";" << std::endl; // Phong by default m_ofs << "\tsetAttr \".cp\" 2.059999942779541;" << std::endl; // what is this number ? // Texture Map if(pMaterial->HasTexMap()) { // Create the texture file std::string textureName(materialName + "F"); m_ofs << "createNode file -n \"" << textureName << "\";" << std::endl; m_ofs << "\tsetAttr \".ftn\" -type \"string\" \"" << pMaterial->GetTexMap() << "\";" << std::endl; // Create the place2dTexture placement std::string place2dTextureName(materialName + "P2D"); m_ofs << "createNode place2dTexture -n \"" << place2dTextureName << "\";" << std::endl; ++textureCount; } ++materialID; } m_ofs << "select -ne :time1;" << std::endl; m_ofs << "\tsetAttr \".o\" 1;" << std::endl; m_ofs << "select -ne :renderPartition;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".st\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "select -ne :renderGlobalsList1;" << std::endl; m_ofs << "select -ne :defaultShaderList1;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount + 2 << " \".s\";" << std::endl; // number of shading group + initialShadingGroup + initialParticleSE m_ofs << "select -ne :postProcessList1;" << std::endl; m_ofs << "\tsetAttr -s 2 \".p\";" << std::endl; m_ofs << "select -ne :defaultRenderUtilityList1;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".u\";" << std::endl; // not sure about that : groups m_ofs << "select -ne :lightList1;" << std::endl; m_ofs << "select -ne :defaultTextureList1;" << std::endl; m_ofs << "\tsetAttr -s " << textureCount << " \".tx\";" << std::endl; // number of texture file m_ofs << "select -ne :initialShadingGroup;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".dsm\";" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; m_ofs << "\tsetAttr -s " << materialCount << " \".gn\";" << std::endl; m_ofs << "select -ne :initialParticleSE;" << std::endl; m_ofs << "\tsetAttr \".ro\" yes;" << std::endl; m_ofs << "select -ne :hardwareRenderGlobals;" << std::endl; m_ofs << "\taddAttr -ci true -sn \"ani\" -ln \"animation\" -bt \"ANIM\" -min 0 -max 1 -at \"bool\";" << std::endl; m_ofs << "\tsetAttr \".fn\" -type \"string\" \"%s.%e\";" << std::endl; m_ofs << "\tsetAttr \".ctrs\" 256;" << std::endl; m_ofs << "\tsetAttr \".btrs\" 512;" << std::endl; m_ofs << "\tsetAttr -k on \".ani\";" << std::endl; m_ofs << "select -ne :defaultHardwareRenderGlobals;" << std::endl; m_ofs << "\tsetAttr \".fn\" -type \"string\" \"im\";" << std::endl; m_ofs << "\tsetAttr \".res\" -type \"string\" \"ntsc_4d 646 485 1.333\";" << std::endl; // Useless commands : //m_ofs << "select -ne :ikSystem;" << std::endl; //m_ofs << "\tsetAttr -s 3 \".sol\";" << std::endl; //connectAttr "myMaterial.mwc" "swordShape.iog.og[1].gco"; // wireframe color StringVector vecShadingGroup; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; // hack : Assuming 1 shading group per mesh vecShadingGroup.push_back(shadingGroupName); } StringVector::iterator nodeIt; StringVector::const_iterator nodeEnd = validNodeVector.end(); StringVector vecMeshName; // for every groups for(meshIt = meshes.begin(); meshIt != meshEnd; ++meshIt) // for each mesh { std::string meshName(meshIt->GetMeshName()); vecMeshName.push_back(meshName); } StringVector::iterator meshNameIt; StringVector::const_iterator meshNameEnd = vecMeshName.end(); uint groupID = 2; for(nodeIt = validNodeVector.begin(); nodeIt != nodeEnd; ++nodeIt) { uint sgIndex = nodeIt - validNodeVector.begin(); if(sgIndex > vecShadingGroup.size()-1) continue; std::string shadingGroupName = vecShadingGroup[sgIndex]; // 3 groupID per mesh std::stringstream groupIDss; groupIDss << groupID+1; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".id\" \"" << (*nodeIt) << "Shape.iog.og[1].gid\";" << std::endl; groupIDss.str(""); groupIDss << groupID; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".id\" \"" << (*nodeIt) << "Shape.ciog.cog[0].cgid\";" << std::endl; groupID += 3; // the first one is always hidden } m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[0].llnk\";" << std::endl; m_ofs << "connectAttr \":initialShadingGroup.msg\" \"lightLinker1.lnk[0].olnk\";" << std::endl; m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[1].llnk\";" << std::endl; m_ofs << "connectAttr \":initialParticleSE.msg\" \"lightLinker1.lnk[1].olnk\";" << std::endl; uint lightLinkerIndex = 2; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::stringstream ssLightLinkerIndex; ssLightLinkerIndex << lightLinkerIndex; m_ofs << "connectAttr \":defaultLightSet.msg\" \"lightLinker1.lnk[" << ssLightLinkerIndex.str() << "].llnk\";" << std::endl; m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \"lightLinker1.lnk[" << ssLightLinkerIndex.str() << "].olnk\";" << std::endl; lightLinkerIndex++; } m_ofs << "connectAttr \"layerManager.dli[0]\" \"defaultLayer.id\";" << std::endl; m_ofs << "connectAttr \"renderLayerManager.rlmi[0]\" \"defaultRenderLayer.rlid\";" << std::endl; uint sgIndex = 0; // shading group index for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each material : Retreive materials { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; //MayaStringCheck(materialName); std::string materialName(shadingGroupName + "1"); // Connection Material.outColor -> ShadingGroup.ss m_ofs << "connectAttr \"" << materialName << ".oc\" \"" << shadingGroupName << ".ss\";" << std::endl; std::stringstream ssSgIndex; ssSgIndex << sgIndex*3+3; m_ofs << "connectAttr \"groupId" << ssSgIndex.str() << ".msg\" \"" << shadingGroupName << ".gn\" -na;" << std::endl; // Assign Shading group to the Mesh first m_ofs << "connectAttr \"" << vecMeshName[sgIndex] << "Shape.iog.og[1]\" \"" << shadingGroupName << ".dsm\" -na;" << std::endl; // Material information ssSgIndex.str(""); ssSgIndex << (sgIndex+1); // starts at 1 m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".sg\";" << std::endl; m_ofs << "connectAttr \"" << materialName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".m\";" << std::endl; if(pMaterial->HasTexMap()) { // Connect texture std::string textureName(materialName + "F"); m_ofs << "connectAttr \"" << textureName << ".msg\" \"materialInfo" << ssSgIndex.str() << ".t\" -na;" << std::endl; m_ofs << "connectAttr \"" << textureName << ".oc\" \"" << materialName << ".c\";" << std::endl; // Connect place2D texture std::string place2dTextureName(materialName + "P2D"); m_ofs << "connectAttr \"" << place2dTextureName << ".c\" \"" << textureName << ".c\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".tf\" \"" << textureName << ".tf\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".rf\" \"" << textureName << ".rf\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".s\" \"" << textureName << ".s\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".wu\" \"" << textureName << ".wu\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".wv\" \"" << textureName << ".wv\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".re\" \"" << textureName << ".re\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".of\" \"" << textureName << ".of\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".r\" \"" << textureName << ".ro\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".o\" \"" << textureName << ".uv\";" << std::endl; m_ofs << "connectAttr \"" << place2dTextureName << ".ofs\" \"" << textureName << ".fs\";" << std::endl; } ++sgIndex; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; m_ofs << "connectAttr \"" << shadingGroupName << ".pa\" \":renderPartition.st\" -na;" << std::endl; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each shading group { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; m_ofs << "connectAttr \"" << shadingGroupName << ".msg\" \":defaultShaderList1.s\" -na;" << std::endl; } for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for place texture 2d { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::string place2dTextureName(shadingGroupName + "1P2D" ); // find a better way if(pMaterial->HasTexMap()) m_ofs << "connectAttr \"" << place2dTextureName << ".msg\" \":defaultRenderUtilityList1.u\" -na;" << std::endl; } // Light linker m_ofs << "connectAttr \"lightLinker1.msg\" \":lightList1.ln\" -na;" << std::endl; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each textures { std::string shadingGroupName(materialIt->first); CMtlFile::CMaterial* pMaterial = &materialIt->second; std::string textureName(shadingGroupName + "1F" ); // find a better way if(pMaterial->HasTexMap()) m_ofs << "connectAttr \"" << textureName << ".msg\" \":defaultTextureList1.tx\" -na;" << std::endl; } for(meshNameIt = vecMeshName.begin(); meshNameIt != meshNameEnd; ++meshNameIt) // mesh -> initial shading group { // Assign Initial shading group to the Mesh second m_ofs << "connectAttr \"" << (*meshNameIt) << "Shape.ciog.cog[0]\" \":initialShadingGroup.dsm\" -na;" << std::endl; } groupID = 2; for(materialIt = materials.begin(); materialIt != materialEnd; ++materialIt) // for each SG : group ID 2,5,8,... { std::stringstream groupIDss; groupIDss << groupID; m_ofs << "connectAttr \"groupId" << groupIDss.str() << ".msg\" \":initialShadingGroup.gn\" -na;" << std::endl; groupID += 3; } m_ofs << "// End of " << fileNameOnly; m_ofs.close(); MSG_DEBUG("Done."); return true; }