void inherit_attributes(umlclasslist parents, umlattrlist umla) { umlattrlist pumla; while (parents != NULL) { pumla = parents->key->attributes; insert_attribute(copy_attributes(pumla), umla); parents = parents->next; } }
bool BatchGeom::add_normals(){ if (m_indices == NULL) return false; if (m_primitive_type != PRIM_TRIANGLES) return false; if (!find_attribute(ATT_NORMAL) && !insert_attribute(ATT_NORMAL, 3) ) return false; for(unsigned int i=0; i<m_num_indices; ++i) { get_normal_by_index( i ) = noVec3( 0.0f, 0.0f, 0.0f ); } for(unsigned int i=0; i<m_num_indices; i+=3) { noVec3 v1 = get_vertex_by_index( i+0 ); noVec3 v2 = get_vertex_by_index( i+1 ); noVec3 v3 = get_vertex_by_index( i+2 ); noVec3 normal = ( v2-v1).Cross(v3-v1 ).NormalizeCopy(); get_normal_by_index( i+0 ) += normal; get_normal_by_index( i+1 ) += normal; get_normal_by_index( i+2 ) += normal; } for(unsigned int i=0; i<m_num_vertices; ++i) { get_normal( i ).Normalize(); } return true; }
xptr deep_copy_node(xptr left, xptr right, xptr parent, xptr node, upd_ns_map** nsupdmap, bool save_types, unsigned short depth) { xptr result; xptr node_indir; schema_node_cptr scmnode; xmlscm_type scm_type; /* Rollback transaction if timeout value's been exceeded */ CHECK_TIMER_FLAG #ifdef SE_ENABLE_FTSEARCH if (!depth) init_ft_sequences(left,right,parent); #endif #ifdef SE_ENABLE_TRIGGERS if (parent == XNULL) { if (left != XNULL) { CHECKP(left); parent = nodeGetParent(left); } else { CHECKP(right); parent = nodeGetParent(right); } } node = apply_per_node_triggers(node, XNULL, parent, XNULL, TRIGGER_BEFORE, TRIGGER_INSERT_EVENT); if (node == XNULL) { if (left == XNULL) { return XNULL; } CHECKP(left); return left; } #endif node_indir = getIndirectionSafeCP(node); scmnode = getSchemaNode(node); switch (scmnode->type) { case element: { xptr result_indir; xmlns_ptr ns = scmnode->get_xmlns(); if (nsupdmap != NULL && ns != NULL_XMLNS) { replaceNamespace(ns, *nsupdmap); } scm_type = (save_types) ? getScmType(node) : xs_untyped; result = insert_element(left, right, parent, scmnode->name, scm_type, ns); result_indir = get_last_mo_inderection(); copy_node_content(result_indir, indirectionDereferenceCP(node_indir), XNULL, nsupdmap, save_types, depth); result = indirectionDereferenceCP(result_indir); CHECKP(result); } break; case text: { if (CommonTextNode(node).isEmpty()) { if (IS_DATA_BLOCK(node)) { throw SYSTEM_EXCEPTION("BAD DATA!!!"); } else { return left; } } else { if (getTextFlags(node, cdata_section) > 0) { cdataflag_hint = cdata_section | cdata_inherit; } result = insert_text(left, right, parent, text_source_node(node)); cdataflag_hint = 0; } } break; case comment: { text_membuf_t buf(text_source_node(node)); result = insert_comment(left, right, parent, buf.getCstr(), buf.getSize()); } break; case pr_ins: { size_t tsize = PINode(node).getPITargetSize(); text_membuf_t buf(text_source_node(node)); result = insert_pi(left, right, parent, buf.getCstr(), tsize, buf.getCstr() + tsize + 1, buf.getSize() - tsize - 1); } break; case attribute: { xmlns_ptr ns = scmnode->get_xmlns(); text_membuf_t buf(text_source_node(node)); if (nsupdmap != NULL && ns != NULL_XMLNS) { replaceNamespace(ns, *nsupdmap); }; if (depth == 0 && ns != NULL_XMLNS) { const xmlns_ptr new_ns = swizzle_namespace(parent, ns); if (new_ns != NULL_XMLNS) { insert_namespace(left, right, parent, new_ns); ns = new_ns; } } CHECKP(node); scm_type = (save_types) ? AttributeNode(node).getType() : xs_untypedAtomic; result = insert_attribute(left, right, parent, scmnode->name, scm_type, buf.getCstr(), buf.getSize(), ns); } break; case xml_namespace: { xmlns_ptr ns = NSNode(node).getNamespaceLocal(); /* That is bad to copy default namespace alone without its node */ if (ns->has_prefix() || depth > 0) { if (nsupdmap != NULL && ns->has_prefix()) { replaceNamespace(ns, *nsupdmap); } if (depth == 0) { const xmlns_ptr new_ns = swizzle_namespace(parent, ns); if (new_ns != NULL_XMLNS) { if (nsupdmap != NULL) { (**nsupdmap)[ns] = new_ns; } ns = new_ns; } } result = insert_namespace(left, right, parent, ns); } else { return left; } } break; default: throw SYSTEM_EXCEPTION("Deep copy error: document node copied"); } CHECKP(result); #ifdef SE_ENABLE_FTSEARCH update_insert_sequence(result, getSchemaNode(result)); #endif #ifdef SE_ENABLE_TRIGGERS if (parent==XNULL) parent= nodeGetParentIndirection(left); apply_per_node_triggers(result, XNULL, parent, XNULL, TRIGGER_AFTER, TRIGGER_INSERT_EVENT); #endif CHECKP(result); return result; }
bool BatchGeom::add_tangent_space(){ if (m_indices == NULL) return false; if (!find_attribute(ATT_TEXCOORD) ) return false; if (m_primitive_type != PRIM_TRIANGLES) return false; if (!find_attribute(ATT_TANGENT_S) && !insert_attribute(ATT_TANGENT_S, 3) ) return false; if (!find_attribute(ATT_TANGENT_T) && !insert_attribute(ATT_TANGENT_T, 3) ) return false; for(unsigned int i=0; i<m_num_indices; ++i) { get_tangent_s_by_index( i ) = noVec3( 0.0f, 0.0f, 0.0f ); get_tangent_t_by_index( i ) = noVec3( 0.0f, 0.0f, 0.0f ); } for(unsigned int i=0; i<m_num_indices; i+=3) { const noVec3 v1 = get_vertex_by_index( i+0 ); const noVec3 v2 = get_vertex_by_index( i+1 ); const noVec3 v3 = get_vertex_by_index( i+2 ); const noVec2 w1 = get_texcoord_by_index( i+0 ); const noVec2 w2 = get_texcoord_by_index( i+1 ); const noVec2 w3 = get_texcoord_by_index( i+2 ); float x1 = v2.x - v1.x; float x2 = v3.x - v1.x; float y1 = v2.y - v1.y; float y2 = v3.y - v1.y; float z1 = v2.z - v1.z; float z2 = v3.z - v1.z; float s1 = w2.x - w1.x; float s2 = w3.x - w1.x; float t1 = w2.y - w1.y; float t2 = w3.y - w1.y; float r; if(fabs(s1*t2 - s2*t1) <= 0.0001f) { r = 1.0f; } else { r = 1.0f / (s1*t2 - s2*t1); } noVec3 sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r); noVec3 tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r); get_tangent_s_by_index( i+0 ) += sdir; get_tangent_s_by_index( i+1 ) += sdir; get_tangent_s_by_index( i+2 ) += sdir; get_tangent_t_by_index( i+0 ) += tdir; get_tangent_t_by_index( i+1 ) += tdir; get_tangent_t_by_index( i+2 ) += tdir; } for(unsigned int i=0; i<m_num_vertices; ++i) { const noVec3 n = get_normal(i); // Gram-Schmidt orthogonalize get_tangent_t(i) = (get_tangent_t(i) - n * n * get_tangent_t(i)).NormalizeCopy(); get_tangent_s(i) = (get_tangent_s(i) - n * n * get_tangent_s(i) - n * (n * get_tangent_t(i))).NormalizeCopy(); } return true; }