コード例 #1
0
Bool ApplinkImporter::createObjects()
{
	BaseDocument* doc = GetActiveDocument();
	Int32 vertCnt = 0;
	const Matrix tM(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f));

	StatusSetText("Create objects...");
	for(unsigned int i = 0; i < groups.size(); i++)
	{
		Vector *vadr = 0;// vertex adress
		CPolygon *padr = 0;// polygon adress

		Group gr = this->groups[i];

		if(this->pSet.impReplace)
		{
			BaseObject* bo = doc->SearchObject(gr.groupName);
			if(bo)
			{				
				BaseObject::Free(bo);
			}
		}

		PolygonObject* pObj = PolygonObject::Alloc(gr.numGVertices, gr.numGFaces);
		if (!pObj){ return false;}

		pObj->SetName(this->groups[i].groupName);

		//GePrint("Name group: " + pObj->GetName());
		GePrint("V count: " + String::IntToString((Int32)gr.numGVertices));
		GePrint("Poly count: " + String::IntToString((Int32)gr.numGFaces));

		vadr = pObj->GetPointW();
		padr = pObj->GetPolygonW();

		for (int p = 0; p < gr.numGFaces; p++)
		{
			padr[p] = CPolygon(gr.faces[p].vp[0] - vertCnt, gr.faces[p].vp[1] - vertCnt, gr.faces[p].vp[2] - vertCnt, gr.faces[p].vp[3] - vertCnt);
			//GePrint("poly " + LongToString(p) + ": " + LongToString(padr[p].a) + ", " + LongToString(padr[p].b) + ", " + LongToString(padr[p].c) + ", " + LongToString(padr[p].d));
		}

		for (int v = 0; v < gr.numGVertices; v++)
		{
			vadr[v] = tM * this->verticies[v + vertCnt] ;
			//GePrint("vert " + LongToString(v) + ": " + LongToString(vadr[v].x) + ", " + LongToString(vadr[v].y) + ", " + LongToString(vadr[v].z));
		}
	
//// import UV
		if(ApplinkImporter::pSet.impUV && gr.numGTVertices > 0)
		{
			UVWStruct us;
			UVWTag* uvwtag = nullptr;

			uvwtag = UVWTag::Alloc(gr.numGFaces);
			if(!uvwtag) return false;

			for (Int32 p = 0; p < gr.numGFaces; p++)
			{
				us = UVWStruct(this->uvw[gr.faces[p].vt[0]], this->uvw[gr.faces[p].vt[1]], this->uvw[gr.faces[p].vt[2]], this->uvw[gr.faces[p].vt[3]]);
				void *dataptr = uvwtag->GetDataAddressW();
				uvwtag->Set(dataptr, p, us);
			}

			pObj->InsertTag(uvwtag, NULL);
			uvwtag->Message(MSG_UPDATE);
		}

////// insert phongTag
		if (!pObj->MakeTag(Tphong)) GePrint("Error on inserting phongTag. Object: " + pObj->GetName());

/////add materials, textures and poly clusters
		if(this->pSet.impMat)
		{
			String selTagName = "";
			if(this->matArray.size() == 1)
			{
				this->InsertTextureTag(pObj, this->matArray[0].Name, selTagName);
			}
			else if(this->matArray.size() > 1)
			{
				this->InsertTextureTag(pObj, this->matArray[0].Name, selTagName);

				CPolygon ps;
				SelectionTag* polyTag = NULL;

				for (Int32 c = 1; c < this->matArray.size(); c++)
				{
					polyTag = SelectionTag::Alloc(Tpolygonselection);
					if(!polyTag) return false;

					selTagName = "Selection " + String::IntToString(c);
					polyTag->SetName(selTagName);
					BaseSelect* sel = polyTag->GetBaseSelect();
					for (Int32 p = 0; p < gr.numGFaces; p++)
					{
						if(gr.polyMatIdx[p] == c)
						{
							sel->Select(p);
						}
					}
					
					pObj->InsertTag(polyTag, this->GetLastTag(pObj));
					polyTag->Message(MSG_UPDATE);

					this->InsertTextureTag(pObj, this->matArray[c].Name, selTagName);
				}
			}
		}

		doc->InsertObject(pObj, NULL, NULL);
		pObj->Message(MSG_UPDATE);

		ModelingCommandData md;
		md.doc = doc;
		md.op  = pObj;
		if(!SendModelingCommand(MCOMMAND_REVERSENORMALS, md)) return false;

		pObj = 0;
		vertCnt += gr.numGVertices;
	}

	return true;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: nr-plugins/auto-connect
  Bool ExecuteAutoConnect()
  {
    ConnectOptions options;
    Bool addDynamicsTag = false, inheritDynamicsTag = true;
    GetInt32(CMB_FORCE, options.forcePluginId);
    GetInt32(CMB_TYPE, options.forceType);
    GetInt32(CMB_MODE, options.connectMode);
    GetInt32(EDT_MAXCONN, options.maxConnections);
    GetFloat(EDT_RADIUS, options.radius);
    GetBool(CHK_CLOSED, options.closedChain);
    GetBool(CHK_ADDDYNAMICS, addDynamicsTag);
    GetBool(CHK_COMPOUND, inheritDynamicsTag);

    // Create an InExcludeData for the selection object.
    GeData ge_selection(CUSTOMGUI_INEXCLUDE_LIST, DEFAULTVALUE);
    auto selectionList = static_cast<InExcludeData*>(
      ge_selection.GetCustomDataType(CUSTOMGUI_INEXCLUDE_LIST));
    if (!selectionList)
      return false;

    // Get the active document and object.
    BaseDocument* doc = GetActiveDocument();
    if (!doc)
      return false;
    BaseObject* op = doc->GetActiveObject();
    if (!op)
      return false;

    // Create the root object that will contain the connectors.
    AutoFree<BaseObject> root(BaseObject::Alloc(Onull));
    if (!root)
      return false;

    // Function to create a dynamics tag.
    auto fAddDynamicsTag = [doc] (BaseObject* op, Int32 mode)
    {
      // Create a dynamics tag for the root object if it
      // does not already exist.
      BaseTag* dyn = op->GetTag(ID_RIGIDBODY);
      if (!dyn)
      {
        dyn = op->MakeTag(ID_RIGIDBODY);
        if (dyn) doc->AddUndo(UNDOTYPE_NEW, dyn);
      }

      // Update the parameters.
      if (dyn)
      {
        dyn->SetParameter(RIGID_BODY_HIERARCHY, mode, DESCFLAGS_SET_0);
        doc->AddUndo(UNDOTYPE_CHANGE_SMALL, dyn);
      }
    };

    // This list will contain all objects that should be connected.
    // While collecting, create the dynamics tags.
    maxon::BaseArray<BaseObject*> objects;
    doc->StartUndo();
    for (BaseObject* child=op->GetDown(); child; child=child->GetNext())
    {
      objects.Append(child);
      if (addDynamicsTag && inheritDynamicsTag)
        fAddDynamicsTag(child, RIGID_BODY_HIERARCHY_COMPOUND);
    }
    if (addDynamicsTag && !inheritDynamicsTag)
      fAddDynamicsTag(op, RIGID_BODY_HIERARCHY_INHERIT);

    // If no objects where collected, quit already.
    if (objects.GetCount() <= 0)
    {
      doc->EndUndo();
      doc->DoUndo(false);
      return true;
    }

    // Create the connection objects.
    ConnectObjects(op->GetName() + ": ", objects, options);

    // Fill the selection list and insert the objects.
    for (auto it=options.output.Begin(); it != options.output.End(); ++it)
    {
      (*it)->InsertUnderLast(root);
      doc->AddUndo(UNDOTYPE_NEW, *it);
      selectionList->InsertObject(*it, 0);
    }

    root->SetName(op->GetName() + ": " + root->GetName() + " (" + options.forceName + ")");
    doc->InsertObject(root, nullptr, nullptr);
    doc->AddUndo(UNDOTYPE_NEW, root);

    // Create the selection object.
    if (selectionList->GetObjectCount() > 0)
    {
      BaseObject* selection = BaseObject::Alloc(Oselection);
      if (selection)
      {
        selection->SetParameter(SELECTIONOBJECT_LIST, ge_selection, DESCFLAGS_SET_0);
        selection->SetName(op->GetName() + ": " + options.forceName + " (" + selection->GetName() + ")");
        doc->InsertObject(selection, nullptr, nullptr);
        doc->AddUndo(UNDOTYPE_NEW, selection);
      }
      ActiveObjectManager_SetMode(ACTIVEOBJECTMODE_OBJECT, false);
      doc->SetActiveObject(selection);
    }
    else
      doc->SetActiveObject(root);

    root.Release();
    doc->EndUndo();
    EventAdd();
    return true;
  }