/*********************************************************************\
	Function name    : CDialogCustomElement::CreateElementBegin
	Description      :
	Created at       : 27.03.02, @ 11:22:38
	Created by       : Thomas Kunert
	Modified by      :
\*********************************************************************/
void CDialogCustomElement::CreateElementBegin(Int32 lID, GeDialog *pDlg)
{
    if (!m_pbcGUI) return;

    if (g_pCustomElements && m_lElement >= 0 && m_lElement < g_pCustomElements->Entries())
    {
        CCustomElements* pElement = g_pCustomElements->GetItem(m_lElement);

        if (pElement)
        {
            BaseContainer bc = m_pbcGUI[m_lElement];
            for (Int32 i = 0; pElement->m_pProp && pElement->m_pProp[i].type != CUSTOMTYPE_END; i++)
            {
                if (pElement->m_pProp[i].type == CUSTOMTYPE_STRING)
                {
                    String str = m_pbcGUI[m_lElement].GetString(pElement->m_pProp[i].id);
                    if (str.Content())
                    {
                        Bool b;
                        String str1 = m_pDocument->GetString(str, b);
                        if (!b) str1 = "[" + str + "]";
                        bc.SetString(pElement->m_pProp[i].id, str1);
                    }
                }
            }
            pDlg->AddCustomGui(lID, pElement->m_lID, m_strName, m_lFlags, CONVERT_WIDTH(m_lInitW), CONVERT_HEIGHT(m_lInitH), bc);
            //BaseCustomGuiLib* pGUI = (BaseCustomGuiLib*)pDlg->FindCustomGui(lID, pElement->m_lID);
            //if (pGUI) pGUI->SetDefaultForResEdit();
        }
    }
}
示例#2
0
//----------------------------------------------------------------------------------------
// Register filter
// Function result:		true/false
//----------------------------------------------------------------------------------------
Bool RegisterSampleMatrix(void)
{
	String name = GeLoadString(IDS_MATRIX);
	if (!name.Content())
		return true;

	// be sure to use a unique ID obtained from www.plugincafe.com
	return GeRegisterPlugin(PLUGINTYPE_BITMAPFILTER, 1000690, name, &smpl_matrix_filter, sizeof(smpl_matrix_filter));
}
Bool RegisterPaintBrushSculpt()
{
	SculptBrushParams *pParams = SculptBrushParams::Alloc();
	if (!pParams) return false;

	pParams->EnableInvertCheckbox(true);
	pParams->EnableBrushAccess(true);
	pParams->SetUndoType(SCULPTBRUSHDATATYPE_POINT);
	pParams->SetMovePointFunc(&SculptMovePointsFunc);

	String name = GeLoadString(IDS_PAINT_BRUSH_SCULPT); if (!name.Content()) return true;
	return RegisterToolPlugin(ID_PAINT_BRUSH_SCULPT, name, PLUGINFLAG_TOOL_SCULPTBRUSH|PLUGINFLAG_TOOL_NO_OBJECTOUTLINE, nullptr, GeLoadString(IDS_PAINT_BRUSH_SCULPT_HELP), NewObjClear(PaintBrushSculpt, pParams));
}
示例#4
0
/// ***************************************************************************
/// ***************************************************************************
Bool ContainerProtect(BaseObject* op, String const& pass, String hash, Bool packup)
{
  if (!op || op->GetType() != Ocontainer) return false;
  ContainerObject* data = GetNodeData<ContainerObject>(op);
  if (!data) return false;
  if (data->m_protected)
    return false;
  if (!hash.Content())
    hash = HashString(pass);
  data->m_protected = true;
  data->m_protectionHash = hash;
  if (packup)
    data->HideNodes(op, nullptr, packup);
  return true;
}
示例#5
0
  void UpdateGadgets(Bool relevants=false)
  {
    Int32 mode;
    Bool add_dynamics;
    GetBool(CHK_ADDDYNAMICS, add_dynamics);
    GetInt32(CMB_MODE, mode);

    BaseDocument* doc = GetActiveDocument();
    BaseObject* op = doc ? doc->GetActiveObject() : nullptr;

    Enable(EDT_MAXCONN, mode != CMB_MODE_CHAIN);
    Enable(EDT_RADIUS, mode != CMB_MODE_CHAIN);
    Enable(CHK_CLOSED, mode == CMB_MODE_CHAIN);
    Enable(CHK_COMPOUND, add_dynamics);

    // Need at least two child objects on the active object.
    Bool execEnabled = op != nullptr && op->GetDown() != nullptr
        && op->GetDown()->GetNext() != nullptr;
    Enable(BTN_EXECUTE, execEnabled);

    if (relevants)
    {
      FreeChildren(CMB_TYPE);

      Int32 pluginid;
      GetInt32(CMB_FORCE, pluginid);

      do {
        BaseObject* op = BaseObject::Alloc(pluginid);
        if (!op) break;
        AutoFree<BaseObject> free(op);

        AutoAlloc<Description> desc;
        if (!op->GetDescription(desc, DESCFLAGS_DESC_0)) break;

        BaseContainer temp;
        AutoAlloc<AtomArray> arr;
        const BaseContainer* param = desc->GetParameter(FORCE_TYPE, temp, arr);
        if (!param) break;

        const BaseContainer* cycle = param->GetContainerInstance(DESC_CYCLE);
        if (!cycle) break;

        const BaseContainer* icons = param->GetContainerInstance(DESC_CYCLEICONS);

        Int32 i = 0;
        Int32 last_id = -1;
        while (true) {
          Int32 id = cycle->GetIndexId(i++);
          if (id == NOTOK) break;

          Int32 icon = icons ? icons->GetInt32(id) : -1;

          String name = cycle->GetString(id);
          if (name.Content()) {
            if (icon > 0) name += "&i" + String::IntToString(icon);
            if (last_id < 0) last_id = id;
            AddChild(CMB_TYPE, id, name);
          }
        }

        SetInt32(CMB_TYPE, last_id);
      } while (0);

      LayoutChanged(CMB_TYPE);
    }
  }
