int main(int argc, char* argv[]) { ros::init(argc, argv, "mental_perspective_transformer"); ros::NodeHandle nh; ros::NodeHandle nhPriv("~"); if(!nhPriv.hasParam("fovy")) { nhPriv.setParam("fovy", 90.0); } MentalPerspectiveTransformer transform_node(nh, nhPriv); (void) transform_node; TransformedPerspectiveVisualizer vis_node(nh, nhPriv, "human_perspective"); (void) vis_node; ros::spin(); return 0; }
void Camera::override_transform(const mat4& matrix) { transform_node()->override_transform(matrix); }
MStatus ScbWriter::dumpData() { MStatus status; MDagPath dag_path; MDagPath mesh_dag_path; MFnSkinCluster fn_skin_cluster; MSelectionList selection_list; if (MStatus::kSuccess != MGlobal::getActiveSelectionList(selection_list)) FAILURE("ScbWriter: MGlobal::getActiveSelectionList()"); MItSelectionList it_selection_list(selection_list, MFn::kMesh, &status); if (status != MStatus::kSuccess) FAILURE("ScbWriter: it_selection_list()"); if (it_selection_list.isDone()) FAILURE("ScbWriter: no mesh selected!"); it_selection_list.getDagPath(mesh_dag_path); it_selection_list.next(); if (!it_selection_list.isDone()) FAILURE("ScbWriter: more than one mesh selected!"); MFnMesh mesh(mesh_dag_path); strcpy_s(data_.name, ScbData::kNameLen, mesh.name().asChar()); // get shaders int instance_num = 0; if (mesh_dag_path.isInstanced()) instance_num = mesh_dag_path.instanceNumber(); MObjectArray shaders; MIntArray shader_indices; mesh.getConnectedShaders(instance_num, shaders, shader_indices); int shader_count = shaders.length(); MGlobal::displayInfo(MString("shaders for this mesh : ") + shader_count); // check for holes MIntArray hole_info_array; MIntArray hole_vertex_array; mesh.getHoles(hole_info_array, hole_vertex_array); if (hole_info_array.length() != 0) FAILURE("ScbWriter: mesh contains holes"); // check for triangulation MItMeshPolygon mesh_polygon_iter(mesh_dag_path); for (mesh_polygon_iter.reset(); !mesh_polygon_iter.isDone(); mesh_polygon_iter.next()) { if (!mesh_polygon_iter.hasValidTriangulation()) FAILURE("ScbWriter: a poly has no valid triangulation"); } // get transform MFnTransform transform_node(mesh.parent(0)); MVector pos = transform_node.getTranslation(MSpace::kTransform); // get vertices int num_vertices = mesh.numVertices(); data_.num_vtxs = num_vertices; MFloatPointArray vertex_array; mesh.getPoints(vertex_array, MSpace::kWorld); // kObject is done by removing translation values // that way scales and rotations are kept. for (int i = 0; i < num_vertices; i++) { ScbVtx vtx; vtx.x = vertex_array[i].x - static_cast<float>(pos.x); vtx.y = vertex_array[i].y - static_cast<float>(pos.y); vtx.z = vertex_array[i].z - static_cast<float>(pos.z); // check for min if (vtx.x < data_.bbx || i == 0) data_.bbx = vtx.x; if (vtx.y < data_.bby || i == 0) data_.bby = vtx.y; if (vtx.z < data_.bbz || i == 0) data_.bbz = vtx.z; // check for max if (vtx.x > data_.bbdx || i == 0) data_.bbdx = vtx.x; if (vtx.y > data_.bbdy || i == 0) data_.bbdy = vtx.y; if (vtx.z > data_.bbdz || i == 0) data_.bbdz = vtx.z; data_.vertices.push_back(vtx); } // bbd is the size so : data_.bbdx -= data_.bbx; data_.bbdy -= data_.bby; data_.bbdz -= data_.bbz; // get UVs MFloatArray u_array; MFloatArray v_array; mesh.getUVs(u_array, v_array); MIntArray uv_counts; MIntArray uv_ids; mesh.getAssignedUVs(uv_counts, uv_ids); // get triangles MIntArray triangle_counts; MIntArray triangle_vertices; mesh.getTriangles(triangle_counts, triangle_vertices); int numPolys = mesh.numPolygons(); // fill data int cur = 0; for (int i = 0; i < numPolys; i++) { int triangle_count = triangle_counts[i]; int shader = shader_indices[i]; for (int j = 0; j < triangle_count; j++) data_.shader_per_triangle.push_back(shader); for (int j = 0; j < triangle_count * 3; j++) { data_.indices.push_back(triangle_vertices[cur]); data_.u_vec.push_back(u_array[uv_ids[cur]]); data_.v_vec.push_back(1 - v_array[uv_ids[cur]]); cur++; } } data_.num_indices = cur; // fill materials for (int i = 0; i < shader_count; i++) { ScbMaterial material; // get the plug for SurfaceShader MPlug shader_plug = MFnDependencyNode(shaders[i]).findPlug("surfaceShader"); // get the connections to this plug MPlugArray plug_array; shader_plug.connectedTo(plug_array, true, false, &status); // first connection is material. MFnDependencyNode surface_shader(plug_array[0].node()); strcpy_s(material.name, ScbMaterial::kNameLen, surface_shader.name().asChar()); data_.materials.push_back(material); } return MS::kSuccess; }