bool loadCostume (persona * cossy, FILE * fp) { int a; cossy -> numDirections = get2bytes (fp); cossy -> animation = new personaAnimation * [cossy -> numDirections * 3]; if (! checkNew (cossy -> animation)) return false; for (a = 0; a < cossy -> numDirections * 3; a ++) { cossy -> animation[a] = new personaAnimation; if (! checkNew (cossy -> animation[a])) return false; if (! loadAnim (cossy -> animation[a], fp)) return false; } // debugCostume ("Loaded", cossy); return true; }
bool AssetManager::loadResource(const gfs::Path& file) { if(!file) { return false; } // this if chain checks what folder the file is in if(file.parent().name().find("anims") != std::string::npos) { return loadAnim(file); } else if(file.parent().name().find("dicts") != std::string::npos) { return loadDict(file); } else if(file.parent().name().find("fonts") != std::string::npos) { return loadFont(file); } else if(file.parent().name().find("music") != std::string::npos) { return loadMusic(file); } else if(file.parent().name().find("scripts") != std::string::npos) { return loadScript(file); } else if(file.parent().name().find("sounds") != std::string::npos) { return loadSound(file); } else if(file.parent().name().find("textures") != std::string::npos) { return loadTexture(file); } else { Logger::get() << "[INFO]: " << file << " is an unknown resource type.\n"; return false; } }
bool loadAnimFile(MMesh * mesh, const char * filename, const char * repertory) { TiXmlDocument doc(filename); if(! doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement * pRootNode; TiXmlHandle hRoot(0); // Maratis pRootNode = hDoc.FirstChildElement().Element(); if(! pRootNode) return false; if(strcmp(pRootNode->Value(), "Maratis") != 0) return false; hRoot = TiXmlHandle(pRootNode); return loadAnim(pRootNode, repertory, mesh); }
bool loadVariable(Variable *to, Common::SeekableReadStream *stream) { to->varType = (VariableType)stream->readByte(); switch (to->varType) { case SVT_INT: case SVT_FUNC: case SVT_BUILT: case SVT_FILE: case SVT_OBJTYPE: to->varData.intValue = stream->readUint32LE(); return true; case SVT_STRING: to->varData.theString = createCString(readString(stream)); return true; case SVT_STACK: to->varData.theStack = loadStackRef(stream); return true; case SVT_COSTUME: to->varData.costumeHandler = new Persona; if (!checkNew(to->varData.costumeHandler)) return false; loadCostume(to->varData.costumeHandler, stream); return true; case SVT_ANIM: to->varData.animHandler = new PersonaAnimation ; if (!checkNew(to->varData.animHandler)) return false; loadAnim(to->varData.animHandler, stream); return true; default: break; } return true; }
GfxObj* Gfx::loadCharacterAnim(const char *name) { return loadAnim(name); }
bool xmlMeshLoad(const char * filename, void * data) { MLOG_DEBUG("xmlMeshLoad " << filename?filename:"NULL"); MLevel * level = MEngine::getInstance()->getLevel(); // read document TiXmlDocument doc(filename); if(! doc.LoadFile()) { MLOG_WARNING("TiXmlDocument load failed : " << doc.ErrorDesc() << " line " << doc.ErrorRow()); return false; } TiXmlHandle hDoc(&doc); TiXmlElement * pRootNode; TiXmlHandle hRoot(0); // Maratis pRootNode = hDoc.FirstChildElement().Element(); if(! pRootNode) { MLOG_WARNING("Cannot find any root node"); return false; } if(strcmp(pRootNode->Value(), "Maratis") != 0) { MLOG_WARNING("Cannot find Maratis root node"); return false; } hRoot = TiXmlHandle(pRootNode); // Mesh TiXmlElement * pMeshNode = pRootNode->FirstChildElement("Mesh"); if(! pMeshNode) { MLOG_WARNING("Cannot find a Mesh node"); return false; } // create new mesh MMesh * mesh = (MMesh *)data; mesh->clear(); char path[256]; char meshRep[256]; char vertShadPath[256]; char fragShadPath[256]; // mesh rep getRepertory(meshRep, filename); // animation if(! loadAnim(pMeshNode, meshRep, mesh)) { // load external anim file (depracated) char animFilename[256]; strcpy(animFilename, filename); strcpy(animFilename + strlen(animFilename) - 4, "anim"); loadAnimFile(mesh, animFilename, meshRep); } // Textures TiXmlElement * texturesNode = pMeshNode->FirstChildElement("Textures"); if(texturesNode) { MLOG_DEBUG("entering Textures node"); unsigned int numTextures = 0; texturesNode->QueryUIntAttribute("num", &numTextures); mesh->allocTextures(numTextures); // Texture TiXmlElement * textureNode = texturesNode->FirstChildElement("Texture"); for(textureNode; textureNode; textureNode=textureNode->NextSiblingElement("Texture")) { const char * file = NULL; bool mipmap = true; // image TiXmlElement * imageNode = textureNode->FirstChildElement("image"); if(imageNode) { int value = 1; file = imageNode->Attribute("filename"); imageNode->QueryIntAttribute("mipmap", &value); mipmap = (value == 1); } if(! file) { mesh->addNewTexture(NULL); continue; } // load texture getGlobalFilename(path, meshRep, file); MTextureRef * texRef = level->loadTexture(path, mipmap); MTexture * texture = mesh->addNewTexture(texRef); // tile TiXmlElement * tileNode = textureNode->FirstChildElement("tile"); if(tileNode) { const char * uTile = tileNode->Attribute("u"); const char * vTile = tileNode->Attribute("v"); if(uTile){ if(strcmp(uTile, "clamp") == 0) texture->setUWrapMode(M_WRAP_CLAMP); else texture->setUWrapMode(M_WRAP_REPEAT); } if(vTile){ if(strcmp(vTile, "clamp") == 0) texture->setVWrapMode(M_WRAP_CLAMP); else texture->setVWrapMode(M_WRAP_REPEAT); } } // translate TiXmlElement * translateNode = textureNode->FirstChildElement("translate"); if(translateNode) { MVector2 translate = texture->getTexTranslate(); translateNode->QueryFloatAttribute("x", &translate.x); translateNode->QueryFloatAttribute("y", &translate.y); texture->setTexTranslate(translate); } // scale TiXmlElement * scaleNode = textureNode->FirstChildElement("scale"); if(scaleNode) { MVector2 scale = texture->getTexScale(); scaleNode->QueryFloatAttribute("x", &scale.x); scaleNode->QueryFloatAttribute("y", &scale.y); texture->setTexScale(scale); } // rotate TiXmlElement * rotateNode = textureNode->FirstChildElement("rotate"); if(rotateNode) { float angle = 0; rotateNode->QueryFloatAttribute("angle", &angle); texture->setTexRotate(angle); } } } // Materials TiXmlElement * materialsNode = pMeshNode->FirstChildElement("Materials"); if(materialsNode) { MLOG_DEBUG("entering Materials node"); unsigned int numMaterials = 0; materialsNode->QueryUIntAttribute("num", &numMaterials); mesh->allocMaterials(numMaterials); // Material TiXmlElement * materialNode = materialsNode->FirstChildElement("Material"); for(materialNode; materialNode; materialNode=materialNode->NextSiblingElement("Material")) { MMaterial * material = mesh->addNewMaterial(); int type = 0; materialNode->QueryIntAttribute("type", &type); material->setType(type); float opacity=1, shininess=0, customValue=0; MVector3 diffuseColor; MVector3 specularColor; MVector3 emitColor; MVector3 customColor; // blend int blendType = 0; TiXmlElement * blendNode = materialNode->FirstChildElement("blend"); if(blendNode) blendNode->QueryIntAttribute("type", &blendType); switch(blendType) { case 2: material->setBlendMode(M_BLENDING_ALPHA); break; case 3: material->setBlendMode(M_BLENDING_ADD); break; case 4: material->setBlendMode(M_BLENDING_PRODUCT); break; } // opacity TiXmlElement * opacityNode = materialNode->FirstChildElement("opacity"); if(opacityNode) opacityNode->QueryFloatAttribute("value", &opacity); // shininess TiXmlElement * shininessNode = materialNode->FirstChildElement("shininess"); if(shininessNode) shininessNode->QueryFloatAttribute("value", &shininess); // customValue TiXmlElement * customValueNode = materialNode->FirstChildElement("customValue"); if(customValueNode) customValueNode->QueryFloatAttribute("value", &customValue); material->setOpacity(opacity); material->setShininess(shininess); material->setCustomValue(customValue); // diffuseColor TiXmlElement * diffuseColorNode = materialNode->FirstChildElement("diffuseColor"); if(diffuseColorNode){ diffuseColorNode->QueryFloatAttribute("r", &diffuseColor.x); diffuseColorNode->QueryFloatAttribute("g", &diffuseColor.y); diffuseColorNode->QueryFloatAttribute("b", &diffuseColor.z); material->setDiffuse(diffuseColor); } // specularColor TiXmlElement * specularColorNode = materialNode->FirstChildElement("specularColor"); if(specularColorNode){ specularColorNode->QueryFloatAttribute("r", &specularColor.x); specularColorNode->QueryFloatAttribute("g", &specularColor.y); specularColorNode->QueryFloatAttribute("b", &specularColor.z); material->setSpecular(specularColor); } // emitColor TiXmlElement * emitColorNode = materialNode->FirstChildElement("emitColor"); if(emitColorNode){ emitColorNode->QueryFloatAttribute("r", &emitColor.x); emitColorNode->QueryFloatAttribute("g", &emitColor.y); emitColorNode->QueryFloatAttribute("b", &emitColor.z); material->setEmit(emitColor); } // customColor TiXmlElement * customColorNode = materialNode->FirstChildElement("customColor"); if(customColorNode){ customColorNode->QueryFloatAttribute("r", &customColor.x); customColorNode->QueryFloatAttribute("g", &customColor.y); customColorNode->QueryFloatAttribute("b", &customColor.z); material->setCustomColor(customColor); } // TexturesPass TiXmlElement * texturesPassNode = materialNode->FirstChildElement("TexturesPass"); if(texturesPassNode) { unsigned int numTexturesPass = 0; texturesPassNode->QueryUIntAttribute("num", &numTexturesPass); material->allocTexturesPass(numTexturesPass); // texturePass TiXmlElement * texturePassNode = texturesPassNode->FirstChildElement("texturePass"); for(texturePassNode; texturePassNode; texturePassNode=texturePassNode->NextSiblingElement("texturePass")) { int textureId = -1; unsigned int mapChannel = 0; const char * mode = texturePassNode->Attribute("mode"); texturePassNode->QueryIntAttribute("texture", &textureId); if(textureId < 0) { material->addTexturePass(NULL, M_TEX_COMBINE_MODULATE, 0); continue; } texturePassNode->QueryUIntAttribute("mapChannel", &mapChannel); // combine mode M_TEX_COMBINE_MODES texCombine = M_TEX_COMBINE_MODULATE; if(strcmp(mode, "modulate") == 0) texCombine = M_TEX_COMBINE_MODULATE; else if(strcmp(mode, "replace") == 0) texCombine = M_TEX_COMBINE_REPLACE; else if(strcmp(mode, "alpha") == 0) texCombine = M_TEX_COMBINE_ALPHA; else if(strcmp(mode, "dot") == 0) texCombine = M_TEX_COMBINE_DOT; else if(strcmp(mode, "add") == 0) texCombine = M_TEX_COMBINE_ADD; else if(strcmp(mode, "sub") == 0) texCombine = M_TEX_COMBINE_SUB; // add texture pass material->addTexturePass(mesh->getTexture(textureId), texCombine, mapChannel); } } // FX { // vertexShader const char * vertShadFile = NULL; TiXmlElement * vertexShaderNode = materialNode->FirstChildElement("vertexShader"); if(vertexShaderNode){ vertShadFile = vertexShaderNode->Attribute("file"); } // fragmentShader const char * fragShadFile = NULL; TiXmlElement * fragmentShaderNode = materialNode->FirstChildElement("fragmentShader"); if(fragmentShaderNode){ fragShadFile = fragmentShaderNode->Attribute("file"); } // create FX if(vertShadFile && fragShadFile) { getGlobalFilename(vertShadPath, meshRep, vertShadFile); getGlobalFilename(fragShadPath, meshRep, fragShadFile); MShaderRef * vertShad = level->loadShader(vertShadPath, M_SHADER_VERTEX); MShaderRef * pixShad = level->loadShader(fragShadPath, M_SHADER_PIXEL); if(vertShad && pixShad) { MFXRef * FXRef = level->createFX(vertShad, pixShad); material->setFXRef(FXRef); } } } // ZFX (optional optim) { // ZVertexShader const char * vertShadFile = NULL; TiXmlElement * vertexShaderNode = materialNode->FirstChildElement("ZVertexShader"); if(vertexShaderNode){ vertShadFile = vertexShaderNode->Attribute("file"); } // ZFragmentShader const char * fragShadFile = NULL; TiXmlElement * fragmentShaderNode = materialNode->FirstChildElement("ZFragmentShader"); if(fragmentShaderNode){ fragShadFile = fragmentShaderNode->Attribute("file"); } // create ZFX if(vertShadFile && fragShadFile) { getGlobalFilename(vertShadPath, meshRep, vertShadFile); getGlobalFilename(fragShadPath, meshRep, fragShadFile); MShaderRef * vertShad = level->loadShader(vertShadPath, M_SHADER_VERTEX); MShaderRef * pixShad = level->loadShader(fragShadPath, M_SHADER_PIXEL); if(vertShad && pixShad) { MFXRef * ZFXRef = level->createFX(vertShad, pixShad); material->setZFXRef(ZFXRef); } } } } } // Bones TiXmlElement * bonesNode = pMeshNode->FirstChildElement("Bones"); if(bonesNode) { MLOG_DEBUG("entering Bones node"); MArmature * armature = mesh->createArmature(); unsigned int b, numBones = 0; bonesNode->QueryUIntAttribute("num", &numBones); armature->allocBones(numBones); // add bones for(b=0; b<numBones; b++) armature->addNewBone(); b = 0; // Bone TiXmlElement * boneNode = bonesNode->FirstChildElement("Bone"); for(boneNode; boneNode; boneNode=boneNode->NextSiblingElement("Bone")) { if(b >= armature->getBonesNumber()) break; MOBone * bone = armature->getBone(b); const char * name = boneNode->Attribute("name"); if(name) bone->setName(name); // parent TiXmlElement * parentNode = boneNode->FirstChildElement("parent"); if(parentNode){ unsigned int boneId = 0; parentNode->QueryUIntAttribute("id", &boneId); bone->linkTo(armature->getBone(boneId)); } // position TiXmlElement * positionNode = boneNode->FirstChildElement("position"); if(positionNode){ MVector3 position; positionNode->QueryFloatAttribute("x", &position.x); positionNode->QueryFloatAttribute("y", &position.y); positionNode->QueryFloatAttribute("z", &position.z); bone->setPosition(position); } // rotation TiXmlElement * rotationNode = boneNode->FirstChildElement("rotation"); if(rotationNode){ MVector3 euler; rotationNode->QueryFloatAttribute("x", &euler.x); rotationNode->QueryFloatAttribute("y", &euler.y); rotationNode->QueryFloatAttribute("z", &euler.z); bone->setEulerRotation(euler); } // scale TiXmlElement * scaleNode = boneNode->FirstChildElement("scale"); if(scaleNode){ MVector3 scale; scaleNode->QueryFloatAttribute("x", &scale.x); scaleNode->QueryFloatAttribute("y", &scale.y); scaleNode->QueryFloatAttribute("z", &scale.z); bone->setScale(scale); } b++; } // construct bones inverse pose matrix armature->constructBonesInversePoseMatrix(); } // SubMeshs TiXmlElement * subMeshsNode = pMeshNode->FirstChildElement("SubMeshs"); if(! subMeshsNode) return true; unsigned int numSubMeshs = 0; subMeshsNode->QueryUIntAttribute("num", &numSubMeshs); if(numSubMeshs == 0) return true; // alloc subMeshs MSubMesh * subMeshs = mesh->allocSubMeshs(numSubMeshs); // BoundingBox TiXmlElement * boundingBoxNode = pMeshNode->FirstChildElement("BoundingBox"); if(boundingBoxNode) { MVector3 * min = &mesh->getBoundingBox()->min; MVector3 * max = &mesh->getBoundingBox()->max; boundingBoxNode->QueryFloatAttribute("minx", &min->x); boundingBoxNode->QueryFloatAttribute("miny", &min->y); boundingBoxNode->QueryFloatAttribute("minz", &min->z); boundingBoxNode->QueryFloatAttribute("maxx", &max->x); boundingBoxNode->QueryFloatAttribute("maxy", &max->y); boundingBoxNode->QueryFloatAttribute("maxz", &max->z); } // SubMesh TiXmlElement * SubMeshNode = subMeshsNode->FirstChildElement("SubMesh"); for(SubMeshNode; SubMeshNode; SubMeshNode=SubMeshNode->NextSiblingElement("SubMesh")) { MSubMesh * subMesh = subMeshs; // BoundingBox boundingBoxNode = SubMeshNode->FirstChildElement("BoundingBox"); if(boundingBoxNode) { MVector3 * min = &subMesh->getBoundingBox()->min; MVector3 * max = &subMesh->getBoundingBox()->max; boundingBoxNode->QueryFloatAttribute("minx", &min->x); boundingBoxNode->QueryFloatAttribute("miny", &min->y); boundingBoxNode->QueryFloatAttribute("minz", &min->z); boundingBoxNode->QueryFloatAttribute("maxx", &max->x); boundingBoxNode->QueryFloatAttribute("maxy", &max->y); boundingBoxNode->QueryFloatAttribute("maxz", &max->z); } // Vertices TiXmlElement * verticesNode = SubMeshNode->FirstChildElement("Vertices"); if(verticesNode) { unsigned int numVertices = 0; verticesNode->QueryUIntAttribute("num", &numVertices); MVector3 * vertices = subMesh->allocVertices(numVertices); // vertex TiXmlElement * vertexNode = verticesNode->FirstChildElement("vertex"); for(vertexNode; vertexNode; vertexNode=vertexNode->NextSiblingElement("vertex")) { vertexNode->QueryFloatAttribute("x", &vertices->x); vertexNode->QueryFloatAttribute("y", &vertices->y); vertexNode->QueryFloatAttribute("z", &vertices->z); vertices++; } } // Normals TiXmlElement * normalsNode = SubMeshNode->FirstChildElement("Normals"); if(normalsNode) { unsigned int numNormals = 0; normalsNode->QueryUIntAttribute("num", &numNormals); MVector3 * normals = subMesh->allocNormals(numNormals); // normal TiXmlElement * normalNode = normalsNode->FirstChildElement("normal"); for(normalNode; normalNode; normalNode=normalNode->NextSiblingElement("normal")) { normalNode->QueryFloatAttribute("x", &normals->x); normalNode->QueryFloatAttribute("y", &normals->y); normalNode->QueryFloatAttribute("z", &normals->z); normals->normalize(); normals++; } } // Tangents TiXmlElement * tangentsNode = SubMeshNode->FirstChildElement("Tangents"); if(tangentsNode) { unsigned int numTangents = 0; tangentsNode->QueryUIntAttribute("num", &numTangents); MVector3 * tangents = subMesh->allocTangents(numTangents); // tangent TiXmlElement * tangentNode = tangentsNode->FirstChildElement("tangent"); for(tangentNode; tangentNode; tangentNode=tangentNode->NextSiblingElement("tangent")) { tangentNode->QueryFloatAttribute("x", &tangents->x); tangentNode->QueryFloatAttribute("y", &tangents->y); tangentNode->QueryFloatAttribute("z", &tangents->z); tangents->normalize(); tangents++; } } // TexCoords TiXmlElement * texCoordsNode = SubMeshNode->FirstChildElement("TexCoords"); if(texCoordsNode) { // num unsigned int numTexCoords = 0; texCoordsNode->QueryUIntAttribute("num", &numTexCoords); MVector2 * texCoords = subMesh->allocTexCoords(numTexCoords); // mapChannels unsigned int numVertices = subMesh->getVerticesSize(); const char * mapChannelsData = texCoordsNode->Attribute("mapChannels"); // read channels if(mapChannelsData) { char str[256]; strcpy(str, mapChannelsData); char * pch; unsigned int offset = 0; pch = strtok(str, " "); while(pch != NULL) { unsigned int channel = 0; sscanf(pch, "%d", &channel); subMesh->setMapChannelOffset(channel, offset); pch = strtok(NULL, " "); offset += numVertices; } } // create default channels else if((numVertices > 0) && (numTexCoords > numVertices)) { unsigned int numChannels = numTexCoords / numVertices; for(unsigned int c=0; c<numChannels; c++) subMesh->setMapChannelOffset(c, numVertices*c); } // texCoord TiXmlElement * texCoordNode = texCoordsNode->FirstChildElement("texCoord"); for(texCoordNode; texCoordNode; texCoordNode=texCoordNode->NextSiblingElement("texCoord")) { texCoordNode->QueryFloatAttribute("x", &texCoords->x); texCoordNode->QueryFloatAttribute("y", &texCoords->y); texCoords++; } } // Colors TiXmlElement * colorsNode = SubMeshNode->FirstChildElement("Colors"); if(colorsNode) { unsigned int numColors = 0; colorsNode->QueryUIntAttribute("num", &numColors); MColor * colors = subMesh->allocColors(numColors); // color TiXmlElement * colorNode = colorsNode->FirstChildElement("color"); for(colorNode; colorNode; colorNode=colorNode->NextSiblingElement("color")) { float x = 1, y = 1, z = 1, w = 1; colorNode->QueryFloatAttribute("x", &x); colorNode->QueryFloatAttribute("y", &y); colorNode->QueryFloatAttribute("z", &z); colorNode->QueryFloatAttribute("w", &w); colors->r = (unsigned char)x*255; colors->g = (unsigned char)y*255; colors->b = (unsigned char)z*255; colors->a = (unsigned char)w*255;; colors++; } } // Indices TiXmlElement * indicesNode = SubMeshNode->FirstChildElement("Indices"); if(indicesNode) { M_TYPES indicesType; unsigned int vSize = subMesh->getVerticesSize(); if(vSize < 65536){ indicesType = M_USHORT; } else{ indicesType = M_UINT; } unsigned int numIndices = 0; indicesNode->QueryUIntAttribute("num", &numIndices); subMesh->allocIndices(numIndices, indicesType); // indices TiXmlElement * indexNode = indicesNode->FirstChildElement("index"); switch(indicesType) { case M_USHORT: { unsigned short * indices = (unsigned short *)subMesh->getIndices(); for(indexNode; indexNode; indexNode=indexNode->NextSiblingElement("index")) { unsigned int id; indexNode->QueryUIntAttribute("value", &id); *indices = (unsigned short)id; indices++; } } break; case M_UINT: { unsigned int * indices = (unsigned int *)subMesh->getIndices(); for(indexNode; indexNode; indexNode=indexNode->NextSiblingElement("index")) { indexNode->QueryUIntAttribute("value", indices); indices++; } } break; } } // Skins TiXmlElement * skinsNode = SubMeshNode->FirstChildElement("Skins"); if(skinsNode) { MSkinData * skinData = subMesh->createSkinData(); unsigned int numSkins = 0; skinsNode->QueryUIntAttribute("num", &numSkins); MSkinPoint * skinPoints = skinData->allocPoints(numSkins); // skin TiXmlElement * skinNode = skinsNode->FirstChildElement("skin"); for(skinNode; skinNode; skinNode=skinNode->NextSiblingElement("skin")) { unsigned int vertexId = 0; unsigned int numBones = 0; skinNode->QueryUIntAttribute("vertex", &vertexId); skinNode->QueryUIntAttribute("numBones", &numBones); if(numBones > 0) { skinPoints->setVertexId(vertexId); skinPoints->allocateBonesLinks(numBones); unsigned short * bonesIds = skinPoints->getBonesIds(); float * bonesWeights = skinPoints->getBonesWeights(); TiXmlElement * boneNode = skinNode->FirstChildElement("bone"); for(boneNode; boneNode; boneNode=boneNode->NextSiblingElement("bone")) { unsigned int id; boneNode->QueryUIntAttribute("id", &id); boneNode->QueryFloatAttribute("weight", bonesWeights); *bonesIds = id; bonesIds++; bonesWeights++; } } skinPoints++; } } // Displays TiXmlElement * displaysNode = SubMeshNode->FirstChildElement("Displays"); if(displaysNode) { unsigned int numDisplays = 0; displaysNode->QueryUIntAttribute("num", &numDisplays); subMesh->allocDisplays(numDisplays); // display TiXmlElement * displayNode = displaysNode->FirstChildElement("display"); for(displayNode; displayNode; displayNode=displayNode->NextSiblingElement("display")) { unsigned int begin, size, material, cullFace = 0; displayNode->QueryUIntAttribute("begin", &begin); displayNode->QueryUIntAttribute("size", &size); displayNode->QueryUIntAttribute("material", &material); displayNode->QueryUIntAttribute("cullFace", &cullFace); // create display MDisplay * display = subMesh->addNewDisplay(M_PRIMITIVE_TRIANGLES, begin, size); // set material if(material < mesh->getMaterialsNumber()) display->setMaterial(mesh->getMaterial(material)); // set cull mode M_CULL_MODES cullMode = M_CULL_BACK; if(cullFace == 1) cullMode = M_CULL_FRONT; else if(cullFace == 2) cullMode = M_CULL_NONE; display->setCullMode(cullMode); } } // generate tangents if needed if(! subMesh->getTangents()) generateTangents(subMesh); subMeshs++; } MLOG_DEBUG("xmlMeshLoad success: "<<numSubMeshs<<" submeshs found"); return true; }
bool loadPeople (FILE * fp) { onScreenPerson * * pointy = & allPeople; onScreenPerson * me; scaleHorizon = getSigned (fp); scaleDivide = getSigned (fp); int countPeople = get2bytes (fp); int a; allPeople = NULL; for (a = 0; a < countPeople; a ++) { me = new onScreenPerson; if (! checkNew (me)) return false; me -> myPersona = new persona; if (! checkNew (me -> myPersona)) return false; me -> myAnim = new personaAnimation; if (! checkNew (me -> myAnim)) return false; me -> x = getFloat (fp); me -> y = getFloat (fp); loadCostume (me -> myPersona, fp); loadAnim (me -> myAnim, fp); me -> lastUsedAnim = fgetc (fp) ? me -> myAnim : NULL; me -> scale = getFloat (fp); me -> extra = get2bytes (fp); me -> height = get2bytes (fp); me -> walkToX = get2bytes (fp); me -> walkToY = get2bytes (fp); me -> thisStepX = get2bytes (fp); me -> thisStepY = get2bytes (fp); me -> frameNum = get2bytes (fp); me -> frameTick = get2bytes (fp); me -> walkSpeed = get2bytes (fp); me -> spinSpeed = get2bytes (fp); me -> floaty = getSigned (fp); me -> show = fgetc (fp); me -> walking = fgetc (fp); me -> spinning = fgetc (fp); if (fgetc (fp)) { me -> continueAfterWalking = loadFunction (fp); if (! me -> continueAfterWalking) return false; } else { me -> continueAfterWalking = NULL; } me -> direction = get2bytes(fp); me -> angle = get2bytes(fp); if (ssgVersion >= VERSION(2,0)) { me -> angleOffset = get2bytes(fp); } else { me -> angleOffset = 0; } me -> wantAngle = get2bytes(fp); me -> directionWhenDoneWalking = getSigned(fp); me -> inPoly = getSigned(fp); me -> walkToPoly = getSigned(fp); if (ssgVersion >= VERSION(2,0)) { me -> r = fgetc (fp); me -> g = fgetc (fp); me -> b = fgetc (fp); me -> colourmix = fgetc (fp); me -> transparency = fgetc (fp); } else { setMyDrawMode(me, get2bytes(fp)); } me -> thisType = loadObjectRef (fp); // Anti-aliasing settings if (ssgVersion >= VERSION(1,6)) { if (ssgVersion < VERSION (2,0)) { // aaLoad fgetc (fp); getFloat (fp); getFloat (fp); } } me -> next = NULL; * pointy = me; pointy = & (me -> next); } // db ("End of loadPeople"); return true; }
int doMain(int argc,char **argv) { int i; char *opt; std::vector<std::string> filenames; std::vector<std::string> servers; std::string connectionType = "StreamSock"; std::string connectionParameters; int rows=1; int cols=-1; char type='M'; bool clientRendering=true; bool compose=false; std::string composerType=""; std::string autostart; for(i=1;i<argc;i++) { if(strlen(argv[i])>1 && argv[i][0]=='-') { switch(argv[i][1]) { case 'o': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionParameters = opt; printf("connectionParameters: '%s'\n", connectionParameters.c_str()); break; case 'A': opt = argv[i][2] ? argv[i]+2 : argv[++i]; autostart = opt; break; case 'D': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%f,%f,%f",&ca,&cb,&cc)!=3) { std::cout << "Copy opton -D x,y,z" << std::endl; return 1; } break; case 'b': opt = argv[i][2] ? argv[i]+2 : argv[++i]; serviceInterface.assign(opt); serviceInterfaceValid = true; break; case 'B': opt = argv[i][2] ? argv[i]+2 : argv[++i]; serviceAddress.assign(opt); serviceAddressValid = true; break; case 'f': opt = argv[i][2] ? argv[i]+2 : argv[++i]; filenames.push_back(opt); printf("<%s>\n",opt); break; case 'm': connectionType="Multicast"; break; case 'r': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d",&rows,&cols) != 2) sscanf(opt,"%d",&rows); break; case 't': opt = argv[i][2] ? argv[i]+2 : argv[++i]; subtilesize=atoi(opt); break; #ifdef FRAMEINTERLEAVE case 'i': opt = argv[i][2] ? argv[i]+2 : argv[++i]; interleave=atoi(opt); break; #endif case 'C': compose=true; break; case 'F': type='F'; break; case 'X': type='X'; break; case 'P': type='P'; break; case 'L': { type='L'; int lpos=2; while(argv[i][lpos]) { if(argv[i][lpos] == 'B') composerType = "BinarySwapComposer"; if(argv[i][lpos] == 'P') composerType = "PipelineComposer"; if(argv[i][lpos] == 'S') composerType = "SepiaComposer"; if(argv[i][lpos] == 'p') pipelinedBufferRead = true; ++lpos; } break; } case 'M': type='M'; break; case 'I': type='I'; break; case 's': stereoMode=1; break; case 'c': stereoMode=2; break; case 'S': info=true; break; case 'e': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%f",&eyedistance); break; case 'z': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%f",&zeroparallax); break; case 'd': clientRendering=false; break; case 'v': multiport=true; break; case 'x': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%d",&serverx); break; case 'y': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%d",&servery); break; case 'a': opt = argv[i][2] ? argv[i]+2 : argv[++i]; animName=opt; loadAnim(); animate=true; break; case 'l': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d",&animLoops,&animLength) != 2) { animLength = 30; if(sscanf(opt,"%d",&animLoops) != 1) { animLoops = -1; } } break; case 'g': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d,%d,%d", &winwidth,&winheight,&winx,&winy) != 4) sscanf(opt,"%d,%d",&winwidth,&winheight); break; case 'G': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionDestination = opt; break; case 'i': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionInterface = opt; break; default: std::cout << argv[0] << "-ffile -m -rrows[,cols] -C -M" << std::endl; std::cout << "-m use multicast" << std::endl << "-G multicast group" << std::endl << "-i interface" << std::endl << "-b service interface" << std::endl << "-M multi display" << std::endl #ifdef FRAMEINTERLEAVE << "-I frame interleave" << std::endl #endif << "-r number of display rows" << std::endl << "-C compose" << std::endl << "-F sort-first" << std::endl << "-L sort-last" << std::endl << "-h this msg" << std::endl << "-s stereo" << std::endl << "-c red/cyan stereo" << std::endl << "-e eye distance" << std::endl << "-z zero parallax" << std::endl << "-d disable client rendering"<<std::endl << "-v use two viewports" << std::endl << "-x server x resolution" << std::endl << "-y server y resolution" << std::endl << "-t subtile size for img composition" << std::endl << "-D x,y,z duplicate geometry" << std::endl << "-A Autostart command" << std::endl << "-o connection parameter string e.g. \"TTL=8\"" << std::endl; return 0; } } else { servers.push_back(argv[i]); } } OSG::ChangeList::setReadWriteDefault(true); OSG::osgInit(argc, argv); glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); if(winx >=0 && winy >=0) glutInitWindowPosition(winx,winy); glutInitWindowSize(winwidth,winheight); winid = glutCreateWindow("OpenSG Cluster Client"); glutKeyboardFunc(key); glutReshapeFunc(reshape); glutDisplayFunc(display); if(animate) glutIdleFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); ract = OSG::RenderAction::create(); #ifdef OSG_OLD_RENDER_ACTION ract->setSortTrans(true); ract->setZWriteTrans(true); ract->setLocalLights(true); ract->setCorrectTwoSidedLighting(true); #endif // clear changelist from prototypes OSG::Thread::getCurrentChangeList()->clear(); // create cluster window switch(type) { case 'M': multidisplay=OSG::MultiDisplayWindow::create(); clusterWindow=multidisplay; break; case 'X': balancedmultidisplay=OSG::BalancedMultiWindow::create(); clusterWindow=balancedmultidisplay; break; case 'F': sortfirst=OSG::SortFirstWindow::create(); if(compose) sortfirst->setCompose(true); else sortfirst->setCompose(false); clusterWindow=sortfirst; break; case 'L': sortlast=OSG::SortLastWindow::create(); if(!composerType.empty()) { OSG::FieldContainerUnrecPtr fcPtr = OSG::FieldContainerFactory::the()-> createContainer(composerType.c_str()); OSG::ImageComposer *icPtr = dynamic_cast<OSG::ImageComposer *>(fcPtr.get()); if(icPtr != NULL) { if(dynamic_cast<OSG::PipelineComposer *>(icPtr) != NULL) { if(subtilesize>0) dynamic_cast<OSG::PipelineComposer *>(icPtr)->setTileSize(subtilesize); dynamic_cast<OSG::PipelineComposer *>(icPtr)->setPipelined(pipelinedBufferRead); } if(dynamic_cast<OSG::BinarySwapComposer *>(icPtr) != NULL) { if(subtilesize>0) dynamic_cast<OSG::BinarySwapComposer *>(icPtr)->setTileSize(subtilesize); } icPtr->setStatistics(info); // icPtr->setShort(false); sortlast->setComposer(icPtr); } } clusterWindow=sortlast; break; #ifdef FRAMEINTERLEAVE case 'I': frameinterleave=OSG::FrameInterleaveWindow::create(); clusterWindow=frameinterleave; if(compose) frameinterleave->setCompose(true); else frameinterleave->setCompose(false); break; #endif case 'P': sortfirst=OSG::SortFirstWindow::create(); sortfirst->setCompose(false); clusterWindow=sortfirst; break; } if(!autostart.empty()) clusterWindow->editMFAutostart()->push_back(autostart); for(i=0 ; i<int(servers.size()) ; ++i) clusterWindow->editMFServers()->push_back(servers[i]); if(cols < 0) cols = clusterWindow->getMFServers()->size32() / rows; switch(type) { case 'M': multidisplay->setHServers(cols); multidisplay->setVServers(rows); break; case 'X': balancedmultidisplay->setHServers(cols); balancedmultidisplay->setVServers(rows); // balancedmultidisplay->setShowBalancing(true); // balancedmultidisplay->setShowBalancing(info); break; } #ifdef FRAMEINTERLEAVE clusterWindow->setInterleave(interleave); #endif // create client window clientWindow=OSG::GLUTWindow::create(); // glutReshapeWindow(800,600); glutReshapeWindow(winwidth,winheight); clientWindow->setGlutId(winid); clientWindow->init(); // init scene graph init(filenames); // init client clusterWindow->setConnectionType(connectionType); // needs to be called before init()! clusterWindow->setConnectionParams(connectionParameters); if(clientRendering) { clusterWindow->setClientWindow(clientWindow); } clusterWindow->setConnectionDestination(connectionDestination); clusterWindow->setConnectionInterface(connectionInterface); clusterWindow->init(); if(serverx > 0) clusterWindow->resize(serverx,servery); else clusterWindow->resize(winwidth,winheight); clientWindow->resize(winwidth,winheight); // OSG::FieldContainerFactory::the()->dump(); OSG::commitChanges(); glutMainLoop(); return 0; }
void key(unsigned char key, int /*x*/, int /*y*/) { switch ( key ) { case 'l': { loadAnim(); break; } case 'c': { FILE *file=fopen(animName.c_str(),"w"); fclose(file); animOri.clear(); animPos.clear(); frameCount = 0; animTime = 0; break; } case 's': { FILE *file=fopen(animName.c_str(),"a"); OSG::Matrix m=cam_trans->getMatrix(); OSG::Quaternion q(m); OSG::Real32 ax,ay,az,r; animPos.push_back(OSG::Vec3f(m[3][0], m[3][1], m[3][2])); animOri.push_back(q); q.getValueAsAxisRad(ax,ay,az,r); fprintf(file,"%f %f %f %f,%f %f %f\n",ax,ay,az,r, m[3][0], m[3][1], m[3][2]); fclose(file); frameCount = 0; animTime = 0; break; } case 'S': { FILE *file=fopen((animName+".wrl").c_str(),"w"); std::vector<OSG::Quaternion>::iterator qit; fprintf(file,"DEF OriInter OrientationInterpolator {\n\tkey ["); for(size_t i = 0; i < animOri.size(); ++i) { fprintf(file, "%f", i / OSG::Real32(animOri.size() - 1) ); if(i < animOri.size() - 1) fprintf(file,", "); } fprintf(file,"]\n\tkeyValue ["); for(qit = animOri.begin(); qit != animOri.end(); ++qit) { OSG::Real32 ax,ay,az,r; (*qit).getValueAsAxisRad(ax,ay,az,r); fprintf(file, "%f %f %f %f", ax, ay, az, r ); if(qit < animOri.end() - 1) fprintf(file,", "); } fprintf(file,"]\n}\n\n"); std::vector<OSG::Vec3f>::iterator vit; fprintf(file,"DEF PosInter PositionInterpolator {\n\tkey ["); for(size_t i = 0; i < animPos.size(); ++i) { fprintf(file, "%f", i / OSG::Real32(animPos.size() - 1) ); if(i < animPos.size() - 1) fprintf(file,", "); } fprintf(file,"]\n\tkeyValue ["); for(vit = animPos.begin(); vit != animPos.end(); ++vit) { OSG::Vec3f v = *vit; fprintf(file, "%f %f %f, ", v[0], v[1], v[2] ); } fprintf(file,"]\n}\n\n"); fclose(file); break; } case 'j': if(sortfirst!=NULL) { sortfirst->setCompression("JPEG"); } break; case 'r': if(sortfirst!=NULL) { sortfirst->setCompression("RLE"); } break; case 'n': if(sortfirst!=NULL) { sortfirst->editCompression().erase(); } break; case 'i': showInfo = !showInfo; break; case 'w': if(polygonChunk->getFrontMode() == GL_FILL) polygonChunk->setFrontMode(GL_LINE); else polygonChunk->setFrontMode(GL_FILL); if(polygonChunk->getBackMode() == GL_FILL) polygonChunk->setBackMode(GL_LINE); else polygonChunk->setBackMode(GL_FILL); break; case 'a': if(animate) { glutIdleFunc(NULL); animate=false; } else { glutIdleFunc(display); animate=true; } frameCount = 0; animTime = 0; break; case 'd': // remove tree while(root->getNChildren()) { root->subChild(0u); } break; case '+': _dsFactor += 0.01f; if(_dsFactor > 1.0f) _dsFactor = 1.0f; setHEyeWallParameter(_dsFactor, _enablecc); break; case '-': _dsFactor -= 0.01f; if(_dsFactor <= 0.0f) _dsFactor = 0.01f; setHEyeWallParameter(_dsFactor, _enablecc); break; case 'f': if(_enablecc) _enablecc = false; else _enablecc = true; setHEyeWallParameter(_dsFactor, _enablecc); break; case 'B': if(bkgnd->getColor()[0] == 0.0) bkgnd->setColor( OSG::Color3f(1,1,1) ); else bkgnd->setColor( OSG::Color3f(0,0,0) ); break; case 27: // should kill the clients here // exit cleanup(); OSG::osgExit(); exit(0); } glutPostRedisplay(); }