/* * @return:'0' for not found, '1' for success, '-1' for update-conflict-rollback. */ int Data_Update(int table_id, TupleId tuple_id, TupleId value, int nid) { int index=0; int h; DataRecord datard; int status; THREAD* threadinfo; /* get the pointer to current thread information. */ threadinfo=(THREAD*)pthread_getspecific(ThreadInfoKey); index=threadinfo->index; int lindex; lindex = GetLocalIndex(index); if (Send3(lindex, nid, cmd_updatefind, table_id, tuple_id) == -1) printf("update find send error\n"); if (Recv(lindex, nid, 2) == -1) printf("update find recv error\n"); status = *(recv_buffer[lindex]); h = *(recv_buffer[lindex]+1); if (status == 0) return 0; /* record the updated data. */ datard.type=DataUpdate; datard.table_id=table_id; datard.tuple_id=tuple_id; datard.value=value; datard.node_id = nid; datard.index=h; DataRecordInsert(&datard); return 1; }
/* * @return: '0' to rollback, '1' to go head. */ int Data_Insert(int table_id, TupleId tuple_id, TupleId value, int nid) { int index; int status; uint64_t h; DataRecord datard; THREAD* threadinfo; /* get the pointer to current thread information. */ threadinfo=(THREAD*)pthread_getspecific(ThreadInfoKey); index=threadinfo->index; /* * the node transaction process must to get the data from the storage process in the * node itself or in the other nodes, both use the socket to communicate. */ int lindex; lindex = GetLocalIndex(index); if ((Send3(lindex, nid, cmd_insert, table_id, tuple_id)) == -1) printf("insert send error!\n"); if ((Recv(lindex, nid, 2)) == -1) printf("insert recv error!\n"); status = *(recv_buffer[lindex]); h = *(recv_buffer[lindex]+1); if (status == 0) return 0; datard.type=DataInsert; datard.table_id=table_id; datard.tuple_id=tuple_id; datard.value=value; datard.index=h; datard.node_id = nid; DataRecordInsert(&datard); return 1; }
/* * @return:'1' for success, '-1' for rollback. */ int TrulyDataInsert(int table_id, int index, TupleId tuple_id, TupleId value, int nid) { int index2; int status; TransactionData* tdata; TransactionId tid; DataLock lockrd; THREAD* threadinfo; tdata=(TransactionData*)pthread_getspecific(TransactionDataKey); tid=tdata->tid; threadinfo=(THREAD*)pthread_getspecific(ThreadInfoKey); index2=threadinfo->index; int lindex; lindex = GetLocalIndex(index2); if((Send6(lindex, nid, cmd_trulyinsert, table_id, tuple_id, value, index, tid)) == -1) printf("truly insert send error!\n"); if((Recv(lindex, nid, 1)) == -1) printf("truly insert recv error!\n"); /* record the lock. */ lockrd.table_id=table_id; lockrd.tuple_id=tuple_id; lockrd.index = index; lockrd.node_id = nid; lockrd.lockmode=LOCK_EXCLUSIVE; DataLockInsert(&lockrd); status = *(recv_buffer[lindex]); if (status == 4) return -1; return 1; }
void PolygonSet::Insert(ostream& fout) const { MStatus status; vector<float> points, normals; vector<int> indices; vector<float> uvs; MFnMesh mesh(dagPath); MItMeshPolygon itMeshPolygon(dagPath, const_cast<MObject&>(component)); // cache the points MPointArray meshPoints; mesh.getPoints( meshPoints, MSpace::kWorld ); // Cache normals for each vertex MFloatVectorArray meshNormals; // Normals are per-vertex per-face.. // use MItMeshPolygon::normalIndex() for index mesh.getNormals( meshNormals ); // cache the UVs // Get UVSets for this mesh MStringArray UVSets; status = mesh.getUVSetNames( UVSets ); // Get all UVs for the first UV set. MFloatArray u, v; mesh.getUVs( u, v, &UVSets[0] ); //int offset =0; int count = 0; fout << "AttributeBegin" << endl; if (material) fout << *material << endl; fout << "Shape \"trianglemesh\" "; // get the indices for the triangles in the mesh for (; !itMeshPolygon.isDone(); itMeshPolygon.next()) { if (!itMeshPolygon.hasValidTriangulation()) { MGlobal::displayError("MItMeshPolygon::hasValidTriangulation"); continue; } int numTriangles; itMeshPolygon.numTriangles(numTriangles); while ( numTriangles-- ) { // Get object-relative indices for the vertices in this face. MIntArray polygonVertices; itMeshPolygon.getVertices( polygonVertices ); MPointArray nonTweaked; // object-relative vertex indices for each triangle MIntArray triangleVertices; // face-relative vertex indices for each triangle MIntArray localIndex; status = itMeshPolygon.getTriangle( numTriangles, nonTweaked, triangleVertices, MSpace::kWorld ); if (status = MStatus::kSuccess) { // push back the points points.push_back(meshPoints[triangleVertices[0]].x); points.push_back(meshPoints[triangleVertices[0]].y); points.push_back(meshPoints[triangleVertices[0]].z); points.push_back(meshPoints[triangleVertices[1]].x); points.push_back(meshPoints[triangleVertices[1]].y); points.push_back(meshPoints[triangleVertices[1]].z); points.push_back(meshPoints[triangleVertices[2]].x); points.push_back(meshPoints[triangleVertices[2]].y); points.push_back(meshPoints[triangleVertices[2]].z); localIndex = GetLocalIndex( polygonVertices, triangleVertices); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[0] ) ].x); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[0] ) ].y); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[0] ) ].z); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[1] ) ].x); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[1] ) ].y); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[1] ) ].z); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[2] ) ].x); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[2] ) ].y); normals.push_back(meshNormals[ itMeshPolygon.normalIndex( localIndex[2] ) ].z); // note: this only looks at the UVs for the default map set // moje upravy // chyba byla, ze se tady nacitaji indexy do pole u a v. Ale pokud akce selze, jde index mimo // rozsah, takze jsem jen pridal kontrolu navratove hodnoty // je-li failure, pak se UVs netisknout do souboru int uvID[3]; MStatus status; // Get UV values for each vertex within this polygon for ( int vtxInPolygon = 0; vtxInPolygon < 3; vtxInPolygon++ ) { if((status = itMeshPolygon.getUVIndex( localIndex[vtxInPolygon], uvID[vtxInPolygon], &UVSets[0] )) == MStatus::kFailure) break; } if(status == MStatus::kSuccess) { uvs.push_back(u[uvID[0]]); uvs.push_back(v[uvID[0]]); uvs.push_back(u[uvID[1]]); uvs.push_back(v[uvID[1]]); uvs.push_back(u[uvID[2]]); uvs.push_back(v[uvID[2]]); } count += 3; } } /* MFloatArray uArray, vArray; MPointArray facePoints; MVectorArray faceNormals; int numverts = itMeshPolygon.polygonVertexCount(); itMeshPolygon.getPoints(facePoints, MSpace::kWorld); itMeshPolygon.getNormals(faceNormals, MSpace::kWorld); itMeshPolygon.getUVs(uArray, vArray); for (int i=0; i < numverts; i++) { points.push_back(facePoints[i].x); points.push_back(facePoints[i].y); points.push_back(facePoints[i].z); normals.push_back(faceNormals[i].x); normals.push_back(faceNormals[i].y); normals.push_back(faceNormals[i].z); uvs.push_back(uArray[i]); uvs.push_back(vArray[i]); } int numtri; itMeshPolygon.numTriangles(numtri); int v0 = 0; int v1 = 1; int v2 = 2; for (int k=0; k<numtri; k++){ indices.push_back(v0+offset); indices.push_back(v1+offset); indices.push_back(v2+offset); v1 = v2; v2 ++; if (v2 >= numverts) { v2 = 0; } } offset += numverts; */ } fout << "\"point P\" ["; for (vector<float>::const_iterator itP = points.begin(); itP != points.end(); itP++) fout << *itP << " "; fout << "]" << endl; fout << "\"normal N\" ["; for (vector<float>::const_iterator itP = normals.begin(); itP != normals.end(); itP++) fout << *itP << " "; fout << "]" << endl; if(!uvs.empty()) { fout << "\"float uv\" ["; for (vector<float>::const_iterator itP = uvs.begin(); itP != uvs.end(); itP++) fout << *itP << " "; fout << "]" << endl; } fout << "\"integer indices\" ["; /* for (vector<int>::const_iterator itP = indices.begin(); itP != indices.end(); itP++) fout << *itP << " "; */ for (int i=0; i < count; i++) fout << i << " "; fout << "]" << endl; fout << "AttributeEnd" << endl; }
void extractPolygons(Model* model) { MStatus stat; MItDag dagIter(MItDag::kBreadthFirst, MFn::kInvalid); for (; !dagIter.isDone(); dagIter.next()) { MDagPath dagPath; stat = dagIter.getPath(dagPath); if (!stat) { continue; }; MFnDagNode dagNode(dagPath, &stat); if (dagNode.isIntermediateObject()) continue; if (!dagPath.hasFn( MFn::kMesh )) continue; if (dagPath.hasFn( MFn::kTransform)) continue; if (!dagPath.isVisible()) continue; MFnMesh fnMesh(dagPath); MStringArray UVSets; stat = fnMesh.getUVSetNames( UVSets ); // Get all UVs for the first UV set. MFloatArray u, v; fnMesh.getUVs(u, v, &UVSets[0]); MPointArray vertexList; fnMesh.getPoints(vertexList, MSpace::kObject); MFloatVectorArray meshNormals; fnMesh.getNormals(meshNormals); unsigned instanceNumber = dagPath.instanceNumber(); MObjectArray sets; MObjectArray comps; fnMesh.getConnectedSetsAndMembers( instanceNumber, sets, comps, true ); //printMaterials(dagPath); unsigned int comlength = comps.length(); for (unsigned int compi = 0; compi < comlength; compi++) { SubMesh submesh; MItMeshPolygon itPolygon(dagPath, comps[compi]); unsigned int polyCount = 0; for (; !itPolygon.isDone(); itPolygon.next()) { polyCount++; MIntArray polygonVertices; itPolygon.getVertices(polygonVertices); int count; itPolygon.numTriangles(count); for (; count > -1; count--) { MPointArray nonTweaked; MIntArray triangleVertices; MIntArray localIndex; MStatus status; status = itPolygon.getTriangle(count, nonTweaked, triangleVertices, MSpace::kObject); if (status == MS::kSuccess) { VertexDefinition vertex1; VertexDefinition vertex2; VertexDefinition vertex3; { // vertices int vertexCount = vertexList.length(); { int vertexIndex0 = triangleVertices[0]; MPoint point0 = vertexList[vertexIndex0]; vertex1.vertex.x = (float)point0.x; vertex1.vertex.y = (float)point0.y; vertex1.vertex.z = (float)point0.z; } { int vertexIndex0 = triangleVertices[1]; MPoint point0 = vertexList[vertexIndex0]; vertex2.vertex.x = (float)point0.x; vertex2.vertex.y = (float)point0.y; vertex2.vertex.z = (float)point0.z; } { int vertexIndex0 = triangleVertices[2]; MPoint point0 = vertexList[vertexIndex0]; vertex3.vertex.x = (float)point0.x; vertex3.vertex.y = (float)point0.y; vertex3.vertex.z = (float)point0.z; } } { // normals // Get face-relative vertex indices for this triangle localIndex = GetLocalIndex(polygonVertices, triangleVertices); { int index0 = itPolygon.normalIndex(localIndex[0]); MPoint point0 = meshNormals[index0]; vertex1.normal.x = (float)point0.x; vertex1.normal.y = (float)point0.y; vertex1.normal.z = (float)point0.z; } { int index0 = itPolygon.normalIndex(localIndex[1]); MPoint point0 = meshNormals[index0]; vertex2.normal.x = (float)point0.x; vertex2.normal.y = (float)point0.y; vertex2.normal.z = (float)point0.z; } { int index0 = itPolygon.normalIndex(localIndex[2]); MPoint point0 = meshNormals[index0]; vertex3.normal.x = (float)point0.x; vertex3.normal.y = (float)point0.y; vertex3.normal.z = (float)point0.z; } } { // uvs int uvID[3]; MStatus uvFetchStatus; for (unsigned int vtxInPolygon = 0; vtxInPolygon < 3; vtxInPolygon++) { uvFetchStatus = itPolygon.getUVIndex(localIndex[vtxInPolygon], uvID[vtxInPolygon]); } if (uvFetchStatus == MStatus::kSuccess) { { int index0 = uvID[0]; float uvu = u[index0]; float uvv = v[index0]; vertex1.uv.x = uvu; vertex1.uv.y = 1.0f - uvv; } { int index0 = uvID[1]; float uvu = u[index0]; float uvv = v[index0]; vertex2.uv.x = uvu; vertex2.uv.y = 1.0f - uvv; } { int index0 = uvID[2]; float uvu = u[index0]; float uvv = v[index0]; vertex3.uv.x = uvu; vertex3.uv.y = 1.0f - uvv; // directx } } } submesh.addVertex(vertex1); submesh.addVertex(vertex2); submesh.addVertex(vertex3); } } } { Material material; { MObjectArray shaders; MIntArray indices; fnMesh.getConnectedShaders(0, shaders, indices); unsigned int shaderCount = shaders.length(); MPlugArray connections; MFnDependencyNode shaderGroup(shaders[compi]); MPlug shaderPlug = shaderGroup.findPlug("surfaceShader"); shaderPlug.connectedTo(connections, true, false); for(unsigned int u = 0; u < connections.length(); u++) { if(connections[u].node().hasFn(MFn::kLambert)) { MFnLambertShader lambertShader(connections[u].node()); MPlugArray plugs; lambertShader.findPlug("color").connectedTo(plugs, true, false); for (unsigned int p = 0; p < plugs.length(); p++) { MPlug object = plugs[p]; if (!object.isNull()) { MObject node = object.node(); if (node.hasFn(MFn::kFileTexture)) { MFnDependencyNode* diffuseMapNode = new MFnDependencyNode(node); MPlug filenamePlug = diffuseMapNode->findPlug ("fileTextureName"); MString mayaFileName; filenamePlug.getValue (mayaFileName); std::string diffuseMapFileName = mayaFileName.asChar(); std::string diffuseMapAssetPath = extractAssetPath(diffuseMapFileName); material.addTexture("ColorMap", diffuseMapAssetPath); } } } MColor color = lambertShader.color(); MString materialNameRaw = lambertShader.name(); std::string materialName = materialNameRaw.asChar(); material.setName(materialName); Vector4MaterialParameter* diffuseColorParameter = new Vector4MaterialParameter("DiffuseColor"); diffuseColorParameter->value.x = color.r; diffuseColorParameter->value.y = color.g; diffuseColorParameter->value.z = color.b; diffuseColorParameter->value.w = color.a; material.addParameter(diffuseColorParameter); } } } { if (material.hasTextures()) { material.setEffect("shaders/deferred_render_colormap_normal_depth.cg"); } else { material.setEffect("shaders/deferred_render_color_normal_depth.cg"); } } { FloatMaterialParameter* specularPowerParameter = new FloatMaterialParameter("SpecularPower"); specularPowerParameter->value = 1.0; material.addParameter(specularPowerParameter); } { FloatMaterialParameter* specularIntensityParameter = new FloatMaterialParameter("SpecularIntensity"); specularIntensityParameter->value = 1.0f; material.addParameter(specularIntensityParameter); } { FloatMaterialParameter* diffusePowerParameter = new FloatMaterialParameter("DiffusePower"); diffusePowerParameter->value = 1.0f; material.addParameter(diffusePowerParameter); } submesh.setMaterial(material); } model->addSubMesh(submesh); } } }
/* * @return:'1' for success, '-1' for rollback. */ int TrulyDataDelete(int table_id, int index, TupleId tuple_id, int nid) { int i; int index2; bool firstadd=false; bool isdelete = true; uint64_t value = 0; TransactionData* tdata; TransactionId tid; DataLock lockrd; Snapshot* snap; int status = 0; THREAD* threadinfo; int size = MAXPROCS + 1+ 3 + 4; /* get the pointer to current thread information. */ threadinfo=(THREAD*)pthread_getspecific(ThreadInfoKey); index2=threadinfo->index; int lindex; lindex = GetLocalIndex(index2); tdata=(TransactionData*)pthread_getspecific(TransactionDataKey); tid=tdata->tid; /* get the pointer to transaction-snapshot-data. */ snap=(Snapshot*)pthread_getspecific(SnapshotDataKey); /* to void repeatedly add lock. */ if(!IsWrLockHolding(table_id,tuple_id,nid)) { /* the first time to hold the wr-lock on data (table_id,tuple_id). */ firstadd=true; } *(send_buffer[lindex]) = cmd_updateconflict; *(send_buffer[lindex]+1) = snap->tcount; *(send_buffer[lindex]+2) = snap->tid_min; *(send_buffer[lindex]+3) = snap->tid_max; for (i = 0; i < MAXPROCS; i++) *(send_buffer[lindex]+4+i) = snap->tid_array[i]; *(send_buffer[lindex]+4+i) = table_id; *(send_buffer[lindex]+5+i) = index; *(send_buffer[lindex]+6+i) = tid; *(send_buffer[lindex]+7+i) = firstadd; if (send(connect_socket[nid][lindex], send_buffer[lindex], size*sizeof(uint64_t), 0) == -1) printf("update conflict send error\n"); if (Recv(lindex, nid, 1) == -1) printf("update conflict recv error\n"); status = *(recv_buffer[lindex]); if (status == 4) return -1; /* record the lock. */ lockrd.table_id=table_id; lockrd.tuple_id=tuple_id; lockrd.index = index; lockrd.node_id = nid; lockrd.lockmode=LOCK_EXCLUSIVE; DataLockInsert(&lockrd); if (Send6(lindex, nid, cmd_updateversion, table_id, index, tid, value, isdelete) == -1) printf("update version send error\n"); if (Recv(lindex, nid, 1) == -1) printf("update version recv error\n"); return 1; }
/* * @input:'isupdate':true for reading before updating, false for commonly reading. * @return:NULL for read nothing, to rollback or just let it go. */ TupleId Data_Read(int table_id, TupleId tuple_id, int nid, int* flag) { int i; int h; int index, visible; int status; uint64_t value; Snapshot* snap; char* DataMemStart; int size; *flag=1; /* send size */ size = 3 + 3 + MAXPROCS; THREAD* threadinfo; /* get the pointer to current thread information. */ threadinfo=(THREAD*)pthread_getspecific(ThreadInfoKey); index=threadinfo->index; int lindex; lindex = GetLocalIndex(index); /* get the pointer to data-memory. */ DataMemStart=(char*)pthread_getspecific(DataMemKey); /* get pointer to transaction-snapshot-data. */ snap=(Snapshot*)pthread_getspecific(SnapshotDataKey); if (Send3(lindex, nid, cmd_readfind, table_id, tuple_id) == -1) printf("read find send error\n"); if (Recv(lindex, nid, 2) == -1) printf("read find recv error\n"); status = *(recv_buffer[lindex]); h = *(recv_buffer[lindex]+1); if (status == 0) { *flag = 0; return 0; } visible=IsDataRecordVisible(DataMemStart, table_id, tuple_id, nid); if(visible == -1) { /* current transaction has deleted the tuple to read, so return to rollback. */ *flag=-1; return 0; } else if(visible > 0) { /* see own transaction's update. */ return visible; } *(send_buffer[lindex]) = cmd_readversion; *(send_buffer[lindex]+1) = snap->tcount; *(send_buffer[lindex]+2) = snap->tid_min; *(send_buffer[lindex]+3) = snap->tid_max; for (i = 0; i < MAXPROCS; i++) *(send_buffer[lindex]+4+i) = snap->tid_array[i]; *(send_buffer[lindex]+4+i) = table_id; *(send_buffer[lindex]+5+i) = h; if (send(connect_socket[nid][lindex], send_buffer[lindex], size*sizeof(uint64_t), 0) == -1) printf("read version send error\n"); if (Recv(lindex, nid, 2) == -1) printf("read version recv error\n"); status = *(recv_buffer[lindex]); value = *(recv_buffer[lindex]+1); if (status == 4) { *flag = -2; return 0; } if (status == 0) { *flag = -3; return 0; } if (status == 1) return value; return 0; }