/** @details * Ze zadaneho korenoveho elementu <em>box</em> vytvori prototyp bedny * reprezentovane timto elementem. Pokud se pri zpracovani dokumentu * vyskytne chyba, zobrazi chybove hlaseni. * Zda jde o element se spravnym nazvem se j*z nezkouma, proto * by melo byt vzdy drive otestovano pomoci @c canHandle(). * Predpoklada j*z nacteny zdrojovy obrazek v @c ResourceHandler. * @param rootEl korenovy element reprezentujici nacitanou bednu * @return Nove vytvoreny prototyp bedny (volajici se stava vlastnikem). * @retval 0 Doslo k chybe, bedna nemuze byt vytvoren. */ BombicMapObject * BoxResourceHandler::createMapObject( const QDomElement & rootEl) { QDomElement imgEl; if(getSubElement(rootEl, imgEl)) { // get attributes int x = 0; int y = 0; int w = 1; int h = 1; int t = 0; // toplapping bool success = getAttrsXY(imgEl, x, y) && getIntAttr(imgEl, w, "width", true) && getIntAttr(imgEl, h, "height", true) && getIntAttr(imgEl, t, "toplapping", true); if(!success) { return 0; } // get pixmap QPixmap pixmap = sourcePixmap().copy( x, y, w*CELL_SIZE, (h+t)*CELL_SIZE); return new BombicBox( rootEl.attribute("name"), pixmap, w, h, t); } else { return 0; } }
/* use PTRefNum1 and PTRefNum2 to propagate attributes to PTRefNumR */ PTErr_t ComposeAttr(PTRefNum_t PTRefNum1, PTRefNum_t PTRefNum2, KpInt32_t mode, PTRefNum_t PTRefNumR) { PTErr_t PTErr; KpInt32_t inspace, outspace; /* get output color space of 1st PT */ PTErr = getIntAttr (PTRefNum1, KCM_SPACE_OUT, KCP_NO_MAX_INTATTR, &outspace); if (PTErr == KCP_SUCCESS) { /* get input color space of 2nd PT */ PTErr = getIntAttr (PTRefNum2, KCM_SPACE_IN, KCP_NO_MAX_INTATTR, &inspace); if (PTErr == KCP_SUCCESS) { if ((outspace == KCM_UNKNOWN) && (inspace != KCM_UNKNOWN)) { PTErr = copyAllAttr (PTRefNum2, PTRefNumR); return (PTErr); } if ((outspace != KCM_UNKNOWN) && (inspace == KCM_UNKNOWN)) { PTErr = copyAllAttr (PTRefNum1, PTRefNumR); return (PTErr); } } } /* propagate "input" attributes */ PTErr = moveAttrList (PTRefNum1, 0, propRule02, 0, PTRefNumR); /* propagate "output" attributes */ if (PTErr == KCP_SUCCESS) PTErr = moveAttrList (PTRefNum2, 0, propRule03, 0, PTRefNumR); /* generate "constant" attributes */ if (PTErr == KCP_SUCCESS) PTErr = generateAttr (PTRefNumR); /* if composition mode is input set input attribute to "is linearized" */ if ((PTErr == KCP_SUCCESS) && (mode == PT_COMBINE_ITBL)) PTErr = setLinearized (PTRefNumR, KCM_DEVICE_LINEARIZED_IN); /* if composition mode is output set output attribute to "is linearized" */ if ((PTErr == KCP_SUCCESS) && (mode == PT_COMBINE_OTBL)) PTErr = setLinearized (PTRefNumR, KCM_DEVICE_LINEARIZED_OUT); /* Set KCM_EFFECT_TYPE attribute */ if (PTErr == KCP_SUCCESS) PTErr = setEFFECTstate (PTRefNum1, PTRefNum2, PTRefNumR); /* propagate "input" attributes, 2nd PT is backup */ if (PTErr == KCP_SUCCESS) PTErr = moveAttrList (PTRefNum1, PTRefNum2, propRule11, 0, PTRefNumR); /* propagate "simulate" attributes */ if (PTErr == KCP_SUCCESS) PTErr = moveAttrList (PTRefNum2, PTRefNum1, propRule13, 1, PTRefNumR); return (PTErr); }
// Parse GFX int parseGfx(TiXmlElement *zbeXML, FILE *output) { // Total # gfx. Do the same like total number assets fpos_t totalGfxPos = tempVal<uint32_t>("Total GFX", output); uint32_t totalGfx = 0; // For all the graphics in the XML file TiXmlElement *graphicsXML = zbeXML->FirstChildElement("bin")->FirstChildElement("graphics"); if (graphicsXML) { TiXmlElement *gfxXML = graphicsXML->FirstChildElement("gfx"); while (gfxXML) { // Increment total gfx counter ++totalGfx; // Get all the needed attributes string thisBin = getStrAttr(gfxXML, "bin"); int w = getIntAttr(gfxXML, "w"); int h = getIntAttr(gfxXML, "h"); int t = getIntAttr(gfxXML, "top"); int l = getIntAttr(gfxXML, "left"); // Copy it into the zbe file debug("\tGFX: %d x %d at (%d, %d)\n", w, h, t, l); fwrite<uint8_t>((uint8_t) w, output); fwrite<uint8_t>((uint8_t) h, output); fwrite<uint8_t>((uint8_t) t, output); fwrite<uint8_t>((uint8_t) l, output); // The length is unknown right now, it'll be counted in the copy op and returned // so we'll return here after that copy is done debug("\t"); fpos_t lenPos = tempVal<uint16_t>("Tiles Length", output); debug("\tAppending GFX's Tiles Data from file %s\n", thisBin.c_str()); uint16_t len = appendData(output, thisBin); // Now we have the length, so go back and write it down goWrite<uint16_t>(uint16_t(len), output, &lenPos); debug("\tTiles' length: %d B\n", int(len)); // Get the next sibling gfxXML = gfxXML->NextSiblingElement("gfx"); debug("GFX done\n"); } } // Now that the total number of gfx are known, go back and write that down goWrite<uint32_t>(totalGfx, output, &totalGfxPos); debug("%d GFX processed\n\n", int(totalGfx)); return totalGfx; }
RoundCorners::RoundCorners(MObject shaderObject) { MFnDependencyNode depFn(shaderObject); radius = getFloatAttr("radius", depFn, 0.0f); samplesCount = getIntAttr("samples", depFn, 10); float globalScaleFactor = 1.0f; if (MayaTo::getWorldPtr()->worldRenderGlobalsPtr != nullptr) globalScaleFactor = MayaTo::getWorldPtr()->worldRenderGlobalsPtr->scaleFactor; else globalScaleFactor = MayaTo::getWorldPtr()->scaleFactor; radius *= globalScaleFactor; };
void MayaToCorona::setLogLevel() { MObject globalsObj = getRenderGlobalsNode(); if (globalsObj == MObject::kNullObj) { Logging::setLogLevel(Logging::Debug); return; } MFnDependencyNode globalsNode(globalsObj); int logLevel = getIntAttr("translatorVerbosity", globalsNode, 0); Logging::setLogLevel((Logging::LogLevel)logLevel); }
bool CoronaRenderer::assingExistingMat(MObject shadingGroup, std::shared_ptr<MayaObject> mobj) { std::shared_ptr<mtco_MayaObject> obj = std::static_pointer_cast<mtco_MayaObject>(mobj); int index = -1; for( size_t i = 0; i < shaderArray.size(); i++) { Logging::debug(MString("assingExistingMat search for ") + getObjectName(shadingGroup) + " current shaderArrayElement: " + getObjectName(shaderArray[i])); if( shaderArray[i] == shadingGroup) { index = i; break; } } if( index > -1) { Logging::info(MString("Reusing material data from :") + getObjectName(shaderArray[index])); Corona::NativeMtlData data = dataArray[index]; MFnDependencyNode depFn(obj->mobject); // this can be a problem because a user may turn off shadow casting for the shader itself what is possible but should not be used normally // the default case is that the user turnes shadowCasting on/off on the geometry. data.castsShadows = true; if (!getBoolAttr("castsShadows", depFn, true)) data.castsShadows = false; data.shadowCatcherMode = Corona::SC_DISABLED; int shadowCatcherMode = getIntAttr("mtco_shadowCatcherMode", depFn, 0); if (shadowCatcherMode > 0) { if (shadowCatcherMode == 1) data.shadowCatcherMode = Corona::SC_ENABLED_FINAL; if (shadowCatcherMode == 2) data.shadowCatcherMode = Corona::SC_ENABLED_COMPOSITE; } Corona::SharedPtr<Corona::IMaterial> mat = data.createMaterial(); Corona::IMaterialSet ms = Corona::IMaterialSet(mat); setRenderStats(ms, obj); obj->instance->addMaterial(ms); return true; } return false; }
bool RenderGlobals::getDefaultGlobals() { MSelectionList defaultGlobals; defaultGlobals.add("defaultRenderGlobals"); if( defaultGlobals.length() == 0 ) { Logging::debug("defaultRenderGlobals not found. Stopping."); return false; } MCommonRenderSettingsData data; MRenderUtil::getCommonRenderSettings(data); MObject node; defaultGlobals.getDependNode(0, node); MFnDependencyNode fnRenderGlobals(node); MTime tv = MAnimControl::currentTime(); this->currentFrameNumber = (float)(tv.value()); tv = data.frameStart; this->startFrame = (float)(tv.value()); tv = data.frameEnd; this->endFrame = (float)(tv.value()); tv = data.frameBy; this->byFrame = (float)(tv.value()); // check if we are in a batch render mode or if we are rendering from UI if( MGlobal::mayaState() == MGlobal::kBatch ) { this->inBatch = true; if( data.isAnimated() ) { Logging::debug(MString("animation on, rendering frame sequence from ") + this->startFrame + " to " + this->endFrame); // these are the frames that are supposed to be rendered in batch mode this->doAnimation = true; for( double frame = this->startFrame; frame <= this->endFrame; frame += this->byFrame) this->frameList.push_back((float)frame); }else{ Logging::debug(MString("animation off, rendering current frame")); this->frameList.push_back(this->currentFrameNumber ); this->doAnimation = false; } }else{ // we are rendering from the UI so only render the current frame this->inBatch = false; this->frameList.push_back(this->currentFrameNumber ); this->doAnimation = false; // at the moment, if rendering comes from UI dont do animation } this->imgHeight = data.height; this->imgWidth = data.width; this->pixelAspect = data.pixelAspectRatio; this->regionLeft = 0; this->regionRight = this->imgWidth; this->regionBottom = 0; this->regionTop = this->imgHeight; regionLeft = getIntAttr("left", fnRenderGlobals, 0); regionRight = getIntAttr("rght", fnRenderGlobals, imgWidth); regionBottom = getIntAttr("bot", fnRenderGlobals, 0); regionTop = getIntAttr("top", fnRenderGlobals, imgHeight); getBool(MString("enableDefaultLight"), fnRenderGlobals, this->createDefaultLight); getString(MString("preRenderMel"), fnRenderGlobals, this->preFrameScript); getString(MString("postRenderMel"), fnRenderGlobals, this->postFrameScript); getString(MString("preRenderLayerMel"), fnRenderGlobals, this->preRenderLayerScript); getString(MString("postRenderLayerMel"), fnRenderGlobals, this->postRenderLayerScript); MFnDependencyNode depFn(getRenderGlobalsNode()); this->maxTraceDepth = getIntAttr("maxTraceDepth", depFn, 4); this->doMb = getBoolAttr("doMotionBlur", depFn, false); this->doDof = getBoolAttr("doDof", depFn, false); this->motionBlurRange = getFloatAttr("motionBlurRange", depFn, 0.4f); this->motionBlurType = 0; // center this->xftimesamples = getIntAttr("xftimesamples", depFn, 2); this->geotimesamples = getIntAttr("geotimesamples", depFn, 2); this->createDefaultLight = false; this->renderType = RenderType::FINAL; this->exportSceneFile = getBoolAttr("exportSceneFile", depFn, false); this->adaptiveSampling = getBoolAttr("adaptiveSampling", depFn, false); this->imageName = getStringAttr("imageName", depFn, ""); this->basePath = getStringAttr("basePath", depFn, ""); this->exportSceneFileName = getStringAttr("exportSceneFileName", depFn, ""); this->imagePath = getStringAttr("imagePath", depFn, ""); this->threads = getIntAttr("threads", depFn, 4); this->translatorVerbosity = getEnumInt("translatorVerbosity", depFn); this->rendererVerbosity = getEnumInt("rendererVerbosity", depFn); this->useSunLightConnection = getBoolAttr("useSunLightConnection", depFn, false); this->tilesize = getIntAttr("tileSize", depFn, 64); this->sceneScale = getFloatAttr("sceneScale", depFn, 1.0f); this->filterSize = getFloatAttr("filterSize", depFn, 3.0f); this->good = true; return true; }
void CoronaRenderer::defineCamera() { MPoint rot, pos, scale; for(int objId = 0; objId < this->mtco_scene->camList.size(); objId++) { mtco_MayaObject *cam = (mtco_MayaObject *)this->mtco_scene->camList[objId]; if( !this->mtco_scene->isCameraRenderable(cam->mobject) && (!(cam->dagPath == this->mtco_scene->uiCamera))) { continue; } logger.debug(MString("using camera ") + cam->shortName); MFnCamera camera(cam->mobject); MPoint pos, rot, scale; MMatrix camMatrix = cam->transformMatrices[0] * this->mtco_renderGlobals->globalConversionMatrix; getMatrixComponents(camMatrix, pos, rot, scale); Corona::Pos cpos(pos.x, pos.y, pos.z); float focusDistance = 0.0; float fStop = 0.0; float focalLength = 35.0f; bool dof; float horizontalFilmAperture, verticalFilmAperture; float coi = 100.0f; getFloat(MString("horizontalFilmAperture"), camera, horizontalFilmAperture); getFloat(MString("verticalFilmAperture"), camera, verticalFilmAperture); getFloat(MString("focalLength"), camera, focalLength); getBool(MString("depthOfField"), camera, dof); getFloat(MString("focusDistance"), camera, focusDistance); getFloat(MString("fStop"), camera, fStop); getFloat(MString("centerOfInterest"), camera, coi); focusDistance *= this->mtco_renderGlobals->scaleFactor; MPoint coiBase(0,0,-coi); MPoint coiTransform = coiBase * camMatrix; //logger.debug(MString("Center of interest: ") + coi + " transformed " + coiTransform.x + " " + coiTransform.y + " " + coiTransform.z); Corona::Pos center(coiTransform.x, coiTransform.y, coiTransform.z); float fov = 2.0 * atan((horizontalFilmAperture * 0.5f) / (focalLength * 0.03937)); float fovDeg = fov * 57.29578; Corona::AnimatedFloat fieldOfView(fov); //logger.debug(MString("fov ") + fov + " deg: " + fovDeg); //Corona::AnimatedFloat fieldOfView(Corona::DEG_TO_RAD(45.f)); Corona::CameraData cameraData; //cameraData.type cameraData.createPerspective(Corona::AnimatedPos(cpos), Corona::AnimatedPos(center), Corona::AnimatedDir(Corona::Dir::UNIT_Z), fieldOfView); Corona::AnimatedFloat focalDist(focusDistance); cameraData.perspective.focalDist = focalDist; cameraData.perspective.fStop = fStop; cameraData.perspective.filmWidth = this->mtco_renderGlobals->toMillimeters(horizontalFilmAperture * 2.54f * 10.0f); //film width in mm if( dof && this->mtco_renderGlobals->doDof) cameraData.perspective.useDof = true; if (getBoolAttr("mtco_useBokeh", camera, false)) { cameraData.perspective.bokeh.use = true; cameraData.perspective.bokeh.blades = getIntAttr("mtco_blades", camera, 6); cameraData.perspective.bokeh.bladesRotation = getIntAttr("mtco_bladeRotation", camera, 0.0); MPlug bokehBitMapPlug = camera.findPlug("mtco_bokehBitmap"); if (!bokehBitMapPlug.isNull()) { if (bokehBitMapPlug.isConnected()) { MObject bitmapNode = getConnectedInNode(bokehBitMapPlug); if (bitmapNode.hasFn(MFn::kFileTexture)) { MFnDependencyNode bitMapFn(bitmapNode); MPlug texNamePlug = bitMapFn.findPlug("fileTextureName"); if (!texNamePlug.isNull()) { MString fileName = texNamePlug.asString(); logger.debug(MString("Found bokeh bitmap file: ") + fileName); Corona::Bitmap<Corona::Rgb> bokehBitmap; Corona::loadImage(fileName.asChar(), bokehBitmap); cameraData.perspective.bokeh.customShape = bokehBitmap; } } } } } this->context.scene->getCamera() = cameraData; } }
uint32_t ItemAttributes::getDecaying() const { return (uint32_t)getIntAttr(ATTR_ITEM_DECAYING); }
int32_t ItemAttributes::getDuration() const { return (int32_t)getIntAttr(ATTR_ITEM_DURATION); }
uint32_t ItemAttributes::getCorpseOwner() { return (uint32_t)getIntAttr(ATTR_ITEM_CORPSEOWNER); }
uint32_t ItemAttributes::getOwner() const { return (uint32_t)getIntAttr(ATTR_ITEM_OWNER); }
// Parse a single background void parseBackground(TiXmlElement *bgXML, FILE *output, int bgNo, uint32_t pal, bool defPal) { // Vector of vectors to store all the ids vector< vector<bgTile> > tiles; // This map corresponds the zbe palette indices with the background palette indices. // It's first-come-first-serve here map<uint32_t, uint16_t> palConv; // Process each row TiXmlElement *bgRowXML = bgXML->FirstChildElement("row"); debug("\tReading background map (tileId, paletteId, hflip, vflip):\n"); unsigned int maxWidth = 0; unsigned int h = 0; uint8_t numPalettes = 0; while (bgRowXML) { ++h; debug("\t\t"); // Vector of ids vector<bgTile> rowTiles; // Process each tile unsigned int w = 0; TiXmlElement *bgTileXML = bgRowXML->FirstChildElement("tile"); while (bgTileXML) { ++w; // Get attributes and fill in the bgTile int tileId, palId = pal, hflip = 0, vflip = 0; // tileId is required if (!getIntAttr(bgTileXML, "id", tileId)) { fprintf(stderr, "ERROR: no tileId defined for tile %d in row %d of background %d\n", w, h, bgNo); exit(EXIT_FAILURE); } // palId is only required if defPal is false if (!getIntAttr(bgTileXML, "palette", palId)) { if (!defPal) { fprintf(stderr, "ERROR: no palette defined for tile %d in row %d of background %d\n", w, h, bgNo); fprintf(stderr, "\t This is requried because no default palette defined in the <background> tag.\n"); exit(EXIT_FAILURE); } } // If this palette is not in the map, add it if (palConv.find(palId) == palConv.end()) { palConv[palId] = numPalettes; ++numPalettes; } // Now change the palId over to reference the appropriate bgPalette id palId = palConv[palId]; // hflip and vflip are optional, defaulting to false getIntAttr(bgTileXML, "hflip", hflip); getIntAttr(bgTileXML, "vflip", vflip); // debug printing made easy debug("(%d %d %d %d) ", tileId, palId, hflip, vflip); // make a new bgTile and add it to the vector bgTile newTile(tileId, palId, hflip == 1, vflip == 1); rowTiles.push_back(newTile); // Get the next tile bgTileXML = bgTileXML->NextSiblingElement("tile"); } // See if that set a new record for maxWidth if (w > maxWidth) maxWidth = w; // Add this row of tiles to the vector of vectors tiles.push_back(rowTiles); debug("\n"); // Get next row bgRowXML = bgRowXML->NextSiblingElement("row"); } // Take the maximum defined width to be the width of the map // (We'll fill in the blanks below) unsigned int w = maxWidth; // Determine the size of the bg debug("\tGot a %d tile x %d tile background\n", w, h); fwrite<uint32_t>(w, output); fwrite<uint32_t>(h, output); // Number of palettes used fwrite<uint8_t>(numPalettes, output); debug("\t%d Palettes used\n", palConv.size()); // Add the palette correspondence ids to the file for (uint16_t i = 0; i < palConv.size(); i++) { // Maps keep things sorted, so we have to actually find the one where it->second == i for ( map<uint32_t, uint16_t>::iterator it = palConv.begin() ; it != palConv.end(); it++ ) { if (it->second == i) { // Just need to write the zbe palette id fwrite<uint32_t>(it->first, output); // echo that debug("\t\tzbe Assets Palette %d = Background Palette %d\n", it->second, it->first); } } } // Write all those uint16_t datas debug("\t"); fpos_t mapLenPos = tempVal<uint32_t>("Background Map Length", output); uint32_t mapLen = 0; debug("\tWriting background map:\n"); for (unsigned int i = 0; i < h; i++) { debug("\t\t"); for (unsigned int j = 0; j < w; j++) { // Make sure to get a value within the range of the vectors uint16_t toWrite = 0; if ( i < tiles.size() && j < tiles[i].size() ) toWrite = tiles[i][j].getTile(); // Write it to the file debug("%x\t", toWrite); fwrite<uint16_t>(toWrite, output); // 16 bits = 2 bytes mapLen += 2; } debug("\n"); } goWrite<uint32_t>(mapLen, output, &mapLenPos); debug("\tBackground map length: %dB\n", mapLen); }
uint16_t ItemAttributes::getActionId() const { return (uint16_t)getIntAttr(ATTR_ITEM_ACTIONID); }
time_t ItemAttributes::getWrittenDate() const { return (time_t)getIntAttr(ATTR_ITEM_WRITTENDATE); }
// Parse level data int parseLevels(TiXmlElement *zbeXML, FILE *output) { // Total # levels fpos_t totalLvlPos = tempVal<uint32_t>("Total Levels", output); uint32_t totalLvl = 0; // For all the levels in the XML file TiXmlElement *levelsXML = zbeXML->FirstChildElement("levels"); if (levelsXML) { TiXmlElement *levelXML = levelsXML->FirstChildElement("level"); while (levelXML) { // Increment total level counter ++totalLvl; // Add level name string TiXmlElement *nameXML = levelXML->FirstChildElement("name"); string lvlName = (nameXML) ? nameXML->GetText() : ""; fwriteStr(lvlName, output); // Add the level's dimensions int w, h; if (!getIntAttr(levelXML, "w", w)) { fprintf(stderr, "ERROR: No width set for level %d.\n", totalLvl); exit(EXIT_FAILURE); } if (!getIntAttr(levelXML, "h", h)) { fprintf(stderr, "ERROR: No height set for level %d.\n", totalLvl); exit(EXIT_FAILURE); } fwrite<uint32_t>(uint32_t(w), output); fwrite<uint32_t>(uint32_t(h), output); debug("\tLevel \"%s\": %d x %d\n", lvlName.c_str(), w, h); // exp, debug, and timer values if making testing if (testing) { // Testing explanation string lvlExp; TiXmlElement *expXML = levelXML->FirstChildElement("exp"); if (expXML) { TiXmlElement *lineXML = expXML->FirstChildElement("line"); while (lineXML) { lvlExp += lineXML->GetText(); lvlExp += "\n"; lineXML = lineXML->NextSiblingElement("line"); } debug("\tTesting Explanation:\n%s", lvlExp.c_str()); } else fprintf(stderr, "WARNING: Making a testing zbe file but no test explanation provided.\n"); fwriteStr(lvlExp, output); // Debug info string lvlDebug; TiXmlElement *dbgXML = levelXML->FirstChildElement("debug"); if (dbgXML) { TiXmlElement *lineXML = dbgXML->FirstChildElement("line"); while (lineXML) { lvlDebug += lineXML->GetText(); lvlDebug += "\n"; lineXML = lineXML->NextSiblingElement("line"); } debug("\tTesting Debug:\n%s", lvlDebug.c_str()); } else fprintf(stderr, "WARNING: Making a testing zbe file but no test debug line provided.\n"); fwriteStr(lvlDebug, output); // timer value int timer; if (!getIntAttr(levelXML, "timer", timer)) { fprintf(stderr, "\tWARNING: No timer value specified for level. Will run for %d minutes unless fixed\n", uint16_t(-1) / 60 / 60); fprintf(stderr, "\t Add timer=\"-1\" to <level> tag if this is desired\n"); timer = uint16_t(-1); } debug("\tTest will run for %d blanks\n", timer); fwrite<uint16_t>(uint16_t(timer), output); } // Add background information TiXmlElement *backgroundsXML = levelXML->FirstChildElement("backgrounds"); map<int, uint32_t> bgIds; map<int, uint8_t> bgDistances; int numBackgrounds = 0; if (backgroundsXML) { TiXmlElement *backgroundXML = backgroundsXML->FirstChildElement("background"); while (backgroundXML) { int layer = numBackgrounds, id, distance = 1; // ID is required if (!getIntAttr(backgroundXML, "id", id)) { fprintf(stderr, "ERROR: No background id specified for background %d in level %d. Ignoring background.\n", numBackgrounds + 1, totalLvl); // Get next background and continue ++numBackgrounds; backgroundXML = backgroundXML->NextSiblingElement("background"); continue; } // Layer isn't so don't overwrite layer if not set getIntAttr(backgroundXML, "layer", layer); // Same for distance getIntAttr(backgroundXML, "distance", distance); // Add this background to the vector bgIds[layer] = id; bgDistances[layer] = distance; debug("\tLevel background %d using background %d at distance %d\n", layer, id, distance); // Got another background ++numBackgrounds; // Next background s.v.p. backgroundXML = backgroundXML->NextSiblingElement("background"); } } else fprintf(stderr, "WARNING: No backgrounds defined for level %d\n", totalLvl); for (int i = 0; i < 4; i++) { // See if this layer was defined if (bgIds.find(i) == bgIds.end()) { // Not defined, Just write -1s fwrite<uint32_t>(uint32_t(-1), output); fwrite<uint8_t>(uint8_t(-1), output); debug("\tBackground %d not defined\n", i); } else { // Write ID fwrite<uint32_t>(bgIds[i], output); // Write Distance fwrite<uint8_t>(bgDistances[i], output); debug("\tBackground %d using %d at distance %d\n", i, bgIds[i], bgDistances[i]); } } // tileset Id int tilesetId = -1; if (!getIntAttr(backgroundsXML, "tileset", tilesetId)) { fprintf(stderr, "ERROR: No tileset specified for Level %d.\n", totalLvl); exit(EXIT_FAILURE); } fwrite<uint32_t>(uint32_t(tilesetId), output); // Level Heroes //Total heroes debug("\t"); fpos_t totalLvlHroPos = tempVal<uint32_t>("Level Heroes", output); uint32_t totalLvlHro = 0; TiXmlElement *heroesXML = levelXML->FirstChildElement("heroes"); if (heroesXML) { TiXmlElement *heroXML = heroesXML->FirstChildElement("hero"); while (heroXML) { ++totalLvlHro; // Get the relevant infos int x = getIntAttr(heroXML, "x"); int y = getIntAttr(heroXML, "y"); int id = getIntAttr(heroXML, "id"); // Horizontal Gravity float fhgrav = 0.0; if (!getFloatAttr(heroXML, "hgrav", fhgrav)) fprintf(stderr, "WARNING: No horizontal gravity set for level hero %d. Using default %f.\n", totalLvlHro, fhgrav); int32_t ihgrav = int32_t(fhgrav * pow(2, 12)); // Vertical Gravity float fvgrav = 0.025; if (!getFloatAttr(heroXML, "vgrav", fvgrav)) fprintf(stderr, "WARNING: No vertical gravity set for level hero %d. Using default %f.\n", totalLvlHro, fvgrav); int32_t ivgrav = int32_t(fvgrav * pow(2, 12)); // Write them up debug("\t\tHero using object id %d at (%d, %d) w/ grav (%f, %f) = (%d, %d) 20.12\n", id, x, y, fhgrav, fvgrav, ihgrav, ivgrav); fwrite<uint32_t>(uint32_t(id), output); fwrite<uint16_t>(uint16_t(x), output); fwrite<uint16_t>(uint16_t(y), output); fwrite<int32_t>(ihgrav, output); fwrite<int32_t>(ivgrav, output); // Get the next object heroXML = heroXML->NextSiblingElement("hero"); } } else fprintf(stderr, "WARNING: No hero defined for level %d\n", totalLvl); //go write the total number of objects goWrite<uint32_t>(totalLvlHro, output, &totalLvlHroPos); debug("\t%d Level Heroes\n", int(totalLvlHro)); // Level Objects // Total objects debug("\t"); fpos_t totalLvlObjPos = tempVal<uint32_t>("Level Objects", output); uint32_t totalLvlObj = 0; TiXmlElement *objectsXML = levelXML->FirstChildElement("objects"); if (objectsXML) { TiXmlElement *objectXML = objectsXML->FirstChildElement("object"); while (objectXML) { ++totalLvlObj; // Get the relevant infos int x = getIntAttr(objectXML, "x"); int y = getIntAttr(objectXML, "y"); int id = getIntAttr(objectXML, "id"); // Horizontal Gravity float fhgrav = 0.0; if (!getFloatAttr(objectXML, "hgrav", fhgrav)) fprintf(stderr, "WARNING: No horizontal gravity set for level object %d. Using default %f.\n", totalLvlObj, fhgrav); int32_t ihgrav = int32_t(fhgrav * pow(2, 12)); // Vertical Gravity float fvgrav = 0.025; if (!getFloatAttr(objectXML, "vgrav", fvgrav)) fprintf(stderr, "WARNING: No vertical gravity set for level object %d. Using default %f.\n", totalLvlObj, fvgrav); int32_t ivgrav = int32_t(fvgrav * pow(2, 12)); // Write them up debug("\t\tObject using object id %d at (%d, %d) w/ grav (%f, %f) = (%d, %d) 20.12\n", id, x, y, fhgrav, fvgrav, ihgrav, ivgrav); fwrite<uint32_t>(uint32_t(id), output); fwrite<uint16_t>(uint16_t(x), output); fwrite<uint16_t>(uint16_t(y), output); fwrite<int32_t>(ihgrav, output); fwrite<int32_t>(ivgrav, output); // Get the next object objectXML = objectXML->NextSiblingElement("object"); } } else fprintf(stderr, "WARNING: No objects defined for level %d\n", totalLvl); //go write the total number of objects goWrite<uint32_t>(totalLvlObj, output, &totalLvlObjPos); debug("\t%d Level objects\n", int(totalLvlObj)); // Get the next sibling levelXML = levelXML->NextSiblingElement("level"); debug("Level Done\n"); } } else fprintf(stderr, "WARNING: No levels defined!\n"); // Now that the total number of palettes are known, go back and write that down goWrite<uint32_t>(totalLvl, output, &totalLvlPos); debug("%d Levels Processed\n\n", int(totalLvl)); return totalLvl; }
// Parse out object definitions int parseObjects(TiXmlElement *zbeXML, FILE *output) { // Total # objects. fpos_t totalObjPos = tempVal<uint32_t>("Total Objects", output); uint32_t totalObj = 0; // For all the objects TiXmlElement *objectsXML = zbeXML->FirstChildElement("objects"); if (objectsXML) { TiXmlElement *objectXML = objectsXML->FirstChildElement("object"); while (objectXML) { ++totalObj; // Weight int weight = 50; if (!getIntAttr(objectXML, "weight", weight)) fprintf(stderr, "WARNING: No weight set for object %d. Using default %d.\n", totalObj, weight); debug("\tWeight : %d\n", weight); fwrite<uint8_t>(uint8_t(weight), output); // Total # Animations uint32_t totalAnimations = 0; debug("\t"); fpos_t totalAnimationsPos = tempVal<uint32_t>("Total Animations", output); // And all the animations TiXmlElement *animationsXML = objectXML->FirstChildElement("animations"); if (animationsXML) { TiXmlElement *animationXML = animationsXML->FirstChildElement("animation"); while (animationXML) { ++totalAnimations; // Total # frames for this animation uint16_t totalFrames = 0; debug("\t\t"); fpos_t totalFramesPos = tempVal<uint16_t>("Total Frames", output); // Start getting frames TiXmlElement *frameXML = animationXML->FirstChildElement("frame"); while (frameXML) { ++totalFrames; // Get the attributes int gfxId = getIntAttr(frameXML, "id"); int palId = getIntAttr(frameXML, "pal"); int time = getIntAttr(frameXML, "time"); // Write them to the file debug("\t\t\tFrame: GFX ID %d with Palette ID %d for %d blanks\n", gfxId, palId, time); fwrite<uint32_t>((uint32_t) gfxId, output); fwrite<uint32_t>((uint32_t) palId, output); fwrite<uint8_t>((uint8_t) time, output); // get the next frame frameXML = frameXML->NextSiblingElement("frame"); } // Go back and write the number of frames in this animation goWrite<uint16_t>(totalFrames, output, &totalFramesPos); debug("\t\t%d Frames Processed\n", int(totalFrames)); // get the next animation animationXML = animationXML->NextSiblingElement("animation"); } } // Go back and write the number of animations for this object goWrite<uint32_t>(totalAnimations, output, &totalAnimationsPos); debug("\t%d Animations Processed\n", int(totalAnimations)); // get the next one objectXML = objectXML->NextSiblingElement("object"); debug("Object done\n"); } } // Finally, go back and write the number of objects goWrite<uint32_t>(totalObj, output, &totalObjPos); debug("%d Objects processed\n\n", int(totalObj)); return totalObj; }
void CoronaRenderer::defineSettings() { MFnDependencyNode depFn(getRenderGlobalsNode()); std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; int w = renderGlobals->getWidth(); int h = renderGlobals->getHeight(); context.settings->set(Corona::PARAM_IMAGE_WIDTH, w); context.settings->set(Corona::PARAM_IMAGE_HEIGHT, h); if (MayaTo::getWorldPtr()->renderType == MayaTo::MayaToWorld::WorldRenderType::IPRRENDER) context.settings->set(Corona::PARAM_MINIMIZE_PRECOMP, true); if (getBoolAttr("lockSamplingPattern",depFn, false)) context.settings->set(Corona::PARAM_RANDOM_SEED, 1234); else context.settings->set(Corona::PARAM_RANDOM_SEED, 0); if (renderGlobals->getUseRenderRegion()) { int left, bottom, right, top; renderGlobals->getRenderRegion(left, bottom, right, top); context.settings->set(Corona::PARAM_IMAGE_REGION_START_X, left); context.settings->set(Corona::PARAM_IMAGE_REGION_START_Y, bottom); context.settings->set(Corona::PARAM_IMAGE_REGION_END_X, right); context.settings->set(Corona::PARAM_IMAGE_REGION_END_Y, top); } int renderer = getIntAttr("renderer", depFn, 0); if( renderer == 0) // progressive context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_PROGRESSIVE); if( renderer == 1) // bucket rendering context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_BUCKET); if( renderer == 2) // vcm rendering context.settings->set(Corona::PARAM_RENDER_ENGINE, Corona::RENDER_ENGINE_VCM); //context.settings->set(Corona::PARAM_RESUME_RENDERING, false); context.settings->set(Corona::PARAM_BUCKET_SIZE, getIntAttr("image_bucketSize", depFn, 64)); context.settings->set(Corona::PARAM_BUCKET_SAMPLES_PER_ITERATION, getIntAttr("buckets_initialSamples", depFn, 4)); context.settings->set(Corona::PARAM_BUCKET_PASSES, getIntAttr("buckets_adaptiveSteps", depFn, 4)); context.settings->set(Corona::PARAM_BUCKET_ADAPTIVE_THRESHOLD, getFloatAttr("buckets_adaptiveThreshold", depFn, 0.03f)); context.settings->set(Corona::PARAM_PROGRESSIVE_PASS_LIMIT, getIntAttr("progressive_maxPasses", depFn, 0)); context.settings->set(Corona::PARAM_PROGRESSIVE_TIME_LIMIT, getIntAttr("progressive_timeLimit", depFn, 60) * 1000); context.settings->set(Corona::PARAM_VCM_MODE, getEnumInt("vcm_mode", depFn)); context.settings->set(Corona::PARAM_PPM_INITIAL_RADIUS, getFloatAttr("ppm_initialRadius", depFn, 2.0f)); //context.settings->set(Corona::PARAM_BIDIR_DO_MIS, getBoolAttr("bidir_doMis", depFn, true)); context.settings->set(Corona::PARAM_PPM_PHOTONS_PER_ITER, getIntAttr("ppm_photonsPerIter", depFn, 5000000)); context.settings->set(Corona::PARAM_PPM_ALPHA, getFloatAttr("ppm_alpha", depFn, .666f)); context.settings->set(Corona::PARAM_MAX_SAMPLE_INTENSITY, getFloatAttr("maxPtSampleIntensity", depFn, 20.0f)); context.settings->set(Corona::PARAM_NUM_THREADS, getIntAttr("threads", depFn, 4)); if (getBoolAttr("exportSceneFile", depFn, false)) context.settings->set(Corona::PARAM_EXPORT_PATH, renderGlobals->exportSceneFileName.asChar()); context.settings->set(Corona::PARAM_THREAD_PRIORITY, Corona::IScheduler::PRIORITY_BELOW_NORMAL); // always render with low priority Corona::DisplaceSubdivType subdivTypes[] = { Corona::DisplaceSubdivType::DISPLACE_SUBDIV_WORLD, Corona::DisplaceSubdivType::DISPLACE_SUBDIV_PROJECTED }; context.settings->set(Corona::PARAM_DISPLACE_SUBDIV_TYPE, subdivTypes[(int)getBoolAttr("displace_useProjectionSize", depFn, true)]); context.settings->set(Corona::PARAM_DISPLACE_MAX_SIZE_SCREEN, getFloatAttr("displace_maxProjectSize", depFn, 2.0f)); context.settings->set(Corona::PARAM_DISPLACE_MAX_SIZE_WORLD, getFloatAttr("displace_maxWorldSize", depFn, 1.0f)); context.settings->set(Corona::PARAM_MAX_RAY_DEPTH, getIntAttr("raycaster_maxDepth", depFn, 25)); context.settings->set(Corona::PARAM_MIN_INSTANCE_SAVING, getIntAttr("instance_minSize", depFn, 50000)); int f = getEnumInt("filtertype", depFn); float fw = getFloatAttr("imagefilter_width", depFn, 1.5f); float fb = getFloatAttr("imagefilter_blurring", depFn, .5f); context.settings->set(Corona::PARAM_IMAGEFILTER, getEnumInt("filtertype", depFn)); context.settings->set(Corona::PARAM_IMAGEFILTER_WIDTH, getFloatAttr("imagefilter_width", depFn, 1.5f)); context.settings->set(Corona::PARAM_IMAGEFILTER_BLURRING, getFloatAttr("imagefilter_blurring", depFn, .5f)); context.settings->set(Corona::PARAM_SHADING_ENABLE, getBoolAttr("doShading", depFn, true)); Corona::GiSolverType solverTypes[] = { Corona::GiSolverType::GISOLVER_NONE, Corona::GiSolverType::GISOLVER_PATHTRACING, Corona::GiSolverType::GISOLVER_HD_CACHE, Corona::GiSolverType::GISOLVER_UHD_CACHE }; context.settings->set(Corona::PARAM_SHADING_PRIMARY_SOLVER, solverTypes[getEnumInt("gi_primarySolver", depFn)]); context.settings->set(Corona::PARAM_SHADING_SECONDARY_SOLVER, solverTypes[getEnumInt("gi_secondarySolver", depFn)]); context.settings->set(Corona::PARAM_GI_TO_AA_RATIO, getIntAttr("pathtracingSamples", depFn, 16)); //context.settings->set(Corona::PARAM_LIGHT_SAMPLES_MULT, getFloatAttr("lights_areaSamplesMult", depFn, 2.0f)); context.settings->set(Corona::PARAM_HDCACHE_SAVE, getBoolAttr("gi_saveSecondary", depFn, false)); context.settings->set(Corona::PARAM_HDCACHE_PRECALC_MODE, getEnumInt("gi_hdCache_precalcMode", depFn)); context.settings->set(Corona::PARAM_HDCACHE_FILE, Corona::String(getStringAttr("gi_secondaryFile", depFn, "").asChar())); context.settings->set(Corona::PARAM_HDCACHE_PRECOMP_DENSITY, getFloatAttr("gi_hdCache_precompMult", depFn, 1.0f)); context.settings->set(Corona::PARAM_HDCACHE_INTERPOLATION_COUNT, getIntAttr("gi_hdCache_interpolationCount", depFn, 3)); context.settings->set(Corona::PARAM_HDCACHE_RECORD_QUALITY, getIntAttr("gi_hdCache_ptSamples", depFn, 256)); context.settings->set(Corona::PARAM_HDCACHE_SMOOTHING, getFloatAttr("gi_hdCache_smoothing", depFn, 2.0f)); context.settings->set(Corona::PARAM_HDCACHE_MAX_RECORDS, getIntAttr("gi_hdCache_maxRecords", depFn, 100000)); context.settings->set(Corona::PARAM_HDCACHE_GLOSS_THRESHOLD, getFloatAttr("gi_hdCache_glossyThreshold", depFn, .9f)); context.settings->set(Corona::PARAM_HDCACHE_WRITABLE_PASSES, getIntAttr("gi_hdCache_writePasses", depFn, 0)); context.settings->set(Corona::PARAM_HDCACHE_DIR_SENSITIVITY, getFloatAttr("gi_hdCache_dirSensitivity", depFn, 2.0f)); context.settings->set(Corona::PARAM_HDCACHE_POS_SENSITIVITY, getFloatAttr("gi_hdCache_posSensitivity", depFn, 20.0f)); context.settings->set(Corona::PARAM_HDCACHE_NORMAL_SENSITIVITY, getFloatAttr("gi_hdCache_normalSensitivity", depFn, 3.0f)); float uhd_precision = getFloatAttr("uhdPrecision", depFn, 1.0f); context.settings->set(Corona::PARAM_UHDCACHE_PRECISION, uhd_precision); int uhd_recordQuality = 512; float uhd_strictness = 0.075f; float uhd_msi = 3.0f; int uhdType = getEnumInt("uhdCacheType", depFn); if (getEnumInt("gi_secondarySolver", depFn) == 4) // uhd cache { // 0 == still, 1 == animation. Only animation needs not default settings. if (uhdType == 1) { context.settings->set(Corona::PARAM_UHDCACHE_MSI, uhd_msi * 3.0f); context.settings->set(Corona::PARAM_UHDCACHE_RECORD_QUALITY, uhd_recordQuality * .5f); context.settings->set(Corona::PARAM_UHDCACHE_STRICTNESS, uhd_strictness * .33f); context.settings->set(Corona::PARAM_UHDCACHE_PRECISION, uhd_precision * .4f); } } float gamma = 2.2f; #if MAYA_API_VERSION > 2015 if (MColorManagementUtilities::isColorManagementEnabled()) gamma = 1.0f; #endif context.settings->set(Corona::PARAM_COLORMAP_GAMMA, gamma); context.settings->set(Corona::PARAM_COLORMAP_HIGHLIGHT_COMPRESSION, getFloatAttr("colorMapping_highlightCompression", depFn, 1.0f)); context.settings->set(Corona::PARAM_COLORMAP_CONTRAST, getFloatAttr("colorMapping_contrast", depFn, 1.0f)); context.settings->set(Corona::PARAM_COLORMAP_COLOR_TEMP, getFloatAttr("colorMapping_colorTemperature", depFn, 6500.0f)); context.settings->set(Corona::PARAM_COLORMAP_SIMPLE_EXPOSURE, getFloatAttr("colorMapping_simpleExposure", depFn, 0.0f)); context.settings->set(Corona::PARAM_COLORMAP_TINT, toCorona(getColorAttr("colorMapping_tint", depFn))); context.settings->set(Corona::PARAM_COLORMAP_USE_PHOTOGRAPHIC, !getBoolAttr("colorMapping_useSimpleExposure", depFn, true)); context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("colorMapping_iso", depFn, 100.0)); context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("colorMapping_fStop", depFn, 5.6)); context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("colorMapping_shutterSpeed", depFn, 250.0f)); // v2.8 exposure from camera std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr; if (mayaScene) { for (auto cam : mayaScene->camList) { if (!isCameraRenderable(cam->mobject) && (!(cam->dagPath == mayaScene->uiCamera))) continue; MFnDependencyNode camFn(cam->mobject); if (getBoolAttr("mtco_overrideRenderSettings", camFn, false)) { context.settings->set(Corona::PARAM_COLORMAP_ISO, getFloatAttr("mtco_iso", camFn, 1.0)); context.settings->set(Corona::PARAM_COLORMAP_F_STOP, getFloatAttr("fStop", camFn, 5.6)); context.settings->set(Corona::PARAM_COLORMAP_SHUTTER_SPEED, 1.0f / getFloatAttr("mtco_shutterSpeed", camFn, 250.0f)); } break; } } }
void TheaRenderer::defineEnvironment() { MFnDependencyNode gFn(getRenderGlobalsNode()); std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; std::shared_ptr<TheaRenderer> renderer = std::static_pointer_cast<TheaRenderer>(MayaTo::getWorldPtr()->worldRendererPtr); if( renderGlobals->exportSceneFile ) { TheaSDK::XML::EnvironmentOptions env; int illumination = getEnumInt("illumination", gFn); switch (illumination) { case 0: break; case 1: // dome light { env.illumination = TheaSDK::DomeIllumination; MColor bg = getColorAttr("backgroundColor", gFn); TheaSDK::Rgb bgColor(bg.r, bg.g, bg.b); env.backgroundColor = bgColor; } break; case 2: // ibl { env.illumination = TheaSDK::IBLIllumination; defineIBLNode(env.illuminationMap, "illuminationMap"); defineIBLNode(env.backgroundMap, "backgroundMap"); defineIBLNode(env.reflectionMap, "reflectionMap"); defineIBLNode(env.refractionMap, "refractionMap"); } break; case 3: // physical sky { env.illumination = TheaSDK::PhysicalSkyIllumination; env.turbidity = getFloatAttr("turbidity", gFn, 2.5f); env.ozone = getFloatAttr("ozone", gFn, 0.35f); env.waterVapor = getFloatAttr("waterVapor", gFn, 2.0f); env.turbidityCoefficient = getFloatAttr("turbidityCoefficient", gFn, .046f); env.wavelengthExponent = getFloatAttr("wavelengthExponent", gFn, 1.3f); env.albedo = getFloatAttr("albedo", gFn, .5f); env.location = getStringAttr("location", gFn, "").asChar(); env.timezone = getIntAttr("timezone", gFn, 0); // from -12 to +12. env.date = getStringAttr("date", gFn, "").asChar(); // format dd/mm/yy. env.localtime = getStringAttr("localtime", gFn, "").asChar(); // format hh/mm/ss. env.latitude = getFloatAttr("latitude", gFn, .0f); env.longitude = getFloatAttr("longitude", gFn, .0f); env.sunDirection = this->getSunDirection(); env.sunPolarAngle = getFloatAttr("sunPolarAngle", gFn, -1.0f); // in degrees. env.sunAzimuth = getFloatAttr("sunAzimuth", gFn, -1.0f); // in degrees. } break; default: break; }; if (illumination > 0) { this->sceneXML.setEnvironmentOptions(env); } }else{ if (TheaSDK::SetRgbParameter(TheaSDK::GetGlobalSettings(),"Background Color",TheaSDK::Rgb(0.1f,0.1f,0.6f))==false) return; if (TheaSDK::SetStringParameter(TheaSDK::GetGlobalSettings(),"Background Type","Background Color")==false) return; if (TheaSDK::SetRealParameter(TheaSDK::GetGlobalSettings(),"./Sun/Polar Angle (deg)",45)==false) return ; if (TheaSDK::SetRealParameter(TheaSDK::GetGlobalSettings(),"./Sun/Azimuth (deg)",45)==false) return; if (TheaSDK::SetStringParameter(TheaSDK::GetGlobalSettings(),"Illumination","Physical Sky")==false) return; if (TheaSDK::SetIntegerParameter(TheaSDK::GetRootObject(),"GenerateSun",2)==false) return; } }
uint16_t ItemAttributes::getUniqueId() const { return (uint16_t)getIntAttr(ATTR_ITEM_UNIQUEID); }
// Parse out backgrounds int parseBackgrounds(TiXmlElement *zbeXML, FILE *output) { // Total # backgrounds. fpos_t totalBgPos = tempVal<uint32_t>("Total Backgrounds", output); uint32_t totalBg = 0; // For all the backgrounds in the XML file TiXmlElement *bgsXML = zbeXML->FirstChildElement("backgrounds"); if (bgsXML) { TiXmlElement *bgXML = bgsXML->FirstChildElement("background"); while (bgXML) { // Increment total bg counter ++totalBg; // Get the palette to use for this background uint32_t pal = 0; bool defPal = false; int palVal; if (!getIntAttr(bgXML, "palette", palVal)) fprintf(stderr, "WARNING: No default palette defined for background #%d.\n", totalBg); else { pal = (uint32_t) palVal; defPal = true; } // See if there's an xml attribute defined string extBgXMLfile = getStrAttr(bgXML, "xml"); string extBgBINfile = getStrAttr(bgXML, "bin"); if (!extBgXMLfile.empty()) { debug("\tOpening external background map XML file: %s\n", extBgXMLfile.c_str()); TiXmlDocument extXML(extBgXMLfile.c_str()); if (!extXML.LoadFile()) { fprintf(stderr, "Failed to parse file %s\n", extBgXMLfile.c_str()); exit(EXIT_FAILURE); } TiXmlElement *extBgXML = extXML.RootElement()->FirstChildElement("backgroundmap"); parseBackground(extBgXML, output, totalBg, pal, defPal); } // See if the map was added as a grit-generated bin else if (!extBgBINfile.empty()) { // Get dimensions of the map int width, height; if (!getIntAttr(bgXML, "w", width)) { fprintf(stderr, "ERROR: no width provided for background %d.\n", totalBg); exit(EXIT_FAILURE); } if (!getIntAttr(bgXML, "h", height)) { fprintf(stderr, "ERROR: no height provided for background %d.\n", totalBg); exit(EXIT_FAILURE); } if (!defPal) { fprintf(stderr, "ERROR: no palette provided for background %d.\n", totalBg); } debug("\tInserting external %d x %d background map BIN file %s using palette #%d\n", width, height, extBgBINfile.c_str(), pal); // dimensions fwrite<uint32_t>(uint32_t(width), output); fwrite<uint32_t>(uint32_t(height), output); // palettes fwrite<uint8_t>(1, output); fwrite<uint32_t>(pal, output); // temp data length followed by data fpos_t dataLenPos = tempVal<uint32_t>("Map Data Length", output); uint32_t dataLen = appendData(output, extBgBINfile); goWrite<uint32_t>(dataLen, output, &dataLenPos); debug("\tWrote %dB of map data.\n", dataLen); } else parseBackground(bgXML, output, totalBg, pal, defPal); // Get the next sibling bgXML = bgXML->NextSiblingElement("background"); debug("Background Done\n"); } } // Now that the total number of backgrounds are known, go back and write that down goWrite<uint32_t>(totalBg, output, &totalBgPos); debug("%d Backgrounds Processed\n\n", int(totalBg)); return totalBg; }
void TheaRenderer::defineCamera() { std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr; std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; for (auto obj : mayaScene->camList) { MFnCamera camFn(obj->mobject); if (!isCameraRenderable(obj->mobject) && (!(obj->dagPath == mayaScene->uiCamera))) { continue; } MMatrix m = obj->transformMatrices[0] * renderGlobals->globalConversionMatrix; uint width, height; int width_, height_; renderGlobals->getWidthHeight(width_, height_); width = width_; height = height_; bool success = true; float focalLen = camFn.focalLength(); float focusDistance = getFloatAttr("focusDistance", camFn, 10.0f); focusDistance *= renderGlobals->scaleFactor; float fStop = getFloatAttr("fStop", camFn, 5.6f); TheaSDK::Transform cameraPos; matrixToTransform(m, cameraPos); TheaSDK::Transform tn; cameraPos = cameraPos * tn.RotateX(-DegToRad(180.0)); if( renderGlobals->exportSceneFile ) { TheaSDK::XML::Camera cam; cam.name = obj->shortName.asChar(); cam.frame = cameraPos; cam.focalLength = focalLen; cam.pixels = width; cam.lines = height; cam.filmHeight = getFloatAttr("verticalFilmAperture", camFn, .9f) * 2.54f * 10.0f; cam.shutterSpeed = getFloatAttr("mtth_shutter_speed", camFn, 250.0); if( getBoolAttr("depthOfField", camFn, false)) { if( renderGlobals->doDof) { cam.focusDistance = focusDistance; cam.depthOfField = getFloatAttr("mtth_focusRange", camFn, 0.1); cam.autofocus = getBoolAttr("mtth_autoFocus", camFn, false); //cam.depthOfField = (focusDistance-nearFocusPlane)/focusDistance; cam.blades = getIntAttr("mtth_diaphragm_blades", camFn, 4); int diaType; getEnum(MString("mtth_diaphragm_type"), camFn, diaType); if( diaType == 0) cam.diaphragm = TheaSDK::Diaphragm::CircularDiaphragm; else cam.diaphragm = TheaSDK::Diaphragm::PolygonalDiaphragm; cam.fNumber = fStop; } } sceneXML.addCamera(cam); } else { TheaSDK::CameraPointer cameraPtr = TheaSDK::AddStandardCamera(obj->shortName.asChar(), cameraPos, focalLen, width, height); } break; // only 1 cam at the moment } }
uint16_t ItemAttributes::getCharges() const { return (uint16_t)getIntAttr(ATTR_ITEM_CHARGES); }
uint16_t ItemAttributes::getFluidType() const { return (uint16_t)getIntAttr(ATTR_ITEM_FLUIDTYPE); }
void IndigoRenderer::defineEnvironment() { std::shared_ptr<MayaScene> mayaScene = MayaTo::getWorldPtr()->worldScenePtr; std::shared_ptr<RenderGlobals> renderGlobals = MayaTo::getWorldPtr()->worldRenderGlobalsPtr; MFnDependencyNode gFn(getRenderGlobalsNode()); switch (getEnumInt("environmentType", gFn)) { case 0: // off { break; } case 1: // environment light map { MString texName; bool useTexture = false; Indigo::String texturePath = ""; MObject fileTexObj; if( getConnectedFileTexturePath(MString("environmentColor"), MString("indigoGlobals"), texName, fileTexObj) ) { useTexture = true; texturePath = texName.asChar(); } MFnDependencyNode fileTexNode(fileTexObj); MColor bgColor = getColorAttr("environmentColor", gFn); int mapType = getIntAttr("environmentMapType", gFn, 0); Indigo::SceneNodeBackgroundSettingsRef background_settings(new Indigo::SceneNodeBackgroundSettings()); Reference<Indigo::DiffuseMaterial> mat(new Indigo::DiffuseMaterial()); // Albedo should be zero. mat->albedo = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(new Indigo::UniformSpectrum(0)))); Indigo::Texture texture; if( useTexture ) { texture.path = texturePath; texture.exponent = 1; // Since we will usually use a HDR image, the exponent (gamma) should be set to one. MColor colorGain(1,1,1); getColor("colorGain", fileTexNode, colorGain); MColor colorOffset(0,0,0); getColor("colorOffset", fileTexNode, colorOffset); double cg = (colorGain.r + colorGain.g + colorGain.b) / 3.0; double co = (colorOffset.r + colorOffset.g + colorOffset.b) / 3.0; texture.a = 0.0; texture.b = cg; texture.c = co; texture.tex_coord_generation = Reference<Indigo::TexCoordGenerator>(new Indigo::SphericalTexCoordGenerator(Reference<Indigo::Rotation>(new Indigo::MatrixRotation()))); if( mapType == 1 ) { texture.tex_coord_generation = Reference<Indigo::TexCoordGenerator>(new Indigo::SphericalEnvTexCoordGenerator(Reference<Indigo::Rotation>(new Indigo::MatrixRotation()))); } mat->emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::TextureWavelengthDependentParam(0)); mat->textures.push_back(texture); }else{ Indigo::RGBSpectrum *iBgColor = new Indigo::RGBSpectrum(Indigo::Vec3d(bgColor.r,bgColor.g,bgColor.b), 2.2); mat->emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(iBgColor))); } // Base emission is the emitted spectral radiance. No effect here? double multiplier = (double)getFloatAttr("environmentMapMultiplier", gFn, 1.0) * 1000.0; mat->base_emission = Reference<Indigo::WavelengthDependentParam>(new Indigo::ConstantWavelengthDependentParam(Reference<Indigo::Spectrum>(new Indigo::UniformSpectrum(multiplier)))); background_settings->background_material = mat; sceneRootRef->addChildNode(background_settings); break; } case 2: // sun/sky { // first get the globals node and serach for a directional light connection MObjectArray nodeList; getConnectedInNodes(MString("sunLightConnection"), gFn.object(), nodeList); if( nodeList.length() > 0) { MObject sunObj = nodeList[0]; if(sunObj.hasFn(MFn::kTransform)) { // we suppose what's connected here is a dir light transform MVector lightDir(0,0,1); // default dir light dir MFnDagNode sunDagNode(sunObj); lightDir *= sunDagNode.transformationMatrix() * renderGlobals->globalConversionMatrix; lightDir.normalize(); Indigo::SceneNodeBackgroundSettingsRef background_settings_node(new Indigo::SceneNodeBackgroundSettings()); Reference<Indigo::SunSkyMaterial> sun_sky_mat(new Indigo::SunSkyMaterial()); MString sky_model; int modelId; getEnum("sky_model", gFn, modelId, sky_model); sun_sky_mat->model = sky_model.asChar(); sun_sky_mat->enable_sky = true; getBool("extra_atmospheric", gFn, sun_sky_mat->extra_atmospheric); sun_sky_mat->name = "sunsky"; getUInt("sky_layer", gFn, sun_sky_mat->sky_layer); getUInt("sun_layer", gFn, sun_sky_mat->sun_layer); getDouble(MString("turbidity"), gFn, sun_sky_mat->turbidity); sun_sky_mat->sundir = Indigo::Vec3d(lightDir.x, lightDir.y, lightDir.z); // Direction to sun. background_settings_node->background_material = sun_sky_mat; sceneRootRef->addChildNode(background_settings_node); } } break; } } }