示例#6
0
Bool ConnectObjects(
    String prefix, const maxon::BaseArray<BaseObject*>& objects,
    ConnectOptions& options)
{

  // Check if the object can successfully be allocatd for the
  // specified plugin id.
  BaseObject* test = BaseObject::Alloc(options.forcePluginId);
  if (!test)
  {
    GeDebugOut("Can not allocate plugin object " + String::IntToString(options.forcePluginId));
    return false;
  }

  // Get the name of the object so we can use it later.
  options.forceName = test->GetName();
  BaseObject::Free(test);
  if (!prefix.Content())
    prefix = options.forceName + ": ";

  // Final result of the function.
  Bool success = true;

  // Create the ConnectionList for the objects.
  ConnectionList list;
  switch (options.connectMode)
  {
    case CMB_MODE_ALL:
    {
      const auto end = objects.End();
      for (auto it=objects.Begin(); it != end; ++it)
      {
        for (auto jt=objects.Begin(); jt != end; ++jt)
        {
          if (*it == *jt) continue;
          if (list.HasConnection(*it, *jt)) continue;
          list.Append(Connection(*it, *jt));
        }
      }
      break;
    }
    case CMB_MODE_NEIGHBOR:
    {
      const auto end = objects.End();
      for (auto it=objects.Begin(); it != end; ++it)
      {

        // Find the nearest object.
        BaseObject* nearest = nullptr;
        Float delta;
        for (auto jt=objects.Begin(); jt != end; ++jt)
        {
          if (*it == *jt) continue;
          if (list.HasConnection(*it, *jt)) continue;

          Connection conn(*it, *jt);
          if (!nearest || conn.delta < delta)
          {
            nearest = *jt;
            delta = conn.delta;
          }
        }

        if (nearest)
          list.Append(Connection(*it, nearest));
      }
      break;
    }
    case CMB_MODE_CHAIN:
    {
      options.radius = 0;
      options.maxConnections = 0;
      const auto first = objects.Begin();
      for (auto it=objects.Begin(); it != objects.End(); ++it)
      {
        Bool isLast = (it + 1) == objects.End();
        if (isLast && (options.closedChain && *it != *first))
        {
          Connection conn(*it, *first);
          list.Append(conn);
        }
        else if (!isLast)
        {
          Connection conn(*it, *(it + 1));
          list.Append(conn);
        }
      }
      break;
    }
    default:
      GeDebugOut(String(__FUNCTION__) + ": Invalid connectMode");
      return false;
  }

  // Sort the list by distance.
  list.SortByDelta();

  // This map contains the number of connections each
  // object already has to make sure no object exceeds the
  // maximum number if connections.
  maxon::Bool created = false;
  maxon::HashMap<C4DAtom*, Int32> map;

  // Iterate over all connections and establish them.
  const auto end = list.End();
  for (auto it=list.Begin(); it != end; ++it)
  {
    if (options.radius > 0.000001 && it->delta > options.radius)
      continue;

    // Find and eventually initialize the entries in the map.
    auto entry1 = map.FindOrCreateEntry(it->obj1, created);
    if (created) entry1->GetValue() = 0;
    auto entry2 = map.FindOrCreateEntry(it->obj2, created);
    if (created) entry2->GetValue() = 0;

    // Determine if the maximum number of connections is reached.
    const Int32 nConn1 = entry1->GetValue();
    const Int32 nConn2 = entry2->GetValue();
    if (options.maxConnections > 0 &&
        (nConn1 >= options.maxConnections || nConn2 >= options.maxConnections))
      continue;

    // Create the force object.
    BaseObject* force = BaseObject::Alloc(options.forcePluginId);
    if (!force)
    {
      success = false;
      break;
    }

    // Update the parameters.
    force->SetParameter(FORCE_TYPE, options.forceType, DESCFLAGS_SET_0);
    force->SetParameter(FORCE_OBJECT_A, it->obj1, DESCFLAGS_SET_0);
    force->SetParameter(FORCE_OBJECT_B, it->obj2, DESCFLAGS_SET_0);
    force->SetBit(BIT_ACTIVE);
    force->SetName(prefix + it->obj1->GetName() + " - " + it->obj2->GetName());
    ++entry1->GetValue();
    ++entry2->GetValue();

    options.output.Append(force);

    // Position the force object in between the two objects.
    Matrix mg;
    mg.off = (it->obj1->GetMg().off + it->obj2->GetMg().off) * 0.5;
    force->SetMl(mg);
  }

  return true;
}
示例#7
0
Bool ApplinkExporter::Execute(BaseDocument* document, BaseContainer* bc)
{
	matDefault = BaseMaterial::Alloc(Mmaterial);
	if(!matDefault) return false;

	Filename fileObjPath;
	fileObjPath.SetDirectory(bc->GetString(IDC_TMP_FOLDER));
	fileObjPath.SetFile(document->GetDocumentName());
	fileObjPath.SetSuffix("obj");
	Filename fileObjOutPath;
	fileObjOutPath.SetDirectory(bc->GetString(IDC_TMP_FOLDER));
	fileObjOutPath.SetFile("output.obj");
	Filename fileImport;
	fileImport.SetDirectory(bc->GetString(IDC_EXCH_FOLDER));
	fileImport.SetFile("import.txt");

	GePrint(fileObjPath.GetString());
	GePrint(fileObjOutPath.GetString());
	GePrint(fileImport.GetString());

	const Matrix tM(LVector(0.0f, 0.0f, 0.0f), LVector(1.0f, 0.0f, 0.0f), LVector(0.0f, 1.0f, 0.0f), LVector(0.0f, 0.0f, -1.0f));

	//BaseDocument* doc = document->Polygonize();
	AutoAlloc<AtomArray> oSel;
	document->GetActiveObjects(oSel, GETACTIVEOBJECTFLAGS_0);

	if(oSel->GetCount() > 0)
	{
//Write import.txt//
		AutoAlloc<BaseFile> basefileImport;
		
		if (!basefileImport->Open(fileImport, FILEOPEN_WRITE, FILEDIALOG_NONE, GeGetByteOrder())) return FALSE;
		
		this->WriteString(fileObjPath.GetString() + "\n", basefileImport);
		this->WriteString(fileObjOutPath.GetString() + "\n", basefileImport);
		this->WriteString(mapType(bc->GetLong(IDC_COMBO_MAP_TYPE)) + "\n", basefileImport);

		Bool bSkipImp = bc->GetBool(IDC_CHK_SKIP_IMP_DIALOG);

		if(bSkipImp)
		{
			this->WriteString("[SkipImport]\n", basefileImport);
		}

		Bool bSkipExp = bc->GetBool(IDC_CHK_SKIP_EXP_DIALOG);

		if(bSkipExp)
		{
			this->WriteString("[SkipExport]\n", basefileImport);
		}

		GePrint(mapType(bc->GetLong(IDC_COMBO_MAP_TYPE)));
		basefileImport->Close();

		GePrint("File " + fileImport.GetString() + " write success!");

//Write file.obj//
		AutoAlloc<BaseFile> objfile;

		//if (!objfile) return FALSE;
		if (!objfile->Open(fileObjPath, FILEOPEN_WRITE, FILEDIALOG_NONE, GeGetByteOrder())) return FALSE;

		String str;
		str = "#Wavefront OBJ Export for 3D-Coat\n";
		this->WriteString(str, objfile);
		DateTime t;
		GetDateTimeNow(t);
		str = "#File created: " + FormatTime("%d.%m.%Y  %H:%M:%S", t) + "\n";
		this->WriteString(str, objfile);
		str = "#Cinema4D Version: " + LongToString(GetC4DVersion()) + "\n";
		this->WriteString(str, objfile);
		this->WriteEndLine(objfile);

		Bool expMat = bc->GetBool(IDC_CHK_EXP_MAT);
		vpcnt = vtcnt = 0;

		for(int i = 0; i < oSel->GetCount(); i++)
		{
			StatusSetSpin();
			PolygonObject* ob = (PolygonObject*) oSel->GetIndex(i);
			if (ob->GetType() == Opolygon)
			{
				StatusSetText("Export object " + ob->GetName());
				ExportObject mObject;

				GePrint("Name " + ob->GetName());
				//GePrint("Type " + LongToString(ob->GetType()));

				if(expMat)
				{
					mObject.pmatidxArray.ReSize(ob->GetPolygonCount());
					mObject.tempMats.ReSize(1);
					mObject.pmatidxArray.Fill(0);
					Bool haveMats = false;
	//////////////////////////////////////////
					for(BaseTag* tag = ob->GetFirstTag(); tag != NULL; tag = tag->GetNext())
					{
						LONG typ = tag->GetType();
						if(typ == Ttexture)
						{
							if (!getParameterLink(*tag, TEXTURETAG_MATERIAL, Mbase)) continue;
						
							haveMats = true;
							TextureTag* txttag = (TextureTag*)tag;
							BaseMaterial* material = txttag->GetMaterial();

							if(material == NULL)
							{
								GePrint("Material not found on " + ob->GetName() + "object.");
								return false;
							}
							//GePrint("Mat Name: " + material->GetName());						

							String restrict = getParameterString(*tag, TEXTURETAG_RESTRICTION);
							if (restrict.Content())
							{
								mObject.tempMats.Push(material);
								//GePrint("Selection: " + restrict);
								for(BaseTag* seltag = ob->GetFirstTag(); seltag != NULL; seltag = seltag->GetNext())
								{
									LONG seltyp = seltag->GetType();
									if(seltyp == Tpolygonselection && seltag->GetName() == restrict)
									{
										SelectionTag* selecttag = (SelectionTag*)seltag;
										BaseSelect* sel = selecttag->GetBaseSelect();
										//GePrint("sel data count: " + LongToString(sel->GetCount()));

										LONG seg = 0, a, b, p;
										while (sel->GetRange(seg++, &a, &b))
										{
											for (p = a; p <= b; ++p)
											{
												//GePrint("seltpolygon: " + LongToString(p));
												mObject.pmatidxArray[p] = mObject.tempMats.GetCount()-1;
											}
										}
									}
								}
							}
							else
							{
								mObject.tempMats[0] = material;
								mObject.pmatidxArray.Fill(0);
							}
						}
					}

					if(!mObject.tempMats[0])
					{
						matDefault->SetName("Default");

						BaseChannel* color = matDefault->GetChannel(CHANNEL_COLOR);
						if (!color) return false;	// return some error
						BaseContainer cdata = color->GetData();
						cdata.SetVector(BASECHANNEL_COLOR_EX, Vector(1.0f, 1.0f, 1.0f));
						
						//document->InsertMaterial(matDefault, NULL, FALSE);
						//matDefault->Update(TRUE, TRUE);
						//matDefault->Message(MSG_UPDATE);

						mObject.tempMats[0] = matDefault;
						//GePrint("Global material not found on object " + ob->GetName() + ".");
						//return false;
					}

					if(haveMats)
					{
						//GePrint("mObject.tempMats.GetCount(): " + LongToString(mObject.tempMats.GetCount()));
						for(LONG m = 0; m < mObject.tempMats.GetCount(); m++)
						{
							Bool inMats = false;
							//GePrint("materialArray.GetCount(): " + LongToString(materialArray.GetCount()));
							for(LONG n = 0; n < materialArray.GetCount(); n++)
							{
								if(mObject.tempMats[m]->GetName() == materialArray[n]->GetName())
								{
									inMats = true;
									break;
								}
							}
							if(!inMats)
							{
								materialArray.Push(mObject.tempMats[m]);
							}
						}
					}

					//String str1;
					//for (LONG p = 0; p < ob->GetPolygonCount(); p++)
					//{
					//	str1 += LongToString(mObject.pmatidxArray[p]) + ",";
					//}
					//GePrint(str1);
				}
/////////////////////////////////////////////////
				const Vector* vadr = ob->GetPointR();
				const CPolygon* padr = ob->GetPolygonR();
				LONG vcnt = ob->GetPointCount();
				LONG pcnt = ob->GetPolygonCount();

				mObject.Fpvnb.ReSize(pcnt);// poly counts
				for(LONG p = 0; p < pcnt; p++)
				{
					if(padr[p].c != padr[p].d)
					{
						mObject.Fpvnb[p] = 4;
					}
					else
					{
						mObject.Fpvnb[p] = 3;
					}
				}
				mObject.pVertexCount = PVertexLength(mObject);

				//Vertex positions
				mObject.Vp.ReSize(vcnt);
				Matrix mg = tM * ob->GetMgn();
				for (LONG v = 0; v < vcnt; v++)
				{
					mObject.Vp[v] = vadr[v] * mg;
					//GePrint("Point[" + LongToString(i) + "] " + LongToString(padr[i].x) + ", " + LongToString(padr[i].y) + ", " + LongToString(padr[i].z));
					//str = "v " + LongToString(vadr[p].x) + " " + LongToString(vadr[p].y) + " " + LongToString(vadr[p].z) + "\n";
					//this->WriteString(str, objfile);
				}
				
				mObject.Fv.ReSize(mObject.pVertexCount);
				LONG y=0;
				for (LONG p = 0; p < pcnt; p++)
				{
					if(mObject.Fpvnb[p] == 4)
					{
						mObject.Fv[y] = padr[p].d;
						mObject.Fv[y+1] = padr[p].c;
						mObject.Fv[y+2] = padr[p].b;
						mObject.Fv[y+3] = padr[p].a;
					}
					else
					{
						mObject.Fv[y] = padr[p].c;
						mObject.Fv[y+1] = padr[p].b;
						mObject.Fv[y+2] = padr[p].a;
					}

					y += mObject.Fpvnb[p];
				}
				
				//String str1;
				//for (LONG p = 0; p < mObject.Fv.GetCount(); p++)
				//{
				//	str1 += LongToString(mObject.Fv[p]) + " ";
				//}
				//GePrint(str1);
///////////////////////////////
///////////vertex UV
//////////////////////////////
				if(bc->GetBool(IDC_CHK_EXP_UV))
				{
					// Get first UV tag (if at least one)
					UVWTag* uvw_tag = (UVWTag*)ob->GetTag(Tuvw, 0);
					if(!uvw_tag)
					{
						GePrint("Object \"" + ob->GetName() + "\" has no UVW tag.\nUV coordinates can't be exported.");
						return FALSE;
					}
					else
					{
						mObject.Vt.ReSize(mObject.pVertexCount);
						mObject.Fvt.ReSize(mObject.pVertexCount);						
						const UVWHandle dataptr = uvw_tag->GetDataAddressR();
						UVWStruct res;
						
						for(LONG t=0, y=0; t < pcnt; t++)
						{
							//GePrint("y: " + LongToString(y));
							UVWTag::Get(dataptr, t, res);
							if(mObject.Fpvnb[t] == 4)
							{
								mObject.Vt[y] = res.d;
								mObject.Vt[y + 1] = res.c;
								mObject.Vt[y + 2] = res.b;
								mObject.Vt[y + 3] = res.a;
							
								mObject.Fvt[y] = y;
								mObject.Fvt[y + 1] = y + 1;
								mObject.Fvt[y + 2] = y + 2;
								mObject.Fvt[y + 3] = y + 3;

							}
							else
							{
								mObject.Vt[y] = res.c;
								mObject.Vt[y + 1] = res.b;
								mObject.Vt[y + 2] = res.a;

								mObject.Fvt[y] = y;
								mObject.Fvt[y + 1] = y + 1;
								mObject.Fvt[y + 2] = y + 2;

							}
							y += mObject.Fpvnb[t];
						}
					}
					//String str1;
					//for (LONG p = 0; p < mObject.Fvt.GetCount(); p++)
					//{
					//	str1 += LongToString(mObject.Fvt[p]) + " ";
					//}
					//GePrint(str1);

				}

				WriteExportFile(bc, ob, objfile, mObject, vcnt, pcnt);
				//GePrint("Fvt: " + LongToString(Fvt.GetCount()));
				vpcnt += mObject.Vp.GetCount();
				if(bc->GetBool(IDC_CHK_EXP_UV))
					vtcnt += mObject.Vt.GetCount();
			}
		}
		objfile->Close();

		if(expMat && materialArray.GetCount() > 0)
			WriteMatsFile(document, bc);
	}
	else
	{
		GePrint("No selected objects!");
	}

	BaseMaterial::Free(matDefault);
	return TRUE;
}