-void DoFlipTerrain()
-{
- UndoableCommand undo("bobToolz.flipTerrain");
- vec3_t vUp = {0.f, 0.f, 1.f};
- int i;
-
- // ensure we have something selected
- if (GlobalSelectionSystem().countSelected() != 2) {
- //DoMessageBox("Invalid number of objects selected, choose 2 only", "Error", eMB_OK);
- globalErrorStream() << "bobToolz FlipTerrain: Invalid number of objects selected, choose 2 only.\n";
- return;
- }
-
- scene::Instance *brushes[2];
- brushes[0] = &GlobalSelectionSystem().ultimateSelected();
- brushes[1] = &GlobalSelectionSystem().penultimateSelected();
- //ensure we have only Brushes selected.
- for (i = 0; i < 2; i++) {
- if (!Node_isBrush(brushes[i]->path().top())) {
- //DoMessageBox("No brushes selected, select ONLY brushes", "Error", eMB_OK);
- globalErrorStream() << "bobToolz FlipTerrain: No brushes selected, select ONLY 2 brushes.\n";
- return;
- }
- }
- DBrush Brushes[2];
- DPlane *Planes[2];
- pntTripple Points[2];
- for (i = 0; i < 2; i++) {
- Brushes[i].LoadFromBrush(*brushes[i], false);
- if (!(Planes[i] = Brushes[i].FindPlaneWithClosestNormal(vUp)) ||
- Brushes[i].FindPointsForPlane(Planes[i], Points[i], 3) != 3) {
- //DoMessageBox("Error", "Error", eMB_OK);
- globalErrorStream() << "bobToolz FlipTerrain: ERROR (FindPlaneWithClosestNormal/FindPointsForPlane).\n";
- return;
- }
- }
-
- vec3_t mins1, mins2, maxs1, maxs2;
- Brushes[0].GetBounds(mins1, maxs1);
- Brushes[1].GetBounds(mins2, maxs2);
-
-
- int dontmatch[2] = {-1, -1};
- bool found = false;
- for (i = 0; i < 3; i++) {
- for (int j = 0; j < 3 && !found; j++) {
- if (VectorCompare((Points[0])[i]->_pnt, (Points[1])[j]->_pnt)) {
- found = true;
- break;
- }
- }
- if (!found) {
- dontmatch[0] = i;
- break;
- }
- found = false;
- }
- if (dontmatch[0] == -1) {
- //DoMessageBox("Error", "Error", eMB_OK);
- globalErrorStream() << "bobToolz FlipTerrain: ERROR (dontmatch[0]).\n";
- return;
- }
-
- for (i = 0; i < 3; i++) {
- for (int j = 0; j < 3 && !found; j++) {
- if (VectorCompare((Points[1])[i]->_pnt, (Points[0])[j]->_pnt)) {
- found = true;
- break;
- }
- }
- if (!found) {
- dontmatch[1] = i;
- break;
- }
- found = false;
- }
- if (dontmatch[1] == -1) {
- //DoMessageBox("Error", "Error", eMB_OK);
- globalErrorStream() << "bobToolz FlipTerrain: ERROR (dontmatch[1]).\n";
- return;
- }
-
- vec3_t plnpnts1[3];
- vec3_t plnpnts2[3];
- vec3_t plnpntsshr[3];
-
- VectorCopy((Points[0])[dontmatch[0]]->_pnt, plnpnts1[0]);
- for (i = 0; i < 3; i++) {
- if (dontmatch[0] != i) {
- VectorCopy((Points[0])[i]->_pnt, plnpnts1[1]);
- break;
- }
- }
- VectorCopy((Points[1])[dontmatch[1]]->_pnt, plnpnts1[2]);
-
- VectorCopy((Points[1])[dontmatch[1]]->_pnt, plnpnts2[0]);
- for (i = 0; i < 3; i++) {
- if (dontmatch[1] != i && !VectorCompare((Points[1])[i]->_pnt, plnpnts1[1])) {
- VectorCopy((Points[1])[i]->_pnt, plnpnts2[1]);
- break;
- }
- }
- VectorCopy((Points[0])[dontmatch[0]]->_pnt, plnpnts2[2]);
-
- VectorCopy((Points[0])[dontmatch[0]]->_pnt, plnpntsshr[0]);
- VectorCopy((Points[1])[dontmatch[1]]->_pnt, plnpntsshr[1]);
- if ((Points[1])[dontmatch[1]]->_pnt[2] < (Points[0])[dontmatch[0]]->_pnt[2]) {
- VectorCopy((Points[1])[dontmatch[1]]->_pnt, plnpntsshr[2]);
- } else {
- VectorCopy((Points[0])[dontmatch[0]]->_pnt, plnpntsshr[2]);
- }
- plnpntsshr[2][2] -= 16;
-
- for (i = 0; i < 3; i++) {
- if (mins2[i] < mins1[i]) {
- mins1[i] = mins2[i];
- }
- if (maxs2[i] > maxs1[i]) {
- maxs1[i] = maxs2[i];
- }
- }
-
- DBrush *newBrushes[2];
- newBrushes[0] = DShape::GetBoundingCube_Ext(mins1, maxs1, "textures/common/caulk", bFacesAll, true);
- newBrushes[1] = DShape::GetBoundingCube_Ext(mins1, maxs1, "textures/common/caulk", bFacesAll, true);
-
- vec3_t normal;
- MakeNormal(plnpnts1[0], plnpnts1[1], plnpnts1[2], normal);
- if (normal[2] >= 0) {
- newBrushes[0]->AddFace(plnpnts1[0], plnpnts1[1], plnpnts1[2], "textures/common/terrain", true);
- } else {
- newBrushes[0]->AddFace(plnpnts1[2], plnpnts1[1], plnpnts1[0], "textures/common/terrain", true);
- }
-
- MakeNormal(plnpnts2[0], plnpnts2[1], plnpnts2[2], normal);
- if (normal[2] >= 0) {
- newBrushes[1]->AddFace(plnpnts2[0], plnpnts2[1], plnpnts2[2], "textures/common/terrain", true);
- } else {
- newBrushes[1]->AddFace(plnpnts2[2], plnpnts2[1], plnpnts2[0], "textures/common/terrain", true);
- }
-
- vec3_t vec;
- MakeNormal(plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], normal);
-
- VectorSubtract(plnpnts1[2], plnpnts1[1], vec);
- if (DotProduct(vec, normal) >= 0) {
- newBrushes[0]->AddFace(plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], "textures/common/caulk", true);
- } else {
- newBrushes[0]->AddFace(plnpntsshr[2], plnpntsshr[1], plnpntsshr[0], "textures/common/caulk", true);
- }
-
- VectorSubtract(plnpnts2[2], plnpnts2[1], vec);
- if (DotProduct(vec, normal) >= 0) {
- newBrushes[1]->AddFace(plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], "textures/common/caulk", true);
- } else {
- newBrushes[1]->AddFace(plnpntsshr[2], plnpntsshr[1], plnpntsshr[0], "textures/common/caulk", true);
- }
-
- for (i = 0; i < 2; i++) {
- newBrushes[i]->RemoveRedundantPlanes();
- newBrushes[i]->BuildInRadiant(false, NULL, brushes[i]->path().parent().get_pointer());
- Path_deleteTop(brushes[i]->path());
- delete newBrushes[i];
- }
+void DoFlipTerrain() {
+ UndoableCommand undo( "bobToolz.flipTerrain" );
+ vec3_t vUp = { 0.f, 0.f, 1.f };
+ int i;
+
+ // ensure we have something selected
+ if ( GlobalSelectionSystem().countSelected() != 2 ) {
+ //DoMessageBox("Invalid number of objects selected, choose 2 only", "Error", eMB_OK);
+ globalErrorStream() << "bobToolz FlipTerrain: Invalid number of objects selected, choose 2 only.\n";
+ return;
+ }
+
+ scene::Instance* brushes[2];
+ brushes[0] = &GlobalSelectionSystem().ultimateSelected();
+ brushes[1] = &GlobalSelectionSystem().penultimateSelected();
+ //ensure we have only Brushes selected.
+ for ( i = 0; i < 2; i++ )
+ {
+ if ( !Node_isBrush( brushes[i]->path().top() ) ) {
+ //DoMessageBox("No brushes selected, select ONLY brushes", "Error", eMB_OK);
+ globalErrorStream() << "bobToolz FlipTerrain: No brushes selected, select ONLY 2 brushes.\n";
+ return;
+ }
+ }
+ DBrush Brushes[2];
+ DPlane* Planes[2];
+ pntTripple Points[2];
+ for ( i = 0; i < 2; i++ ) {
+ Brushes[i].LoadFromBrush( *brushes[i], false );
+ if ( !( Planes[i] = Brushes[i].FindPlaneWithClosestNormal( vUp ) ) || Brushes[i].FindPointsForPlane( Planes[i], Points[i], 3 ) != 3 ) {
+ //DoMessageBox("Error", "Error", eMB_OK);
+ globalErrorStream() << "bobToolz FlipTerrain: ERROR (FindPlaneWithClosestNormal/FindPointsForPlane).\n";
+ return;
+ }
+ }
+
+ vec3_t mins1, mins2, maxs1, maxs2;
+ Brushes[0].GetBounds( mins1, maxs1 );
+ Brushes[1].GetBounds( mins2, maxs2 );
+
+
+
+ int dontmatch[2] = { -1, -1 };
+ bool found = false;
+ for ( i = 0; i < 3; i++ ) {
+ for ( int j = 0; j < 3 && !found; j++ ) {
+ if ( VectorCompare( ( Points[0] )[i]->_pnt, ( Points[1] )[j]->_pnt ) ) {
+ found = true;
+ break;
+ }
+ }
+ if ( !found ) {
+ dontmatch[0] = i;
+ break;
+ }
+ found = false;
+ }
+ if ( dontmatch[0] == -1 ) {
+ //DoMessageBox("Error", "Error", eMB_OK);
+ globalErrorStream() << "bobToolz FlipTerrain: ERROR (dontmatch[0]).\n";
+ return;
+ }
+
+ for ( i = 0; i < 3; i++ ) {
+ for ( int j = 0; j < 3 && !found; j++ ) {
+ if ( VectorCompare( ( Points[1] )[i]->_pnt, ( Points[0] )[j]->_pnt ) ) {
+ found = true;
+ break;
+ }
+ }
+ if ( !found ) {
+ dontmatch[1] = i;
+ break;
+ }
+ found = false;
+ }
+ if ( dontmatch[1] == -1 ) {
+ //DoMessageBox("Error", "Error", eMB_OK);
+ globalErrorStream() << "bobToolz FlipTerrain: ERROR (dontmatch[1]).\n";
+ return;
+ }
+
+ vec3_t plnpnts1[3];
+ vec3_t plnpnts2[3];
+ vec3_t plnpntsshr[3];
+
+ VectorCopy( ( Points[0] )[dontmatch[0]]->_pnt, plnpnts1[0] );
+ for ( i = 0; i < 3; i++ ) {
+ if ( dontmatch[0] != i ) {
+ VectorCopy( ( Points[0] )[i]->_pnt, plnpnts1[1] );
+ break;
+ }
+ }
+ VectorCopy( ( Points[1] )[dontmatch[1]]->_pnt, plnpnts1[2] );
+
+ VectorCopy( ( Points[1] )[dontmatch[1]]->_pnt, plnpnts2[0] );
+ for ( i = 0; i < 3; i++ ) {
+ if ( dontmatch[1] != i && !VectorCompare( ( Points[1] )[i]->_pnt, plnpnts1[1] ) ) {
+ VectorCopy( ( Points[1] )[i]->_pnt, plnpnts2[1] );
+ break;
+ }
+ }
+ VectorCopy( ( Points[0] )[dontmatch[0]]->_pnt, plnpnts2[2] );
+
+ VectorCopy( ( Points[0] )[dontmatch[0]]->_pnt, plnpntsshr[0] );
+ VectorCopy( ( Points[1] )[dontmatch[1]]->_pnt, plnpntsshr[1] );
+ if ( ( Points[1] )[dontmatch[1]]->_pnt[2] < ( Points[0] )[dontmatch[0]]->_pnt[2] ) {
+ VectorCopy( ( Points[1] )[dontmatch[1]]->_pnt, plnpntsshr[2] );
+ }
+ else {
+ VectorCopy( ( Points[0] )[dontmatch[0]]->_pnt, plnpntsshr[2] );
+ }
+ plnpntsshr[2][2] -= 16;
+
+ for ( i = 0; i < 3; i++ ) {
+ if ( mins2[i] < mins1[i] ) {
+ mins1[i] = mins2[i];
+ }
+ if ( maxs2[i] > maxs1[i] ) {
+ maxs1[i] = maxs2[i];
+ }
+ }
+
+ DBrush* newBrushes[2];
+ newBrushes[0] = DShape::GetBoundingCube_Ext( mins1, maxs1, "textures/common/caulk", bFacesAll, true );
+ newBrushes[1] = DShape::GetBoundingCube_Ext( mins1, maxs1, "textures/common/caulk", bFacesAll, true );
+
+ vec3_t normal;
+ MakeNormal( plnpnts1[0], plnpnts1[1], plnpnts1[2], normal );
+ if ( normal[2] >= 0 ) {
+ newBrushes[0]->AddFace( plnpnts1[0], plnpnts1[1], plnpnts1[2], "textures/common/terrain", true );
+ }
+ else {
+ newBrushes[0]->AddFace( plnpnts1[2], plnpnts1[1], plnpnts1[0], "textures/common/terrain", true );
+ }
+
+ MakeNormal( plnpnts2[0], plnpnts2[1], plnpnts2[2], normal );
+ if ( normal[2] >= 0 ) {
+ newBrushes[1]->AddFace( plnpnts2[0], plnpnts2[1], plnpnts2[2], "textures/common/terrain", true );
+ }
+ else {
+ newBrushes[1]->AddFace( plnpnts2[2], plnpnts2[1], plnpnts2[0], "textures/common/terrain", true );
+ }
+
+ vec3_t vec;
+ MakeNormal( plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], normal );
+
+ VectorSubtract( plnpnts1[2], plnpnts1[1], vec );
+ if ( DotProduct( vec, normal ) >= 0 ) {
+ newBrushes[0]->AddFace( plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], "textures/common/caulk", true );
+ }
+ else {
+ newBrushes[0]->AddFace( plnpntsshr[2], plnpntsshr[1], plnpntsshr[0], "textures/common/caulk", true );
+ }
+
+ VectorSubtract( plnpnts2[2], plnpnts2[1], vec );
+ if ( DotProduct( vec, normal ) >= 0 ) {
+ newBrushes[1]->AddFace( plnpntsshr[0], plnpntsshr[1], plnpntsshr[2], "textures/common/caulk", true );
+ }
+ else {
+ newBrushes[1]->AddFace( plnpntsshr[2], plnpntsshr[1], plnpntsshr[0], "textures/common/caulk", true );
+ }
+
+ for ( i = 0; i < 2; i++ ) {
+ newBrushes[i]->RemoveRedundantPlanes();
+ newBrushes[i]->BuildInRadiant( false, NULL, brushes[i]->path().parent().get_pointer() );
+ Path_deleteTop( brushes[i]->path() );
+ delete newBrushes[i];
+ }