void getAnimationChannels(const domNodeRef& node, std::list<domChannelRef>& channels) { assert(node->getId()); std::string nodeIdSlash (node->getId()); nodeIdSlash.append("/"); domCOLLADA* root = (domCOLLADA*)node->getDocument()->getDomRoot(); domLibrary_animations_Array& animationLibrary = root->getLibrary_animations_array(); size_t animationLibraryCount = animationLibrary.getCount(); for (size_t i = 0; i < animationLibraryCount; ++i) { domLibrary_animationsRef& animationsRef = animationLibrary.get(i); domAnimation_Array& animationArray = animationsRef->getAnimation_array(); size_t animationCount = animationArray.getCount(); for (size_t j = 0; j < animationCount; ++j) { domAnimationRef& animationRef = animationArray.get(j); getAnimationChannels(animationRef, nodeIdSlash, channels); } } // Recursively do the same for all nodes daeTArray< daeSmartRef<daeElement> > children; node->getChildren(children); size_t childCount = children.getCount(); for (size_t i = 0; i < childCount; ++i) { daeElementRef childElement = children[i]; if (childElement->typeID() == COLLADA_TYPE::NODE) { domNodeRef childNode = daeSafeCast<domNode>(childElement); getAnimationChannels(childNode, channels); } } }
void processNode(domNodeRef node, DAE &dae, const char *cmdlntexfn) { daeTArray<daeElementRef> nodeChildren = node->getChildren(); for (size_t j = 0; j < nodeChildren.getCount(); j++) { const daeElementRef nodeChild = nodeChildren[j]; const daeString nodeChildKind = nodeChild->getElementName(); if (!strcmp(nodeChildKind, "node")) processNode(daeSafeCast<domNode>(nodeChild), dae, cmdlntexfn); else if (!strcmp(nodeChildKind, "instance_geometry")) { const daeTArray<daeElementRef> geometryChildren = daeSafeCast<domInstance_geometry>(nodeChild)->getUrl().getElement()->getChildren(); for (size_t k = 0; k < geometryChildren.getCount(); k++) { const daeElementRef geometryChild = geometryChildren[k]; const daeString geometryChildKind = geometryChild->getElementName(); if (!strcmp(geometryChildKind, "mesh")) { const domMeshRef mesh = daeSafeCast<domMesh>(geometryChild); const domTriangles_Array trianglesArray = mesh->getTriangles_array(); for (size_t i = 0; i < trianglesArray.getCount(); i++) { char *effect = NULL; string windex; string texturefnstr; const char *texturefn = cmdlntexfn; daeElement *squeegee = nodeChild->getChild("bind_material"); if (squeegee) { squeegee = squeegee->getChild("technique_common"); if (squeegee) { squeegee = squeegee->getChild("instance_material"); if (squeegee) { windex = squeegee->getAttribute("target"); effect = (char*)malloc(windex.length()+1); if (!effect) { perror("malloc"); exit(0); } strcpy(effect, windex.c_str()); daeElement *effectel = daeSafeCast<domInstance_material>(squeegee)->getTarget().getElement(); if (effectel) { daeElement *profile_COMMON = effectel->getChild("profile_COMMON"); if (profile_COMMON) { daeElement *technique = profile_COMMON->getChild("technique"); if (technique) { daeElement *phong = technique->getChild("phong"); if (phong) { daeElement *diffuse = phong->getChild("diffuse"); if (diffuse) { daeElement *texture = diffuse->getChild("texture"); if (texture) { const string samplerSid = texture->getAttribute("texture"); daeElement *samplernewparam = daeSidRef(samplerSid, effectel, "COMMON").resolve().elt; if (samplernewparam) { daeElement *sampler2D = samplernewparam->getChild("sampler2D"); if (sampler2D) { daeElement *samplersrcel = sampler2D->getChild("source"); daeElement *minfilterel = sampler2D->getChild("minfilter"); daeElement *magfilterel = sampler2D->getChild("magfilter"); if (samplersrcel && minfilterel && magfilterel) { const string surfSid = samplersrcel->getCharData(); daeElement *surfnewparam = daeSidRef(surfSid, effectel, "COMMON").resolve().elt; if (surfnewparam) { daeElement *surface = surfnewparam->getChild("surface"); if (surface) { daeElement *init_from = surface->getChild("init_from"); if (init_from) { daeElement *imageel = dae.getDatabase()->idLookup(init_from->getCharData(), init_from->getDocument()); if (imageel) { daeElement *imageinit_from = imageel->getChild("init_from"); if (imageinit_from) { texturefnstr = imageinit_from->getCharData(); texturefn = texturefnstr.c_str(); } } } } } } } } } } } } } } } } } TriangleMesh x(trianglesArray[i], effect); x.transform(texturefn); } } } } } }
void processNode(domNodeRef node, Matrix4 m_trans, vector<AmbientLight> *ambientLights, vector<PointLight> *pointLights, vector<Cube> *cubes, vector<Sphere> *spheres, vector<Cylinder> *cylinders, vector<Cone> *cones, vector<Torus> *toruses, vector<PartialTorus> *partialToruses, vector<TaperedCylinder> *taperedCylinders, vector<Square> *squares) { daeTArray<daeElementRef> nodeChildren = node->getChildren(); for (size_t j = 0; j < nodeChildren.getCount(); j++) { const daeElementRef nodeChild = nodeChildren[j]; const daeString nodeChildKind = nodeChild->getElementName(); if (!strcmp(nodeChildKind, "node")) processNode(daeSafeCast<domNode>(nodeChild), m_trans, ambientLights, pointLights, cubes, spheres, cylinders, cones, toruses, partialToruses, taperedCylinders, squares); else if (!strcmp(nodeChildKind, "translate")) { const domFloat3 val = daeSafeCast<domTranslate>(nodeChild)->getValue(); m_trans = m_trans * trans_mat(Vector3(val[0], val[1], val[2])); } else if (!strcmp(nodeChildKind, "rotate")) { const domFloat3 val = daeSafeCast<domRotate>(nodeChild)->getValue(); m_trans = m_trans * rot_mat(Point3(), Vector3(val[0], val[1], val[2]), val[3]); } else if (!strcmp(nodeChildKind, "scale")) { const domFloat3 val = daeSafeCast<domScale>(nodeChild)->getValue(); m_trans = m_trans * scale_mat(Vector3(val[0], val[1], val[2])); } else if (!strcmp(nodeChildKind, "instance_geometry")) { const daeTArray<daeElementRef> geometryChildren = daeSafeCast<domInstance_geometry>(nodeChild)->getUrl().getElement()->getChildren(); for (size_t k = 0; k < geometryChildren.getCount(); k++) { const daeElementRef geometryChild = geometryChildren[k]; const daeString geometryChildKind = geometryChild->getElementName(); double KdR = 0.8, KdG = 0.8, KdB = 0.8, KsR = 1.f, KsG = 1.f, KsB = 1.f, shiny = 25.f, reflectivity = 1.f, transparency = 0.f, refractiveIndex = 1.f; daeElement *squeegee = nodeChild->getChild("bind_material"); if (squeegee) { squeegee = squeegee->getChild("technique_common"); if (squeegee) { squeegee = squeegee->getChild("instance_material"); if (squeegee) { squeegee = daeSafeCast<domInstance_material>(squeegee)->getTarget().getElement(); if (squeegee) { squeegee = squeegee->getChild("instance_effect"); if (squeegee) { daeElement *effectel = daeSafeCast<domInstance_effect>(squeegee)->getUrl().getElement(); if (effectel) { daeElement *profile_COMMON = effectel->getChild("profile_COMMON"); if (profile_COMMON) { daeElement *technique = profile_COMMON->getChild("technique"); if (technique) { daeElement *phong = technique->getChild("phong"); if (phong) { daeElement *diffuse = phong->getChild("diffuse"); daeElement *specular = phong->getChild("specular"); daeElement *shininess = phong->getChild("shininess"); daeElement *reflectivityel = phong->getChild("reflectivity"); daeElement *transparencyel = phong->getChild("transparency"); daeElement *index_of_refraction = phong->getChild("index_of_refraction"); if (diffuse && specular && shininess && reflectivityel && transparencyel && index_of_refraction) { daeElement *diffusecolorel = diffuse->getChild("color"); daeElement *specularcolorel = specular->getChild("color"); daeElement *shininessfloatel = shininess->getChild("float"); daeElement *reflectivityfloatel = reflectivityel->getChild("float"); daeElement *transparencyfloatel = transparencyel->getChild("float"); daeElement *index_of_refractionfloatel = index_of_refraction->getChild("float"); if (diffusecolorel && specularcolorel && shininessfloatel && reflectivityfloatel && transparencyfloatel && index_of_refractionfloatel) { istringstream parsediffusecolorel(diffusecolorel->getCharData()); parsediffusecolorel >> KdR; parsediffusecolorel >> KdG; parsediffusecolorel >> KdB; istringstream parsespecularcolorel(specularcolorel->getCharData()); parsespecularcolorel >> KsR; parsespecularcolorel >> KsG; parsespecularcolorel >> KsB; istringstream parseshininessfloatel(shininessfloatel->getCharData()); parseshininessfloatel >> shiny; istringstream parsereflectivityfloatel(reflectivityfloatel->getCharData()); parsereflectivityfloatel >> reflectivity; istringstream parsetransparencyfloatel(transparencyfloatel->getCharData()); parsetransparencyfloatel >> transparency; istringstream parseindex_of_refractionfloatel(index_of_refractionfloatel->getCharData()); parseindex_of_refractionfloatel >> refractiveIndex; } } } } } } } } } } } #define INJECTMESH \ mesh.transform(m_trans); \ mesh.KdR = KdR; \ mesh.KdG = KdG; \ mesh.KdB = KdB; \ mesh.KsR = KsR; \ mesh.KsG = KsG; \ mesh.KsB = KsB; \ mesh.shiny = shiny; \ mesh.reflectivity = reflectivity; \ mesh.transparency = transparency; \ mesh.refractiveIndex = refractiveIndex; \ buf->addObject(mesh); if (!strcmp(geometryChildKind, "block")) { const domBlockRef block = daeSafeCast<domBlock>(geometryChild); cubes->push_back(Cube(block->getEdgelen(), KdR, KdG, KdB, KsR, KsG, KsB, shiny, reflectivity, transparency, refractiveIndex, m_trans)); TriangleMesh mesh(block); INJECTMESH } else if (!strcmp(geometryChildKind, "ball")) { const domBallRef ball = daeSafeCast<domBall>(geometryChild); spheres->push_back(Sphere(ball->getRadius(), KdR, KdG, KdB, KsR, KsG, KsB, shiny, reflectivity, transparency, refractiveIndex, m_trans)); TriangleMesh mesh(ball); INJECTMESH } else if (!strcmp(geometryChildKind, "rod")) {