void SciVisMaterial::commit() { map_d = (Texture2D*)getParamObject("map_d", nullptr); map_Kd = (Texture2D*)getParamObject("map_Kd", getParamObject("map_kd", nullptr)); map_Ks = (Texture2D*)getParamObject("map_Ks", getParamObject("map_ks", nullptr)); map_Ns = (Texture2D*)getParamObject("map_Ns", getParamObject("map_ns", nullptr)); map_Bump = (Texture2D*)getParamObject("map_Bump", getParamObject("map_bump",nullptr)); d = getParam1f("d", 1.f); Kd = getParam3f("kd", getParam3f("Kd", vec3f(.8f))); Ks = getParam3f("ks", getParam3f("Ks", vec3f(0.f))); Ns = getParam1f("ns", getParam1f("Ns", 10.f)); volume = (Volume *)getParamObject("volume", nullptr); ispc::SciVisMaterial_set(getIE(), map_d ? map_d->getIE() : nullptr, d, map_Kd ? map_Kd->getIE() : nullptr, (ispc::vec3f&)Kd, map_Ks ? map_Ks->getIE() : nullptr, (ispc::vec3f&)Ks, map_Ns ? map_Ns->getIE() : nullptr, Ns, map_Bump != nullptr ? map_Bump->getIE():nullptr, volume ? volume->getIE() : nullptr); }
void AO16Material::commit() { Kd = getParam3f("color", getParam3f("kd", getParam3f("Kd", vec3f(.8f)))); map_Kd = (Texture2D*)getParamObject("map_Kd", getParamObject("map_kd", NULL)); ispc::AO16Material_set(getIE(), (const ispc::vec3f&)Kd, map_Kd.ptr!=NULL?map_Kd->getIE():NULL); }
//! \brief commit the material's parameters virtual void commit() override { const vec3f& color = getParam3f("color", vec3f(0.9f)); Texture2D *map_color = (Texture2D*)getParamObject("map_color"); affine2f xform_color = getTextureTransform("map_color"); const vec3f& edgeColor = getParam3f("edgeColor", vec3f(1.f)); Texture2D *map_edgeColor = (Texture2D*)getParamObject("map_edgeColor"); affine2f xform_edgeColor = getTextureTransform("map_edgeColor"); const float roughness = getParamf("roughness", 0.1f); Texture2D *map_roughness = (Texture2D*)getParamObject("map_roughness"); affine2f xform_roughness = getTextureTransform("map_roughness"); ispc::PathTracer_Alloy_set(getIE() , (const ispc::vec3f&)color , map_color ? map_color->getIE() : nullptr , (const ispc::AffineSpace2f&)xform_color , (const ispc::vec3f&)edgeColor , map_edgeColor ? map_edgeColor->getIE() : nullptr , (const ispc::AffineSpace2f&)xform_edgeColor , roughness , map_roughness ? map_roughness->getIE() : nullptr , (const ispc::AffineSpace2f&)xform_roughness ); }
//! \brief commit the material's parameters void OBJMaterial::commit() { if (ispcEquivalent == NULL) ispcEquivalent = ispc::OBJMaterial_create(this); map_d = (Texture2D*)getParamObject("map_d", NULL); map_Kd = (Texture2D*)getParamObject("map_Kd", getParamObject("map_kd", NULL)); map_Ks = (Texture2D*)getParamObject("map_Ks", getParamObject("map_ks", NULL)); map_Ns = (Texture2D*)getParamObject("map_Ns", getParamObject("map_ns", NULL)); map_Bump = (Texture2D*)getParamObject("map_Bump", getParamObject("map_bump", NULL)); d = getParam1f("d", 1.f); Kd = getParam3f("kd", getParam3f("Kd", vec3f(.8f))); Ks = getParam3f("ks", getParam3f("Ks", vec3f(0.f))); Ns = getParam1f("ns", getParam1f("Ns", 10.f)); ispc::OBJMaterial_set(getIE(), map_d ? map_d->getIE() : NULL, d, map_Kd ? map_Kd->getIE() : NULL, (ispc::vec3f&)Kd, map_Ks ? map_Ks->getIE() : NULL, (ispc::vec3f&)Ks, map_Ns ? map_Ns->getIE() : NULL, Ns, map_Bump != NULL ? map_Bump->getIE() : NULL ); }
void AO16Renderer<NUM_SAMPLES_PER_FRAME>::commit() { Renderer::commit(); model = (Model *)getParamObject("world",NULL); // old naming model = (Model *)getParamObject("model",model); // new naming camera = (Camera *)getParamObject("camera",NULL); bgColor = getParam3f("bgColor",vec3f(1.f)); ispc::AO16Renderer_set(getIE(), NUM_SAMPLES_PER_FRAME, (const ispc::vec3f&)bgColor, model?model->getIE():NULL, camera?camera->getIE():NULL); }
void Functions::setItemCursedFlag(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (item) { const bool cursed = ctx.getParams()[1].getInt() != 0; item->setItemCursedFlag(cursed); } }
void Functions::setItemCharges(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (item) { const uint8 charges = (uint8)(ctx.getParams()[1].getInt()); item->setItemCharges(charges); } }
void Functions::setPickpocketableFlag(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (item) { const bool pickpocketable = ctx.getParams()[1].getInt() != 0; item->setPickpocketableFlag(pickpocketable); } }
void Functions::executeScript(Aurora::NWScript::FunctionContext &ctx) { Common::UString script = ctx.getParams()[0].getString(); // Max resource name length is 16, and ExecuteScript should truncate accordingly script.truncate(16); if (!ResMan.hasResource(script, Aurora::kFileTypeNCS)) return; Aurora::NWScript::Object *object = getParamObject(ctx, 1); try { Aurora::NWScript::NCSFile ncs(script); // Let the child script inherit the environment of this parent script Aurora::NWScript::VariableContainer *env = ctx.getCurrentEnvironment(); if (env) ncs.setEnvironment(*env); ncs.run(object); } catch (Common::Exception &e) { e.add("Failed ExecuteScript(\"%s\", %s)", script.c_str(), Aurora::NWScript::formatTag(object).c_str()); Common::printException(e, "WARNING: "); } }
void Functions::setItemIcon(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (item) { const uint32 icon = (uint32)(ctx.getParams()[1].getInt()); item->setItemIcon(icon); } }
void RaycastVolumeRenderer::Material::commit() { Kd = getParam3f("color", getParam3f("kd", getParam3f("Kd", vec3f(1.0f)))); volume = (Volume *)getParamObject("volume", NULL); ispc::RaycastVolumeRendererMaterial_set(getIE(), (const ispc::vec3f&)Kd, volume ? volume->getIE() : NULL); }
void Functions::actionStartConversation(Aurora::NWScript::FunctionContext &ctx) { NWN::Object *source = NWN::ObjectContainer::toObject(ctx.getCaller()); NWN::Object *target = NWN::ObjectContainer::toObject(getParamObject(ctx, 0)); if (!source || !target) return; Creature *pc = NWN::ObjectContainer::toPC(target); if (!pc) { warning("TODO: ActionStartConversation: Non-PC target \"%s\"", target->getTag().c_str()); return; } if (source->getPCSpeaker()) { if (source->getPCSpeaker() != pc) { Creature *otherPC = NWN::ObjectContainer::toPC(source->getPCSpeaker()); warning("Functions::actionStartConversation(): " "Object \"%s\" already in conversation with PC \"%s\"", source->getTag().c_str(), otherPC ? otherPC->getName().c_str() : ""); return; } } Common::UString conversation = ctx.getParams()[1].getString(); if (conversation.empty()) conversation = source->getConversation(); // TODO: privateConv // bool privateConv = ctx.getParams()[2].getInt() != 0; const bool playHello = ctx.getParams()[2].getInt() != 0; _game->getModule().startConversation(conversation, *pc, *source, playHello); }
void Functions::setItemStackSize(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (item) { const uint16 stackSize = (uint16)(ctx.getParams()[1].getInt()); item->setItemStackSize(stackSize); } }
void Functions::getItemHasItemProperty(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (!item) return; const ItemPropertyType type = (ItemPropertyType)(ctx.getParams()[1].getInt()); ctx.getReturn() = (int) item->getItemHasItemProperty(type); }
void Functions::soundObjectStop(Aurora::NWScript::FunctionContext &ctx) { SoundObject *sound = KotOR::ObjectContainer::toSoundObject(getParamObject(ctx, 0)); if (!sound) throw Common::Exception("Function::soundObjectStop(): object is not a sound"); sound->stop(); }
void Functions::assignCommand(Aurora::NWScript::FunctionContext &ctx) { Common::UString script = ctx.getScriptName(); if (script.empty()) throw Common::Exception("Functions::assignCommand(): Script needed"); const Aurora::NWScript::ScriptState &state = ctx.getParams()[1].getScriptState(); _game->getModule().delayScript(script, state, getParamObject(ctx, 0), ctx.getTriggerer(), 0); }
void Functions::sendMessageToPC(Aurora::NWScript::FunctionContext &ctx) { Creature *pc = NWN2::ObjectContainer::toPC(getParamObject(ctx, 0)); if (!pc) return; const Common::UString &msg = ctx.getParams()[1].getString(); warning("Send message to PC \"%s\": \"%s\"", pc->getName().c_str(), msg.c_str()); }
void Renderer::commit() { autoEpsilon = getParam1i("autoEpsilon", true); epsilon = getParam1f("epsilon", 1e-6f); spp = std::max(1, getParam1i("spp", 1)); const int32 maxDepth = getParam1i("maxDepth", 20); const float minContribution = getParam1f("minContribution", 0.001f); errorThreshold = getParam1f("varianceThreshold", 0.f); maxDepthTexture = (Texture2D*)getParamObject("maxDepthTexture", nullptr); model = (Model*)getParamObject("model", getParamObject("world")); if (maxDepthTexture) { if (maxDepthTexture->type != OSP_TEXTURE_R32F || !(maxDepthTexture->flags & OSP_TEXTURE_FILTER_NEAREST)) { static WarnOnce warning("maxDepthTexture provided to the renderer " "needs to be of type OSP_TEXTURE_R32F and have " "the OSP_TEXTURE_FILTER_NEAREST flag"); } } vec3f bgColor3 = getParam3f("bgColor", vec3f(getParam1f("bgColor", 0.f))); bgColor = getParam4f("bgColor", vec4f(bgColor3, 0.f)); if (getIE()) { ManagedObject* camera = getParamObject("camera"); if (model) { const float diameter = model->bounds.empty() ? 1.0f : length(model->bounds.size()); epsilon *= diameter; } ispc::Renderer_set(getIE() , model ? model->getIE() : nullptr , camera ? camera->getIE() : nullptr , autoEpsilon , epsilon , spp , maxDepth , minContribution , (ispc::vec4f&)bgColor , maxDepthTexture ? maxDepthTexture->getIE() : nullptr ); } }
//! \brief commit the material's parameters virtual void commit() override { if (getIE() == nullptr) ispcEquivalent = ispc::PathTracer_Mix_create(); float factor = getParam1f("factor", 0.5f); Texture2D *map_factor = (Texture2D*)getParamObject("map_factor", nullptr); affine2f xform_factor = getTextureTransform("map_factor"); ospray::Material* mat1 = (ospray::Material*)getParamObject("material1", nullptr); ospray::Material* mat2 = (ospray::Material*)getParamObject("material2", nullptr); ispc::PathTracer_Mix_set(ispcEquivalent , factor , map_factor ? map_factor->getIE() : nullptr , (const ispc::AffineSpace2f&)xform_factor , mat1 ? mat1->getIE() : nullptr , mat2 ? mat2->getIE() : nullptr ); }
void Functions::speakOneLinerConversation(Aurora::NWScript::FunctionContext &ctx) { NWN::Object *object = NWN::ObjectContainer::toObject(ctx.getCaller()); if (!object) return; const Common::UString &dlg = ctx.getParams()[0].getString(); NWN::Object *tokenTarget = NWN::ObjectContainer::toObject(getParamObject(ctx, 1)); object->speakOneLiner(dlg, tokenTarget); }
void Functions::playVoiceChat(Aurora::NWScript::FunctionContext &ctx) { NWN2::Object *object = NWN2::ObjectContainer::toObject(getParamObject(ctx, 1)); if (!object) return; const Aurora::SSFFile *ssf = object->getSSF(); if (!ssf) return; object->playSound(ssf->getSoundFile(ctx.getParams()[0].getInt()), true); }
//! \brief commit the material's parameters virtual void commit() override { if (getIE() == nullptr) ispcEquivalent = ispc::PathTracer_OBJ_create(); Texture2D *map_d = (Texture2D*)getParamObject("map_d"); affine2f xform_d = getTextureTransform("map_d"); Texture2D *map_Kd = (Texture2D*)getParamObject("map_Kd", getParamObject("map_kd", getParamObject("colorMap"))); affine2f xform_Kd = getTextureTransform("map_Kd") * getTextureTransform("map_kd") * getTextureTransform("colorMap"); Texture2D *map_Ks = (Texture2D*)getParamObject("map_Ks", getParamObject("map_ks")); affine2f xform_Ks = getTextureTransform("map_Ks") * getTextureTransform("map_ks"); Texture2D *map_Ns = (Texture2D*)getParamObject("map_Ns", getParamObject("map_ns")); affine2f xform_Ns = getTextureTransform("map_Ns") * getTextureTransform("map_ns"); Texture2D *map_Bump = (Texture2D*)getParamObject("map_Bump", getParamObject("map_bump", getParamObject("normalMap", getParamObject("bumpMap")))); affine2f xform_Bump = getTextureTransform("map_Bump") * getTextureTransform("map_bump") * getTextureTransform("normalMap") * getTextureTransform("BumpMap"); linear2f rot_Bump = xform_Bump.l.orthogonal().transposed(); const float d = getParam1f("d", getParam1f("alpha", 1.f)); vec3f Kd = getParam3f("Kd", getParam3f("kd", getParam3f("color", vec3f(0.8f)))); vec3f Ks = getParam3f("Ks", getParam3f("ks", vec3f(0.f))); const float Ns = getParam1f("Ns", getParam1f("ns", 10.f)); vec3f Tf = getParam3f("Tf", getParam3f("tf", vec3f(0.0f))); const float color_total = reduce_max(Kd + Ks + Tf); if (color_total > 1.0) { postStatusMsg() << "#osp:PT: warning: OBJ material produces energy " << "(Kd + Ks + Tf = " << color_total << ", should be <= 1). Scaling down to 1."; Kd /= color_total; Ks /= color_total; Tf /= color_total; } ispc::PathTracer_OBJ_set(ispcEquivalent, map_d ? map_d->getIE() : nullptr, (const ispc::AffineSpace2f&)xform_d, d, map_Kd ? map_Kd->getIE() : nullptr, (const ispc::AffineSpace2f&)xform_Kd, (const ispc::vec3f&)Kd, map_Ks ? map_Ks->getIE() : nullptr, (const ispc::AffineSpace2f&)xform_Ks, (const ispc::vec3f&)Ks, map_Ns ? map_Ns->getIE() : nullptr, (const ispc::AffineSpace2f&)xform_Ns, Ns, (const ispc::vec3f&)Tf, map_Bump ? map_Bump->getIE() : nullptr, (const ispc::AffineSpace2f&)xform_Bump, (const ispc::LinearSpace2f&)rot_Bump); }
void Functions::createItemOnObject(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 1)); if (item && item->getHasInventory()) { const Common::UString &blueprint = ctx.getParams()[0].getString(); if (blueprint.empty()) return; int stackSize = ctx.getParams()[2].getInt(); const Common::UString &tag = ctx.getParams()[3].getString(); ctx.getReturn() = item->createItemOnObject(blueprint, stackSize, tag); } }
void Functions::getNextItemProperty(Aurora::NWScript::FunctionContext &ctx) { Item *item = NWN2::ObjectContainer::toItem(getParamObject(ctx, 0)); if (!item) return; ItemProperty *nextIP = item->getNextItemProperty(); if (!nextIP) return; ItemProperty iprop(*nextIP); ctx.getReturn() = iprop; }
void Slices::finalize(Model *model) { planesData = getParamData("planes", NULL); volume = (Volume *)getParamObject("volume", NULL); Assert(planesData); Assert(volume); numPlanes = planesData->numItems; planes = (const vec4f*)planesData->data; ispc::Slices_set(getIE(), model->getIE(), numPlanes, (ispc::vec4f*)planes, volume->getIE()); }
void Functions::actionMoveToObject(Aurora::NWScript::FunctionContext &ctx) { NWN::Object *object = NWN::ObjectContainer::toObject(ctx.getCaller()); NWN::Object *moveTo = NWN::ObjectContainer::toObject(getParamObject(ctx, 0)); if (!object || !moveTo) return; float x, y, z; moveTo->getPosition(x, y, z); jumpTo(object, moveTo->getArea(), x, y, z); unimplementedFunction(ctx); }
void Functions::actionJumpToObject(Aurora::NWScript::FunctionContext &ctx) { // TODO: walkStraightLineToPoint // bool walkStraightLineToPoint = ctx.getParams()[1].getInt() != 0; Jade::Object *object = Jade::ObjectContainer::toObject(ctx.getCaller()); Jade::Object *moveTo = Jade::ObjectContainer::toObject(getParamObject(ctx, 0)); if (!object || !moveTo) return; float x, y, z; moveTo->getPosition(x, y, z); jumpTo(object, moveTo->getArea(), x, y, z); }
void BlockBrickedVolume::updateEditableParameters() { //! Get the transfer function. transferFunction = (TransferFunction *) getParamObject("transferFunction", NULL); exitOnCondition(transferFunction == NULL, "no transfer function specified"); //! Get the gamma correction coefficient and exponent. vec2f gammaCorrection = getParam2f("gammaCorrection", vec2f(1.0f)); //! Set the gamma correction coefficient and exponent. ispc::BlockBrickedVolume_setGammaCorrection(ispcEquivalent, (const ispc::vec2f &) gammaCorrection); //! Set the recommended sampling rate for ray casting based renderers. ispc::BlockBrickedVolume_setSamplingRate(ispcEquivalent, getParam1f("samplingRate", 1.0f)); //! Set the transfer function. ispc::BlockBrickedVolume_setTransferFunction(ispcEquivalent, transferFunction->getEquivalentISPC()); }
void Functions::actionMoveToObject(Aurora::NWScript::FunctionContext &ctx) { // TODO: runType and range // int32 runType = ctx.getParams()[1].getInt(); // int32 range = ctx.getParams()[2].getInt(); // int32 moveAnim = ctx.getParams()[3].getInt(); Jade::Object *object = Jade::ObjectContainer::toObject(ctx.getCaller()); Jade::Object *moveTo = Jade::ObjectContainer::toObject(getParamObject(ctx, 0)); if (!object || !moveTo) return; float x, y, z; moveTo->getPosition(x, y, z); jumpTo(object, moveTo->getArea(), x, y, z); unimplementedFunction(ctx); }
void Functions::beginConversation(Aurora::NWScript::FunctionContext &ctx) { ctx.getReturn() = 0; // Get the script object parameters Aurora::NWScript::Object *obj1 = ctx.getCaller(); Aurora::NWScript::Object *obj2 = getParamObject(ctx, 1); if (!obj2) obj2 = ctx.getTriggerer(); if (!obj2) obj2 = _game->getModule().getPC(); // Try to convert them to an NWN Creature and Object NWN::Creature *pc = NWN::ObjectContainer::toPC(obj2); NWN::Object *object = NWN::ObjectContainer::toObject(obj1); // Try the other way round, if necessary if (!pc || !object) { pc = NWN::ObjectContainer::toPC(obj1); object = NWN::ObjectContainer::toObject(obj2); } // Fail if (!pc || !object) return; if (object->getPCSpeaker()) { if (object->getPCSpeaker() != pc) { Creature *otherPC = NWN::ObjectContainer::toPC(object->getPCSpeaker()); warning("Functions::beginConversation(): " "Object \"%s\" already in conversation with PC \"%s\"", object->getTag().c_str(), otherPC ? otherPC->getName().c_str() : ""); return; } } Common::UString conversation = ctx.getParams()[0].getString(); if (conversation.empty()) conversation = object->getConversation(); ctx.getReturn() = _game->getModule().startConversation(conversation, *pc, *object); }