void ImporterGeometryTWM::build_skeleton( std::vector<std::string> &joint_names, std::vector<Joint> &src_joints, std::vector<SkeletonJoint> &dst_joints) { if (src_joints.size() <= 0) return; // allocate space for destination joints dst_joints.resize(src_joints.size()); for (DTuint i = 0; i < src_joints.size(); ++i) { Joint &joint = src_joints[i]; // find index of joint in names DTsize joint_index = 0; std::size_t j; for (j = 0; j < joint_names.size(); ++j) { if (joint_names[j] == joint._name) { joint_index = j; break; } } if (j == joint_names.size()) { LOG_MESSAGE << "Warning: Unknown joint found in skeleton: " << joint._name; joint_names.push_back(joint._name); joint_index = joint_names.size()-1; } // Buid copy of joint SkeletonJoint &dest_joint = dst_joints[i]; dest_joint.set_name(joint._name); dest_joint.set_joint_index( static_cast<DTuint>(joint_index) ); dest_joint.set_local_transform(joint._local_transform); dest_joint.set_world_transform(joint._world_transform); // Build child joints std::vector<SkeletonJoint> dest_joints; build_skeleton(joint_names, joint._children, dest_joints); dest_joint.set_children(dest_joints); } }
void class2(graph_t* g) { int c; node_t *n,*t,*h; edge_t *e,*prev,*opp; g->u.nlist = NULL; g->u.n_nodes = 0; /* new */ mark_clusters(g); for (c = 1; c <= g->u.n_cluster; c++) build_skeleton(g,g->u.clust[c]); for (n = agfstnode(g); n; n = agnxtnode(g,n)) for (e = agfstout(g,n); e; e = agnxtout(g,e)) { if (e->head->u.weight_class <= 2) e->head->u.weight_class++; if (e->tail->u.weight_class <= 2) e->tail->u.weight_class++; } for (n = agfstnode(g); n; n = agnxtnode(g,n)) { if ((n->u.clust == NULL) && (n == UF_find(n))) {fast_node(g,n); g->u.n_nodes++;} prev = NULL; for (e = agfstout(g,n); e; e = agnxtout(g,e)) { /* already processed */ if (e->u.to_virt) continue; /* edges involving sub-clusters of g */ if (is_cluster_edge(e)) { /* following is new cluster multi-edge code */ if (mergeable(prev,e)) { if (prev->u.to_virt) { merge_chain(g,e,prev->u.to_virt,FALSE); other_edge(e); } else if (e->tail->u.rank == e->head->u.rank) { merge_oneway(e,prev); other_edge(e); } /* else is an intra-cluster edge */ continue; } interclrep(g,e); prev = e; continue; } /* merge multi-edges */ if (prev && (e->tail == prev->tail) && (e->head == prev->head)) { if (e->tail->u.rank == e->head->u.rank) { merge_oneway(e,prev); other_edge(e); continue; } if ((e->u.label == NULL) && (prev->u.label == NULL) && ports_eq(e,prev)) { if (Concentrate) e->u.edge_type = IGNORED; else{ merge_chain(g,e,prev->u.to_virt,TRUE); other_edge(e); } continue; } /* parallel edges with different labels fall through here */ } /* self edges */ if (e->tail == e->head) { other_edge(e); prev = e; continue; } t = UF_find(e->tail); h = UF_find(e->head); /* non-leader leaf nodes */ if ((e->tail != t) || (e->head != h)) { /* ### need to merge stuff */ continue; } /* flat edges */ if (e->tail->u.rank == e->head->u.rank) { flat_edge(g,e); prev = e; continue; } /* forward edges */ if (e->head->u.rank > e->tail->u.rank) { make_chain(g,e->tail,e->head,e); prev = e; continue; } /* backward edges */ else { /*other_edge(e);*/ if ((opp = agfindedge(g,e->head,e->tail))) { /* shadows a forward edge */ if (opp->u.to_virt == NULL) make_chain(g,opp->tail,opp->head,opp); if ((e->u.label == NULL) && (opp->u.label == NULL) && ports_eq(e,opp)) { if (Concentrate) { e->u.edge_type = IGNORED; opp->u.conc_opp_flag = TRUE; } else{ /* see above. this is getting out of hand */ other_edge(e); merge_chain(g,e,opp->u.to_virt,TRUE); } continue; } } make_chain(g,e->head,e->tail,e); prev = e; } } } /* since decompose() is not called on subgraphs */ if (g != g->root) { g->u.comp.list = ALLOC(1,g->u.comp.list,node_t*); g->u.comp.list[0] = g->u.nlist; }
DTerr ImporterGeometryTWM::import(GeometryResource *target, std::string args) { FilePath pathname(target->path()); // open the file BinaryFileStream file; FileManager::open(file, pathname, true); // // Read_ in header // DTuint magic; file >> magic; if (magic != MAGIC) { return DT3_ERR_FILE_WRONG_TYPE; } DTuint version; file >> version; // // Read_ in data // _normals_count = 0; _uv_set_0_count = 0; _uv_set_1_count = 0; _weights_count = 0; DTint section,size; file >> section >> size; switch(section) { case FILE: read_file(file, size); break; default: WARNINGMSG("Invalid section"); break; }; // // Build Streams // // Calculate sizes needed DTuint joints_size = 0; for (DTuint i = 0; i < _meshes.size(); ++i) { joints_size += _meshes[i]._joint_names.size(); } // allocate joint names, force first one to always be identity std::vector<std::string> joint_names; joint_names.resize(joints_size); DTuint joint_offset = 0; // Account for identity above for (DTuint i = 0; i < _meshes.size(); ++i) { MeshData &meshdata = _meshes[i]; if (meshdata._vertices.size() == 0) continue; std::shared_ptr<Mesh> mesh = Mesh::create(); // copy joint names for (DTuint j = 0; j < meshdata._joint_names.size(); ++j) { joint_names[joint_offset + j] = meshdata._joint_names[j]; } std::vector<Vector3> vertex_stream; std::vector<Vector3> normals_stream; std::vector<Vector2> uvs_stream_0; std::vector<Vector2> uvs_stream_1; std::vector<Vector4> weights_strength; std::vector<WeightsIndex> weights_index; std::vector<Triangle> indices; vertex_stream = meshdata._vertices; normals_stream = meshdata._normals; uvs_stream_0 = meshdata._uv_sets[0]._uvs; uvs_stream_1 = meshdata._uv_sets[1]._uvs; indices = meshdata._indices; if (meshdata._weights.size()) { weights_index.resize(meshdata._weights.size()); weights_strength.resize(meshdata._weights.size()); for (DTuint j = 0; j < meshdata._weights.size(); ++j) { weights_strength[j] = Vector4( meshdata._weights[j].weight_1(), meshdata._weights[j].weight_2(), meshdata._weights[j].weight_3(), meshdata._weights[j].weight_4() ); weights_index[j] = WeightsIndex( meshdata._weights[j].bone_1(), meshdata._weights[j].bone_2(), meshdata._weights[j].bone_3(), meshdata._weights[j].bone_4() ); } } mesh->set_vertex_stream(vertex_stream); mesh->set_normals_stream(normals_stream); mesh->set_uv_stream0(uvs_stream_0); mesh->set_uv_stream1(uvs_stream_1); mesh->set_index_stream(indices); mesh->set_weights_index_stream(weights_index); mesh->set_weights_strength_stream(weights_strength); // Some stuff we can generate if (normals_stream.size() == 0) mesh->generate_normals(); if (uvs_stream_0.size() != 0) mesh->generate_tangents(); // Add the mesh target->add_mesh(mesh); joint_offset += (DTushort) meshdata._joint_names.size(); } // Build skeleton std::vector<SkeletonJoint> s; build_skeleton(joint_names, _skeleton._joints, s); Skeleton skeleton; skeleton.set_skeleton(s); target->set_skeleton(skeleton); return DT3_ERR_NONE; }