2 BobToolz plugin for GtkRadiant
3 Copyright (C) 2001 Gordon Biggans
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "funchandlers.h"
37 #include "qerplugin.h"
46 #include "texturelib.h"
48 //#include "dialogs-gtk.h"
50 /************************
52 ************************/
63 | / | / ----> WEST, definitely
69 /************************
71 ************************/
73 vec3_t g_Origin = {0.0f, 0.0f, 0.0f};
75 extern bool bFacesAll[];
77 /************************
79 ************************/
81 float Deg2Rad(float angle)
83 return (float)(angle*Q_PI/180);
86 void AddFaceWithTexture(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc, const char* texture, bool detail)
88 _QERFaceData faceData;
89 FillDefaultTexture(&faceData, va, vb, vc, texture);
91 faceData.contents |= FACE_DETAIL;
92 GlobalBrushCreator().Brush_addFace(brush, faceData);
95 void AddFaceWithTextureScaled(scene::Node& brush, vec3_t va, vec3_t vb, vec3_t vc,
96 const char* texture, bool bVertScale, bool bHorScale,
97 float minX, float minY, float maxX, float maxY)
99 qtexture_t* pqtTexInfo;
101 // TTimo: there used to be a call to pfnHasShader here
102 // this was not necessary. In Radiant everything is shader.
103 // If a texture doesn't have a shader script, a default shader object is used.
104 // The IShader object was leaking also
105 // collect texture info: sizes, etc
106 IShader* i = GlobalShaderSystem().getShaderForName(texture);
107 pqtTexInfo = i->getTexture(); // shader width/height doesn't come out properly
111 float scale[2] = {0.5f, 0.5f};
112 float shift[2] = {0, 0};
116 int texWidth = pqtTexInfo->width;
117 float width = maxX - minX;
119 scale[0] = width/texWidth;
120 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
125 int texHeight = pqtTexInfo->height;
126 float height = maxY - minY;
128 scale[1] = height/texHeight;
129 shift[1] = (float)((int)minY%(int)height)/scale[1];
132 _QERFaceData addFace;
133 FillDefaultTexture(&addFace, va, vb, vc, texture);
134 addFace.m_texdef.scale[0] = scale[0];
135 addFace.m_texdef.scale[1] = scale[1];
136 addFace.m_texdef.shift[0] = shift[0];
137 addFace.m_texdef.shift[1] = shift[1];
139 GlobalBrushCreator().Brush_addFace(brush, addFace);
143 // shouldn't even get here, as default missing texture should be returned if
144 // texture doesn't exist, but just in case
145 AddFaceWithTexture(brush, va, vb, vc, texture, false);
146 globalErrorStream() << "BobToolz::Invalid Texture Name-> " << texture;
148 // the IShader is not kept referenced, DecRef it
152 /************************
154 ************************/
156 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
158 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
160 vec3_t v1, v2, v3, v5, v6, v7, v8;
180 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
183 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", false);
185 if(dir != MOVE_NORTH)
186 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
188 if(dir != MOVE_SOUTH)
189 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", false);
191 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", false);
194 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", false);
197 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", false);
199 if(dir == MOVE_NORTH)
200 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", false);
202 if(dir == MOVE_SOUTH)
203 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", false);
208 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", false);
211 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
213 if(dir != MOVE_NORTH)
214 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", false);
216 if(dir != MOVE_SOUTH)
217 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
220 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", false);
223 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", false);
226 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", false);
228 if(dir == MOVE_NORTH)
229 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", false);
231 if(dir == MOVE_SOUTH)
232 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", false);
235 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
238 //-----------------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------------
241 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
243 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
245 //----- Build Outer Bounds ---------
247 vec3_t v1, v2, v3, v5, v6, v7, v8;
263 //v8 needed this time, becoz of sloping faces (2-4-6-8)
265 //----------------------------------
267 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
272 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
274 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
280 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
282 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
285 if(dir != MOVE_NORTH)
287 if(dir == MOVE_SOUTH)
288 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
290 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
293 if(dir != MOVE_SOUTH)
295 if(dir == MOVE_NORTH)
296 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
298 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
303 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
306 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
308 if(dir == MOVE_NORTH)
309 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
311 if(dir == MOVE_SOUTH)
312 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
314 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
317 //-----------------------------------------------------------------------------------
318 //-----------------------------------------------------------------------------------
320 // internal use only, to get a box without finishing construction
321 scene::Node& Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
323 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
325 //----- Build Outer Bounds ---------
327 vec3_t v1, v2, v3, v5, v6, v7;
341 //----------------------------------
343 //----- Add Six Cube Faces ---------
346 AddFaceWithTexture(newBrush, v1, v2, v3, texture, false);
348 AddFaceWithTexture(newBrush, v1, v3, v6, texture, false);
350 AddFaceWithTexture(newBrush, v1, v7, v2, texture, false);
353 AddFaceWithTexture(newBrush, v5, v6, v3, texture, false);
355 AddFaceWithTexture(newBrush, v5, v2, v7, texture, false);
357 AddFaceWithTexture(newBrush, v5, v7, v6, texture, false);
359 //----------------------------------
364 scene::Node& Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
366 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
369 //-----------------------------------------------------------------------------------
370 //-----------------------------------------------------------------------------------
372 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
374 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
376 //----- Build Outer Bounds ---------
378 vec3_t v1, v2, v3, v5, v6, v7;
392 //----------------------------------
394 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, false);
395 // top gets current texture
398 if(direction == MOVE_EAST)
399 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, false);
401 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
402 // west facing side, etc...
405 if(direction == MOVE_NORTH)
406 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, false);
408 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
410 if(direction == MOVE_SOUTH)
411 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, false);
413 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", false);
415 if(direction == MOVE_WEST)
416 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, false);
418 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", false);
421 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", false);
424 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
428 //-----------------------------------------------------------------------------------
429 //-----------------------------------------------------------------------------------
431 void BuildDoorsX2(vec3_t min, vec3_t max,
432 bool bSclMainHor, bool bSclMainVert,
433 bool bSclTrimHor, bool bSclTrimVert,
434 const char* mainTexture, const char* trimTexture,
443 //----- Build Outer Bounds ---------
445 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
459 float width = (max[xy] - min[xy])/2;
463 VectorCopy(v1, ve_1);
464 VectorCopy(v3, ve_2);
465 VectorCopy(v6, ve_3);
469 VectorCopy(v7, ve_1);
470 VectorCopy(v1, ve_2);
471 VectorCopy(v2, ve_3);
478 //----------------------------------
480 NodeSmartReference newBrush1(GlobalBrushCreator().createBrush());
481 NodeSmartReference newBrush2(GlobalBrushCreator().createBrush());
483 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", false);
484 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", false);
486 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", false);
487 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", false);
491 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", false);
492 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", false);
496 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", false);
497 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", false);
502 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
503 min[0], min[2], max[0], max[2]);
504 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
505 max[0], min[2], min[0], max[2]);
508 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
509 min[0], min[2], max[0], max[2]);
510 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
511 max[0], min[2], min[0], max[2]); // flip max/min to reverse tex dir
515 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
516 min[1], min[2], max[1], max[2]);
518 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
519 max[1], min[2], min[1], max[2]);
523 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
524 min[1], min[2], max[1], max[2]);
525 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
526 max[1], min[2], min[1], max[2]);
529 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
530 min[1], min[2], max[1], max[2]);
531 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
532 max[1], min[2], min[1], max[2]); // flip max/min to reverse tex dir
535 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
536 min[0], min[2], max[0], max[2]);
538 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
539 max[0], min[2], min[0], max[2]);
542 //----------------------------------
545 EntityClass* doorClass = GlobalEntityClassManager().findOrInsert("func_door", true);
546 NodeSmartReference pEDoor1(GlobalEntityCreator().createEntity(doorClass));
547 NodeSmartReference pEDoor2(GlobalEntityCreator().createEntity(doorClass));
551 Node_getEntity(pEDoor1)->setKeyValue("angle", "180");
552 Node_getEntity(pEDoor2)->setKeyValue("angle", "360");
556 Node_getEntity(pEDoor1)->setKeyValue("angle", "270");
557 Node_getEntity(pEDoor2)->setKeyValue("angle", "90");
560 srand((unsigned)time(NULL));
563 sprintf(teamname, "t%i", rand());
564 Node_getEntity(pEDoor1)->setKeyValue("team", teamname);
565 Node_getEntity(pEDoor2)->setKeyValue("team", teamname);
567 Node_getTraversable(pEDoor1)->insert(newBrush1);
568 Node_getTraversable(pEDoor2)->insert(newBrush2);
570 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1);
571 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2);
573 // ResetCurrentTexture();
576 //-----------------------------------------------------------------------------------
577 //-----------------------------------------------------------------------------------
579 void MakeBevel(vec3_t vMin, vec3_t vMax)
581 NodeSmartReference patch(GlobalPatchCreator().createPatch());
582 PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch);
584 GlobalPatchCreator().Patch_setShader(patch, "textures/common/caulk");
585 GlobalPatchCreator().Patch_resize(patch, 3, 3);
587 vec3_t x_3, y_3, z_3;
588 x_3[0] = vMin[0]; x_3[1] = vMin[0]; x_3[2] = vMax[0];
589 y_3[0] = vMin[1]; y_3[1] = vMax[1]; y_3[2] = vMax[1];
590 z_3[0] = vMin[2]; z_3[1] = (vMax[2] + vMin[2])/2; z_3[2] = vMax[2];
592 /* x_3[0] = 0; x_3[1] = 0; x_3[2] = 64;
593 y_3[0] = 0; y_3[1] = 64; y_3[2] = 64;
594 z_3[0] = 0; z_3[1] = 32; z_3[2] = 64;*/
596 for(int i = 0; i < 3; i++)
598 for(int j = 0; j < 3; j++)
600 matrix(i, j).m_vertex[0] = x_3[i];
601 matrix(i, j).m_vertex[1] = y_3[i];
602 matrix(i, j).m_vertex[2] = z_3[j];
606 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(patch);
609 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
611 vec3_t* topPoints = new vec3_t[nSteps+1];
612 vec3_t* botPoints = new vec3_t[nSteps+1];
614 bool bFacesUse[6] = {true, true, false, true, false, false};
617 VectorCopy(vMin, centre);
620 int height = (int)(vMax[2] - vMin[2]) / nSteps;
623 VectorCopy(vMax, vTop);
624 VectorCopy(vMin, vBot);
625 vTop[2] = vMin[2] + height;
628 for(i = 0; i <= nSteps; i++)
630 VectorCopy(centre, topPoints[i]);
631 VectorCopy(centre, botPoints[i]);
633 topPoints[i][2] = vMax[2];
634 botPoints[i][2] = vMin[2];
636 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
637 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
639 botPoints[i][0] = topPoints[i][0];
640 botPoints[i][1] = topPoints[i][1];
644 for(int j = 0; j < 3; j++)
645 VectorCopy(topPoints[j], tp[j]);
647 for(i = 0; i < nSteps; i++)
649 scene::Node& brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
651 for(int j = 0; j < 3; j++)
654 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, false);
656 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", false);
657 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, false);
659 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(brush);
670 MakeBevel(vMin, vMax);