Code Vonc

Troueur

v 1.1

Script COFFEE pour Cinéma 4D R13.

TéléchargerDownload
Faire un donMake a donation
Comment installer ?How to install ?
CommentairesComments

Une nouvelle version est disponible en Python ici.

Soustrait, à l'aide d'un booléen, un cylindre aux polygones sélectionnés.


var dlg;

class Menu:GeModalDialog {
			public:
			CreateLayout();
			Command(id, msg); 
			Init();
};

Menu::Init() 
{
	SetInt(12, 6, 3, 1000, 1);
	SetCheckbox(14, 1);
	SetCheckbox(15, 0);
	Enable(15, GetCheckbox(14));
}

Menu::CreateLayout()
{
	SetTitle("Troueur v1.1");
	AddGroupBeginV(10, BFH_SCALEFIT, 2, "Groupe", 0); // Groupe (0, Alignement, Colonnes, ...)
	{
		AddStaticText(13, BFH_CENTER, 0, 0, "Côtés :", 0);
		AddEditNumberArrows(12, BFH_SCALEFIT, 0, 0);
		AddCheckbox(14, BFH_SCALEFIT, 0, 0, "Booléen");
		AddCheckbox(15, BFH_SCALEFIT, 0, 0, "Intersection");
		AddGroupEnd();
	}
	AddButton(1, BFH_SCALEFIT, 200, 30, "Trouer");
	AddStaticText(100, BFH_CENTER, 0, 0, "César Vonc - www.cesarvonc.fr", 1);
	return TRUE;
}

positionneur(point, pP) {
	var neo = 456123.789123456;
	if (point.x < pP.x || pP.x == neo) pP.x = point.x;
	if (point.y < pP.y || pP.y == neo) pP.y = point.y;
	if (point.z < pP.z || pP.z == neo) pP.z = point.z;
	return(pP);
}

tailleur(point, pT) {
	var neo = 456123.789123456;
	if (point.x > pT.x || pT.x == neo) pT.x = point.x;
	if (point.y > pT.y || pT.y == neo) pT.y = point.y;
	if (point.z > pT.z || pT.z == neo) pT.z = point.z;
	return(pT);
}

troueur(doc, op, cote, bool, inter) {
	if (!op) return;
	if (!instanceof(op, PolygonObject)) return;
	var polSel = op->GetPolygonSelection();
		if (!polSel || polSel->GetCount() == 0) return;

	var polTot = op->GetPolygonCount();
	
	var i;
	var neo = 456123.789123456;
	var pP = vector(neo);
	var pT = vector(neo);
	var pos = op->GetPosition();
	var rot = op->GetRotation();

	var ptsNorm = new(array, polSel->GetCount());	
	var j = 0;
	for (i = 0 ; i < polTot ; i++) {
		if (polSel->IsSelected(i)) {
			var ptnA = op->GetPoint(op->GetPolygon(i)->a);
			var ptnB = op->GetPoint(op->GetPolygon(i)->b);
			var ptnC = op->GetPoint(op->GetPolygon(i)->c);
			var ptnD = op->GetPoint(op->GetPolygon(i)->d);

			ptsNorm[j] = vcross((ptnA - ptnC) , (ptnB - ptnD)); // Normale du poly

			pP = positionneur(ptnA, pP);
			pP = positionneur(ptnB, pP);
			pP = positionneur(ptnC, pP);
			pP = positionneur(ptnD, pP);
			pT = tailleur(ptnA, pT);
			pT = tailleur(ptnB, pT);
			pT = tailleur(ptnC, pT);
			pT = tailleur(ptnD, pT);

			j++;
		}
	}

	var mil = (pP + pT) / 2;
	var long = vlen(pP - pT) / 4;
		var k = 0;
		var somme = vector(0, 0, 0);
		for (k = 0 ; k < j ; k++) {
			somme += ptsNorm[k];
		}
	var vec = vnorm(somme / j); // Moyenne des normales des polys

	CallCommand(13324); // Tout désélectionner

	//Création du cylindre
	var cylindre = new(CylinderObject);
	cylindre->SetName("Trou"); 
	doc->InsertObject(cylindre, op, NULL) ;
	doc->AddUndo(UNDO_OBJECT_NEW, cylindre);
	cylindre#PRIM_CYLINDER_SEG = cote;
	cylindre#PRIM_CYLINDER_HEIGHT = long;
	cylindre#PRIM_CYLINDER_RADIUS = long;
	cylindre#ID_BASEOBJECT_POSITION = mil;
	cylindre#PRIM_AXIS = 4;
	cylindre#ID_BASEOBJECT_ROTATION = VectorToHPB(vec);
	if (inter == 1 && bool == 1) {
		cylindre#PRIM_CYLINDER_CAPS = 0;
	}

	// Création du booléen
	if (bool == 1) {
		var booleen = new(BooleObject);
		booleen#BOOLEOBJECT_SINGLE_OBJECT = true;
		booleen#BOOLEOBJECT_HIDE_NEW_EDGES = true;

		if (inter == 1) {
			booleen#BOOLEOBJECT_TYPE = 3;
		}

		doc->InsertObject(booleen, NULL, op);
		doc->AddUndo(UNDO_OBJECT_NEW , booleen);
		doc->AddUndo(UNDO_CHANGE, op);

		var cyGlob = cylindre->GetMg();
		cylindre->Remove();
		cylindre->InsertUnder(booleen);
		cylindre->SetMg(cyGlob);
		op->Remove();
		op->InsertUnder(booleen);
	}
}

Menu::Command(id,msg) 
{
	if (id == 14) 
	{
		Enable(15, GetCheckbox(14));
	}

	if (id == 1)
	{
		var doc = GetActiveDocument();
		var op = doc->GetActiveObject();
		troueur(doc, op, GetInt(12), GetInt(14), GetInt(15));
	}
}

main(doc, op) {
	dlg = new(Menu);
	dlg->Open(-1, -1);
}