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 float width = maxX - minX;
118 scale[0] = width/pqtTexInfo->width;
119 shift[0] = -(float)((int)maxX%(int)width)/scale[0];
124 float height = maxY - minY;
126 scale[1] = height/pqtTexInfo->height;
127 shift[1] = (float)((int)minY%(int)height)/scale[1];
130 _QERFaceData addFace;
131 FillDefaultTexture(&addFace, va, vb, vc, texture);
132 addFace.m_texdef.scale[0] = scale[0];
133 addFace.m_texdef.scale[1] = scale[1];
134 addFace.m_texdef.shift[0] = shift[0];
135 addFace.m_texdef.shift[1] = shift[1];
137 GlobalBrushCreator().Brush_addFace(brush, addFace);
141 // shouldn't even get here, as default missing texture should be returned if
142 // texture doesn't exist, but just in case
143 AddFaceWithTexture(brush, va, vb, vc, texture, false);
144 globalErrorStream() << "BobToolz::Invalid Texture Name-> " << texture;
146 // the IShader is not kept referenced, DecRef it
150 /************************
152 ************************/
154 void Build_Wedge(int dir, vec3_t min, vec3_t max, bool bUp)
156 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
158 vec3_t v1, v2, v3, v5, v6, v7, v8;
178 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
181 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", false);
183 if(dir != MOVE_NORTH)
184 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
186 if(dir != MOVE_SOUTH)
187 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", false);
189 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", false);
192 AddFaceWithTexture(newBrush, v1, v3, v5, "textures/common/caulk", false);
195 AddFaceWithTexture(newBrush, v2, v6, v8, "textures/common/caulk", false);
197 if(dir == MOVE_NORTH)
198 AddFaceWithTexture(newBrush, v1, v6, v5, "textures/common/caulk", false);
200 if(dir == MOVE_SOUTH)
201 AddFaceWithTexture(newBrush, v7, v3, v8, "textures/common/caulk", false);
206 AddFaceWithTexture(newBrush, v7, v5, v8, "textures/common/caulk", false);
209 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
211 if(dir != MOVE_NORTH)
212 AddFaceWithTexture(newBrush, v3, v8, v6, "textures/common/caulk", false);
214 if(dir != MOVE_SOUTH)
215 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
218 AddFaceWithTexture(newBrush, v6, v5, v7, "textures/common/caulk", false);
221 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", false);
224 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", false);
226 if(dir == MOVE_NORTH)
227 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", false);
229 if(dir == MOVE_SOUTH)
230 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", false);
233 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
236 //-----------------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------------
239 void Build_StairStep_Wedge(int dir, vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, bool detail)
241 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
243 //----- Build Outer Bounds ---------
245 vec3_t v1, v2, v3, v5, v6, v7, v8;
261 //v8 needed this time, becoz of sloping faces (2-4-6-8)
263 //----------------------------------
265 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, detail);
270 AddFaceWithTexture(newBrush, v5, v2, v7, riserTexture, detail);
272 AddFaceWithTexture(newBrush, v5, v2, v7, "textures/common/caulk", detail);
278 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, detail);
280 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", detail);
283 if(dir != MOVE_NORTH)
285 if(dir == MOVE_SOUTH)
286 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, detail);
288 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", detail);
291 if(dir != MOVE_SOUTH)
293 if(dir == MOVE_NORTH)
294 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, detail);
296 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", detail);
301 AddFaceWithTexture(newBrush, v1, v5, v3, "textures/common/caulk", detail);
304 AddFaceWithTexture(newBrush, v2, v8, v6, "textures/common/caulk", detail);
306 if(dir == MOVE_NORTH)
307 AddFaceWithTexture(newBrush, v1, v5, v6, "textures/common/caulk", detail);
309 if(dir == MOVE_SOUTH)
310 AddFaceWithTexture(newBrush, v7, v8, v3, "textures/common/caulk", detail);
312 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
315 //-----------------------------------------------------------------------------------
316 //-----------------------------------------------------------------------------------
318 // internal use only, to get a box without finishing construction
319 scene::Node& Build_Get_BoundingCube_Selective(vec3_t min, vec3_t max, char* texture, bool* useFaces)
321 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
323 //----- Build Outer Bounds ---------
325 vec3_t v1, v2, v3, v5, v6, v7;
339 //----------------------------------
341 //----- Add Six Cube Faces ---------
344 AddFaceWithTexture(newBrush, v1, v2, v3, texture, false);
346 AddFaceWithTexture(newBrush, v1, v3, v6, texture, false);
348 AddFaceWithTexture(newBrush, v1, v7, v2, texture, false);
351 AddFaceWithTexture(newBrush, v5, v6, v3, texture, false);
353 AddFaceWithTexture(newBrush, v5, v2, v7, texture, false);
355 AddFaceWithTexture(newBrush, v5, v7, v6, texture, false);
357 //----------------------------------
362 scene::Node& Build_Get_BoundingCube(vec3_t min, vec3_t max, char* texture)
364 return Build_Get_BoundingCube_Selective(min, max, texture, bFacesAll);
367 //-----------------------------------------------------------------------------------
368 //-----------------------------------------------------------------------------------
370 void Build_StairStep(vec3_t min, vec3_t max, const char* mainTexture, const char* riserTexture, int direction)
372 NodeSmartReference newBrush(GlobalBrushCreator().createBrush());
374 //----- Build Outer Bounds ---------
376 vec3_t v1, v2, v3, v5, v6, v7;
390 //----------------------------------
392 AddFaceWithTexture(newBrush, v6, v5, v7, mainTexture, false);
393 // top gets current texture
396 if(direction == MOVE_EAST)
397 AddFaceWithTexture(newBrush, v1, v3, v6, riserTexture, false);
399 AddFaceWithTexture(newBrush, v1, v3, v6, "textures/common/caulk", false);
400 // west facing side, etc...
403 if(direction == MOVE_NORTH)
404 AddFaceWithTexture(newBrush, v1, v7, v2, riserTexture, false);
406 AddFaceWithTexture(newBrush, v1, v7, v2, "textures/common/caulk", false);
408 if(direction == MOVE_SOUTH)
409 AddFaceWithTexture(newBrush, v3, v5, v6, riserTexture, false);
411 AddFaceWithTexture(newBrush, v3, v5, v6, "textures/common/caulk", false);
413 if(direction == MOVE_WEST)
414 AddFaceWithTexture(newBrush, v7, v5, v2, riserTexture, false);
416 AddFaceWithTexture(newBrush, v7, v5, v2, "textures/common/caulk", false);
419 AddFaceWithTexture(newBrush, v1, v2, v3, "textures/common/caulk", false);
422 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(newBrush);
426 //-----------------------------------------------------------------------------------
427 //-----------------------------------------------------------------------------------
429 void BuildDoorsX2(vec3_t min, vec3_t max,
430 bool bSclMainHor, bool bSclMainVert,
431 bool bSclTrimHor, bool bSclTrimVert,
432 const char* mainTexture, const char* trimTexture,
441 //----- Build Outer Bounds ---------
443 vec3_t v1, v2, v3, v5, v6, v7, ve_1, ve_2, ve_3;
457 float width = (max[xy] - min[xy])/2;
461 VectorCopy(v1, ve_1);
462 VectorCopy(v3, ve_2);
463 VectorCopy(v6, ve_3);
467 VectorCopy(v7, ve_1);
468 VectorCopy(v1, ve_2);
469 VectorCopy(v2, ve_3);
476 //----------------------------------
478 NodeSmartReference newBrush1(GlobalBrushCreator().createBrush());
479 NodeSmartReference newBrush2(GlobalBrushCreator().createBrush());
481 AddFaceWithTexture(newBrush1, v1, v2, v3, "textures/common/caulk", false);
482 AddFaceWithTexture(newBrush1, v5, v7, v6, "textures/common/caulk", false);
484 AddFaceWithTexture(newBrush2, v1, v2, v3, "textures/common/caulk", false);
485 AddFaceWithTexture(newBrush2, v5, v7, v6, "textures/common/caulk", false);
489 AddFaceWithTexture(newBrush1, v1, v3, v6, "textures/common/caulk", false);
490 AddFaceWithTexture(newBrush2, v5, v2, v7, "textures/common/caulk", false);
494 AddFaceWithTexture(newBrush1, v1, v7, v2, "textures/common/caulk", false);
495 AddFaceWithTexture(newBrush2, v5, v6, v3, "textures/common/caulk", false);
500 AddFaceWithTextureScaled(newBrush1, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
501 min[0], min[2], max[0], max[2]);
502 AddFaceWithTextureScaled(newBrush1, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
503 max[0], min[2], min[0], max[2]);
506 AddFaceWithTextureScaled(newBrush2, v1, v7, v2, mainTexture, bSclMainVert, bSclMainHor,
507 min[0], min[2], max[0], max[2]);
508 AddFaceWithTextureScaled(newBrush2, v5, v6, v3, mainTexture, bSclMainVert, bSclMainHor,
509 max[0], min[2], min[0], max[2]); // flip max/min to reverse tex dir
513 AddFaceWithTextureScaled(newBrush1, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
514 min[1], min[2], max[1], max[2]);
516 AddFaceWithTextureScaled(newBrush2, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
517 max[1], min[2], min[1], max[2]);
521 AddFaceWithTextureScaled(newBrush1, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
522 min[1], min[2], max[1], max[2]);
523 AddFaceWithTextureScaled(newBrush1, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
524 max[1], min[2], min[1], max[2]);
527 AddFaceWithTextureScaled(newBrush2, v1, v3, v6, mainTexture, bSclMainVert, bSclMainHor,
528 min[1], min[2], max[1], max[2]);
529 AddFaceWithTextureScaled(newBrush2, v5, v2, v7, mainTexture, bSclMainVert, bSclMainHor,
530 max[1], min[2], min[1], max[2]); // flip max/min to reverse tex dir
533 AddFaceWithTextureScaled(newBrush1, ve_1, ve_2, ve_3, trimTexture, bSclTrimVert, bSclTrimHor,
534 min[0], min[2], max[0], max[2]);
536 AddFaceWithTextureScaled(newBrush2, ve_3, ve_2, ve_1, trimTexture, bSclTrimVert, bSclTrimHor,
537 max[0], min[2], min[0], max[2]);
540 //----------------------------------
543 EntityClass* doorClass = GlobalEntityClassManager().findOrInsert("func_door", true);
544 NodeSmartReference pEDoor1(GlobalEntityCreator().createEntity(doorClass));
545 NodeSmartReference pEDoor2(GlobalEntityCreator().createEntity(doorClass));
549 Node_getEntity(pEDoor1)->setKeyValue("angle", "180");
550 Node_getEntity(pEDoor2)->setKeyValue("angle", "360");
554 Node_getEntity(pEDoor1)->setKeyValue("angle", "270");
555 Node_getEntity(pEDoor2)->setKeyValue("angle", "90");
558 srand((unsigned)time(NULL));
561 sprintf(teamname, "t%i", rand());
562 Node_getEntity(pEDoor1)->setKeyValue("team", teamname);
563 Node_getEntity(pEDoor2)->setKeyValue("team", teamname);
565 Node_getTraversable(pEDoor1)->insert(newBrush1);
566 Node_getTraversable(pEDoor2)->insert(newBrush2);
568 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor1);
569 Node_getTraversable(GlobalSceneGraph().root())->insert(pEDoor2);
571 // ResetCurrentTexture();
574 //-----------------------------------------------------------------------------------
575 //-----------------------------------------------------------------------------------
577 void MakeBevel(vec3_t vMin, vec3_t vMax)
579 NodeSmartReference patch(GlobalPatchCreator().createPatch());
580 PatchControlMatrix matrix = GlobalPatchCreator().Patch_getControlPoints(patch);
582 GlobalPatchCreator().Patch_setShader(patch, "textures/common/caulk");
583 GlobalPatchCreator().Patch_resize(patch, 3, 3);
585 vec3_t x_3, y_3, z_3;
586 x_3[0] = vMin[0]; x_3[1] = vMin[0]; x_3[2] = vMax[0];
587 y_3[0] = vMin[1]; y_3[1] = vMax[1]; y_3[2] = vMax[1];
588 z_3[0] = vMin[2]; z_3[1] = (vMax[2] + vMin[2])/2; z_3[2] = vMax[2];
590 /* x_3[0] = 0; x_3[1] = 0; x_3[2] = 64;
591 y_3[0] = 0; y_3[1] = 64; y_3[2] = 64;
592 z_3[0] = 0; z_3[1] = 32; z_3[2] = 64;*/
594 for(int i = 0; i < 3; i++)
596 for(int j = 0; j < 3; j++)
598 matrix(i, j).m_vertex[0] = x_3[i];
599 matrix(i, j).m_vertex[1] = y_3[i];
600 matrix(i, j).m_vertex[2] = z_3[j];
604 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(patch);
607 void BuildCornerStairs(vec3_t vMin, vec3_t vMax, int nSteps, const char* mainTexture, const char* riserTex)
609 vec3_t* topPoints = new vec3_t[nSteps+1];
610 vec3_t* botPoints = new vec3_t[nSteps+1];
612 bool bFacesUse[6] = {true, true, false, true, false, false};
615 VectorCopy(vMin, centre);
618 int height = (int)(vMax[2] - vMin[2]) / nSteps;
621 VectorCopy(vMax, vTop);
622 VectorCopy(vMin, vBot);
623 vTop[2] = vMin[2] + height;
626 for(i = 0; i <= nSteps; i++)
628 VectorCopy(centre, topPoints[i]);
629 VectorCopy(centre, botPoints[i]);
631 topPoints[i][2] = vMax[2];
632 botPoints[i][2] = vMin[2];
634 topPoints[i][0] -= 10 * sinf( Q_PI * i / ( 2 * nSteps ) );
635 topPoints[i][1] += 10 * cosf( Q_PI * i / ( 2 * nSteps ) );
637 botPoints[i][0] = topPoints[i][0];
638 botPoints[i][1] = topPoints[i][1];
642 for(int j = 0; j < 3; j++)
643 VectorCopy(topPoints[j], tp[j]);
645 for(i = 0; i < nSteps; i++)
647 scene::Node& brush = Build_Get_BoundingCube_Selective(vBot, vTop, "textures/common/caulk", bFacesUse);
649 for(int j = 0; j < 3; j++)
652 AddFaceWithTexture(brush, tp[2], tp[1], tp[0], mainTexture, false);
654 AddFaceWithTexture(brush, centre, botPoints[i+1], topPoints[i+1], "textures/common/caulk", false);
655 AddFaceWithTexture(brush, centre, topPoints[i], botPoints[i], riserTex, false);
657 Node_getTraversable(GlobalRadiant().getMapWorldEntity())->insert(brush);
668 MakeBevel(vMin, vMax);