Bool ApplinkImporter::CreateChannelDisplacement(long i, BaseMaterial* mat) { if(this->matArray[i].disp_map != "") { BaseChannel *color = mat->GetChannel(CHANNEL_DISPLACEMENT); if (!color) return false; GeData b; mat->GetParameter(DescID(MATERIAL_USE_DISPLACEMENT), b, DESCFLAGS_GET_0); if(!b.GetBool()) mat->SetParameter(DescID(MATERIAL_USE_DISPLACEMENT), true, DESCFLAGS_SET_0); BaseContainer cdata = color->GetData(); //GePrint("disp: " + RealToString(this->matArray[i].disp_k)); mat->SetParameter(DescID(MATERIAL_DISPLACEMENT_STRENGTH), this->matArray[i].disp_k/100, DESCFLAGS_SET_0); if (this->matArray[i].useTextures) { //GePrint ("Material Use texture: " + this->matArray[i].map_Kd); cdata.SetString(BASECHANNEL_TEXTURE, this->matArray[i].disp_map); cdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, this->pSet.tempPath); } color->SetData(cdata); } return true; }
Bool ApplinkImporter::CreateChannelNormal(long i, BaseMaterial* mat) { if(this->matArray[i].norm_map != "") { BaseChannel *color = mat->GetChannel(CHANNEL_NORMAL); if (!color) return false; GeData b; mat->GetParameter(DescID(MATERIAL_USE_NORMAL), b, DESCFLAGS_GET_0); if(!b.GetBool()) mat->SetParameter(DescID(MATERIAL_USE_NORMAL), true, DESCFLAGS_SET_0); mat->SetParameter(DescID(MATERIAL_NORMAL_REVERSEY), true, DESCFLAGS_SET_0); BaseContainer cdata = color->GetData(); if (this->matArray[i].useTextures) { //GePrint ("Material Use texture: " + this->matArray[i].map_Kd); cdata.SetString(BASECHANNEL_TEXTURE, this->matArray[i].norm_map); cdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, this->pSet.tempPath); } color->SetData(cdata); } return true; }
Bool ApplinkImporter::CreateChannelSpecular(long i, BaseMaterial* mat) { if(this->matArray[i].map_Ks != "") { BaseChannel *color = mat->GetChannel(CHANNEL_SPECULARCOLOR); if (!color) return false; GeData b; mat->GetParameter(DescID(MATERIAL_USE_SPECULARCOLOR), b, DESCFLAGS_GET_0); if(!b.GetBool()) mat->SetParameter(DescID(MATERIAL_USE_SPECULARCOLOR), true, DESCFLAGS_SET_0); BaseContainer cdata = color->GetData(); cdata.SetVector(BASECHANNEL_COLOR_EX, this->matArray[i].Ks); cdata.SetData(BAKE_TEX_NORMAL_FLIP_Y, GeData(true)); if (this->matArray[i].useTextures) { //GePrint ("Material Use texture: " + this->matArray[i].map_Kd); cdata.SetString(BASECHANNEL_TEXTURE, this->matArray[i].map_Ks); cdata.SetFilename(BASECHANNEL_SUGGESTEDFOLDER, this->pSet.tempPath); } color->SetData(cdata); } return true; }
Filename ApplinkExporter::getParameterFilename(C4DAtom& atom, LONG paramID) { GeData parameter; if (atom.GetParameter(DescLevel(paramID), parameter, DESCFLAGS_GET_0)) { return parameter.GetFilename(); } return NULL; }
Real ApplinkExporter::getParameterReal(C4DAtom& atom, LONG paramID, Real preset) { GeData parameter; if (atom.GetParameter(DescLevel(paramID), parameter, DESCFLAGS_GET_0) && (parameter.GetType() != DA_NIL)) { return parameter.GetReal(); } return preset; }
LONG ApplinkExporter::getParameterLong(BaseMaterial& mat, LONG paramID) { GeData parameter; if (mat.GetParameter(DescLevel(paramID), parameter, DESCFLAGS_GET_0)) { return parameter.GetLong(); } return 0; }
String ApplinkExporter::getParameterString(BaseTag& tag, LONG paramID) { GeData parameter; if (tag.GetParameter(DescLevel(paramID), parameter, DESCFLAGS_GET_0)) { return parameter.GetString(); } return ""; }
Bool CSVNodeData::GetDEnabling(GeListNode* node, const DescID& id, const GeData& t_data, DESCFLAGS_ENABLE flags, const BaseContainer* itemdesc) { if (id == CSVNODE_FORCEOUTPORTS_COUNT) { GeData data; if (node->GetParameter(CSVNODE_FORCEOUTPORTS, data, DESCFLAGS_GET_0)) { return data.GetBool(); } } return super::GetDEnabling(node, id, t_data, flags, itemdesc); }
static LONG _hook_GetInfo(GeListNode* op) { if (op && op->GetType() == Ocontainer) { GeData data; op->GetParameter(NRCONTAINER_GENERATOR_CHECKMARK, data, DESCFLAGS_GET_0); if (data.GetBool()) return OBJECT_GENERATOR; else return 0; } return _orig_GetInfo(op); }
BaseList2D* ApplinkExporter::getParameterLink(GeListNode& node, LONG paramID, LONG instanceOf) { GeData parameter; if (node.GetParameter(DescLevel(paramID), parameter, DESCFLAGS_GET_0)) { BaseLink* link = parameter.GetBaseLink(); if (link) { return link->GetLink(node.GetDocument(), instanceOf); } } return 0; }
// ------------------------------------------------------------------------------------------------ void C4DImporter::ReadMaterials(_melange_::BaseMaterial* mat) { // based on Melange sample code while (mat) { const String& name = mat->GetName(); if (mat->GetType() == Mmaterial) { aiMaterial* out = new aiMaterial(); material_mapping[mat] = static_cast<unsigned int>(materials.size()); materials.push_back(out); aiString ai_name; name.GetCString(ai_name.data, MAXLEN-1); ai_name.length = ::strlen(ai_name.data); out->AddProperty(&ai_name, AI_MATKEY_NAME); Material& m = dynamic_cast<Material&>(*mat); if (m.GetChannelState(CHANNEL_COLOR)) { GeData data; mat->GetParameter(MATERIAL_COLOR_COLOR, data); Vector color = data.GetVector(); mat->GetParameter(MATERIAL_COLOR_BRIGHTNESS, data); const Real brightness = data.GetReal(); color *= brightness; aiVector3D v; v.x = color.x; v.y = color.y; v.z = color.z; out->AddProperty(&v, 1, AI_MATKEY_COLOR_DIFFUSE); } BaseShader* const shader = m.GetShader(MATERIAL_COLOR_SHADER); if(shader) { ReadShader(out, shader); } } else { LogWarn("ignoring plugin material: " + std::string(GetObjectTypeName(mat->GetType()))); } mat = mat->GetNext(); } }
Bool BlinkerTrack::Animate(CTrack *track, const CAnimInfo *info, Bool *chg, void *data) { if ((!info->k1 && !info->k2) || !info->op->IsInstanceOf(Obase)) return TRUE; GeData res; BaseTime t; Real p1=0.0,p2=0.0,number=0.0; if (info->k1 && info->k1->GetParameter(DescLevel(BLINKERKEY_NUMBER),res,DESCFLAGS_GET_0)) p1=res.GetReal(); if (info->k2 && info->k2->GetParameter(DescLevel(BLINKERKEY_NUMBER),res,DESCFLAGS_GET_0)) p2=res.GetReal(); if (info->k1 && info->k2) number = p1*(1.0-info->rel)+p2*info->rel; else if (info->k1) number = p1; else if (info->k2) number = p2; LONG mode; Real v=Sin(number*info->fac*pi2); if (v>=0.0) mode=MODE_ON; else mode=MODE_OFF; ((BaseObject*)info->op)->SetEditorMode(mode); return TRUE; }
/// *************************************************************************** /// This function hides or unhides all materials used by the object *op*. /// If *doc* is not \c nullptr, undos will be added. /// *************************************************************************** static void HideMaterials(BaseObject* op, Bool hide, BaseDocument* doc) { BaseTag* tag = op->GetFirstTag(); GeData data; while (tag) { if (tag->GetType() == Ttexture && tag->GetParameter(TEXTURETAG_MATERIAL, data, DESCFLAGS_GET_0)) { BaseMaterial* mat = static_cast<BaseMaterial*>(data.GetLink(doc, Mbase)); if (mat) HideHierarchy(mat, hide, doc, false); } tag = tag->GetNext(); } BaseObject* child = op->GetDown(); while (child) { HideMaterials(child, hide, doc); child = child->GetNext(); } }
virtual Bool GetDParameter(GeListNode* node, const DescID& id, GeData& data, DESCFLAGS_GET& flags) override { switch (id[0].id) { case NRCONTAINER_DEV_INFO: data.SetString(""); flags |= DESCFLAGS_GET_PARAM_GET; return true; } return super::GetDParameter(node, id, data, flags); }
// ------------------------------------------------------------------------------------------------ bool C4DImporter::ReadShader(aiMaterial* out, _melange_::BaseShader* shader) { // based on Melange sample code (C4DImportExport.cpp) while(shader) { if(shader->GetType() == Xlayer) { BaseContainer* container = shader->GetDataInstance(); GeData blend = container->GetData(SLA_LAYER_BLEND); iBlendDataType* blend_list = reinterpret_cast<iBlendDataType*>(blend.GetCustomDataType(CUSTOMDATA_BLEND_LIST)); if (!blend_list) { LogWarn("ignoring XLayer shader: no blend list given"); continue; } LayerShaderLayer *lsl = dynamic_cast<LayerShaderLayer*>(blend_list->m_BlendLayers.GetObject(0)); // Ignore the actual layer blending - models for real-time rendering should not // use them in a non-trivial way. Just try to find textures that we can apply // to the model. while (lsl) { if (lsl->GetType() == TypeFolder) { BlendFolder* const folder = dynamic_cast<BlendFolder*>(lsl); LayerShaderLayer *subLsl = dynamic_cast<LayerShaderLayer*>(folder->m_Children.GetObject(0)); while (subLsl) { if (subLsl->GetType() == TypeShader) { BlendShader* const shader = dynamic_cast<BlendShader*>(subLsl); if(ReadShader(out, static_cast<BaseShader*>(shader->m_pLink->GetLink()))) { return true; } } subLsl = subLsl->GetNext(); } } else if (lsl->GetType() == TypeShader) { BlendShader* const shader = dynamic_cast<BlendShader*>(lsl); if(ReadShader(out, static_cast<BaseShader*>(shader->m_pLink->GetLink()))) { return true; } } lsl = lsl->GetNext(); } } else if ( shader->GetType() == Xbitmap ) { aiString path; shader->GetFileName().GetString().GetCString(path.data, MAXLEN-1); path.length = ::strlen(path.data); out->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0)); return true; } else { LogWarn("ignoring shader type: " + std::string(GetObjectTypeName(shader->GetType()))); } shader = shader->GetNext(); } return false; }