PMESH.CPP 116 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. //
  19. // Preliminary patch stuff
  20. //
  21. //
  22. #include "stdafx.h"
  23. #include "qe3.h"
  24. #include "DialogInfo.h"
  25. #include "CapDialog.h"
  26. // externs
  27. extern void MemFile_fprintf(CMemFile* pMemFile, const char* pText, ...);
  28. extern face_t *Face_Alloc( void );
  29. void _Write3DMatrix (FILE *f, int y, int x, int z, float *m);
  30. void _Write3DMatrix (CMemFile *f, int y, int x, int z, float *m);
  31. #define CBLOCK_SUBDIVISIONS 6
  32. patchMesh_t* MakeNewPatch()
  33. {
  34. patchMesh_t *pm = reinterpret_cast<patchMesh_t*>(qmalloc(sizeof(patchMesh_t)));
  35. if (g_qeglobals.bSurfacePropertiesPlugin)
  36. {
  37. pm->pData = static_cast<void *>( g_SurfaceTable.m_pfnPatchAlloc( pm ) );
  38. }
  39. return pm;
  40. }
  41. // FIXME: this needs to be dynamic
  42. //#define MAX_PATCH_MESHES 4096
  43. //patchMesh_t patchMeshes[MAX_PATCH_MESHES];
  44. //int numPatchMeshes = 0;
  45. // used for a save spot
  46. patchMesh_t patchSave;
  47. // Tracks the selected patch for point manipulation/update. FIXME: Need to revert back to a generalized
  48. // brush approach
  49. //--int g_nSelectedPatch = -1;
  50. // HACK: for tracking which view generated the click
  51. // as we dont want to deselect a point on a same point
  52. // click if it is from a different view
  53. int g_nPatchClickedView = -1;
  54. bool g_bSameView = false;
  55. // globals
  56. bool g_bPatchShowBounds = true;
  57. bool g_bPatchWireFrame = false;
  58. bool g_bPatchWeld = true;
  59. bool g_bPatchDrillDown = true;
  60. bool g_bPatchInsertMode = false;
  61. bool g_bPatchBendMode = false;
  62. int g_nPatchBendState = -1;
  63. int g_nPatchInsertState = -1;
  64. int g_nBendOriginIndex = 0;
  65. vec3_t g_vBendOrigin;
  66. bool g_bPatchAxisOnRow = true;
  67. int g_nPatchAxisIndex = 0;
  68. bool g_bPatchLowerEdge = true;
  69. // BEND states
  70. enum
  71. {
  72. BEND_SELECT_ROTATION = 0,
  73. BEND_SELECT_ORIGIN,
  74. BEND_SELECT_EDGE,
  75. BEND_BENDIT,
  76. BEND_STATE_COUNT
  77. };
  78. const char *g_pBendStateMsg[] =
  79. {
  80. "Use TAB to cycle through available bend axis. Press ENTER when the desired one is highlighted.",
  81. "Use TAB to cycle through available rotation axis. This will LOCK around that point. You may also use Shift + Middle Click to select an arbitrary point. Press ENTER when the desired one is highlighted",
  82. "Use TAB to choose which side to bend. Press ENTER when the desired one is highlighted.",
  83. "Use the MOUSE to bend the patch. It uses the same ui rules as Free Rotation. Press ENTER to accept the bend, press ESC to abandon it and exit Bend mode",
  84. ""
  85. };
  86. // INSERT states
  87. enum
  88. {
  89. INSERT_SELECT_EDGE = 0,
  90. INSERT_STATE_COUNT
  91. };
  92. const char* g_pInsertStateMsg[] =
  93. {
  94. "Use TAB to cycle through available rows/columns for insertion/deletion. Press INS to insert at the highlight, DEL to remove the pair"
  95. };
  96. float *g_InversePoints[1024];
  97. const float fFullBright = 1.0;
  98. const float fLowerLimit = .50;
  99. const float fDec = .05;
  100. void _SetColor(face_t* f, float fColor[3])
  101. {
  102. return;
  103. fColor[0] = f->d_color[0];
  104. fColor[1] = f->d_color[1];
  105. fColor[2] = f->d_color[2];
  106. qglColor3fv(fColor);
  107. }
  108. void _DecColor(float fColor[3])
  109. {
  110. return;
  111. fColor[0] -= fDec;
  112. fColor[1] -= fDec ;
  113. fColor[2] -= fDec;
  114. for (int i = 0; i < 3; i++)
  115. {
  116. if (fColor[i] <= fLowerLimit)
  117. {
  118. fColor[0] = fFullBright;
  119. fColor[1] = fFullBright;
  120. fColor[2] = fFullBright;
  121. break;
  122. }
  123. }
  124. qglColor3fv(fColor);
  125. }
  126. vec_t __VectorNormalize (vec3_t in, vec3_t out)
  127. {
  128. vec_t length, ilength;
  129. length = sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
  130. if (length == 0)
  131. {
  132. VectorClear (out);
  133. return 0;
  134. }
  135. ilength = 1.0/length;
  136. out[0] = in[0]*ilength;
  137. out[1] = in[1]*ilength;
  138. out[2] = in[2]*ilength;
  139. return length;
  140. }
  141. void Patch_SetType(patchMesh_t *p, int nType)
  142. {
  143. p->type = (p->type & PATCH_STYLEMASK) | nType;
  144. }
  145. void Patch_SetStyle(patchMesh_t *p, int nStyle)
  146. {
  147. p->type = (p->type & PATCH_TYPEMASK) | nStyle;
  148. }
  149. /*
  150. ==================
  151. Patch_MemorySize
  152. ==================
  153. */
  154. int Patch_MemorySize(patchMesh_t *p)
  155. {
  156. return _msize(p);
  157. }
  158. /*
  159. ===============
  160. InterpolateInteriorPoints
  161. ===============
  162. */
  163. void InterpolateInteriorPoints( patchMesh_t *p )
  164. {
  165. int i, j, k;
  166. int next, prev;
  167. for ( i = 0 ; i < p->width ; i += 2 )
  168. {
  169. next = ( i == p->width - 1 ) ? 1 : ( i + 1 ) % p->width;
  170. prev = ( i == 0 ) ? p->width - 2 : i - 1;
  171. #if 0
  172. if ( i == 0 )
  173. {
  174. next = ( i + 1 ) % p->width;
  175. prev = p->width - 2; // joined wrap case
  176. }
  177. else if ( i == p->width - 1 )
  178. {
  179. next = 1;
  180. prev = i - 1;
  181. }
  182. else
  183. {
  184. next = ( i + 1 ) % p->width;
  185. prev = i - 1;
  186. }
  187. #endif
  188. for ( j = 0 ; j < p->height ; j++ )
  189. {
  190. for ( k = 0 ; k < 3 ; k++ )
  191. {
  192. p->ctrl[i][j].xyz[k] = ( p->ctrl[next][j].xyz[k] + p->ctrl[prev][j].xyz[k] ) * 0.5;
  193. }
  194. }
  195. }
  196. }
  197. /*
  198. =================
  199. MakeMeshNormals
  200. =================
  201. */
  202. int neighbors[8][2] = {
  203. {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}
  204. };
  205. void Patch_MeshNormals(patchMesh_t *in )
  206. {
  207. int i, j, k, dist;
  208. vec3_t normal;
  209. vec3_t sum;
  210. int count;
  211. vec3_t base;
  212. vec3_t delta;
  213. int x, y;
  214. drawVert_t *dv;
  215. vec3_t around[8], temp;
  216. qboolean good[8];
  217. qboolean wrapWidth, wrapHeight;
  218. float len;
  219. wrapWidth = false;
  220. for ( i = 0 ; i < in->height ; i++ )
  221. {
  222. VectorSubtract( in->ctrl[0][i].xyz,
  223. in->ctrl[in->width-1][i].xyz, delta );
  224. len = VectorLength( delta );
  225. if ( len > 1.0 )
  226. {
  227. break;
  228. }
  229. }
  230. if ( i == in->height )
  231. {
  232. wrapWidth = true;
  233. }
  234. wrapHeight = false;
  235. for ( i = 0 ; i < in->width ; i++ )
  236. {
  237. VectorSubtract( in->ctrl[i][0].xyz,
  238. in->ctrl[i][in->height-1].xyz, delta );
  239. len = VectorLength( delta );
  240. if ( len > 1.0 )
  241. {
  242. break;
  243. }
  244. }
  245. if ( i == in->width)
  246. {
  247. wrapHeight = true;
  248. }
  249. for ( i = 0 ; i < in->width ; i++ )
  250. {
  251. for ( j = 0 ; j < in->height ; j++ )
  252. {
  253. count = 0;
  254. //--dv = reinterpret_cast<drawVert_t*>(in.ctrl[j*in.width+i]);
  255. dv = &in->ctrl[i][j];
  256. VectorCopy( dv->xyz, base );
  257. for ( k = 0 ; k < 8 ; k++ )
  258. {
  259. VectorClear( around[k] );
  260. good[k] = false;
  261. for ( dist = 1 ; dist <= 3 ; dist++ )
  262. {
  263. x = i + neighbors[k][0] * dist;
  264. y = j + neighbors[k][1] * dist;
  265. if ( wrapWidth )
  266. {
  267. if ( x < 0 )
  268. {
  269. x = in->width - 1 + x;
  270. }
  271. else if ( x >= in->width )
  272. {
  273. x = 1 + x - in->width;
  274. }
  275. }
  276. if ( wrapHeight )
  277. {
  278. if ( y < 0 )
  279. {
  280. y = in->height - 1 + y;
  281. }
  282. else if ( y >= in->height )
  283. {
  284. y = 1 + y - in->height;
  285. }
  286. }
  287. if ( x < 0 || x >= in->width || y < 0 || y >= in->height )
  288. {
  289. break; // edge of patch
  290. }
  291. //--VectorSubtract( in.ctrl[y*in.width+x]->xyz, base, temp );
  292. VectorSubtract( in->ctrl[x][y].xyz, base, temp );
  293. if ( __VectorNormalize( temp, temp ) == 0 )
  294. {
  295. continue; // degenerate edge, get more dist
  296. }
  297. else
  298. {
  299. good[k] = true;
  300. VectorCopy( temp, around[k] );
  301. break; // good edge
  302. }
  303. }
  304. }
  305. VectorClear( sum );
  306. for ( k = 0 ; k < 8 ; k++ )
  307. {
  308. if ( !good[k] || !good[(k+1)&7] )
  309. {
  310. continue; // didn't get two points
  311. }
  312. CrossProduct( around[(k+1)&7], around[k], normal );
  313. if ( __VectorNormalize( normal, normal ) == 0 )
  314. {
  315. continue;
  316. }
  317. VectorAdd( normal, sum, sum );
  318. count++;
  319. }
  320. if ( count == 0 )
  321. {
  322. //printf("bad normal\n");
  323. count = 1;
  324. //continue;
  325. }
  326. __VectorNormalize( sum, dv->normal );
  327. }
  328. }
  329. }
  330. /*
  331. ==================
  332. Patch_CalcBounds
  333. ==================
  334. */
  335. void Patch_CalcBounds(patchMesh_t *p, vec3_t& vMin, vec3_t& vMax)
  336. {
  337. vMin[0] = vMin[1] = vMin[2] = 99999;
  338. vMax[0] = vMax[1] = vMax[2] = -99999;
  339. p->bDirty = true;
  340. for (int w = 0; w < p->width; w++)
  341. {
  342. for (int h = 0; h < p->height; h++)
  343. {
  344. for (int j = 0; j < 3; j++)
  345. {
  346. float f = p->ctrl[w][h].xyz[j];
  347. if (f < vMin[j])
  348. vMin[j] = f;
  349. if (f > vMax[j])
  350. vMax[j] = f;
  351. }
  352. }
  353. }
  354. }
  355. /*
  356. ==================
  357. Brush_RebuildBrush
  358. ==================
  359. */
  360. void Brush_RebuildBrush(brush_t *b, vec3_t vMins, vec3_t vMaxs)
  361. {
  362. //
  363. // Total hack job
  364. // Rebuilds a brush
  365. int i, j;
  366. face_t *f, *next;
  367. vec3_t pts[4][2];
  368. texdef_t texdef;
  369. // free faces
  370. for (j = 0; j < 3; j++)
  371. {
  372. if ((int)vMins[j] == (int)vMaxs[j])
  373. {
  374. vMins[j] -= 4;
  375. vMaxs[j] += 4;
  376. }
  377. }
  378. for (f=b->brush_faces ; f ; f=next)
  379. {
  380. next = f->next;
  381. if (f)
  382. texdef = f->texdef;
  383. Face_Free( f );
  384. }
  385. b->brush_faces = NULL;
  386. // left the last face so we can use its texdef
  387. for (i=0 ; i<3 ; i++)
  388. if (vMaxs[i] < vMins[i])
  389. Error ("Brush_RebuildBrush: backwards");
  390. pts[0][0][0] = vMins[0];
  391. pts[0][0][1] = vMins[1];
  392. pts[1][0][0] = vMins[0];
  393. pts[1][0][1] = vMaxs[1];
  394. pts[2][0][0] = vMaxs[0];
  395. pts[2][0][1] = vMaxs[1];
  396. pts[3][0][0] = vMaxs[0];
  397. pts[3][0][1] = vMins[1];
  398. for (i=0 ; i<4 ; i++)
  399. {
  400. pts[i][0][2] = vMins[2];
  401. pts[i][1][0] = pts[i][0][0];
  402. pts[i][1][1] = pts[i][0][1];
  403. pts[i][1][2] = vMaxs[2];
  404. }
  405. for (i=0 ; i<4 ; i++)
  406. {
  407. f = Face_Alloc();
  408. f->texdef = texdef;
  409. f->texdef.flags &= ~SURF_KEEP;
  410. f->texdef.contents &= ~CONTENTS_KEEP;
  411. if ( b->patchBrush )
  412. {
  413. f->texdef.flags |= SURF_PATCH;
  414. }
  415. f->next = b->brush_faces;
  416. b->brush_faces = f;
  417. j = (i+1)%4;
  418. VectorCopy (pts[j][1], f->planepts[0]);
  419. VectorCopy (pts[i][1], f->planepts[1]);
  420. VectorCopy (pts[i][0], f->planepts[2]);
  421. }
  422. f = Face_Alloc();
  423. f->texdef = texdef;
  424. f->texdef.flags &= ~SURF_KEEP;
  425. f->texdef.contents &= ~CONTENTS_KEEP;
  426. if ( b->patchBrush )
  427. {
  428. f->texdef.flags |= SURF_PATCH;
  429. }
  430. f->next = b->brush_faces;
  431. b->brush_faces = f;
  432. VectorCopy (pts[0][1], f->planepts[0]);
  433. VectorCopy (pts[1][1], f->planepts[1]);
  434. VectorCopy (pts[2][1], f->planepts[2]);
  435. f = Face_Alloc();
  436. f->texdef = texdef;
  437. f->texdef.flags &= ~SURF_KEEP;
  438. f->texdef.contents &= ~CONTENTS_KEEP;
  439. if ( b->patchBrush )
  440. {
  441. f->texdef.flags |= SURF_PATCH;
  442. }
  443. f->next = b->brush_faces;
  444. b->brush_faces = f;
  445. VectorCopy (pts[2][0], f->planepts[0]);
  446. VectorCopy (pts[1][0], f->planepts[1]);
  447. VectorCopy (pts[0][0], f->planepts[2]);
  448. Brush_Build(b);
  449. }
  450. void WINAPI Patch_Rebuild(patchMesh_t *p)
  451. {
  452. vec3_t vMin, vMax;
  453. Patch_CalcBounds(p, vMin, vMax);
  454. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  455. p->bDirty = true;
  456. }
  457. /*
  458. ==================
  459. AddBrushForPatch
  460. ==================
  461. adds a patch brush and ties it to this patch id
  462. */
  463. brush_t* AddBrushForPatch(patchMesh_t *pm, bool bLinkToWorld )
  464. {
  465. // find the farthest points in x,y,z
  466. vec3_t vMin, vMax;
  467. Patch_CalcBounds(pm, vMin, vMax);
  468. for (int j = 0; j < 3; j++)
  469. {
  470. if (vMin[j] == vMax[j])
  471. {
  472. vMin[j] -= 4;
  473. vMax[j] += 4;
  474. }
  475. }
  476. brush_t *b = Brush_Create(vMin, vMax, &g_qeglobals.d_texturewin.texdef);
  477. face_t *f;
  478. for (f=b->brush_faces ; f ; f=f->next)
  479. {
  480. f->texdef.flags |= SURF_PATCH;
  481. }
  482. // FIXME: this entire type of linkage needs to be fixed
  483. b->pPatch = pm;
  484. pm->pSymbiot = b;
  485. pm->bSelected = false;
  486. pm->bOverlay = false;
  487. pm->bDirty = true;
  488. pm->nListID = -1;
  489. if (bLinkToWorld)
  490. {
  491. Brush_AddToList (b, &active_brushes);
  492. Entity_LinkBrush (world_entity, b);
  493. Brush_Build(b);
  494. }
  495. return b;
  496. }
  497. void Patch_SetPointIntensities(int n)
  498. {
  499. #if 0
  500. patchMesh_t *p = patchMeshes[n];
  501. for (int i = 0; i < p->width; i++)
  502. {
  503. for (int j = 0; j < p->height; j++)
  504. {
  505. }
  506. }
  507. #endif
  508. }
  509. // very approximate widths and heights
  510. /*
  511. ==================
  512. Patch_Width
  513. ==================
  514. */
  515. float Patch_Width(patchMesh_t *p)
  516. {
  517. float f = 0;
  518. for (int i = 0; i < p->width-1; i++)
  519. {
  520. vec3_t vTemp;
  521. VectorSubtract(p->ctrl[i][0].xyz, p->ctrl[i+1][0].xyz, vTemp);
  522. f += VectorLength(vTemp);
  523. }
  524. return f;
  525. }
  526. float Patch_WidthDistanceTo(patchMesh_t *p, int j)
  527. {
  528. float f = 0;
  529. for (int i = 0; i < j; i++)
  530. {
  531. vec3_t vTemp;
  532. VectorSubtract(p->ctrl[i][0].xyz, p->ctrl[i+1][0].xyz, vTemp);
  533. f += VectorLength(vTemp);
  534. }
  535. return f;
  536. }
  537. /*
  538. ==================
  539. Patch_Height
  540. ==================
  541. */
  542. float Patch_Height(patchMesh_t *p)
  543. {
  544. float f = 0;
  545. for (int i = 0; i < p->height-1; i++)
  546. {
  547. vec3_t vTemp;
  548. VectorSubtract(p->ctrl[0][i].xyz, p->ctrl[0][i+1].xyz, vTemp);
  549. f += VectorLength(vTemp);
  550. }
  551. return f;
  552. }
  553. float Patch_HeightDistanceTo(patchMesh_t *p, int j)
  554. {
  555. float f = 0;
  556. for (int i = 0; i < j; i++)
  557. {
  558. vec3_t vTemp;
  559. VectorSubtract(p->ctrl[0][i].xyz, p->ctrl[0][i+1].xyz, vTemp);
  560. f += VectorLength(vTemp);
  561. }
  562. return f;
  563. }
  564. /*
  565. ==================
  566. Patch_Naturalize
  567. ==================
  568. texture = TotalTexture * LengthToThisControlPoint / TotalControlPointLength
  569. dist( this control point to first control point ) / dist ( last control pt to first)
  570. */
  571. void Patch_Naturalize(patchMesh_t *p)
  572. {
  573. int nWidth = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? p->d_texture->width * 0.5 : p->d_texture->width;
  574. int nHeight = (g_PrefsDlg.m_bHiColorTextures == TRUE) ? p->d_texture->height * 0.5 : p->d_texture->height;
  575. float fPWidth = Patch_Width(p);
  576. float fPHeight = Patch_Height(p);
  577. float xAccum = 0;
  578. for ( int i = 0 ; i < p->width ; i++ )
  579. {
  580. float yAccum = 0;
  581. for ( int j = 0 ; j < p->height ; j++ )
  582. {
  583. p->ctrl[i][j].st[0] = (fPWidth / nWidth) * xAccum / fPWidth;
  584. p->ctrl[i][j].st[1] = (fPHeight / nHeight) * yAccum / fPHeight;
  585. yAccum = Patch_HeightDistanceTo(p,j+1);
  586. //p->ctrl[i][j][3] = (fPWidth / nWidth) * (float)i / (p->width - 1);
  587. //p->ctrl[i][j][4] = (fPHeight/ nHeight) * (float)j / (p->height - 1);
  588. }
  589. xAccum = Patch_WidthDistanceTo(p,i+1);
  590. }
  591. p->bDirty = true;
  592. }
  593. /*
  594. if (bIBevel)
  595. {
  596. VectorCopy(p->ctrl[1][0], p->ctrl[1][1]);
  597. }
  598. if (bIEndcap)
  599. {
  600. VectorCopy(p->ctrl[3][0], p->ctrl[4][1]);
  601. VectorCopy(p->ctrl[2][0], p->ctrl[3][1]);
  602. VectorCopy(p->ctrl[2][0], p->ctrl[2][1]);
  603. VectorCopy(p->ctrl[2][0], p->ctrl[1][1]);
  604. VectorCopy(p->ctrl[1][0], p->ctrl[0][1]);
  605. VectorCopy(p->ctrl[1][0], p->ctrl[0][2]);
  606. VectorCopy(p->ctrl[1][0], p->ctrl[1][2]);
  607. VectorCopy(p->ctrl[2][0], p->ctrl[2][2]);
  608. VectorCopy(p->ctrl[3][0], p->ctrl[3][2]);
  609. VectorCopy(p->ctrl[3][0], p->ctrl[4][2]);
  610. }
  611. */
  612. int Index3By[][2] =
  613. {
  614. {0,0},
  615. {1,0},
  616. {2,0},
  617. {2,1},
  618. {2,2},
  619. {1,2},
  620. {0,2},
  621. {0,1},
  622. {0,0},
  623. {0,0},
  624. {0,0},
  625. {0,0},
  626. {0,0},
  627. {0,0},
  628. {0,0}
  629. };
  630. int Index5By[][2] =
  631. {
  632. {0,0},
  633. {1,0},
  634. {2,0},
  635. {3,0},
  636. {4,0},
  637. {4,1},
  638. {4,2},
  639. {4,3},
  640. {4,4},
  641. {3,4},
  642. {2,4},
  643. {1,4},
  644. {0,4},
  645. {0,3},
  646. {0,2},
  647. {0,1}
  648. };
  649. int Interior3By[][2] =
  650. {
  651. {1,1}
  652. };
  653. int Interior5By[][2] =
  654. {
  655. {1,1},
  656. {2,1},
  657. {3,1},
  658. {1,2},
  659. {2,2},
  660. {3,2},
  661. {1,3},
  662. {2,3},
  663. {3,3}
  664. };
  665. int Interior3ByCount = sizeof(Interior3By) / sizeof(int[2]);
  666. int Interior5ByCount = sizeof(Interior5By) / sizeof(int[2]);
  667. face_t* Patch_GetAxisFace(patchMesh_t *p)
  668. {
  669. face_t *f = NULL;
  670. vec3_t vTemp;
  671. brush_t *b = p->pSymbiot;
  672. for (f = b->brush_faces ; f ; f = f->next)
  673. {
  674. VectorSubtract(f->face_winding->points[1], f->face_winding->points[0], vTemp);
  675. int nScore = 0;
  676. // default edge faces on caps are 8 high so
  677. // as soon as we hit one that is bigger it should be on the right axis
  678. for (int j = 0; j < 3; j++)
  679. {
  680. if (vTemp[j] > 8)
  681. nScore++;
  682. }
  683. if (nScore > 0)
  684. break;
  685. }
  686. if (f == NULL)
  687. f = b->brush_faces;
  688. return f;
  689. }
  690. int g_nFaceCycle = 0;
  691. face_t* nextFace(patchMesh_t *p)
  692. {
  693. brush_t *b = p->pSymbiot;
  694. face_t *f = NULL;
  695. int n = 0;
  696. for (f = b->brush_faces ; f && n <= g_nFaceCycle; f = f->next)
  697. {
  698. n++;
  699. }
  700. g_nFaceCycle++;
  701. if (g_nFaceCycle > 5)
  702. {
  703. g_nFaceCycle =0;
  704. f = b->brush_faces;
  705. }
  706. return f;
  707. }
  708. extern void EmitTextureCoordinates ( float *xyzst, qtexture_t *q, face_t *f);
  709. void Patch_CapTexture(patchMesh_t *p, bool bFaceCycle = false)
  710. {
  711. Patch_MeshNormals(p);
  712. face_t *f = (bFaceCycle) ? nextFace(p) : Patch_GetAxisFace(p);
  713. vec3_t vSave;
  714. VectorCopy(f->plane.normal, vSave);
  715. float fRotate = f->texdef.rotate;
  716. f->texdef.rotate = 0;
  717. float fScale[2];
  718. fScale[0] = f->texdef.scale[0];
  719. fScale[1] = f->texdef.scale[1];
  720. f->texdef.scale[0] = 0.5;
  721. f->texdef.scale[1] = 0.5;
  722. float fShift[2];
  723. fShift[0] = f->texdef.shift[0];
  724. fShift[1] = f->texdef.shift[1];
  725. f->texdef.shift[0] = 0;
  726. f->texdef.shift[1] = 0;
  727. for (int i = 0; i < p->width; i++)
  728. {
  729. for (int j = 0; j < p->height; j++)
  730. {
  731. if (!bFaceCycle)
  732. {
  733. VectorCopy(p->ctrl[i][j].normal, f->plane.normal);
  734. }
  735. EmitTextureCoordinates( p->ctrl[i][j].xyz, f->d_texture, f);
  736. }
  737. }
  738. VectorCopy(vSave, f->plane.normal);
  739. f->texdef.rotate = fRotate;
  740. f->texdef.scale[0] = fScale[0];
  741. f->texdef.scale[1] = fScale[1];
  742. f->texdef.shift[0] = fShift[0];
  743. f->texdef.shift[1] = fShift[1];
  744. p->bDirty = true;
  745. }
  746. void FillPatch(patchMesh_t *p, vec3_t v)
  747. {
  748. for (int i = 0; i < p->width; i++)
  749. {
  750. for (int j = 0; j < p->height; j++)
  751. {
  752. VectorCopy(v, p->ctrl[i][j].xyz);
  753. }
  754. }
  755. }
  756. brush_t* Cap(patchMesh_t *pParent, bool bByColumn, bool bFirst)
  757. {
  758. brush_t *b;
  759. patchMesh_t *p;
  760. vec3_t vMin, vMax;
  761. int i, j;
  762. bool bSmall = true;
  763. // make a generic patch
  764. if (pParent->width <= 9)
  765. {
  766. b = Patch_GenericMesh(3, 3, 2, false);
  767. }
  768. else
  769. {
  770. b = Patch_GenericMesh(5, 5, 2, false);
  771. bSmall = false;
  772. }
  773. if (!b)
  774. {
  775. Sys_Printf("Unable to cap. You may need to ungroup the patch.\n");
  776. return NULL;
  777. }
  778. p = b->pPatch;
  779. p->type |= PATCH_CAP;
  780. vMin[0] = vMin[1] = vMin[2] = 9999;
  781. vMax[0] = vMax[1] = vMax[2] = -9999;
  782. // we seam the column edge, FIXME: this might need to be able to seem either edge
  783. //
  784. int nSize = (bByColumn) ? pParent->width : pParent->height;
  785. int nIndex = (bFirst) ? 0 : (bByColumn) ? pParent->height-1 : pParent->width-1;
  786. FillPatch(p, pParent->ctrl[0][nIndex].xyz);
  787. for (i = 0; i < nSize; i++)
  788. {
  789. if (bByColumn)
  790. {
  791. if (bSmall)
  792. {
  793. VectorCopy(pParent->ctrl[i][nIndex].xyz, p->ctrl[Index3By[i][0]][Index3By[i][1]].xyz);
  794. }
  795. else
  796. {
  797. VectorCopy(pParent->ctrl[i][nIndex].xyz, p->ctrl[Index5By[i][0]][Index5By[i][1]].xyz);
  798. }
  799. }
  800. else
  801. {
  802. if (bSmall)
  803. {
  804. VectorCopy(pParent->ctrl[nIndex][i].xyz, p->ctrl[Index3By[i][0]][Index3By[i][1]].xyz);
  805. }
  806. else
  807. {
  808. VectorCopy(pParent->ctrl[nIndex][i].xyz, p->ctrl[Index5By[i][0]][Index5By[i][1]].xyz);
  809. }
  810. }
  811. for (j = 0; j < 3; j++)
  812. {
  813. float f = (bSmall) ? p->ctrl[Index3By[i][0]][Index3By[i][1]].xyz[j] : p->ctrl[Index5By[i][0]][Index5By[i][1]].xyz[j];
  814. if (f < vMin[j])
  815. vMin[j] = f;
  816. if (f > vMax[j])
  817. vMax[j] = f;
  818. }
  819. }
  820. vec3_t vTemp;
  821. for (j = 0; j < 3; j++)
  822. {
  823. vTemp[j] = vMin[j] + abs((vMax[j] - vMin[j]) * 0.5);
  824. }
  825. int nCount = (bSmall) ? Interior3ByCount : Interior5ByCount;
  826. for (j = 0; j < nCount; j++)
  827. {
  828. if (bSmall)
  829. {
  830. VectorCopy(vTemp, p->ctrl[Interior3By[j][0]][Interior3By[j][1]].xyz);
  831. }
  832. else
  833. {
  834. VectorCopy(vTemp, p->ctrl[Interior5By[j][0]][Interior5By[j][1]].xyz);
  835. }
  836. }
  837. if (bFirst)
  838. {
  839. drawVert_t vertTemp;
  840. for (i = 0; i < p->width; i++)
  841. {
  842. for (j = 0; j < p->height / 2; j++)
  843. {
  844. memcpy(&vertTemp, &p->ctrl[i][p->height - 1- j], sizeof (drawVert_t));
  845. memcpy(&p->ctrl[i][p->height - 1 - j], &p->ctrl[i][j], sizeof(drawVert_t));
  846. memcpy(&p->ctrl[i][j], &vertTemp, sizeof(drawVert_t));
  847. }
  848. }
  849. }
  850. Patch_Rebuild(p);
  851. Patch_CapTexture(p);
  852. return p->pSymbiot;
  853. }
  854. brush_t* CapSpecial(patchMesh_t *pParent, int nType, bool bFirst)
  855. {
  856. brush_t *b;
  857. patchMesh_t *p;
  858. vec3_t vMin, vMax, vTemp;
  859. int i, j;
  860. if (nType == CCapDialog::IENDCAP)
  861. b = Patch_GenericMesh(5, 3, 2, false);
  862. else
  863. b = Patch_GenericMesh(3, 3, 2, false);
  864. if (!b)
  865. {
  866. Sys_Printf("Unable to cap. Make sure you ungroup before re-capping.");
  867. return NULL;
  868. }
  869. p = b->pPatch;
  870. p->type |= PATCH_CAP;
  871. vMin[0] = vMin[1] = vMin[2] = 9999;
  872. vMax[0] = vMax[1] = vMax[2] = -9999;
  873. int nSize = pParent->width;
  874. int nIndex = (bFirst) ? 0 : pParent->height-1;
  875. // parent bounds are used for some things
  876. Patch_CalcBounds(pParent, vMin, vMax);
  877. for (j = 0; j < 3; j++)
  878. {
  879. vTemp[j] = vMin[j] + abs((vMax[j] - vMin[j]) * 0.5);
  880. }
  881. if (nType == CCapDialog::IBEVEL)
  882. {
  883. VectorCopy(pParent->ctrl[0][nIndex].xyz, p->ctrl[0][0].xyz);
  884. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[0][2].xyz);
  885. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[0][1].xyz);
  886. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[2][2].xyz);
  887. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][0].xyz);
  888. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][1].xyz);
  889. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][2].xyz);
  890. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[2][0].xyz);
  891. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[2][1].xyz);
  892. }
  893. else if (nType == CCapDialog::BEVEL)
  894. {
  895. vec3_t p1, p2, p3, p4, temp, dir;
  896. VectorCopy(pParent->ctrl[0][nIndex].xyz, p3);
  897. VectorCopy(pParent->ctrl[1][nIndex].xyz, p1);
  898. VectorCopy(pParent->ctrl[2][nIndex].xyz, p2);
  899. VectorSubtract(p3, p2, dir);
  900. VectorNormalize(dir);
  901. VectorSubtract(p1, p2, temp);
  902. vec_t dist = _DotProduct(temp, dir);
  903. VectorScale(dir, dist, temp);
  904. VectorAdd(p2, temp, temp);
  905. VectorSubtract(temp, p1, temp);
  906. VectorScale(temp, 2, temp);
  907. VectorAdd(p1, temp, p4);
  908. VectorCopy(p4, p->ctrl[0][0].xyz);
  909. VectorCopy(p4, p->ctrl[1][0].xyz);
  910. VectorCopy(p4, p->ctrl[0][1].xyz);
  911. VectorCopy(p4, p->ctrl[1][1].xyz);
  912. VectorCopy(p4, p->ctrl[0][2].xyz);
  913. VectorCopy(p4, p->ctrl[1][2].xyz);
  914. VectorCopy(p3, p->ctrl[2][0].xyz);
  915. VectorCopy(p1, p->ctrl[2][1].xyz);
  916. VectorCopy(p2, p->ctrl[2][2].xyz);
  917. }
  918. else if (nType == CCapDialog::ENDCAP)
  919. {
  920. VectorAdd(pParent->ctrl[4][nIndex].xyz, pParent->ctrl[0][nIndex].xyz, vTemp);
  921. VectorScale(vTemp, 0.5, vTemp);
  922. VectorCopy(pParent->ctrl[0][nIndex].xyz, p->ctrl[0][0].xyz);
  923. VectorCopy(vTemp, p->ctrl[1][0].xyz);
  924. VectorCopy(pParent->ctrl[4][nIndex].xyz, p->ctrl[2][0].xyz);
  925. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[0][2].xyz);
  926. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[1][2].xyz);
  927. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[2][2].xyz);
  928. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[1][1].xyz);
  929. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[0][1].xyz);
  930. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[2][1].xyz);
  931. }
  932. else
  933. {
  934. VectorCopy(pParent->ctrl[0][nIndex].xyz, p->ctrl[0][0].xyz);
  935. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][0].xyz);
  936. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[2][0].xyz);
  937. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[3][0].xyz);
  938. VectorCopy(pParent->ctrl[4][nIndex].xyz, p->ctrl[4][0].xyz);
  939. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[0][1].xyz);
  940. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][1].xyz);
  941. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[2][1].xyz);
  942. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[3][1].xyz);
  943. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[4][1].xyz);
  944. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[0][2].xyz);
  945. VectorCopy(pParent->ctrl[1][nIndex].xyz, p->ctrl[1][2].xyz);
  946. VectorCopy(pParent->ctrl[2][nIndex].xyz, p->ctrl[2][2].xyz);
  947. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[3][2].xyz);
  948. VectorCopy(pParent->ctrl[3][nIndex].xyz, p->ctrl[4][2].xyz);
  949. }
  950. bool bEndCap = (nType == CCapDialog::ENDCAP || nType == CCapDialog::IENDCAP);
  951. if ((!bFirst && !bEndCap) || (bFirst && bEndCap))
  952. {
  953. drawVert_t vertTemp;
  954. for (i = 0; i < p->width; i++)
  955. {
  956. for (j = 0; j < p->height / 2; j++)
  957. {
  958. memcpy(&vertTemp, &p->ctrl[i][p->height - 1- j], sizeof (drawVert_t));
  959. memcpy(&p->ctrl[i][p->height - 1 - j], &p->ctrl[i][j], sizeof(drawVert_t));
  960. memcpy(&p->ctrl[i][j], &vertTemp, sizeof(drawVert_t));
  961. }
  962. }
  963. }
  964. //--Patch_CalcBounds(p, vMin, vMax);
  965. //--Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  966. Patch_Rebuild(p);
  967. Patch_CapTexture(p);
  968. return p->pSymbiot;
  969. }
  970. void Patch_CapCurrent(bool bInvertedBevel, bool bInvertedEndcap)
  971. {
  972. patchMesh_t *pParent = NULL;
  973. brush_t *b[4];
  974. brush_t *pCap = NULL;
  975. b[0] = b[1] = b[2] = b[3] = NULL;
  976. int nIndex = 0;
  977. if (!QE_SingleBrush())
  978. {
  979. Sys_Printf("Cannot cap multiple selection. Please select a single patch.\n");
  980. return;
  981. }
  982. for (brush_t *pb = selected_brushes.next ; pb != NULL && pb != &selected_brushes ; pb = pb->next)
  983. {
  984. if (pb->patchBrush)
  985. {
  986. pParent = pb->pPatch;
  987. // decide which if any ends we are going to cap
  988. // if any of these compares hit, it is a closed patch and as such
  989. // the generic capping will work.. if we do not find a closed edge
  990. // then we need to ask which kind of cap to add
  991. if (VectorCompare(pParent->ctrl[0][0].xyz, pParent->ctrl[pParent->width-1][0].xyz))
  992. {
  993. pCap = Cap(pParent, true, false);
  994. if (pCap != NULL)
  995. {
  996. b[nIndex++] = pCap;
  997. }
  998. }
  999. if (VectorCompare(pParent->ctrl[0][pParent->height-1].xyz, pParent->ctrl[pParent->width-1][pParent->height-1].xyz))
  1000. {
  1001. pCap = Cap(pParent, true, true);
  1002. if (pCap != NULL)
  1003. {
  1004. b[nIndex++] = pCap;
  1005. }
  1006. }
  1007. if (VectorCompare(pParent->ctrl[0][0].xyz, pParent->ctrl[0][pParent->height-1].xyz))
  1008. {
  1009. pCap = Cap(pParent, false, false);
  1010. if (pCap != NULL)
  1011. {
  1012. b[nIndex++] = pCap;
  1013. }
  1014. }
  1015. if (VectorCompare(pParent->ctrl[pParent->width-1][0].xyz, pParent->ctrl[pParent->width-1][pParent->height-1].xyz))
  1016. {
  1017. pCap = Cap(pParent, false, true);
  1018. if (pCap != NULL)
  1019. {
  1020. b[nIndex++] = pCap;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. if (pParent)
  1026. {
  1027. // if we did not cap anything with the above tests
  1028. if (nIndex == 0)
  1029. {
  1030. CCapDialog dlg;
  1031. if (dlg.DoModal() == IDOK)
  1032. {
  1033. b[nIndex++] = CapSpecial(pParent, dlg.getCapType(), false);
  1034. b[nIndex++] = CapSpecial(pParent, dlg.getCapType(), true);
  1035. }
  1036. }
  1037. if (nIndex > 0)
  1038. {
  1039. while (nIndex > 0)
  1040. {
  1041. nIndex--;
  1042. if (b[nIndex])
  1043. {
  1044. Select_Brush(b[nIndex]);
  1045. }
  1046. }
  1047. eclass_t *pecNew = Eclass_ForName("func_group", false);
  1048. if (pecNew)
  1049. {
  1050. entity_t *e = Entity_Create(pecNew);
  1051. SetKeyValue(e, "type", "patchCapped");
  1052. }
  1053. }
  1054. }
  1055. }
  1056. //FIXME: Table drive all this crap
  1057. //
  1058. void GenerateEndCaps(brush_t *brushParent, bool bBevel, bool bEndcap, bool bInverted)
  1059. {
  1060. brush_t *b, *b2;
  1061. patchMesh_t *p, *p2, *pParent;
  1062. vec3_t vTemp, vMin, vMax;
  1063. int i, j;
  1064. pParent = brushParent->pPatch;
  1065. Patch_CalcBounds(pParent, vMin, vMax);
  1066. // basically generate two endcaps, place them, and link the three brushes with a func_group
  1067. if (pParent->width > 9)
  1068. b = Patch_GenericMesh(5, 3, 2, false);
  1069. else
  1070. b = Patch_GenericMesh(3, 3, 2, false);
  1071. p = b->pPatch;
  1072. vMin[0] = vMin[1] = vMin[2] = 9999;
  1073. vMax[0] = vMax[1] = vMax[2] = -9999;
  1074. for (i = 0; i < pParent->width; i++)
  1075. {
  1076. VectorCopy(pParent->ctrl[i][0].xyz, p->ctrl[Index3By[i][0]][Index3By[i][1]].xyz);
  1077. for (j = 0; j < 3; j++)
  1078. {
  1079. if (pParent->ctrl[i][0].xyz[j] < vMin[j])
  1080. vMin[j] = pParent->ctrl[i][0].xyz[j];
  1081. if (pParent->ctrl[i][0].xyz[j] > vMax[j])
  1082. vMax[j] = pParent->ctrl[i][0].xyz[j];
  1083. }
  1084. }
  1085. for (j = 0; j < 3; j++)
  1086. {
  1087. vTemp[j] = vMin[j] + abs((vMax[j] - vMin[j]) * 0.5);
  1088. }
  1089. for (i = 0; i < Interior3ByCount; i++)
  1090. {
  1091. VectorCopy(vTemp, p->ctrl[Interior3By[i][0]][Interior3By[i][1]].xyz);
  1092. }
  1093. Patch_CalcBounds(p, vMin, vMax);
  1094. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  1095. Select_Brush(p->pSymbiot);
  1096. return;
  1097. bool bCreated = false;
  1098. if (bInverted)
  1099. {
  1100. if (bBevel)
  1101. {
  1102. b = Patch_GenericMesh(3, 3, 2, false);
  1103. p = b->pPatch;
  1104. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[1][2].xyz);
  1105. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[2][1].xyz);
  1106. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[0][1].xyz);
  1107. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[1][0].xyz);
  1108. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[1][1].xyz);
  1109. VectorCopy(p->ctrl[2][0].xyz, p->ctrl[0][0].xyz);
  1110. b2 = Patch_GenericMesh(3, 3, 2, false);
  1111. p2 = b2->pPatch;
  1112. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[1][2].xyz);
  1113. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[2][1].xyz);
  1114. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[0][1].xyz);
  1115. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[1][0].xyz);
  1116. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[1][1].xyz);
  1117. VectorCopy(p2->ctrl[2][0].xyz, p2->ctrl[0][0].xyz);
  1118. bCreated = true;
  1119. }
  1120. else if (bEndcap)
  1121. {
  1122. b = Patch_GenericMesh(5, 5, 2, false);
  1123. p = b->pPatch;
  1124. VectorCopy(p->ctrl[4][4].xyz, p->ctrl[4][3].xyz);
  1125. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[1][4].xyz);
  1126. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[2][4].xyz);
  1127. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[3][4].xyz);
  1128. VectorCopy(p->ctrl[4][0].xyz, p->ctrl[4][1].xyz);
  1129. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[1][0].xyz);
  1130. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[2][0].xyz);
  1131. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[3][0].xyz);
  1132. for (i = 1; i < 4; i++)
  1133. {
  1134. for (j = 0; j < 4; j++)
  1135. {
  1136. VectorCopy(p->ctrl[4][i].xyz, p->ctrl[j][i].xyz);
  1137. }
  1138. }
  1139. b2 = Patch_GenericMesh(5, 5, 2, false);
  1140. p2 = b2->pPatch;
  1141. VectorCopy(p2->ctrl[4][4].xyz, p2->ctrl[4][3].xyz);
  1142. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[1][4].xyz);
  1143. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[2][4].xyz);
  1144. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[3][4].xyz);
  1145. VectorCopy(p2->ctrl[4][0].xyz, p2->ctrl[4][1].xyz);
  1146. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[1][0].xyz);
  1147. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[2][0].xyz);
  1148. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[3][0].xyz);
  1149. for (i = 1; i < 4; i++)
  1150. {
  1151. for (j = 0; j < 4; j++)
  1152. {
  1153. VectorCopy(p2->ctrl[4][i].xyz, p2->ctrl[j][i].xyz);
  1154. }
  1155. }
  1156. bCreated = true;
  1157. }
  1158. }
  1159. else
  1160. {
  1161. if (bBevel)
  1162. {
  1163. b = Patch_GenericMesh(3, 3, 2, false);
  1164. p = b->pPatch;
  1165. VectorCopy(p->ctrl[2][0].xyz, p->ctrl[2][1].xyz);
  1166. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[1][0].xyz);
  1167. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[2][0].xyz);
  1168. b2 = Patch_GenericMesh(3, 3, 2, false);
  1169. p2 = b2->pPatch;
  1170. VectorCopy(p2->ctrl[2][0].xyz, p2->ctrl[2][1].xyz);
  1171. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[1][0].xyz);
  1172. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[2][0].xyz);
  1173. bCreated = true;
  1174. }
  1175. else if (bEndcap)
  1176. {
  1177. b = Patch_GenericMesh(5, 5, 2, false);
  1178. p = b->pPatch;
  1179. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[1][0].xyz);
  1180. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[2][0].xyz);
  1181. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[3][0].xyz);
  1182. VectorCopy(p->ctrl[4][0].xyz, p->ctrl[4][1].xyz);
  1183. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[4][0].xyz);
  1184. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[1][4].xyz);
  1185. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[2][4].xyz);
  1186. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[3][4].xyz);
  1187. VectorCopy(p->ctrl[4][4].xyz, p->ctrl[4][3].xyz);
  1188. VectorCopy(p->ctrl[0][4].xyz, p->ctrl[4][4].xyz);
  1189. b2 = Patch_GenericMesh(5, 5, 2, false);
  1190. p2 = b2->pPatch;
  1191. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[1][0].xyz);
  1192. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[2][0].xyz);
  1193. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[3][0].xyz);
  1194. VectorCopy(p2->ctrl[4][0].xyz, p2->ctrl[4][1].xyz);
  1195. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[4][0].xyz);
  1196. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[1][4].xyz);
  1197. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[2][4].xyz);
  1198. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[3][4].xyz);
  1199. VectorCopy(p2->ctrl[4][4].xyz, p2->ctrl[4][3].xyz);
  1200. VectorCopy(p2->ctrl[0][4].xyz, p2->ctrl[4][4].xyz);
  1201. bCreated = true;
  1202. }
  1203. else
  1204. {
  1205. b = Patch_GenericMesh(3, 3, 2, false);
  1206. p = b->pPatch;
  1207. VectorCopy(p->ctrl[0][1].xyz, vTemp);
  1208. VectorCopy(p->ctrl[0][2].xyz, p->ctrl[0][1].xyz)
  1209. VectorCopy(p->ctrl[1][2].xyz, p->ctrl[0][2].xyz)
  1210. VectorCopy(p->ctrl[2][2].xyz, p->ctrl[1][2].xyz)
  1211. VectorCopy(p->ctrl[2][1].xyz, p->ctrl[2][2].xyz)
  1212. VectorCopy(p->ctrl[2][0].xyz, p->ctrl[2][1].xyz)
  1213. VectorCopy(p->ctrl[1][0].xyz, p->ctrl[2][0].xyz)
  1214. VectorCopy(p->ctrl[0][0].xyz, p->ctrl[1][0].xyz)
  1215. VectorCopy(vTemp, p->ctrl[0][0].xyz)
  1216. b2 = Patch_GenericMesh(3, 3, 2, false);
  1217. p2 = b2->pPatch;
  1218. VectorCopy(p2->ctrl[0][1].xyz, vTemp);
  1219. VectorCopy(p2->ctrl[0][2].xyz, p2->ctrl[0][1].xyz)
  1220. VectorCopy(p2->ctrl[1][2].xyz, p2->ctrl[0][2].xyz)
  1221. VectorCopy(p2->ctrl[2][2].xyz, p2->ctrl[1][2].xyz)
  1222. VectorCopy(p2->ctrl[2][1].xyz, p2->ctrl[2][2].xyz)
  1223. VectorCopy(p2->ctrl[2][0].xyz, p2->ctrl[2][1].xyz)
  1224. VectorCopy(p2->ctrl[1][0].xyz, p2->ctrl[2][0].xyz)
  1225. VectorCopy(p2->ctrl[0][0].xyz, p2->ctrl[1][0].xyz)
  1226. VectorCopy(vTemp, p2->ctrl[0][0].xyz)
  1227. bCreated = true;
  1228. }
  1229. }
  1230. if (bCreated)
  1231. {
  1232. drawVert_t vertTemp;
  1233. for (i = 0; i < p->width; i++)
  1234. {
  1235. for (j = 0; j < p->height; j++)
  1236. {
  1237. p->ctrl[i][j].xyz[2] = vMin[2];
  1238. p2->ctrl[i][j].xyz[2] = vMax[2];
  1239. }
  1240. for (j = 0; j < p->height / 2; j++)
  1241. {
  1242. memcpy(&vertTemp, &p->ctrl[i][p->height - 1- j], sizeof (drawVert_t));
  1243. memcpy(&p->ctrl[i][p->height - 1 - j], &p->ctrl[i][j], sizeof(drawVert_t));
  1244. memcpy(&p->ctrl[i][j], &vertTemp, sizeof(drawVert_t));
  1245. }
  1246. }
  1247. //Select_Delete();
  1248. Patch_CalcBounds(p, vMin, vMax);
  1249. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  1250. Patch_CalcBounds(p2, vMin, vMax);
  1251. Brush_RebuildBrush(p2->pSymbiot, vMin, vMax);
  1252. Select_Brush(p->pSymbiot);
  1253. Select_Brush(p2->pSymbiot);
  1254. }
  1255. else
  1256. {
  1257. Select_Delete();
  1258. }
  1259. //Select_Brush(brushParent);
  1260. }
  1261. /*
  1262. ===============
  1263. BrushToPatchMesh
  1264. ===============
  1265. */
  1266. void Patch_BrushToMesh(bool bCone, bool bBevel, bool bEndcap, bool bSquare, int nHeight)
  1267. {
  1268. brush_t *b;
  1269. patchMesh_t *p;
  1270. int i,j;
  1271. if (!QE_SingleBrush())
  1272. return;
  1273. b = selected_brushes.next;
  1274. p = MakeNewPatch();
  1275. p->d_texture = b->brush_faces->d_texture;
  1276. p->height = nHeight;
  1277. p->type = PATCH_CYLINDER;
  1278. if (bBevel & !bSquare)
  1279. {
  1280. p->type = PATCH_BEVEL;
  1281. p->width = 3;
  1282. int nStep = (b->maxs[2] - b->mins[2]) / (p->height-1);
  1283. int nStart = b->mins[2];
  1284. for (i = 0; i < p->height; i++)
  1285. {
  1286. p->ctrl[0][i].xyz[0] = b->mins[0];
  1287. p->ctrl[0][i].xyz[1] = b->mins[1];
  1288. p->ctrl[0][i].xyz[2] = nStart;
  1289. p->ctrl[1][i].xyz[0] = b->maxs[0];
  1290. p->ctrl[1][i].xyz[1] = b->mins[1];
  1291. p->ctrl[1][i].xyz[2] = nStart;
  1292. p->ctrl[2][i].xyz[0] = b->maxs[0];
  1293. p->ctrl[2][i].xyz[1] = b->maxs[1];
  1294. p->ctrl[2][i].xyz[2] = nStart;
  1295. nStart += nStep;
  1296. }
  1297. }
  1298. else if (bEndcap & !bSquare)
  1299. {
  1300. p->type = PATCH_ENDCAP;
  1301. p->width = 5;
  1302. int nStep = (b->maxs[2] - b->mins[2]) / (p->height-1);
  1303. int nStart = b->mins[2];
  1304. for (i = 0; i < p->height; i++)
  1305. {
  1306. p->ctrl[0][i].xyz[0] = b->mins[0];
  1307. p->ctrl[0][i].xyz[1] = b->mins[1];
  1308. p->ctrl[0][i].xyz[2] = nStart;
  1309. p->ctrl[1][i].xyz[0] = b->mins[0];
  1310. p->ctrl[1][i].xyz[1] = b->maxs[1];
  1311. p->ctrl[1][i].xyz[2] = nStart;
  1312. p->ctrl[2][i].xyz[0] = b->mins[0] + ((b->maxs[0] - b->mins[0]) * 0.5);
  1313. p->ctrl[2][i].xyz[1] = b->maxs[1];
  1314. p->ctrl[2][i].xyz[2] = nStart;
  1315. p->ctrl[3][i].xyz[0] = b->maxs[0];
  1316. p->ctrl[3][i].xyz[1] = b->maxs[1];
  1317. p->ctrl[3][i].xyz[2] = nStart;
  1318. p->ctrl[4][i].xyz[0] = b->maxs[0];
  1319. p->ctrl[4][i].xyz[1] = b->mins[1];
  1320. p->ctrl[4][i].xyz[2] = nStart;
  1321. nStart += nStep;
  1322. }
  1323. }
  1324. else
  1325. {
  1326. p->width = 9;
  1327. p->ctrl[1][0].xyz[0] = b->mins[0];
  1328. p->ctrl[1][0].xyz[1] = b->mins[1];
  1329. p->ctrl[3][0].xyz[0] = b->maxs[0];
  1330. p->ctrl[3][0].xyz[1] = b->mins[1];
  1331. p->ctrl[5][0].xyz[0] = b->maxs[0];
  1332. p->ctrl[5][0].xyz[1] = b->maxs[1];
  1333. p->ctrl[7][0].xyz[0] = b->mins[0];
  1334. p->ctrl[7][0].xyz[1] = b->maxs[1];
  1335. for ( i = 1 ; i < p->width - 1 ; i += 2 )
  1336. {
  1337. p->ctrl[i][0].xyz[2] = b->mins[2];
  1338. VectorCopy( p->ctrl[i][0].xyz, p->ctrl[i][2].xyz );
  1339. p->ctrl[i][2].xyz[2] = b->maxs[2];
  1340. p->ctrl[i][1].xyz[0] = ( p->ctrl[i][0].xyz[0] + p->ctrl[i][2].xyz[0] ) * 0.5;
  1341. p->ctrl[i][1].xyz[1] = ( p->ctrl[i][0].xyz[1] + p->ctrl[i][2].xyz[1] ) * 0.5;
  1342. p->ctrl[i][1].xyz[2] = ( p->ctrl[i][0].xyz[2] + p->ctrl[i][2].xyz[2] ) * 0.5;
  1343. }
  1344. InterpolateInteriorPoints( p );
  1345. if (bSquare)
  1346. {
  1347. if (bBevel || bEndcap)
  1348. {
  1349. if (bBevel)
  1350. {
  1351. for (i = 0; i < p->height; i++)
  1352. {
  1353. VectorCopy(p->ctrl[1][i].xyz, p->ctrl[2][i].xyz);
  1354. VectorCopy(p->ctrl[7][i].xyz, p->ctrl[6][i].xyz);
  1355. }
  1356. }
  1357. else
  1358. {
  1359. for (i = 0; i < p->height; i++)
  1360. {
  1361. VectorCopy(p->ctrl[5][i].xyz, p->ctrl[4][i].xyz);
  1362. VectorCopy(p->ctrl[1][i].xyz, p->ctrl[2][i].xyz);
  1363. VectorCopy(p->ctrl[7][i].xyz, p->ctrl[6][i].xyz);
  1364. VectorCopy(p->ctrl[8][i].xyz, p->ctrl[7][i].xyz);
  1365. }
  1366. }
  1367. }
  1368. else
  1369. {
  1370. for (i = 0; i < p->width-1; i ++)
  1371. {
  1372. for (j = 0; j < p->height; j++)
  1373. {
  1374. VectorCopy(p->ctrl[i+1][j].xyz, p->ctrl[i][j].xyz);
  1375. }
  1376. }
  1377. for (j = 0; j < p->height; j++)
  1378. {
  1379. VectorCopy(p->ctrl[0][j].xyz, p->ctrl[8][j].xyz);
  1380. }
  1381. }
  1382. }
  1383. }
  1384. Patch_Naturalize(p);
  1385. if (bCone)
  1386. {
  1387. p->type = PATCH_CONE;
  1388. float xc = (b->maxs[0] + b->mins[0]) * 0.5;
  1389. float yc = (b->maxs[1] + b->mins[1]) * 0.5;
  1390. for ( i = 0 ; i < p->width ; i ++)
  1391. {
  1392. p->ctrl[i][2].xyz[0] = xc;
  1393. p->ctrl[i][2].xyz[1] = yc;
  1394. }
  1395. }
  1396. /*
  1397. if (bEndcap || bBevel)
  1398. {
  1399. if (bInverted)
  1400. {
  1401. for ( i = 0 ; i < p->height ; i ++)
  1402. {
  1403. if (bBevel)
  1404. {
  1405. VectorCopy(p->ctrl[7][i], p->ctrl[0][i]);
  1406. VectorCopy(p->ctrl[7][i], p->ctrl[8][i]);
  1407. VectorCopy(p->ctrl[3][i], p->ctrl[2][i]);
  1408. VectorCopy(p->ctrl[5][i], p->ctrl[1][i]);
  1409. VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
  1410. VectorCopy(p->ctrl[5][i], p->ctrl[6][i]);
  1411. }
  1412. else
  1413. {
  1414. VectorCopy(p->ctrl[4][i], p->ctrl[8][i]);
  1415. VectorCopy(p->ctrl[1][i], p->ctrl[0][i]);
  1416. VectorCopy(p->ctrl[1][i], p->ctrl[10][i]);
  1417. VectorCopy(p->ctrl[3][i], p->ctrl[2][i]);
  1418. VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
  1419. VectorCopy(p->ctrl[7][i], p->ctrl[6][i]);
  1420. VectorCopy(p->ctrl[5][i], p->ctrl[7][i]);
  1421. VectorCopy(p->ctrl[3][i], p->ctrl[9][i]);
  1422. }
  1423. }
  1424. }
  1425. else
  1426. {
  1427. for ( i = 0 ; i < p->height ; i ++)
  1428. {
  1429. VectorCopy(p->ctrl[1][i], p->ctrl[2][i]);
  1430. VectorCopy(p->ctrl[7][i], p->ctrl[6][i]);
  1431. if (bBevel)
  1432. {
  1433. VectorCopy(p->ctrl[5][i], p->ctrl[4][i]);
  1434. }
  1435. }
  1436. }
  1437. }
  1438. */
  1439. b = AddBrushForPatch(p);
  1440. #if 1
  1441. Select_Delete();
  1442. Select_Brush(b);
  1443. #else
  1444. if (!bCone)
  1445. {
  1446. Select_Delete();
  1447. Select_Brush(b);
  1448. GenerateEndCaps(b, bBevel, bEndcap, bInverted);
  1449. eclass_t *pecNew = Eclass_ForName("func_group", false);
  1450. if (pecNew)
  1451. {
  1452. Entity_Create(pecNew);
  1453. }
  1454. }
  1455. else
  1456. {
  1457. Select_Delete();
  1458. Select_Brush(b);
  1459. }
  1460. #endif
  1461. }
  1462. /*
  1463. ==================
  1464. Patch_GenericMesh
  1465. ==================
  1466. */
  1467. brush_t* Patch_GenericMesh(int nWidth, int nHeight, int nOrientation, bool bDeleteSource, bool bOverride)
  1468. {
  1469. int i,j;
  1470. if (nHeight < 3 || nHeight > 15 || nWidth < 3 || nWidth > 15)
  1471. {
  1472. Sys_Printf("Invalid patch width or height.\n");
  1473. return NULL;
  1474. }
  1475. if (! bOverride && !QE_SingleBrush())
  1476. {
  1477. Sys_Printf("Cannot generate a patch from multiple selections.\n");
  1478. return NULL;
  1479. }
  1480. patchMesh_t* p = MakeNewPatch();
  1481. p->d_texture = Texture_ForName(g_qeglobals.d_texturewin.texdef.name);
  1482. p->width = nWidth;
  1483. p->height = nHeight;
  1484. p->type = PATCH_GENERIC;
  1485. int nFirst = 0;
  1486. int nSecond = 1;
  1487. if (nOrientation == 0)
  1488. {
  1489. nFirst = 1;
  1490. nSecond = 2;
  1491. }
  1492. else if (nOrientation == 1)
  1493. {
  1494. nSecond = 2;
  1495. }
  1496. brush_t *b = selected_brushes.next;
  1497. int xStep = b->mins[nFirst];
  1498. float xAdj = abs((b->maxs[nFirst] - b->mins[nFirst]) / (nWidth - 1));
  1499. float yAdj = abs((b->maxs[nSecond] - b->mins[nSecond]) / (nHeight - 1));
  1500. for (i = 0; i < nWidth; i++)
  1501. {
  1502. int yStep = b->mins[nSecond];
  1503. for (j = 0; j < nHeight; j++)
  1504. {
  1505. p->ctrl[i][j].xyz[nFirst] = xStep;
  1506. p->ctrl[i][j].xyz[nSecond] = yStep;
  1507. p->ctrl[i][j].xyz[nOrientation] = 0;
  1508. yStep += yAdj;
  1509. }
  1510. xStep += xAdj;
  1511. }
  1512. Patch_Naturalize(p);
  1513. b = AddBrushForPatch(p);
  1514. if (bDeleteSource)
  1515. {
  1516. Select_Delete();
  1517. Select_Brush(b);
  1518. }
  1519. return b;
  1520. //g_qeglobals.d_select_mode = sel_curvepoint;
  1521. }
  1522. /*
  1523. ==================
  1524. PointInMoveList
  1525. ==================
  1526. */
  1527. int PointInMoveList(float *pf)
  1528. {
  1529. for (int i = 0; i < g_qeglobals.d_num_move_points; i++)
  1530. {
  1531. if (pf == &g_qeglobals.d_move_points[i][0])
  1532. return i;
  1533. }
  1534. return -1;
  1535. }
  1536. /*
  1537. ==================
  1538. PointValueInMoveList
  1539. ==================
  1540. */
  1541. int PointValueInMoveList(vec3_t v)
  1542. {
  1543. for (int i = 0; i < g_qeglobals.d_num_move_points; i++)
  1544. {
  1545. if (VectorCompare(v, g_qeglobals.d_move_points[i]))
  1546. return i;
  1547. }
  1548. return -1;
  1549. }
  1550. /*
  1551. ==================
  1552. RemovePointFromMoveList
  1553. ==================
  1554. */
  1555. void RemovePointFromMoveList(vec3_t v)
  1556. {
  1557. int n;
  1558. while ( (n = PointValueInMoveList(v)) >= 0)
  1559. {
  1560. for (int i = n; i < g_qeglobals.d_num_move_points-1; i++)
  1561. {
  1562. g_qeglobals.d_move_points[i] = g_qeglobals.d_move_points[i+1];
  1563. }
  1564. g_qeglobals.d_num_move_points--;
  1565. }
  1566. }
  1567. /*
  1568. ==================
  1569. ColumnSelected
  1570. ==================
  1571. */
  1572. bool ColumnSelected(patchMesh_t* p, int nCol)
  1573. {
  1574. for (int i = 0; i < p->height; i++)
  1575. {
  1576. if (PointInMoveList(p->ctrl[nCol][i].xyz) == -1)
  1577. return false;
  1578. }
  1579. return true;
  1580. }
  1581. /*
  1582. ==================
  1583. AddPoint
  1584. ==================
  1585. */
  1586. void AddPoint(patchMesh_t* p, vec3_t v, bool bWeldOrDrill = true)
  1587. {
  1588. int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
  1589. int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
  1590. g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = v;
  1591. if ((g_bPatchWeld || g_bPatchDrillDown) && bWeldOrDrill)
  1592. {
  1593. for ( int i = 0 ; i < p->width ; i++ )
  1594. {
  1595. for ( int j = 0 ; j < p->height ; j++ )
  1596. {
  1597. if (g_bPatchWeld)
  1598. {
  1599. if ( VectorCompare(v, p->ctrl[i][j].xyz)
  1600. && PointInMoveList(p->ctrl[i][j].xyz) == -1)
  1601. {
  1602. g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
  1603. continue;
  1604. }
  1605. }
  1606. if (g_bPatchDrillDown && g_nPatchClickedView != W_CAMERA)
  1607. {
  1608. if ( (fabs(v[nDim1] - p->ctrl[i][j].xyz[nDim1]) <= EQUAL_EPSILON)
  1609. &&(fabs(v[nDim2] - p->ctrl[i][j].xyz[nDim2]) <= EQUAL_EPSILON))
  1610. {
  1611. if (PointInMoveList(p->ctrl[i][j].xyz) == -1)
  1612. {
  1613. g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
  1614. continue;
  1615. }
  1616. }
  1617. #if 0
  1618. int l = 0;
  1619. for ( int k = 0; k < 2; k++ )
  1620. {
  1621. if (fabs(v[k] - p->ctrl[i][j].xyz[k]) > EQUAL_EPSILON)
  1622. continue;
  1623. l++;
  1624. }
  1625. if (l >= 2 && PointInMoveList(p->ctrl[i][j].xyz) == -1)
  1626. {
  1627. g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
  1628. continue;
  1629. }
  1630. #endif
  1631. }
  1632. }
  1633. }
  1634. }
  1635. #if 0
  1636. if (g_qeglobals.d_num_move_points == 1)
  1637. {
  1638. // single point selected
  1639. // FIXME: the two loops can probably be reduced to one
  1640. for ( int i = 0 ; i < p->width ; i++ )
  1641. {
  1642. for ( int j = 0 ; j < p->height ; j++ )
  1643. {
  1644. int n = PointInMoveList(v);
  1645. if (n >= 0)
  1646. {
  1647. if (((i & 0x01) && (j & 0x01)) == 0)
  1648. {
  1649. // put any sibling fixed points
  1650. // into the inverse list
  1651. int p1, p2, p3, p4;
  1652. p1 = i + 2;
  1653. p2 = i - 2;
  1654. p3 = j + 2;
  1655. p4 = j - 2;
  1656. if (p1 < p->width)
  1657. {
  1658. }
  1659. if (p2 >= 0)
  1660. {
  1661. }
  1662. if (p3 < p->height)
  1663. {
  1664. }
  1665. if (p4 >= 0)
  1666. {
  1667. }
  1668. }
  1669. }
  1670. }
  1671. }
  1672. }
  1673. #endif
  1674. }
  1675. /*
  1676. ==================
  1677. SelectRow
  1678. ==================
  1679. */
  1680. void SelectRow(patchMesh_t* p, int nRow, bool bMulti)
  1681. {
  1682. if (!bMulti)
  1683. g_qeglobals.d_num_move_points = 0;
  1684. for (int i = 0; i < p->width; i++)
  1685. {
  1686. AddPoint(p, p->ctrl[i][nRow].xyz, false);
  1687. }
  1688. //Sys_Printf("Selected Row %d\n", nRow);
  1689. }
  1690. /*
  1691. ==================
  1692. SelectColumn
  1693. ==================
  1694. */
  1695. void SelectColumn(patchMesh_t* p, int nCol, bool bMulti)
  1696. {
  1697. if (!bMulti)
  1698. g_qeglobals.d_num_move_points = 0;
  1699. for (int i = 0; i < p->height; i++)
  1700. {
  1701. AddPoint(p, p->ctrl[nCol][i].xyz, false);
  1702. }
  1703. //Sys_Printf("Selected Col %d\n", nCol);
  1704. }
  1705. /*
  1706. ==================
  1707. AddPatchMovePoint
  1708. ==================
  1709. */
  1710. void AddPatchMovePoint(vec3_t v, bool bMulti, bool bFull)
  1711. {
  1712. if (!g_bSameView && !bMulti && !bFull)
  1713. {
  1714. g_bSameView = true;
  1715. return;
  1716. }
  1717. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  1718. {
  1719. if (pb->patchBrush)
  1720. {
  1721. patchMesh_t* p = pb->pPatch;
  1722. for ( int i = 0 ; i < p->width ; i++ )
  1723. {
  1724. for ( int j = 0 ; j < p->height ; j++ )
  1725. {
  1726. if (VectorCompare(v, p->ctrl[i][j].xyz))
  1727. {
  1728. if (PointInMoveList(p->ctrl[i][j].xyz) == -1)
  1729. {
  1730. if (bFull) // if we want the full row/col this is on
  1731. {
  1732. SelectColumn(p, i, bMulti);
  1733. }
  1734. else
  1735. {
  1736. if (!bMulti)
  1737. g_qeglobals.d_num_move_points = 0;
  1738. AddPoint(p, p->ctrl[i][j].xyz);
  1739. //Sys_Printf("Selected col:row %d:%d\n", i, j);
  1740. }
  1741. //--if (!bMulti)
  1742. return;
  1743. }
  1744. else
  1745. {
  1746. if (bFull)
  1747. {
  1748. if (ColumnSelected(p, i))
  1749. {
  1750. SelectRow(p, j, bMulti);
  1751. }
  1752. else
  1753. {
  1754. SelectColumn(p, i, bMulti);
  1755. }
  1756. return;
  1757. }
  1758. if (g_bSameView)
  1759. {
  1760. RemovePointFromMoveList(v);
  1761. return;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. /*
  1771. ==================
  1772. Patch_UpdateSelected
  1773. ==================
  1774. */
  1775. void Patch_UpdateSelected(vec3_t vMove)
  1776. {
  1777. int i, j;
  1778. for (i=0 ; i < g_qeglobals.d_num_move_points ; i++)
  1779. {
  1780. VectorAdd (g_qeglobals.d_move_points[i], vMove, g_qeglobals.d_move_points[i]);
  1781. if (g_qeglobals.d_num_move_points == 1)
  1782. {
  1783. }
  1784. }
  1785. //--patchMesh_t* p = &patchMeshes[g_nSelectedPatch];
  1786. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  1787. {
  1788. if (pb->patchBrush)
  1789. {
  1790. patchMesh_t* p = pb->pPatch;
  1791. g_qeglobals.d_numpoints = 0;
  1792. for (i = 0 ; i < p->width ; i++ )
  1793. {
  1794. for ( j = 0 ; j < p->height ; j++ )
  1795. {
  1796. VectorCopy (p->ctrl[i][j].xyz, g_qeglobals.d_points[g_qeglobals.d_numpoints]);
  1797. if (g_qeglobals.d_numpoints < MAX_POINTS-1)
  1798. {
  1799. g_qeglobals.d_numpoints++;
  1800. }
  1801. }
  1802. }
  1803. vec3_t vMin, vMax;
  1804. Patch_CalcBounds(p, vMin, vMax);
  1805. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  1806. }
  1807. }
  1808. //Brush_Free(p->pSymbiot);
  1809. //Select_Brush(AddBrushForPatch(g_nSelectedPatch));
  1810. }
  1811. /*
  1812. ===============
  1813. SampleSinglePatch
  1814. ===============
  1815. */
  1816. void SampleSinglePatch (float ctrl[3][3][5], float u, float v, float out[5]) {
  1817. float vCtrl[3][5];
  1818. int vPoint;
  1819. int axis;
  1820. // find the control points for the v coordinate
  1821. for (vPoint = 0 ; vPoint < 3 ; vPoint++)
  1822. {
  1823. for (axis = 0 ; axis < 5 ; axis++)
  1824. {
  1825. float a, b, c;
  1826. float qA, qB, qC;
  1827. a = ctrl[0][vPoint][axis];
  1828. b = ctrl[1][vPoint][axis];
  1829. c = ctrl[2][vPoint][axis];
  1830. qA = a - 2 * b + c;
  1831. qB = 2 * b - 2 * a;
  1832. qC = a;
  1833. vCtrl[vPoint][axis] = qA * u * u + qB * u + qC;
  1834. }
  1835. }
  1836. // interpolate the v value
  1837. for (axis = 0 ; axis < 5 ; axis++)
  1838. {
  1839. float a, b, c;
  1840. float qA, qB, qC;
  1841. a = vCtrl[0][axis];
  1842. b = vCtrl[1][axis];
  1843. c = vCtrl[2][axis];
  1844. qA = a - 2 * b + c;
  1845. qB = 2 * b - 2 * a;
  1846. qC = a;
  1847. out[axis] = qA * v * v + qB * v + qC;
  1848. }
  1849. }
  1850. /*
  1851. ===================
  1852. DrawSinglePatch
  1853. ===================
  1854. */
  1855. void DrawSinglePatch (float ctrl[3][3][5], bool bPoints)
  1856. {
  1857. int i, j;
  1858. float u, v;
  1859. float verts[CBLOCK_SUBDIVISIONS+1][CBLOCK_SUBDIVISIONS+1][5];
  1860. for (i = 0 ; i <= CBLOCK_SUBDIVISIONS ; i++)
  1861. {
  1862. for (j = 0 ; j <= CBLOCK_SUBDIVISIONS ; j++)
  1863. {
  1864. u = (float)i / CBLOCK_SUBDIVISIONS;
  1865. v = (float)j / CBLOCK_SUBDIVISIONS;
  1866. SampleSinglePatch (ctrl, u, v, verts[i][j]);
  1867. }
  1868. }
  1869. // at this point we have
  1870. int nCount = -1;
  1871. for (i = 0 ; i < CBLOCK_SUBDIVISIONS ; i++)
  1872. {
  1873. qglBegin (GL_QUAD_STRIP);
  1874. for (j = 0 ; j <= CBLOCK_SUBDIVISIONS ; j++)
  1875. {
  1876. qglTexCoord2fv( verts[i+1][j] + 3 );
  1877. qglVertex3fv( verts[i+1][j] );
  1878. /*
  1879. if (nCount >= 0)
  1880. {
  1881. VectorCopy(verts[i+1][j], vNormals[nCount]);
  1882. }
  1883. nCount++;
  1884. if (nCount == 3)
  1885. {
  1886. VectorSubtract(vNormals[0], vNormals[1], vNormals[0]);
  1887. VectorSubtract(vNormals[1], vNormals[2], vNormals[1]);
  1888. CrossProduct(vNormals[0], vNormals[1], vNormals[2]);
  1889. //VectorNormalize(vNormals[2]);
  1890. qglNormal3fv(vNormals[2]);
  1891. nCount = -1;
  1892. }
  1893. */
  1894. qglTexCoord2fv( verts[i][j] + 3 );
  1895. qglVertex3fv( verts[i][j] );
  1896. /*
  1897. VectorCopy(verts[i][j], vNormals[nCount]);
  1898. nCount++;
  1899. if (nCount == 3)
  1900. {
  1901. VectorSubtract(vNormals[0], vNormals[1], vNormals[0]);
  1902. VectorSubtract(vNormals[1], vNormals[2], vNormals[1]);
  1903. CrossProduct(vNormals[0], vNormals[1], vNormals[2]);
  1904. //VectorNormalize(vNormals[2]);
  1905. qglNormal3fv(vNormals[2]);
  1906. nCount = -1;
  1907. }
  1908. */
  1909. }
  1910. qglEnd ();
  1911. }
  1912. }
  1913. /*
  1914. =================
  1915. DrawPatchMesh
  1916. =================
  1917. */
  1918. //FIXME: this routine needs to be reorganized.. should be about 1/4 the size and complexity
  1919. void DrawPatchMesh( patchMesh_t *pm, bool bPoints, bool bShade = false ) {
  1920. int i, j, k, l;
  1921. float ctrl[3][3][5];
  1922. bool bOverlay = pm->bOverlay;
  1923. int nDrawMode = g_pParentWnd->GetCamera()->Camera().draw_mode;
  1924. //--float fColor[3];
  1925. //--if (bShade)
  1926. //--{
  1927. //-- face_t *f = pm->pSymbiot->brush_faces;
  1928. //-- _SetColor(f, fColor);
  1929. //--}
  1930. if (g_PrefsDlg.m_bDisplayLists)
  1931. {
  1932. if (pm->bDirty || pm->nListID <= 0)
  1933. {
  1934. if (pm->nListID <= 0)
  1935. pm->nListID = qglGenLists(1);
  1936. if (pm->nListID > 0)
  1937. {
  1938. qglNewList(pm->nListID, GL_COMPILE_AND_EXECUTE);
  1939. }
  1940. if (pm->type != PATCH_TRIANGLE)
  1941. {
  1942. //vec3_t *vMeshData = new vec3_t[pm->width * pm->height];
  1943. // wasteful
  1944. if (g_PrefsDlg.m_bGLLighting)
  1945. {
  1946. Patch_MeshNormals(pm);
  1947. for (i = 0; i < pm->width; i++)
  1948. {
  1949. for (j = 0; j < pm->height; j++)
  1950. {
  1951. //VectorCopy(pm->ctrl[i][j].xyz, vMeshData[(j * pm->width) + i]);
  1952. qglNormal3fv(pm->ctrl[i][j].normal);
  1953. }
  1954. }
  1955. }
  1956. for ( i = 0 ; i + 2 < pm->width ; i += 2 )
  1957. {
  1958. for ( j = 0 ; j + 2 < pm->height ; j += 2 )
  1959. {
  1960. for ( k = 0 ; k < 3 ; k++ )
  1961. {
  1962. vec3_t vAvg;
  1963. vAvg[0] = vAvg[1] = vAvg[2] = 0;
  1964. for ( l = 0 ; l < 3 ; l++ )
  1965. {
  1966. ctrl[k][l][0] = pm->ctrl[ i + k ][ j + l ].xyz[ 0 ];
  1967. ctrl[k][l][1] = pm->ctrl[ i + k ][ j + l ].xyz[ 1 ];
  1968. ctrl[k][l][2] = pm->ctrl[ i + k ][ j + l ].xyz[ 2 ];
  1969. ctrl[k][l][3] = pm->ctrl[ i + k ][ j + l ].xyz[ 3 ];
  1970. ctrl[k][l][4] = pm->ctrl[ i + k ][ j + l ].xyz[ 4 ];
  1971. if (g_PrefsDlg.m_bGLLighting)
  1972. {
  1973. qglNormal3fv(pm->ctrl[i+k][j+l].normal);
  1974. }
  1975. }
  1976. }
  1977. //-- if (g_pParentWnd->GetCamera()->Camera().draw_mode == cd_texture)
  1978. //-- {
  1979. //-- VectorCopy(pm->ctrl[i][j].normal, plane.normal);
  1980. //-- float shade = SetShadeForPlane(&plane);
  1981. //-- qtexture_t *q = pm->d_texture;
  1982. //-- vec3_t vColor;
  1983. //--
  1984. //-- vColor[0] = shade;// * q->color[0];
  1985. //-- vColor[1] = shade;// * q->color[1];
  1986. //-- vColor[2] = shade;// * q->color[2];
  1987. //-- qglColor3fv(vColor);
  1988. //-- }
  1989. //-- if (g_PrefsDlg.m_bGLLighting)
  1990. //-- {
  1991. //-- //qglNormal3fv(pm->ctrl[i][j].normal);
  1992. //-- }
  1993. DrawSinglePatch( ctrl, bPoints );
  1994. }
  1995. }
  1996. // we have an array of clean control points
  1997. //
  1998. /*
  1999. qglMap2f(GL_MAP2_NORMAL, 0, 1, 3, 3, 0, 1, 9, 3, (float*)&vMeshData);
  2000. for (i = 0; i < pm->width; i++)
  2001. {
  2002. for (j = 0; j < pm->height; j++)
  2003. {
  2004. qglEvalPoint2(i, j);
  2005. }
  2006. }
  2007. delete []vMeshData;
  2008. */
  2009. }
  2010. else
  2011. {
  2012. qglBegin (GL_TRIANGLES);
  2013. qglTexCoord2fv( pm->ctrl[0][0].st);
  2014. qglVertex3fv( pm->ctrl[0][0].xyz);
  2015. qglTexCoord2fv( pm->ctrl[2][0].st);
  2016. qglVertex3fv( pm->ctrl[2][0].xyz);
  2017. qglTexCoord2fv( pm->ctrl[2][2].st);
  2018. qglVertex3fv( pm->ctrl[2][2].xyz);
  2019. qglEnd();
  2020. }
  2021. if (pm->nListID > 0)
  2022. {
  2023. qglEndList();
  2024. pm->bDirty = false;
  2025. }
  2026. }
  2027. else
  2028. {
  2029. qglCallList(pm->nListID);
  2030. }
  2031. }
  2032. else
  2033. {
  2034. for ( i = 0 ; i + 2 < pm->width ; i += 2 )
  2035. {
  2036. for ( j = 0 ; j + 2 < pm->height ; j += 2 )
  2037. {
  2038. for ( k = 0 ; k < 3 ; k++ )
  2039. {
  2040. for ( l = 0 ; l < 3 ; l++ )
  2041. {
  2042. ctrl[k][l][0] = pm->ctrl[ i + k ][ j + l ].xyz[ 0 ];
  2043. ctrl[k][l][1] = pm->ctrl[ i + k ][ j + l ].xyz[ 1 ];
  2044. ctrl[k][l][2] = pm->ctrl[ i + k ][ j + l ].xyz[ 2 ];
  2045. ctrl[k][l][3] = pm->ctrl[ i + k ][ j + l ].xyz[ 3 ];
  2046. ctrl[k][l][4] = pm->ctrl[ i + k ][ j + l ].xyz[ 4 ];
  2047. }
  2048. }
  2049. //--if (bShade)
  2050. //--{
  2051. //-- _DecColor(fColor);
  2052. //--}
  2053. DrawSinglePatch( ctrl, bPoints );
  2054. }
  2055. }
  2056. }
  2057. vec3_t* pSelectedPoints[256];
  2058. int nIndex = 0;
  2059. qglPushAttrib(GL_CURRENT_BIT);
  2060. //--qglDisable(GL_BLEND);
  2061. //--qglDisable (GL_DEPTH_TEST);
  2062. //qglDisable (GL_TEXTURE_2D);
  2063. bool bDisabledLighting = qglIsEnabled(GL_LIGHTING);
  2064. if (bDisabledLighting)
  2065. {
  2066. qglDisable(GL_LIGHTING);
  2067. }
  2068. // FIXME: this bend painting code needs to be rolled up significantly as it is a cluster fuck right now
  2069. if (bPoints && (g_qeglobals.d_select_mode == sel_curvepoint || g_qeglobals.d_select_mode == sel_area || g_bPatchBendMode || g_bPatchInsertMode))
  2070. {
  2071. bOverlay = false;
  2072. // bending or inserting
  2073. if (g_bPatchBendMode || g_bPatchInsertMode)
  2074. {
  2075. qglPointSize(6);
  2076. if (g_bPatchAxisOnRow)
  2077. {
  2078. qglColor3f(1, 0, 1);
  2079. qglBegin(GL_POINTS);
  2080. for (i = 0; i < pm->width; i++)
  2081. {
  2082. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[i][g_nPatchAxisIndex].xyz));
  2083. }
  2084. qglEnd();
  2085. // could do all of this in one loop but it was pretty messy
  2086. if (g_bPatchInsertMode)
  2087. {
  2088. qglColor3f(0, 0, 1);
  2089. qglBegin(GL_POINTS);
  2090. for (i = 0; i < pm->width; i++)
  2091. {
  2092. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[i][g_nPatchAxisIndex].xyz));
  2093. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[i][g_nPatchAxisIndex+1].xyz));
  2094. }
  2095. qglEnd();
  2096. }
  2097. else
  2098. {
  2099. if (g_nPatchBendState == BEND_SELECT_EDGE || g_nPatchBendState == BEND_BENDIT || g_nPatchBendState == BEND_SELECT_ORIGIN)
  2100. {
  2101. qglColor3f(0, 0, 1);
  2102. qglBegin(GL_POINTS);
  2103. if (g_nPatchBendState == BEND_SELECT_ORIGIN)
  2104. {
  2105. qglVertex3fv(g_vBendOrigin);
  2106. }
  2107. else
  2108. {
  2109. for (i = 0; i < pm->width; i++)
  2110. {
  2111. if (g_bPatchLowerEdge)
  2112. {
  2113. for (j = 0; j < g_nPatchAxisIndex; j++)
  2114. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[i][j].xyz));
  2115. }
  2116. else
  2117. {
  2118. for (j = pm->height-1; j > g_nPatchAxisIndex; j--)
  2119. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[i][j].xyz));
  2120. }
  2121. }
  2122. }
  2123. qglEnd();
  2124. }
  2125. }
  2126. }
  2127. else
  2128. {
  2129. qglColor3f(1, 0, 1);
  2130. qglBegin(GL_POINTS);
  2131. for (i = 0; i < pm->height; i++)
  2132. {
  2133. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[g_nPatchAxisIndex][i].xyz));
  2134. }
  2135. qglEnd();
  2136. // could do all of this in one loop but it was pretty messy
  2137. if (g_bPatchInsertMode)
  2138. {
  2139. qglColor3f(0, 0, 1);
  2140. qglBegin(GL_POINTS);
  2141. for (i = 0; i < pm->height; i++)
  2142. {
  2143. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[g_nPatchAxisIndex][i].xyz));
  2144. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[g_nPatchAxisIndex+1][i].xyz));
  2145. }
  2146. qglEnd();
  2147. }
  2148. else
  2149. {
  2150. if (g_nPatchBendState == BEND_SELECT_EDGE || g_nPatchBendState == BEND_BENDIT || g_nPatchBendState == BEND_SELECT_ORIGIN)
  2151. {
  2152. qglColor3f(0, 0, 1);
  2153. qglBegin(GL_POINTS);
  2154. for (i = 0; i < pm->height; i++)
  2155. {
  2156. if (g_nPatchBendState == BEND_SELECT_ORIGIN)
  2157. {
  2158. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[g_nBendOriginIndex][i].xyz));
  2159. }
  2160. else
  2161. {
  2162. if (g_bPatchLowerEdge)
  2163. {
  2164. for (j = 0; j < g_nPatchAxisIndex; j++)
  2165. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[j][i].xyz));
  2166. }
  2167. else
  2168. {
  2169. for (j = pm->width-1; j > g_nPatchAxisIndex; j--)
  2170. qglVertex3fv(reinterpret_cast<float(*)>(&pm->ctrl[j][i].xyz));
  2171. }
  2172. }
  2173. }
  2174. qglEnd();
  2175. }
  2176. }
  2177. }
  2178. }
  2179. else // just painting the grid for selection
  2180. {
  2181. qglPointSize(6);
  2182. for ( i = 0 ; i < pm->width ; i++ )
  2183. {
  2184. for ( j = 0 ; j < pm->height ; j++ )
  2185. {
  2186. qglBegin(GL_POINTS);
  2187. // FIXME: need to not do loop lookups inside here
  2188. int n = PointValueInMoveList(pm->ctrl[i][j].xyz);
  2189. if (n >= 0)
  2190. {
  2191. pSelectedPoints[nIndex++] = reinterpret_cast<float(*)[3]>(&pm->ctrl[i][j].xyz);
  2192. }
  2193. if (i & 0x01 || j & 0x01)
  2194. qglColor3f(1, 0, 1);
  2195. else
  2196. qglColor3f(0, 1, 0);
  2197. qglVertex3fv(pm->ctrl[i][j].xyz);
  2198. qglEnd();
  2199. }
  2200. }
  2201. }
  2202. if (nIndex > 0)
  2203. {
  2204. qglBegin(GL_POINTS);
  2205. qglColor3f(0, 0, 1);
  2206. while (nIndex-- > 0)
  2207. {
  2208. qglVertex3fv(*pSelectedPoints[nIndex]);
  2209. }
  2210. qglEnd();
  2211. }
  2212. }
  2213. if (bOverlay)
  2214. {
  2215. qglPointSize(6);
  2216. qglColor3f(0.5, 0.5, 0.5);
  2217. for ( i = 0 ; i < pm->width ; i++ )
  2218. {
  2219. qglBegin(GL_POINTS);
  2220. for ( j = 0 ; j < pm->height ; j++ )
  2221. {
  2222. if (i & 0x01 || j & 0x01)
  2223. qglColor3f(0.5, 0, 0.5);
  2224. else
  2225. qglColor3f(0, 0.5, 0);
  2226. qglVertex3fv(pm->ctrl[i][j].xyz);
  2227. }
  2228. qglEnd();
  2229. }
  2230. }
  2231. //--qglEnable (GL_TEXTURE_2D);
  2232. //--qglEnable (GL_DEPTH_TEST);
  2233. if (bDisabledLighting)
  2234. {
  2235. qglEnable(GL_LIGHTING);
  2236. }
  2237. qglPopAttrib();
  2238. }
  2239. /*
  2240. ==================
  2241. Patch_DrawXY
  2242. ==================
  2243. */
  2244. void Patch_DrawXY(patchMesh_t *pm)
  2245. {
  2246. qglPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
  2247. if (pm->bSelected)
  2248. {
  2249. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES]);
  2250. //qglDisable (GL_LINE_STIPPLE);
  2251. //qglLineWidth (1);
  2252. }
  2253. else
  2254. qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_BRUSHES]);
  2255. DrawPatchMesh( pm , pm->bSelected );
  2256. qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
  2257. if (pm->bSelected)
  2258. {
  2259. //qglLineWidth (2);
  2260. //qglEnable (GL_LINE_STIPPLE);
  2261. }
  2262. }
  2263. /*
  2264. ==================
  2265. Patch_DrawCam
  2266. ==================
  2267. */
  2268. void Patch_DrawCam(patchMesh_t *pm)
  2269. {
  2270. qglColor3f (1,1,1);
  2271. qglPushAttrib(GL_ALL_ATTRIB_BITS);
  2272. if (g_bPatchWireFrame)
  2273. {
  2274. qglDisable( GL_CULL_FACE );
  2275. qglPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
  2276. qglDisable(GL_TEXTURE_2D);
  2277. if (g_PrefsDlg.m_bGLLighting)
  2278. {
  2279. qglDisable(GL_LIGHTING);
  2280. }
  2281. DrawPatchMesh( pm , pm->bSelected, true );
  2282. if (g_PrefsDlg.m_bGLLighting)
  2283. {
  2284. qglEnable(GL_LIGHTING);
  2285. }
  2286. qglEnable( GL_CULL_FACE );
  2287. }
  2288. else
  2289. {
  2290. if (g_PrefsDlg.m_bGLLighting)
  2291. {
  2292. //qglEnable(GL_NORMALIZE);
  2293. }
  2294. qglEnable( GL_CULL_FACE );
  2295. qglCullFace(GL_FRONT);
  2296. qglBindTexture (GL_TEXTURE_2D, pm->d_texture->texture_number);
  2297. if (pm->d_texture->bFromShader && pm->d_texture->fTrans < 1.0)
  2298. {
  2299. //qglEnable ( GL_BLEND );
  2300. //qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  2301. qglColor4f(pm->d_texture->color[0], pm->d_texture->color[1], pm->d_texture->color[2], pm->d_texture->fTrans);
  2302. }
  2303. DrawPatchMesh( pm , pm->bSelected, true );
  2304. qglCullFace(GL_BACK);
  2305. //qglDisable(GL_TEXTURE_2D);
  2306. qglPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
  2307. qglDisable ( GL_BLEND );
  2308. DrawPatchMesh( pm , pm->bSelected, true );
  2309. }
  2310. #if 0 // this paints normal indicators on the ctrl points
  2311. //--qglDisable (GL_DEPTH_TEST);
  2312. qglDisable (GL_TEXTURE_2D);
  2313. qglColor3f (1,1,1);
  2314. for (int i = 0; i < pm->width; i++)
  2315. {
  2316. for (int j = 0; j < pm->height; j++)
  2317. {
  2318. vec3_t temp;
  2319. qglBegin (GL_LINES);
  2320. qglVertex3fv (pm->ctrl[i][j].xyz);
  2321. VectorMA (pm->ctrl[i][j].xyz, 8, pm->ctrl[i][j].normal, temp);
  2322. qglVertex3fv (temp);
  2323. qglEnd ();
  2324. }
  2325. }
  2326. qglEnable (GL_TEXTURE_2D);
  2327. //--qglEnable (GL_DEPTH_TEST);
  2328. #endif
  2329. qglPopAttrib();
  2330. }
  2331. void ConvexHullForSection( float section[2][4][7] ) {
  2332. }
  2333. void BrushesForSection( float section[2][4][7] ) {
  2334. }
  2335. //
  2336. //================
  2337. //Patch_BuildPoints
  2338. //================
  2339. void Patch_BuildPoints (brush_t *b)
  2340. {
  2341. face_t *f;
  2342. b->patchBrush = false;
  2343. for (f=b->brush_faces ; f ; f=f->next)
  2344. {
  2345. if (f->texdef.flags & SURF_PATCH)
  2346. {
  2347. b->patchBrush = true;
  2348. //vec3_t vMin, vMax;
  2349. //Patch_CalcBounds(&patchMeshes[b->nPatchID], vMin, vMax);
  2350. //VectorCopy(vMin, b->mins);
  2351. //VectorCopy(vMax, b->maxs);
  2352. break;
  2353. }
  2354. }
  2355. }
  2356. //
  2357. //===============
  2358. //Patch_WriteFile
  2359. //===============
  2360. //
  2361. #if 0
  2362. void Patch_WriteFile (char *name)
  2363. {
  2364. char patchName[1024];
  2365. time_t ltime;
  2366. strcpy(patchName, name);
  2367. StripExtension (patchName);
  2368. strcat (patchName, ".patch");
  2369. FILE *file = fopen(patchName, "w");
  2370. if (file)
  2371. {
  2372. time(&ltime);
  2373. fprintf (file, "// %s saved on %s\n", name, ctime(&ltime) );
  2374. for (int i = 0; i < numPatchMeshes; i++)
  2375. {
  2376. fprintf(file, "{\n");
  2377. fprintf(file, " %s\n", patchMeshes[i].d_texture->name);
  2378. fprintf(file, " ( %i %i %i ) \n", patchMeshes[i].width, patchMeshes[i].height, patchMeshes[i].negative);
  2379. for (int w = 0; w < patchMeshes[i].width; w++)
  2380. {
  2381. for (int h = 0; h < patchMeshes[i].height; h++)
  2382. {
  2383. fprintf(file, " ( ");
  2384. for (int k = 0; k < 5; k++)
  2385. {
  2386. float f = patchMeshes[i].ctrl[w][h][k];
  2387. if (f == int(f))
  2388. fprintf(file, "%i ", (int)f);
  2389. else
  2390. fprintf(file, "%f ", f);
  2391. }
  2392. fprintf(file, ")\n");
  2393. }
  2394. }
  2395. fprintf(file, "}\n");
  2396. }
  2397. fclose(file);
  2398. }
  2399. }
  2400. #endif
  2401. /*
  2402. ==================
  2403. Patch_Move
  2404. ==================
  2405. */
  2406. void Patch_Move(patchMesh_t *pm, const vec3_t vMove, bool bRebuild)
  2407. {
  2408. pm->bDirty = true;
  2409. for (int w = 0; w < pm->width; w++)
  2410. {
  2411. for (int h = 0; h < pm->height; h++)
  2412. {
  2413. VectorAdd(pm->ctrl[w][h].xyz, vMove, pm->ctrl[w][h].xyz);
  2414. }
  2415. }
  2416. if (bRebuild)
  2417. {
  2418. vec3_t vMin, vMax;
  2419. Patch_CalcBounds(pm, vMin, vMax);
  2420. //Brush_RebuildBrush(patchMeshes[n].pSymbiot, vMin, vMax);
  2421. }
  2422. UpdatePatchInspector();
  2423. }
  2424. /*
  2425. ==================
  2426. Patch_ApplyMatrix
  2427. ==================
  2428. */
  2429. void Patch_ApplyMatrix(patchMesh_t *p, const vec3_t vOrigin, const vec3_t vMatrix[3], bool bSnap)
  2430. {
  2431. vec3_t vTemp;
  2432. for (int w = 0; w < p->width; w++)
  2433. {
  2434. for (int h = 0; h < p->height; h++)
  2435. {
  2436. if ( (g_qeglobals.d_select_mode == sel_curvepoint || g_bPatchBendMode)
  2437. && PointInMoveList(p->ctrl[w][h].xyz) == -1)
  2438. continue;
  2439. VectorSubtract (p->ctrl[w][h].xyz, vOrigin, vTemp);
  2440. for (int j = 0; j < 3; j++)
  2441. {
  2442. p->ctrl[w][h].xyz[j] = DotProduct(vTemp, vMatrix[j]) + vOrigin[j];
  2443. if (bSnap)
  2444. {
  2445. p->ctrl[w][h].xyz[j] = floor(p->ctrl[w][h].xyz[j] + 0.5);
  2446. }
  2447. }
  2448. }
  2449. }
  2450. vec3_t vMin, vMax;
  2451. Patch_CalcBounds(p, vMin, vMax);
  2452. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  2453. }
  2454. /*
  2455. ==================
  2456. Patch_EditPatch
  2457. ==================
  2458. */
  2459. void Patch_EditPatch()
  2460. {
  2461. //--patchMesh_t* p = &patchMeshes[n];
  2462. g_qeglobals.d_numpoints = 0;
  2463. g_qeglobals.d_num_move_points = 0;
  2464. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  2465. {
  2466. if (pb->patchBrush)
  2467. {
  2468. patchMesh_t* p = pb->pPatch;
  2469. for ( int i = 0 ; i < p->width ; i++ )
  2470. {
  2471. for ( int j = 0 ; j < p->height ; j++ )
  2472. {
  2473. VectorCopy (p->ctrl[i][j].xyz, g_qeglobals.d_points[g_qeglobals.d_numpoints]);
  2474. if (g_qeglobals.d_numpoints < MAX_POINTS-1)
  2475. {
  2476. g_qeglobals.d_numpoints++;
  2477. }
  2478. }
  2479. }
  2480. }
  2481. }
  2482. g_qeglobals.d_select_mode = sel_curvepoint;
  2483. //--g_nSelectedPatch = n;
  2484. }
  2485. /*
  2486. ==================
  2487. Patch_Deselect
  2488. ==================
  2489. */
  2490. //FIXME: need all sorts of asserts throughout a lot of this crap
  2491. void Patch_Deselect()
  2492. {
  2493. //--g_nSelectedPatch = -1;
  2494. clearSelection();
  2495. for (brush_t *b = selected_brushes.next ; b != &selected_brushes ; b=b->next)
  2496. {
  2497. if (b->patchBrush)
  2498. {
  2499. b->pPatch->bSelected = false;
  2500. }
  2501. }
  2502. //for (int i = 0; i < numPatchMeshes; i++)
  2503. // patchMeshes[i].bSelected = false;
  2504. if (g_bPatchBendMode)
  2505. Patch_BendToggle();
  2506. if (g_bPatchInsertMode)
  2507. Patch_InsDelToggle();
  2508. }
  2509. /*
  2510. ==================
  2511. Patch_Select
  2512. ==================
  2513. */
  2514. void Patch_Select(patchMesh_t *p)
  2515. {
  2516. // maintained for point manip.. which i need to fix as this
  2517. // is pf error prone
  2518. //--g_nSelectedPatch = n;
  2519. p->bSelected = true;
  2520. }
  2521. /*
  2522. ==================
  2523. Patch_Deselect
  2524. ==================
  2525. */
  2526. void Patch_Deselect(patchMesh_t *p)
  2527. {
  2528. p->bSelected = false;
  2529. }
  2530. /*
  2531. ==================
  2532. Patch_Delete
  2533. ==================
  2534. */
  2535. void Patch_Delete(patchMesh_t *p)
  2536. {
  2537. p->pSymbiot->pPatch = NULL;
  2538. p->pSymbiot->patchBrush = false;
  2539. if (g_qeglobals.bSurfacePropertiesPlugin)
  2540. {
  2541. #ifdef _DEBUG
  2542. if (!p->pData)
  2543. Sys_Printf("WARNING: unexpected IPluginTexdef* is NULL in Patch_Delete\n");
  2544. else
  2545. #endif
  2546. {
  2547. GETPLUGINTEXDEF(p)->DecRef();
  2548. p->pData = NULL;
  2549. }
  2550. }
  2551. free(p);
  2552. p = NULL;
  2553. // bump the array down
  2554. //for (int i = n; i < numPatchMeshes; i++)
  2555. //{
  2556. // patchMeshes[i].pSymbiot->nPatchID--;
  2557. // patchMeshes[i] = patchMeshes[i+1];
  2558. //}
  2559. //numPatchMeshes--;
  2560. UpdatePatchInspector();
  2561. }
  2562. /*
  2563. ==================
  2564. Patch_Scale
  2565. ==================
  2566. */
  2567. void Patch_Scale(patchMesh_t *p, const vec3_t vOrigin, const vec3_t vAmt, bool bRebuild)
  2568. {
  2569. for (int w = 0; w < p->width; w++)
  2570. {
  2571. for (int h = 0; h < p->height; h++)
  2572. {
  2573. if (g_qeglobals.d_select_mode == sel_curvepoint && PointInMoveList(p->ctrl[w][h].xyz) == -1)
  2574. continue;
  2575. for (int i=0 ; i<3 ; i++)
  2576. {
  2577. p->ctrl[w][h].xyz[i] -= vOrigin[i];
  2578. p->ctrl[w][h].xyz[i] *= vAmt[i];
  2579. p->ctrl[w][h].xyz[i] += vOrigin[i];
  2580. }
  2581. }
  2582. }
  2583. if (bRebuild)
  2584. {
  2585. vec3_t vMin, vMax;
  2586. Patch_CalcBounds(p, vMin, vMax);
  2587. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  2588. }
  2589. UpdatePatchInspector();
  2590. }
  2591. /*
  2592. ==================
  2593. Patch_Cleanup
  2594. ==================
  2595. */
  2596. void Patch_Cleanup()
  2597. {
  2598. //--g_nSelectedPatch = -1;
  2599. //numPatchMeshes = 0;
  2600. }
  2601. /*
  2602. ==================
  2603. Patch_SetView
  2604. ==================
  2605. */
  2606. void Patch_SetView(int n)
  2607. {
  2608. g_bSameView = (n == g_nPatchClickedView);
  2609. g_nPatchClickedView = n;
  2610. }
  2611. /*
  2612. ==================
  2613. Patch_SetTexture
  2614. ==================
  2615. */
  2616. // FIXME: need array validation throughout
  2617. void Patch_SetTexture(patchMesh_t *p, texdef_t *tex_def, IPluginTexdef* pPlugTexdef)
  2618. {
  2619. p->d_texture = Texture_ForName(tex_def->name);
  2620. if (g_qeglobals.bSurfacePropertiesPlugin)
  2621. {
  2622. #ifdef _DEBUG
  2623. if (!p->pData)
  2624. Sys_Printf("WARNING: unexpected p->pData is NULL in Patch_SetTexture\n");
  2625. else
  2626. #endif
  2627. GETPLUGINTEXDEF(p)->DecRef();
  2628. if (pPlugTexdef)
  2629. {
  2630. p->pData = pPlugTexdef->Copy();
  2631. GETPLUGINTEXDEF(p)->Hook(p);
  2632. }
  2633. else
  2634. {
  2635. g_SurfaceTable.m_pfnPatchAlloc( p );
  2636. GETPLUGINTEXDEF(p)->SetDefaultTexdef();
  2637. }
  2638. }
  2639. UpdatePatchInspector();
  2640. }
  2641. /*
  2642. ==================
  2643. Patch_DragScale
  2644. ==================
  2645. */
  2646. bool Patch_DragScale(patchMesh_t *p, vec3_t vAmt, vec3_t vMove)
  2647. {
  2648. vec3_t vMin, vMax, vScale, vTemp, vMid;
  2649. int i;
  2650. Patch_CalcBounds(p, vMin, vMax);
  2651. VectorSubtract(vMax, vMin, vTemp);
  2652. // if we are scaling in the same dimension the patch has no depth
  2653. for (i = 0; i < 3; i ++)
  2654. {
  2655. if (vTemp[i] == 0 && vMove[i] != 0)
  2656. {
  2657. //Patch_Move(n, vMove, true);
  2658. return false;
  2659. }
  2660. }
  2661. for (i=0 ; i<3 ; i++)
  2662. vMid[i] = (vMin[i] + ((vMax[i] - vMin[i]) / 2));
  2663. for (i = 0; i < 3; i++)
  2664. {
  2665. if (vAmt[i] != 0)
  2666. {
  2667. vScale[i] = 1.0 + vAmt[i] / vTemp[i];
  2668. }
  2669. else
  2670. {
  2671. vScale[i] = 1.0;
  2672. }
  2673. }
  2674. Patch_Scale(p, vMid, vScale, false);
  2675. VectorSubtract(vMax, vMin, vTemp);
  2676. Patch_CalcBounds(p, vMin, vMax);
  2677. VectorSubtract(vMax, vMin, vMid);
  2678. VectorSubtract(vMid, vTemp, vTemp);
  2679. VectorScale(vTemp, 0.5, vTemp);
  2680. // abs of both should always be equal
  2681. if (!VectorCompare(vMove, vAmt))
  2682. {
  2683. for (i = 0; i < 3; i++)
  2684. {
  2685. if (vMove[i] != vAmt[i])
  2686. vTemp[i] = -(vTemp[i]);
  2687. }
  2688. }
  2689. Patch_Move(p, vTemp);
  2690. return true;
  2691. }
  2692. /*
  2693. ==================
  2694. Patch_AddRow
  2695. ==================
  2696. */
  2697. void Patch_AddRow(patchMesh_t *p)
  2698. {
  2699. vec3_t vMin, vMax, vTemp;
  2700. int i, j;
  2701. if (p->height+2 < MAX_PATCH_HEIGHT)
  2702. {
  2703. Patch_CalcBounds(p, vMin, vMax);
  2704. VectorSubtract(vMax, vMin, vTemp);
  2705. for (i = 0; i < 3; i++)
  2706. {
  2707. vTemp[i] /= p->height + 2;
  2708. }
  2709. for (j = 0; j < p->width; j++)
  2710. {
  2711. VectorCopy(p->ctrl[j][p->height].xyz, p->ctrl[j][p->height+1].xyz);
  2712. VectorCopy(p->ctrl[j][p->height].xyz, p->ctrl[j][p->height+2].xyz);
  2713. p->height += 2;
  2714. i = 1;
  2715. while (i < p->height)
  2716. {
  2717. VectorAdd(p->ctrl[j][i].xyz, vTemp, p->ctrl[j][i].xyz);
  2718. i++;
  2719. }
  2720. }
  2721. Patch_CalcBounds(p, vMin, vMax);
  2722. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  2723. }
  2724. UpdatePatchInspector();
  2725. }
  2726. /*
  2727. ==================
  2728. Patch_InsertColumn
  2729. ==================
  2730. */
  2731. void Patch_InsertColumn(patchMesh_t *p, bool bAdd)
  2732. {
  2733. int h, w, i, j;
  2734. vec3_t vTemp;
  2735. if (p->width + 2 >= MAX_PATCH_WIDTH)
  2736. return;
  2737. if (bAdd) // add column?
  2738. {
  2739. for (h = 0; h < p->height; h++)
  2740. {
  2741. j = p->width-1;
  2742. VectorSubtract(p->ctrl[j][h].xyz, p->ctrl[j-1][h].xyz, vTemp);
  2743. for (i = 0; i < 3; i++)
  2744. vTemp[i] /= 3;
  2745. memcpy(&p->ctrl[j+2][h],&p->ctrl[j][h], sizeof(drawVert_t));
  2746. memcpy(&p->ctrl[j][h],&p->ctrl[j-1][h], sizeof(drawVert_t));
  2747. VectorAdd(p->ctrl[j][h].xyz, vTemp, p->ctrl[j][h].xyz);
  2748. memcpy(&p->ctrl[j+1][h], &p->ctrl[j][h], sizeof(drawVert_t));
  2749. VectorAdd(p->ctrl[j+1][h].xyz, vTemp, p->ctrl[j+1][h].xyz);
  2750. }
  2751. }
  2752. else
  2753. {
  2754. for (h = 0; h < p->height; h++)
  2755. {
  2756. w = p->width-1;
  2757. while (w >= 0)
  2758. {
  2759. memcpy(&p->ctrl[w+2][h],&p->ctrl[w][h], sizeof(drawVert_t));
  2760. w--;
  2761. }
  2762. VectorSubtract(p->ctrl[1][h].xyz, p->ctrl[0][h].xyz, vTemp);
  2763. for (i = 0; i < 3; i++)
  2764. vTemp[i] /= 3;
  2765. VectorCopy(p->ctrl[0][h].xyz, p->ctrl[1][h].xyz);
  2766. VectorAdd(p->ctrl[1][h].xyz, vTemp, p->ctrl[1][h].xyz);
  2767. VectorCopy(p->ctrl[1][h].xyz, p->ctrl[2][h].xyz);
  2768. VectorAdd(p->ctrl[2][h].xyz, vTemp, p->ctrl[2][h].xyz);
  2769. }
  2770. }
  2771. p->width += 2;
  2772. UpdatePatchInspector();
  2773. }
  2774. /*
  2775. ==================
  2776. Patch_InsertRow
  2777. ==================
  2778. */
  2779. void Patch_InsertRow(patchMesh_t *p, bool bAdd)
  2780. {
  2781. int h, w, i, j;
  2782. vec3_t vTemp;
  2783. if (p->height + 2 >= MAX_PATCH_HEIGHT)
  2784. return;
  2785. if (bAdd) // add column?
  2786. {
  2787. for (w = 0; w < p->width; w++)
  2788. {
  2789. j = p->height-1;
  2790. VectorSubtract(p->ctrl[w][j].xyz, p->ctrl[w][j-1].xyz, vTemp);
  2791. for (i = 0; i < 3; i++)
  2792. vTemp[i] /= 3;
  2793. memcpy(&p->ctrl[w][j+2],&p->ctrl[w][j], sizeof(drawVert_t));
  2794. memcpy(&p->ctrl[w][j],&p->ctrl[w][j-1], sizeof(drawVert_t));
  2795. VectorAdd(p->ctrl[w][j].xyz, vTemp, p->ctrl[w][j].xyz);
  2796. memcpy(&p->ctrl[w][j+1], &p->ctrl[w][j], sizeof(drawVert_t));
  2797. VectorAdd(p->ctrl[w][j+1].xyz, vTemp, p->ctrl[w][j+1].xyz);
  2798. }
  2799. }
  2800. else
  2801. {
  2802. for (w = 0; w < p->width; w++)
  2803. {
  2804. h = p->height-1;
  2805. while (h >= 0)
  2806. {
  2807. memcpy(&p->ctrl[w][h+2],&p->ctrl[w][h], sizeof(drawVert_t));
  2808. h--;
  2809. }
  2810. VectorSubtract(p->ctrl[w][1].xyz, p->ctrl[w][0].xyz, vTemp);
  2811. for (i = 0; i < 3; i++)
  2812. vTemp[i] /= 3;
  2813. VectorCopy(p->ctrl[w][0].xyz, p->ctrl[w][1].xyz);
  2814. VectorAdd(p->ctrl[w][1].xyz, vTemp, p->ctrl[w][1].xyz);
  2815. VectorCopy(p->ctrl[w][1].xyz, p->ctrl[w][2].xyz);
  2816. VectorAdd(p->ctrl[w][2].xyz, vTemp, p->ctrl[w][2].xyz);
  2817. }
  2818. }
  2819. p->height += 2;
  2820. UpdatePatchInspector();
  2821. }
  2822. /*
  2823. ==================
  2824. Patch_RemoveRow
  2825. ==================
  2826. */
  2827. void Patch_RemoveRow(patchMesh_t *p, bool bFirst)
  2828. {
  2829. if (p->height <= MIN_PATCH_HEIGHT)
  2830. return;
  2831. p->height -= 2;
  2832. if (bFirst)
  2833. {
  2834. for (int w = 0; w < p->width; w++)
  2835. {
  2836. for (int h = 0; h < p->height; h++)
  2837. {
  2838. memcpy(&p->ctrl[w][h], &p->ctrl[w][h+2], sizeof(drawVert_t));
  2839. }
  2840. }
  2841. }
  2842. UpdatePatchInspector();
  2843. }
  2844. /*
  2845. ==================
  2846. Patch_RemoveColumn
  2847. ==================
  2848. */
  2849. void Patch_RemoveColumn(patchMesh_t *p, bool bFirst)
  2850. {
  2851. if (p->width <= MIN_PATCH_WIDTH)
  2852. return;
  2853. p->width -= 2;
  2854. if (bFirst)
  2855. {
  2856. for (int h = 0; h < p->height; h++)
  2857. {
  2858. for (int w = 0; w < p->width; w++)
  2859. {
  2860. memcpy(&p->ctrl[w][h], &p->ctrl[w+2][h], sizeof(drawVert_t));
  2861. }
  2862. }
  2863. }
  2864. UpdatePatchInspector();
  2865. }
  2866. /*
  2867. ==================
  2868. Patch_AdjustColumns
  2869. ==================
  2870. */
  2871. void Patch_AdjustColumns(patchMesh_t *p, int nCols)
  2872. {
  2873. vec3_t vTemp, vTemp2;
  2874. int i, w, h;
  2875. if (nCols & 0x01 || p->width + nCols < 3 || p->width + nCols > MAX_PATCH_WIDTH)
  2876. return;
  2877. // add in column adjustment
  2878. p->width += nCols;
  2879. for (h = 0; h < p->height; h++)
  2880. {
  2881. // for each column, we need to evenly disperse p->width number
  2882. // of points across the old bounds
  2883. // calc total distance to interpolate
  2884. VectorSubtract(p->ctrl[p->width - 1 - nCols][h].xyz, p->ctrl[0][h].xyz, vTemp);
  2885. // amount per cycle
  2886. for (i = 0; i < 3; i ++)
  2887. {
  2888. vTemp2[i] = vTemp[i] / (p->width - 1);
  2889. }
  2890. // move along
  2891. for (w = 0; w < p->width-1; w++)
  2892. {
  2893. VectorAdd(p->ctrl[w][h].xyz, vTemp2, p->ctrl[w+1][h].xyz);
  2894. }
  2895. }
  2896. for ( w = 0 ; w < p->width ; w++ )
  2897. {
  2898. for ( h = 0 ; h < p->height ; h++ )
  2899. {
  2900. p->ctrl[w][h].st[0] = 4 * (float)w / (p->width - 1);
  2901. p->ctrl[w][h].st[1] = 4 * (float)h / (p->height - 1);
  2902. }
  2903. }
  2904. UpdatePatchInspector();
  2905. }
  2906. /*
  2907. ==================
  2908. Patch_AdjustRows
  2909. ==================
  2910. */
  2911. void Patch_AdjustRows(patchMesh_t *p, int nRows)
  2912. {
  2913. vec3_t vTemp, vTemp2;
  2914. int i, w, h;
  2915. if (nRows & 0x01 || p->height + nRows < 3 || p->height + nRows > MAX_PATCH_HEIGHT)
  2916. return;
  2917. // add in column adjustment
  2918. p->height += nRows;
  2919. for (w = 0; w < p->width; w++)
  2920. {
  2921. // for each row, we need to evenly disperse p->height number
  2922. // of points across the old bounds
  2923. // calc total distance to interpolate
  2924. VectorSubtract(p->ctrl[w][p->height - 1 - nRows].xyz, p->ctrl[w][0].xyz, vTemp);
  2925. //vTemp[0] = vTemp[1] = vTemp[2] = 0;
  2926. //for (h = 0; h < p->height - nRows; h ++)
  2927. //{
  2928. // VectorAdd(vTemp, p->ctrl[w][h], vTemp);
  2929. //}
  2930. // amount per cycle
  2931. for (i = 0; i < 3; i ++)
  2932. {
  2933. vTemp2[i] = vTemp[i] / (p->height - 1);
  2934. }
  2935. // move along
  2936. for (h = 0; h < p->height-1; h++)
  2937. {
  2938. VectorAdd(p->ctrl[w][h].xyz, vTemp2, p->ctrl[w][h+1].xyz);
  2939. }
  2940. }
  2941. for ( w = 0 ; w < p->width ; w++ )
  2942. {
  2943. for ( h = 0 ; h < p->height ; h++ )
  2944. {
  2945. p->ctrl[w][h].st[0] = 4 * (float)w / (p->width - 1);
  2946. p->ctrl[w][h].st[1] = 4 * (float)h / (p->height - 1);
  2947. }
  2948. }
  2949. UpdatePatchInspector();
  2950. }
  2951. void Patch_DisperseRows()
  2952. {
  2953. vec3_t vTemp, vTemp2;
  2954. int i, w, h;
  2955. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  2956. {
  2957. if (pb->patchBrush)
  2958. {
  2959. patchMesh_t *p = pb->pPatch;
  2960. Patch_Rebuild(p);
  2961. for (w = 0; w < p->width; w++)
  2962. {
  2963. // for each row, we need to evenly disperse p->height number
  2964. // of points across the old bounds
  2965. // calc total distance to interpolate
  2966. VectorSubtract(p->ctrl[w][p->height - 1].xyz, p->ctrl[w][0].xyz, vTemp);
  2967. //vTemp[0] = vTemp[1] = vTemp[2] = 0;
  2968. //for (h = 0; h < p->height - nRows; h ++)
  2969. //{
  2970. // VectorAdd(vTemp, p->ctrl[w][h], vTemp);
  2971. //}
  2972. // amount per cycle
  2973. for (i = 0; i < 3; i ++)
  2974. {
  2975. vTemp2[i] = vTemp[i] / (p->height - 1);
  2976. }
  2977. // move along
  2978. for (h = 0; h < p->height-1; h++)
  2979. {
  2980. VectorAdd(p->ctrl[w][h].xyz, vTemp2, p->ctrl[w][h+1].xyz);
  2981. }
  2982. Patch_Naturalize(p);
  2983. }
  2984. }
  2985. }
  2986. UpdatePatchInspector();
  2987. }
  2988. /*
  2989. ==================
  2990. Patch_AdjustColumns
  2991. ==================
  2992. */
  2993. void Patch_DisperseColumns()
  2994. {
  2995. vec3_t vTemp, vTemp2;
  2996. int i, w, h;
  2997. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  2998. {
  2999. if (pb->patchBrush)
  3000. {
  3001. patchMesh_t *p = pb->pPatch;
  3002. Patch_Rebuild(p);
  3003. for (h = 0; h < p->height; h++)
  3004. {
  3005. // for each column, we need to evenly disperse p->width number
  3006. // of points across the old bounds
  3007. // calc total distance to interpolate
  3008. VectorSubtract(p->ctrl[p->width - 1][h].xyz, p->ctrl[0][h].xyz, vTemp);
  3009. // amount per cycle
  3010. for (i = 0; i < 3; i ++)
  3011. {
  3012. vTemp2[i] = vTemp[i] / (p->width - 1);
  3013. }
  3014. // move along
  3015. for (w = 0; w < p->width-1; w++)
  3016. {
  3017. VectorAdd(p->ctrl[w][h].xyz, vTemp2, p->ctrl[w+1][h].xyz);
  3018. }
  3019. }
  3020. Patch_Naturalize(p);
  3021. }
  3022. }
  3023. UpdatePatchInspector();
  3024. }
  3025. /*
  3026. ==================
  3027. Patch_AdjustSelected
  3028. ==================
  3029. */
  3030. void Patch_AdjustSelected(bool bInsert, bool bColumn, bool bFlag)
  3031. {
  3032. bool bUpdate = false;
  3033. for (brush_t* pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3034. {
  3035. if (pb->patchBrush)
  3036. {
  3037. if (bInsert)
  3038. {
  3039. if (bColumn)
  3040. {
  3041. Patch_InsertColumn(pb->pPatch, bFlag);
  3042. }
  3043. else
  3044. {
  3045. Patch_InsertRow(pb->pPatch, bFlag);
  3046. }
  3047. }
  3048. else
  3049. {
  3050. if (bColumn)
  3051. {
  3052. Patch_RemoveColumn(pb->pPatch, bFlag);
  3053. }
  3054. else
  3055. {
  3056. Patch_RemoveRow(pb->pPatch, bFlag);
  3057. }
  3058. }
  3059. bUpdate = true;
  3060. vec3_t vMin, vMax;
  3061. patchMesh_t *p = pb->pPatch;
  3062. Patch_CalcBounds(p, vMin, vMax);
  3063. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  3064. }
  3065. }
  3066. if (bUpdate)
  3067. {
  3068. Sys_UpdateWindows(W_ALL);
  3069. }
  3070. }
  3071. /*
  3072. ==================
  3073. Patch_AdjustSelectedRowCols
  3074. ==================
  3075. */
  3076. void Patch_AdjustSelectedRowCols(int nRows, int nCols)
  3077. {
  3078. for (brush_t* pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3079. {
  3080. if (pb->patchBrush)
  3081. {
  3082. Patch_InsertColumn(pb->pPatch, false);
  3083. if (nRows != 0)
  3084. {
  3085. Patch_AdjustRows(pb->pPatch, nRows);
  3086. }
  3087. if (nCols != 0)
  3088. {
  3089. Patch_AdjustColumns(pb->pPatch, nCols);
  3090. }
  3091. }
  3092. }
  3093. UpdatePatchInspector();
  3094. }
  3095. void Parse1DMatrix(int x, float* p)
  3096. {
  3097. GetToken(true); // (
  3098. for (int i = 0; i < x; i++)
  3099. {
  3100. GetToken(false);
  3101. p[i] = atof(token);
  3102. }
  3103. GetToken(true); // )
  3104. }
  3105. void Parse2DMatrix(int y, int x, float* p)
  3106. {
  3107. GetToken(true); // (
  3108. for (int i = 0; i < y; i++)
  3109. {
  3110. Parse1DMatrix(x, p + i*x);
  3111. }
  3112. GetToken(true); // )
  3113. }
  3114. void Parse3DMatrix(int z, int y, int x, float* p)
  3115. {
  3116. GetToken(true); // (
  3117. for (int i = 0; i < z; i++)
  3118. {
  3119. Parse2DMatrix(y, x, p + i*(x*MAX_PATCH_HEIGHT));
  3120. }
  3121. GetToken(true); // )
  3122. }
  3123. // parses a patch
  3124. brush_t* Patch_Parse(bool bOld)
  3125. {
  3126. //--if (bOld)
  3127. //--{
  3128. //-- return Patch_ParseOld();
  3129. //--}
  3130. GetToken(true);
  3131. if (strcmp(token, "{"))
  3132. return NULL;
  3133. patchMesh_t *pm = MakeNewPatch();
  3134. if (g_qeglobals.bSurfacePropertiesPlugin)
  3135. {
  3136. GETPLUGINTEXDEF(pm)->ParsePatchTexdef();
  3137. }
  3138. else
  3139. {
  3140. // texture def
  3141. GetToken(true);
  3142. // band-aid
  3143. if (strcmp(token, "("))
  3144. {
  3145. pm->d_texture = Texture_ForName(token);
  3146. GetToken(true);
  3147. }
  3148. else
  3149. {
  3150. pm->d_texture = notexture;
  3151. Sys_Printf("Warning: Patch read with no texture, using notexture... \n");
  3152. }
  3153. if (strcmp(token, "("))
  3154. return NULL;
  3155. // width, height, flags (currently only negative)
  3156. GetToken(false);
  3157. pm->width = atoi(token);
  3158. GetToken(false);
  3159. pm->height = atoi(token);
  3160. GetToken(false);
  3161. pm->contents = atoi(token);
  3162. GetToken(false);
  3163. pm->flags = atoi(token);
  3164. GetToken(false);
  3165. pm->value = atoi(token);
  3166. if (!bOld)
  3167. {
  3168. GetToken(false);
  3169. pm->type = atoi(token);
  3170. }
  3171. GetToken(false);
  3172. if (strcmp(token, ")"))
  3173. return NULL;
  3174. }
  3175. float ctrl[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT][5];
  3176. Parse3DMatrix(pm->width, pm->height, 5, reinterpret_cast<float*>(&ctrl));
  3177. int w, h;
  3178. for (w = 0; w < pm->width; w++)
  3179. {
  3180. for (h = 0; h < pm->height; h++)
  3181. {
  3182. pm->ctrl[w][h].xyz[0] = ctrl[w][h][0];
  3183. pm->ctrl[w][h].xyz[1] = ctrl[w][h][1];
  3184. pm->ctrl[w][h].xyz[2] = ctrl[w][h][2];
  3185. pm->ctrl[w][h].st[0] = ctrl[w][h][3];
  3186. pm->ctrl[w][h].st[1] = ctrl[w][h][4];
  3187. }
  3188. }
  3189. GetToken(true);
  3190. if (g_qeglobals.m_bBrushPrimitMode)
  3191. {
  3192. // we are in brush primit mode, but maybe it's a classic patch that needs converting, test "}"
  3193. if (strcmp(token, "}") && strcmp (token, "(") )
  3194. {
  3195. epair_t *ep = ParseEpair();
  3196. ep->next = pm->epairs;
  3197. pm->epairs = ep;
  3198. GetToken(true);
  3199. }
  3200. }
  3201. if (strcmp(token, "}"))
  3202. return NULL;
  3203. brush_t *b = AddBrushForPatch(pm, false);
  3204. return b;
  3205. }
  3206. /*
  3207. ==================
  3208. Patch_Write
  3209. ==================
  3210. */
  3211. void Patch_Write (patchMesh_t *p, CMemFile *file)
  3212. {
  3213. if (g_qeglobals.bSurfacePropertiesPlugin)
  3214. {
  3215. Sys_Printf("WARNING: Patch_Write to a CMemFile and Surface Properties plugin not done\n");
  3216. }
  3217. //--MemFile_fprintf(file, " {\n patchDef3\n {\n");
  3218. MemFile_fprintf(file, " {\n patchDef2\n {\n");
  3219. MemFile_fprintf(file, " %s\n",p->d_texture->name);
  3220. //--MemFile_fprintf(file, " ( %i %i %i %i %i %i ) \n", p->width, p->height, p->contents, p->flags, p->value, p->type);
  3221. MemFile_fprintf(file, " ( %i %i %i %i %i ) \n", p->width, p->height, p->contents, p->flags, p->value);
  3222. float ctrl[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT][5];
  3223. int w, h;
  3224. for (w = 0; w < p->width; w++)
  3225. {
  3226. for (h = 0; h < p->height; h++)
  3227. {
  3228. ctrl[w][h][0] = p->ctrl[w][h].xyz[0];
  3229. ctrl[w][h][1] = p->ctrl[w][h].xyz[1];
  3230. ctrl[w][h][2] = p->ctrl[w][h].xyz[2];
  3231. ctrl[w][h][3] = p->ctrl[w][h].st[0];
  3232. ctrl[w][h][4] = p->ctrl[w][h].st[1];
  3233. }
  3234. }
  3235. _Write3DMatrix(file, p->width, p->height, 5, reinterpret_cast<float*>(&ctrl));
  3236. if (g_qeglobals.m_bBrushPrimitMode)
  3237. {
  3238. if (p->epairs)
  3239. {
  3240. for (epair_t *ep = p->epairs ; ep ; ep=ep->next)
  3241. {
  3242. MemFile_fprintf (file, "\"%s\" \"%s\"\n", ep->key, ep->value);
  3243. }
  3244. }
  3245. }
  3246. MemFile_fprintf(file, " }\n }\n");
  3247. }
  3248. void Patch_Write (patchMesh_t *p, FILE *file)
  3249. {
  3250. fprintf(file, " {\n patchDef2\n {\n");
  3251. if (g_qeglobals.bSurfacePropertiesPlugin)
  3252. {
  3253. #ifdef _DEBUG
  3254. if ( !p->pData )
  3255. Sys_Printf("ERROR: no IPluginTexdef in patch\n");
  3256. #endif
  3257. g_File = file;
  3258. GETPLUGINTEXDEF(p)->WritePatchTexdef( QERApp_MapPrintf_FILE );
  3259. }
  3260. else
  3261. {
  3262. fprintf(file, " %s\n",p->d_texture->name);
  3263. fprintf(file, " ( %i %i %i %i %i ) \n", p->width, p->height, p->contents, p->flags, p->value);
  3264. }
  3265. float ctrl[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT][5];
  3266. int w, h;
  3267. for (w = 0; w < p->width; w++)
  3268. {
  3269. for (h = 0; h < p->height; h++)
  3270. {
  3271. ctrl[w][h][0] = p->ctrl[w][h].xyz[0];
  3272. ctrl[w][h][1] = p->ctrl[w][h].xyz[1];
  3273. ctrl[w][h][2] = p->ctrl[w][h].xyz[2];
  3274. ctrl[w][h][3] = p->ctrl[w][h].st[0];
  3275. ctrl[w][h][4] = p->ctrl[w][h].st[1];
  3276. }
  3277. }
  3278. _Write3DMatrix(file, p->width, p->height, 5, reinterpret_cast<float*>(&ctrl));
  3279. if (g_qeglobals.m_bBrushPrimitMode)
  3280. {
  3281. if (p->epairs)
  3282. {
  3283. for (epair_t *ep = p->epairs ; ep ; ep=ep->next)
  3284. {
  3285. fprintf (file, "\"%s\" \"%s\"\n", ep->key, ep->value);
  3286. }
  3287. }
  3288. }
  3289. fprintf(file, " }\n }\n");
  3290. }
  3291. /*
  3292. ==================
  3293. Patch_RotateTexture
  3294. ==================
  3295. */
  3296. void Patch_RotateTexture(patchMesh_t *p, float fAngle)
  3297. {
  3298. vec3_t vMin, vMax;
  3299. Patch_CalcBounds(p, vMin, vMax);
  3300. p->bDirty = true;
  3301. for (int w = 0; w < p->width; w++)
  3302. {
  3303. for (int h = 0; h < p->height; h++)
  3304. {
  3305. if (g_qeglobals.d_select_mode == sel_curvepoint && PointInMoveList(p->ctrl[w][h].xyz) == -1)
  3306. continue;
  3307. float x = p->ctrl[w][h].st[0];
  3308. float y = p->ctrl[w][h].st[1];
  3309. p->ctrl[w][h].st[0] = x * cos(fAngle * Q_PI / 180) - y * sin(fAngle * Q_PI / 180);
  3310. p->ctrl[w][h].st[1] = y * cos(fAngle * Q_PI / 180) + x * sin(fAngle * Q_PI / 180);
  3311. }
  3312. }
  3313. }
  3314. /*
  3315. ==================
  3316. Patch_ScaleTexture
  3317. ==================
  3318. */
  3319. void Patch_ScaleTexture(patchMesh_t *p, float fx, float fy, bool bFixup)
  3320. {
  3321. // FIXME:
  3322. // this hack turns scales into 1.1 or 0.9
  3323. if (bFixup)
  3324. {
  3325. fx = (fx == 0) ? 1.0 : (fx > 0) ? 0.9 : 1.10;
  3326. fy = (fy == 0) ? 1.0 : (fy > 0) ? 0.9 : 1.10;
  3327. }
  3328. else
  3329. {
  3330. if (fx == 0)
  3331. fx = 1.0;
  3332. if (fy == 0)
  3333. fy = 1.0;
  3334. }
  3335. for (int w = 0; w < p->width; w++)
  3336. {
  3337. for (int h = 0; h < p->height; h++)
  3338. {
  3339. if (g_qeglobals.d_select_mode == sel_curvepoint && PointInMoveList(p->ctrl[w][h].xyz) == -1)
  3340. continue;
  3341. p->ctrl[w][h].st[0] *= fx;
  3342. p->ctrl[w][h].st[1] *= fy;
  3343. }
  3344. }
  3345. p->bDirty = true;
  3346. }
  3347. /*
  3348. ==================
  3349. Patch_ShiftTexture
  3350. ==================
  3351. */
  3352. void Patch_ShiftTexture(patchMesh_t *p, float fx, float fy)
  3353. {
  3354. //if (fx)
  3355. // fx = (fx > 0) ? 0.1 : -0.1;
  3356. //if (fy)
  3357. // fy = (fy > 0) ? 0.1 : -0.1;
  3358. fx = (abs(fx) >= 1) ? fx / 10 : fx;
  3359. fy = (abs(fy) >= 1) ? fy / 10 : fy;
  3360. for (int w = 0; w < p->width; w++)
  3361. {
  3362. for (int h = 0; h < p->height; h++)
  3363. {
  3364. if (g_qeglobals.d_select_mode == sel_curvepoint && PointInMoveList(p->ctrl[w][h].xyz) == -1)
  3365. continue;
  3366. p->ctrl[w][h].st[0] += fx;
  3367. p->ctrl[w][h].st[1] += fy;
  3368. }
  3369. }
  3370. p->bDirty = true;
  3371. }
  3372. void patchInvert(patchMesh_t *p)
  3373. {
  3374. drawVert_t vertTemp;
  3375. p->bDirty = true;
  3376. for ( int i = 0 ; i < p->width ; i++ )
  3377. {
  3378. for (int j = 0; j < p->height / 2; j++)
  3379. {
  3380. memcpy(&vertTemp, &p->ctrl[i][p->height - 1- j], sizeof (drawVert_t));
  3381. memcpy(&p->ctrl[i][p->height - 1 - j], &p->ctrl[i][j], sizeof(drawVert_t));
  3382. memcpy(&p->ctrl[i][j], &vertTemp, sizeof(drawVert_t));
  3383. }
  3384. }
  3385. }
  3386. /*
  3387. ==================
  3388. Patch_ToggleInverted
  3389. ==================
  3390. */
  3391. void Patch_ToggleInverted()
  3392. {
  3393. bool bUpdate = false;
  3394. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3395. {
  3396. if (pb->patchBrush)
  3397. {
  3398. bUpdate = true;
  3399. patchInvert(pb->pPatch);
  3400. }
  3401. }
  3402. if (bUpdate)
  3403. {
  3404. Sys_UpdateWindows(W_ALL);
  3405. }
  3406. UpdatePatchInspector();
  3407. }
  3408. /*
  3409. ==================
  3410. Patch_ToggleInverted
  3411. ==================
  3412. */
  3413. void Patch_InvertTexture(bool bY)
  3414. {
  3415. bool bUpdate = false;
  3416. float fTemp[2];
  3417. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3418. {
  3419. if (pb->patchBrush)
  3420. {
  3421. bUpdate = true;
  3422. patchMesh_t *p = pb->pPatch;
  3423. p->bDirty = true;
  3424. if (bY)
  3425. {
  3426. for ( int i = 0 ; i < p->height ; i++ )
  3427. {
  3428. for (int j = 0; j < p->width / 2; j++)
  3429. {
  3430. memcpy(fTemp, &p->ctrl[p->width - 1- j][i].st[0], sizeof (float[2]));
  3431. memcpy(&p->ctrl[p->width - 1- j][i].st[0], &p->ctrl[j][i].st[0], sizeof(float[2]));
  3432. memcpy(&p->ctrl[j][i].st[0], fTemp, sizeof(float[2]));
  3433. }
  3434. }
  3435. }
  3436. else
  3437. {
  3438. for ( int i = 0 ; i < p->width ; i++ )
  3439. {
  3440. for (int j = 0; j < p->height / 2; j++)
  3441. {
  3442. memcpy(fTemp, &p->ctrl[i][p->height - 1- j].st[0], sizeof (float[2]));
  3443. memcpy(&p->ctrl[i][p->height - 1 - j].st[0], &p->ctrl[i][j].st[0], sizeof(float[2]));
  3444. memcpy(&p->ctrl[i][j].st[0], fTemp, sizeof(float[2]));
  3445. }
  3446. }
  3447. }
  3448. }
  3449. }
  3450. if (bUpdate)
  3451. {
  3452. Sys_UpdateWindows(W_ALL);
  3453. }
  3454. UpdatePatchInspector();
  3455. }
  3456. /*
  3457. ==================
  3458. Patch_Save
  3459. ==================
  3460. Saves patch ctrl info (originally to deal with a
  3461. cancel in the surface dialog
  3462. */
  3463. void Patch_Save(patchMesh_t *p)
  3464. {
  3465. patchSave.width = p->width;
  3466. patchSave.height = p->height;
  3467. memcpy(patchSave.ctrl, p->ctrl, sizeof(p->ctrl));
  3468. }
  3469. /*
  3470. ==================
  3471. Patch_Restore
  3472. ==================
  3473. */
  3474. void Patch_Restore(patchMesh_t *p)
  3475. {
  3476. p->width = patchSave.width;
  3477. p->height = patchSave.height;
  3478. memcpy(p->ctrl, patchSave.ctrl, sizeof(p->ctrl));
  3479. }
  3480. void Patch_ResetTexturing(float fx, float fy)
  3481. {
  3482. for (brush_t* pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3483. {
  3484. if (pb->patchBrush)
  3485. {
  3486. patchMesh_t *p = pb->pPatch;
  3487. p->bDirty = true;
  3488. for ( int i = 0 ; i < p->width ; i++ )
  3489. {
  3490. for ( int j = 0 ; j < p->height ; j++ )
  3491. {
  3492. p->ctrl[i][j].st[0] = fx * (float)i / (p->width - 1);
  3493. p->ctrl[i][j].st[1] = fy * (float)j / (p->height - 1);
  3494. }
  3495. }
  3496. }
  3497. }
  3498. }
  3499. void Patch_FitTexturing()
  3500. {
  3501. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3502. {
  3503. if (pb->patchBrush)
  3504. {
  3505. patchMesh_t *p = pb->pPatch;
  3506. p->bDirty = true;
  3507. for ( int i = 0 ; i < p->width ; i++ )
  3508. {
  3509. for ( int j = 0 ; j < p->height ; j++ )
  3510. {
  3511. p->ctrl[i][j].st[0] = 1 * (float)i / (p->width - 1);
  3512. p->ctrl[i][j].st[1] = 1 * (float)j / (p->height - 1);
  3513. }
  3514. }
  3515. }
  3516. }
  3517. }
  3518. void Patch_SetTextureInfo(texdef_t *pt)
  3519. {
  3520. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3521. {
  3522. if (pb->patchBrush)
  3523. {
  3524. if (pt->rotate)
  3525. Patch_RotateTexture(pb->pPatch, pt->rotate);
  3526. if (pt->shift[0] || pt->shift[1])
  3527. Patch_ShiftTexture(pb->pPatch, pt->shift[0], pt->shift[1]);
  3528. if (pt->scale[0] || pt->scale[1])
  3529. Patch_ScaleTexture(pb->pPatch, pt->scale[0], pt->scale[1], false);
  3530. patchMesh_t *p = pb->pPatch;
  3531. p->contents = pt->contents;
  3532. p->flags = pt->flags;
  3533. p->value = pt->value;
  3534. }
  3535. }
  3536. }
  3537. bool WINAPI OnlyPatchesSelected()
  3538. {
  3539. if (g_ptrSelectedFaces.GetSize() > 0 || selected_brushes.next == &selected_brushes)
  3540. return false;
  3541. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3542. {
  3543. if (!pb->patchBrush)
  3544. {
  3545. return false;
  3546. }
  3547. }
  3548. return true;
  3549. }
  3550. bool WINAPI AnyPatchesSelected()
  3551. {
  3552. if (g_ptrSelectedFaces.GetSize() > 0 || selected_brushes.next == &selected_brushes)
  3553. return false;
  3554. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3555. {
  3556. if (pb->patchBrush)
  3557. {
  3558. return true;
  3559. }
  3560. }
  3561. return false;
  3562. }
  3563. patchMesh_t* SinglePatchSelected()
  3564. {
  3565. if (selected_brushes.next->patchBrush)
  3566. {
  3567. return selected_brushes.next->pPatch;
  3568. }
  3569. return NULL;
  3570. }
  3571. void Patch_BendToggle()
  3572. {
  3573. if (g_bPatchBendMode)
  3574. {
  3575. g_bPatchBendMode = false;
  3576. HideInfoDialog();
  3577. g_pParentWnd->UpdatePatchToolbarButtons() ;
  3578. return;
  3579. }
  3580. brush_t* b = selected_brushes.next;
  3581. if (!QE_SingleBrush() || !b->patchBrush)
  3582. {
  3583. Sys_Printf("Must bend a single patch");
  3584. return;
  3585. }
  3586. Patch_Save(b->pPatch);
  3587. g_bPatchBendMode = true;
  3588. g_nPatchBendState = BEND_SELECT_ROTATION;
  3589. g_bPatchAxisOnRow = true;
  3590. g_nPatchAxisIndex = 1;
  3591. ShowInfoDialog(g_pBendStateMsg[BEND_SELECT_ROTATION]);
  3592. }
  3593. void Patch_BendHandleTAB()
  3594. {
  3595. if (!g_bPatchBendMode)
  3596. {
  3597. return;
  3598. }
  3599. brush_t* b = selected_brushes.next;
  3600. if (!QE_SingleBrush() || !b->patchBrush)
  3601. {
  3602. Patch_BendToggle();
  3603. Sys_Printf("No patch to bend!");
  3604. return;
  3605. }
  3606. patchMesh_t *p = b->pPatch;
  3607. bool bShift = (GetKeyState(VK_SHIFT) & 0x8000);
  3608. if (g_nPatchBendState == BEND_SELECT_ROTATION)
  3609. {
  3610. // only able to deal with odd numbered rows/cols
  3611. g_nPatchAxisIndex += (bShift) ? -2 : 2;
  3612. if (g_bPatchAxisOnRow)
  3613. {
  3614. if ((bShift) ? g_nPatchAxisIndex <= 0 : g_nPatchAxisIndex >= p->height)
  3615. {
  3616. g_bPatchAxisOnRow = false;
  3617. g_nPatchAxisIndex = (bShift) ? p->width-1 : 1;
  3618. }
  3619. }
  3620. else
  3621. {
  3622. if ((bShift) ? g_nPatchAxisIndex <= 0 : g_nPatchAxisIndex >= p->width)
  3623. {
  3624. g_bPatchAxisOnRow = true;
  3625. g_nPatchAxisIndex = (bShift) ? p->height-1 : 1;
  3626. }
  3627. }
  3628. }
  3629. else
  3630. if (g_nPatchBendState == BEND_SELECT_ORIGIN)
  3631. {
  3632. g_nBendOriginIndex += (bShift) ? -1 : 1;
  3633. if (g_bPatchAxisOnRow)
  3634. {
  3635. if (bShift)
  3636. {
  3637. if (g_nBendOriginIndex < 0)
  3638. g_nBendOriginIndex = p->width-1;
  3639. }
  3640. else
  3641. {
  3642. if (g_nBendOriginIndex > p->width-1)
  3643. g_nBendOriginIndex = 0;
  3644. }
  3645. VectorCopy(p->ctrl[g_nBendOriginIndex][g_nPatchAxisIndex].xyz, g_vBendOrigin);
  3646. }
  3647. else
  3648. {
  3649. if (bShift)
  3650. {
  3651. if (g_nBendOriginIndex < 0)
  3652. g_nBendOriginIndex = p->height-1;
  3653. }
  3654. else
  3655. {
  3656. if (g_nBendOriginIndex > p->height-1)
  3657. g_nBendOriginIndex = 0;
  3658. }
  3659. VectorCopy(p->ctrl[g_nPatchAxisIndex][g_nBendOriginIndex].xyz, g_vBendOrigin);
  3660. }
  3661. }
  3662. else
  3663. if (g_nPatchBendState == BEND_SELECT_EDGE)
  3664. {
  3665. g_bPatchLowerEdge ^= 1;
  3666. }
  3667. Sys_UpdateWindows(W_ALL);
  3668. }
  3669. void Patch_BendHandleENTER()
  3670. {
  3671. if (!g_bPatchBendMode)
  3672. {
  3673. return;
  3674. }
  3675. if (g_nPatchBendState < BEND_BENDIT)
  3676. {
  3677. g_nPatchBendState++;
  3678. ShowInfoDialog(g_pBendStateMsg[g_nPatchBendState]);
  3679. if (g_nPatchBendState == BEND_SELECT_ORIGIN)
  3680. {
  3681. g_vBendOrigin[0] = g_vBendOrigin[1] = g_vBendOrigin[2] = 0;
  3682. g_nBendOriginIndex = 0;
  3683. Patch_BendHandleTAB();
  3684. }
  3685. else
  3686. if (g_nPatchBendState == BEND_SELECT_EDGE)
  3687. {
  3688. g_bPatchLowerEdge = true;
  3689. }
  3690. else
  3691. if (g_nPatchBendState == BEND_BENDIT)
  3692. {
  3693. // basically we go into rotation mode, set the axis to the center of the
  3694. }
  3695. }
  3696. else
  3697. {
  3698. // done
  3699. Patch_BendToggle();
  3700. }
  3701. Sys_UpdateWindows(W_ALL);
  3702. }
  3703. void Patch_BendHandleESC()
  3704. {
  3705. if (!g_bPatchBendMode)
  3706. {
  3707. return;
  3708. }
  3709. Patch_BendToggle();
  3710. brush_t* b = selected_brushes.next;
  3711. if (QE_SingleBrush() && b->patchBrush)
  3712. {
  3713. Patch_Restore(b->pPatch);
  3714. }
  3715. Sys_UpdateWindows(W_ALL);
  3716. }
  3717. void Patch_SetBendRotateOrigin(patchMesh_t *p)
  3718. {
  3719. #if 1
  3720. int nType = g_pParentWnd->ActiveXY()->GetViewType();
  3721. int nDim3 = (nType == XY) ? 2 : (nType == YZ) ? 0 : 1;
  3722. g_vBendOrigin[nDim3] = 0;
  3723. VectorCopy(g_vBendOrigin, g_pParentWnd->ActiveXY()->RotateOrigin());
  3724. return;
  3725. #else
  3726. int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
  3727. int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
  3728. float fxLo, fyLo, fxHi, fyHi;
  3729. fxLo = fyLo = 9999;
  3730. fxHi = fyHi = -9999;
  3731. if (g_bPatchAxisOnRow)
  3732. {
  3733. for (int i = 0; i < p->width; i++)
  3734. {
  3735. if (p->ctrl[i][g_nPatchAxisIndex].xyz[nDim1] < fxLo)
  3736. fxLo = p->ctrl[i][g_nPatchAxisIndex].xyz[nDim1];
  3737. if (p->ctrl[i][g_nPatchAxisIndex].xyz[nDim1] > fxHi)
  3738. fxHi = p->ctrl[i][g_nPatchAxisIndex].xyz[nDim1];
  3739. if (p->ctrl[i][g_nPatchAxisIndex].xyz[nDim2] < fyLo)
  3740. fyLo = p->ctrl[i][g_nPatchAxisIndex].xyz[nDim2];
  3741. if (p->ctrl[i][g_nPatchAxisIndex].xyz[nDim2] > fyHi)
  3742. fyHi = p->ctrl[i][g_nPatchAxisIndex].xyz[nDim2];
  3743. }
  3744. }
  3745. else
  3746. {
  3747. for (int i = 0; i < p->height; i++)
  3748. {
  3749. if (p->ctrl[g_nPatchAxisIndex][i].xyz[nDim1] < fxLo)
  3750. fxLo = p->ctrl[g_nPatchAxisIndex][i].xyz[nDim1];
  3751. if (p->ctrl[g_nPatchAxisIndex][i].xyz[nDim1] > fxHi)
  3752. fxHi = p->ctrl[g_nPatchAxisIndex][i].xyz[nDim1];
  3753. if (p->ctrl[g_nPatchAxisIndex][i].xyz[nDim2] < fyLo)
  3754. fyLo = p->ctrl[g_nPatchAxisIndex][i].xyz[nDim2];
  3755. if (p->ctrl[g_nPatchAxisIndex][i].xyz[nDim2] > fyHi)
  3756. fyHi = p->ctrl[g_nPatchAxisIndex][i].xyz[nDim2];
  3757. }
  3758. }
  3759. g_pParentWnd->ActiveXY()->RotateOrigin()[0] = g_pParentWnd->ActiveXY()->RotateOrigin()[1] = g_pParentWnd->ActiveXY()->RotateOrigin()[2] = 0.0;
  3760. g_pParentWnd->ActiveXY()->RotateOrigin()[nDim1] = (fxLo + fxHi) * 0.5;
  3761. g_pParentWnd->ActiveXY()->RotateOrigin()[nDim2] = (fyLo + fyHi) * 0.5;
  3762. #endif
  3763. }
  3764. // also sets the rotational origin
  3765. void Patch_SelectBendAxis()
  3766. {
  3767. brush_t* b = selected_brushes.next;
  3768. if (!QE_SingleBrush() || !b->patchBrush)
  3769. {
  3770. // should not ever happen
  3771. Patch_BendToggle();
  3772. return;
  3773. }
  3774. patchMesh_t *p = b->pPatch;
  3775. if (g_bPatchAxisOnRow)
  3776. {
  3777. SelectRow(p, g_nPatchAxisIndex, false);
  3778. }
  3779. else
  3780. {
  3781. SelectColumn(p, g_nPatchAxisIndex, false);
  3782. }
  3783. //FIXME: this only needs to be set once...
  3784. Patch_SetBendRotateOrigin(p);
  3785. }
  3786. void Patch_SelectBendNormal()
  3787. {
  3788. brush_t* b = selected_brushes.next;
  3789. if (!QE_SingleBrush() || !b->patchBrush)
  3790. {
  3791. // should not ever happen
  3792. Patch_BendToggle();
  3793. return;
  3794. }
  3795. patchMesh_t *p = b->pPatch;
  3796. g_qeglobals.d_num_move_points = 0;
  3797. if (g_bPatchAxisOnRow)
  3798. {
  3799. if (g_bPatchLowerEdge)
  3800. {
  3801. for (int j = 0; j < g_nPatchAxisIndex; j++)
  3802. SelectRow(p, j, true);
  3803. }
  3804. else
  3805. {
  3806. for (int j = p->height-1; j > g_nPatchAxisIndex; j--)
  3807. SelectRow(p, j, true);
  3808. }
  3809. }
  3810. else
  3811. {
  3812. if (g_bPatchLowerEdge)
  3813. {
  3814. for (int j = 0; j < g_nPatchAxisIndex; j++)
  3815. SelectColumn(p, j, true);
  3816. }
  3817. else
  3818. {
  3819. for (int j = p->width-1; j > g_nPatchAxisIndex; j--)
  3820. SelectColumn(p, j, true);
  3821. }
  3822. }
  3823. Patch_SetBendRotateOrigin(p);
  3824. }
  3825. void Patch_InsDelToggle()
  3826. {
  3827. if (g_bPatchInsertMode)
  3828. {
  3829. g_bPatchInsertMode = false;
  3830. HideInfoDialog();
  3831. g_pParentWnd->UpdatePatchToolbarButtons() ;
  3832. return;
  3833. }
  3834. brush_t* b = selected_brushes.next;
  3835. if (!QE_SingleBrush() || !b->patchBrush)
  3836. {
  3837. Sys_Printf("Must work with a single patch");
  3838. return;
  3839. }
  3840. Patch_Save(b->pPatch);
  3841. g_bPatchInsertMode = true;
  3842. g_nPatchInsertState = INSERT_SELECT_EDGE;
  3843. g_bPatchAxisOnRow = true;
  3844. g_nPatchAxisIndex = 0;
  3845. ShowInfoDialog(g_pInsertStateMsg[INSERT_SELECT_EDGE]);
  3846. }
  3847. void Patch_InsDelESC()
  3848. {
  3849. if (!g_bPatchInsertMode)
  3850. {
  3851. return;
  3852. }
  3853. Patch_InsDelToggle();
  3854. Sys_UpdateWindows(W_ALL);
  3855. }
  3856. void Patch_InsDelHandleENTER()
  3857. {
  3858. }
  3859. void Patch_InsDelHandleTAB()
  3860. {
  3861. if (!g_bPatchInsertMode)
  3862. {
  3863. Patch_InsDelToggle();
  3864. return;
  3865. }
  3866. brush_t* b = selected_brushes.next;
  3867. if (!QE_SingleBrush() || !b->patchBrush)
  3868. {
  3869. Patch_BendToggle();
  3870. Sys_Printf("No patch to bend!");
  3871. return;
  3872. }
  3873. patchMesh_t *p = b->pPatch;
  3874. // only able to deal with odd numbered rows/cols
  3875. g_nPatchAxisIndex += 2;
  3876. if (g_bPatchAxisOnRow)
  3877. {
  3878. if (g_nPatchAxisIndex >= p->height-1)
  3879. {
  3880. g_bPatchAxisOnRow = false;
  3881. g_nPatchAxisIndex = 0;
  3882. }
  3883. }
  3884. else
  3885. {
  3886. if (g_nPatchAxisIndex >= p->width-1)
  3887. {
  3888. g_bPatchAxisOnRow = true;
  3889. g_nPatchAxisIndex = 0;
  3890. }
  3891. }
  3892. Sys_UpdateWindows(W_ALL);
  3893. }
  3894. void _Write1DMatrix (FILE *f, int x, float *m) {
  3895. int i;
  3896. fprintf (f, "( ");
  3897. for (i = 0 ; i < x ; i++) {
  3898. if (m[i] == (int)m[i] ) {
  3899. fprintf (f, "%i ", (int)m[i]);
  3900. } else {
  3901. fprintf (f, "%f ", m[i]);
  3902. }
  3903. }
  3904. fprintf (f, ")");
  3905. }
  3906. void _Write2DMatrix (FILE *f, int y, int x, float *m) {
  3907. int i;
  3908. fprintf (f, "( ");
  3909. for (i = 0 ; i < y ; i++) {
  3910. _Write1DMatrix (f, x, m + i*x);
  3911. fprintf (f, " ");
  3912. }
  3913. fprintf (f, ")\n");
  3914. }
  3915. void _Write3DMatrix (FILE *f, int z, int y, int x, float *m) {
  3916. int i;
  3917. fprintf (f, "(\n");
  3918. for (i = 0 ; i < z ; i++) {
  3919. _Write2DMatrix (f, y, x, m + i*(x*MAX_PATCH_HEIGHT) );
  3920. }
  3921. fprintf (f, ")\n");
  3922. }
  3923. void _Write1DMatrix (CMemFile *f, int x, float *m) {
  3924. int i;
  3925. MemFile_fprintf (f, "( ");
  3926. for (i = 0 ; i < x ; i++) {
  3927. if (m[i] == (int)m[i] ) {
  3928. MemFile_fprintf (f, "%i ", (int)m[i]);
  3929. } else {
  3930. MemFile_fprintf (f, "%f ", m[i]);
  3931. }
  3932. }
  3933. MemFile_fprintf (f, ")");
  3934. }
  3935. void _Write2DMatrix (CMemFile *f, int y, int x, float *m) {
  3936. int i;
  3937. MemFile_fprintf (f, "( ");
  3938. for (i = 0 ; i < y ; i++) {
  3939. _Write1DMatrix (f, x, m + i*x);
  3940. MemFile_fprintf (f, " ");
  3941. }
  3942. MemFile_fprintf (f, ")\n");
  3943. }
  3944. void _Write3DMatrix (CMemFile *f, int z, int y, int x, float *m) {
  3945. int i;
  3946. MemFile_fprintf (f, "(\n");
  3947. for (i = 0 ; i < z ; i++) {
  3948. _Write2DMatrix (f, y, x, m + i*(x*MAX_PATCH_HEIGHT) );
  3949. }
  3950. MemFile_fprintf (f, ")\n");
  3951. }
  3952. void Patch_NaturalizeSelected(bool bCap, bool bCycleCap)
  3953. {
  3954. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3955. {
  3956. if (pb->patchBrush)
  3957. {
  3958. if (bCap)
  3959. Patch_CapTexture(pb->pPatch, bCycleCap);
  3960. else
  3961. Patch_Naturalize(pb->pPatch);
  3962. }
  3963. }
  3964. }
  3965. bool within(vec3_t vTest, vec3_t vTL, vec3_t vBR)
  3966. {
  3967. int nDim1 = (g_pParentWnd->ActiveXY()->GetViewType() == YZ) ? 1 : 0;
  3968. int nDim2 = (g_pParentWnd->ActiveXY()->GetViewType() == XY) ? 1 : 2;
  3969. if ((vTest[nDim1] > vTL[nDim1] && vTest[nDim1] < vBR[nDim1]) ||
  3970. (vTest[nDim1] < vTL[nDim1] && vTest[nDim1] > vBR[nDim1]))
  3971. {
  3972. if ((vTest[nDim2] > vTL[nDim2] && vTest[nDim2] < vBR[nDim2]) ||
  3973. (vTest[nDim2] < vTL[nDim2] && vTest[nDim2] > vBR[nDim2]))
  3974. return true;
  3975. }
  3976. return false;
  3977. }
  3978. void Patch_SelectAreaPoints()
  3979. {
  3980. g_qeglobals.d_num_move_points = 0;
  3981. g_nPatchClickedView = -1;
  3982. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  3983. {
  3984. if (pb->patchBrush)
  3985. {
  3986. patchMesh_t *p = pb->pPatch;
  3987. for (int i = 0; i < p->width; i++)
  3988. {
  3989. for (int j = 0; j < p->height; j++)
  3990. {
  3991. if (within(p->ctrl[i][j].xyz, g_qeglobals.d_vAreaTL, g_qeglobals.d_vAreaBR))
  3992. {
  3993. g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = p->ctrl[i][j].xyz;
  3994. }
  3995. }
  3996. }
  3997. }
  3998. }
  3999. }
  4000. const char* Patch_GetTextureName()
  4001. {
  4002. brush_t* b = selected_brushes.next;
  4003. if (b->patchBrush)
  4004. {
  4005. patchMesh_t *p = b->pPatch;
  4006. if (p->d_texture->name)
  4007. return p->d_texture->name;
  4008. }
  4009. return "";
  4010. }
  4011. patchMesh_t* Patch_Duplicate(patchMesh_t *pFrom)
  4012. {
  4013. patchMesh_t* p = MakeNewPatch();
  4014. memcpy(p, pFrom , sizeof(patchMesh_t));
  4015. p->bSelected = false;
  4016. p->bDirty = true;
  4017. p->bOverlay = false;
  4018. p->nListID = -1;
  4019. // surface plugin
  4020. if (g_qeglobals.bSurfacePropertiesPlugin)
  4021. {
  4022. #ifdef _DEBUG
  4023. if (!pFrom->pData)
  4024. Sys_Printf("WARNING: unexpected pFrom->pData is NULL in Patch_Duplicate\n");
  4025. else
  4026. #endif
  4027. p->pData = GETPLUGINTEXDEF(pFrom)->Copy();
  4028. }
  4029. AddBrushForPatch(p);
  4030. return p;
  4031. }
  4032. void Patch_Thicken(int nAmount, bool bSeam)
  4033. {
  4034. int i, j, h, w;
  4035. brush_t *b;
  4036. patchMesh_t *pSeam;
  4037. vec3_t vMin, vMax;
  4038. CPtrArray brushes;
  4039. nAmount = -nAmount;
  4040. if (!QE_SingleBrush())
  4041. {
  4042. Sys_Printf("Cannot thicken multiple patches. Please select a single patch.\n");
  4043. return;
  4044. }
  4045. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4046. {
  4047. if (pb->patchBrush)
  4048. {
  4049. patchMesh_t *p = pb->pPatch;
  4050. Patch_MeshNormals(p);
  4051. patchMesh_t *pNew = Patch_Duplicate(p);
  4052. for (i = 0; i < p->width; i++)
  4053. {
  4054. for (j = 0; j < p->height; j++)
  4055. {
  4056. VectorMA (p->ctrl[i][j].xyz, nAmount, p->ctrl[i][j].normal, pNew->ctrl[i][j].xyz);
  4057. }
  4058. }
  4059. Patch_Rebuild(pNew);
  4060. pNew->type |= PATCH_THICK;
  4061. brushes.Add(pNew->pSymbiot);
  4062. if (bSeam)
  4063. {
  4064. // FIXME: this should detect if any edges of the patch are closed and act appropriately
  4065. //
  4066. if (!(p->type & PATCH_CYLINDER))
  4067. {
  4068. b = Patch_GenericMesh(3, p->height, 2, false, true);
  4069. pSeam = b->pPatch;
  4070. pSeam->type |= PATCH_SEAM;
  4071. for (i = 0; i < p->height; i++)
  4072. {
  4073. VectorCopy(p->ctrl[0][i].xyz, pSeam->ctrl[0][i].xyz);
  4074. VectorCopy(pNew->ctrl[0][i].xyz, pSeam->ctrl[2][i].xyz);
  4075. VectorAdd(pSeam->ctrl[0][i].xyz, pSeam->ctrl[2][i].xyz, pSeam->ctrl[1][i].xyz);
  4076. VectorScale(pSeam->ctrl[1][i].xyz, 0.5, pSeam->ctrl[1][i].xyz);
  4077. }
  4078. Patch_CalcBounds(pSeam, vMin, vMax);
  4079. Brush_RebuildBrush(pSeam->pSymbiot, vMin, vMax);
  4080. //--Patch_CapTexture(pSeam);
  4081. Patch_Naturalize(pSeam);
  4082. patchInvert(pSeam);
  4083. brushes.Add(b);
  4084. w = p->width - 1;
  4085. b = Patch_GenericMesh(3, p->height, 2, false, true);
  4086. pSeam = b->pPatch;
  4087. pSeam->type |= PATCH_SEAM;
  4088. for (i = 0; i < p->height; i++)
  4089. {
  4090. VectorCopy(p->ctrl[w][i].xyz, pSeam->ctrl[0][i].xyz);
  4091. VectorCopy(pNew->ctrl[w][i].xyz, pSeam->ctrl[2][i].xyz);
  4092. VectorAdd(pSeam->ctrl[0][i].xyz, pSeam->ctrl[2][i].xyz, pSeam->ctrl[1][i].xyz);
  4093. VectorScale(pSeam->ctrl[1][i].xyz, 0.5, pSeam->ctrl[1][i].xyz);
  4094. }
  4095. Patch_CalcBounds(pSeam, vMin, vMax);
  4096. Brush_RebuildBrush(pSeam->pSymbiot, vMin, vMax);
  4097. //--Patch_CapTexture(pSeam);
  4098. Patch_Naturalize(pSeam);
  4099. brushes.Add(b);
  4100. }
  4101. //--{
  4102. // otherwise we will add one per end
  4103. b = Patch_GenericMesh(p->width, 3, 2, false, true);
  4104. pSeam = b->pPatch;
  4105. pSeam->type |= PATCH_SEAM;
  4106. for (i = 0; i < p->width; i++)
  4107. {
  4108. VectorCopy(p->ctrl[i][0].xyz, pSeam->ctrl[i][0].xyz);
  4109. VectorCopy(pNew->ctrl[i][0].xyz, pSeam->ctrl[i][2].xyz);
  4110. VectorAdd(pSeam->ctrl[i][0].xyz, pSeam->ctrl[i][2].xyz, pSeam->ctrl[i][1].xyz);
  4111. VectorScale(pSeam->ctrl[i][1].xyz, 0.5, pSeam->ctrl[i][1].xyz);
  4112. }
  4113. Patch_CalcBounds(pSeam, vMin, vMax);
  4114. Brush_RebuildBrush(pSeam->pSymbiot, vMin, vMax);
  4115. //--Patch_CapTexture(pSeam);
  4116. Patch_Naturalize(pSeam);
  4117. patchInvert(pSeam);
  4118. brushes.Add(b);
  4119. h = p->height - 1;
  4120. b = Patch_GenericMesh(p->width, 3, 2, false, true);
  4121. pSeam = b->pPatch;
  4122. pSeam->type |= PATCH_SEAM;
  4123. for (i = 0; i < p->width; i++)
  4124. {
  4125. VectorCopy(p->ctrl[i][h].xyz, pSeam->ctrl[i][0].xyz);
  4126. VectorCopy(pNew->ctrl[i][h].xyz, pSeam->ctrl[i][2].xyz);
  4127. VectorAdd(pSeam->ctrl[i][0].xyz, pSeam->ctrl[i][2].xyz, pSeam->ctrl[i][1].xyz);
  4128. VectorScale(pSeam->ctrl[i][1].xyz, 0.5, pSeam->ctrl[i][1].xyz);
  4129. }
  4130. Patch_CalcBounds(pSeam, vMin, vMax);
  4131. Brush_RebuildBrush(pSeam->pSymbiot, vMin, vMax);
  4132. //--Patch_CapTexture(pSeam);
  4133. Patch_Naturalize(pSeam);
  4134. brushes.Add(b);
  4135. eclass_t *pecNew = Eclass_ForName("func_group", false);
  4136. if (pecNew)
  4137. {
  4138. entity_t *e = Entity_Create(pecNew);
  4139. SetKeyValue(e, "type", "patchThick");
  4140. }
  4141. //--}
  4142. }
  4143. patchInvert(pNew);
  4144. }
  4145. }
  4146. for (i = 0; i < brushes.GetSize(); i++)
  4147. {
  4148. Select_Brush(reinterpret_cast<brush_t*>(brushes.GetAt(i)));
  4149. }
  4150. UpdatePatchInspector();
  4151. }
  4152. /*
  4153. lets get another list together as far as necessities..
  4154. *snapping stuff to the grid (i will only snap movements by the mouse to the grid.. snapping the rotational bend stuff will fubar everything)
  4155. capping bevels/endcaps
  4156. hot keys
  4157. texture fix for caps
  4158. clear clipboard
  4159. *region fix
  4160. *surface dialog
  4161. */
  4162. void Patch_SetOverlays()
  4163. {
  4164. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4165. {
  4166. if (pb->patchBrush)
  4167. {
  4168. pb->pPatch->bOverlay = true;
  4169. }
  4170. }
  4171. }
  4172. void Patch_ClearOverlays()
  4173. {
  4174. brush_t *pb;
  4175. for (pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4176. {
  4177. if (pb->patchBrush)
  4178. {
  4179. pb->pPatch->bOverlay = false;
  4180. }
  4181. }
  4182. for (pb = active_brushes.next ; pb != &active_brushes ; pb = pb->next)
  4183. {
  4184. if (pb->patchBrush)
  4185. {
  4186. pb->pPatch->bOverlay = false;
  4187. }
  4188. }
  4189. }
  4190. // freezes selected vertices
  4191. void Patch_Freeze()
  4192. {
  4193. brush_t *pb;
  4194. for (pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4195. {
  4196. if (pb->patchBrush)
  4197. {
  4198. pb->pPatch->bOverlay = false;
  4199. }
  4200. }
  4201. for (pb = active_brushes.next ; pb != &active_brushes ; pb = pb->next)
  4202. {
  4203. if (pb->patchBrush)
  4204. {
  4205. pb->pPatch->bOverlay = false;
  4206. }
  4207. }
  4208. }
  4209. void Patch_UnFreeze(bool bAll)
  4210. {
  4211. }
  4212. void Patch_Transpose()
  4213. {
  4214. int i, j, w;
  4215. drawVert_t dv;
  4216. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4217. {
  4218. if (pb->patchBrush)
  4219. {
  4220. patchMesh_t *p = pb->pPatch;
  4221. if ( p->width > p->height )
  4222. {
  4223. for ( i = 0 ; i < p->height ; i++ )
  4224. {
  4225. for ( j = i + 1 ; j < p->width ; j++ )
  4226. {
  4227. if ( j < p->height )
  4228. {
  4229. // swap the value
  4230. memcpy(&dv,&p->ctrl[j][i],sizeof(drawVert_t));
  4231. memcpy(&p->ctrl[j][i],&p->ctrl[i][j], sizeof(drawVert_t));
  4232. memcpy(&p->ctrl[i][j],&dv, sizeof(drawVert_t));
  4233. }
  4234. else
  4235. {
  4236. // just copy
  4237. memcpy(&p->ctrl[j][i],&p->ctrl[i][j], sizeof(drawVert_t));
  4238. }
  4239. }
  4240. }
  4241. }
  4242. else
  4243. {
  4244. for ( i = 0 ; i < p->width ; i++ )
  4245. {
  4246. for ( j = i + 1 ; j < p->height ; j++ )
  4247. {
  4248. if ( j < p->width )
  4249. {
  4250. // swap the value
  4251. memcpy(&dv,&p->ctrl[i][j], sizeof(drawVert_t));
  4252. memcpy(&p->ctrl[i][j],&p->ctrl[j][i], sizeof(drawVert_t));
  4253. memcpy(&p->ctrl[j][i],&dv, sizeof(drawVert_t));
  4254. }
  4255. else
  4256. {
  4257. // just copy
  4258. memcpy(&p->ctrl[i][j],&p->ctrl[j][i], sizeof(drawVert_t));
  4259. }
  4260. }
  4261. }
  4262. }
  4263. w = p->width;
  4264. p->width = p->height;
  4265. p->height = w;
  4266. patchInvert(p);
  4267. Patch_Rebuild(p);
  4268. }
  4269. }
  4270. }
  4271. void Select_SnapToGrid()
  4272. {
  4273. int i,j, k;
  4274. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  4275. {
  4276. if (pb->patchBrush)
  4277. {
  4278. patchMesh_t *p = pb->pPatch;
  4279. #if 0
  4280. float ctrl[MAX_PATCH_WIDTH][MAX_PATCH_HEIGHT][5];
  4281. memcpy(ctrl, p->ctrl, sizeof(p->ctrl));
  4282. i = p->width;
  4283. p->width = p->height;
  4284. p->height = i;
  4285. for (i = 0; i < p->width; i++)
  4286. {
  4287. int l = p->height-1;
  4288. for (j = 0; j < p->height; j++)
  4289. {
  4290. for (k = 0; k < 5; k++)
  4291. {
  4292. p->ctrl[i][l][k] = ctrl[j][i][k];
  4293. }
  4294. l--;
  4295. }
  4296. }
  4297. #else
  4298. for (i = 0; i < p->width; i++)
  4299. {
  4300. for (j = 0; j < p->height; j++)
  4301. {
  4302. for (k = 0; k < 3; k++)
  4303. {
  4304. p->ctrl[i][j].xyz[k] = floor(p->ctrl[i][j].xyz[k] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
  4305. }
  4306. }
  4307. }
  4308. #endif
  4309. vec3_t vMin, vMax;
  4310. Patch_CalcBounds(p, vMin, vMax);
  4311. Brush_RebuildBrush(p->pSymbiot, vMin, vMax);
  4312. }
  4313. else
  4314. {
  4315. Brush_SnapToGrid(pb);
  4316. }
  4317. }
  4318. }
  4319. void Patch_FindReplaceTexture(brush_t *pb, const char *pFind, const char *pReplace, bool bForce)
  4320. {
  4321. if (pb->patchBrush)
  4322. {
  4323. patchMesh_t *p = pb->pPatch;
  4324. if (bForce || strcmpi(p->d_texture->name, pFind) == 0)
  4325. {
  4326. p->d_texture = Texture_ForName(pReplace);
  4327. //strcpy(p->d_texture->name, pReplace);
  4328. }
  4329. }
  4330. }
  4331. void Patch_ReplaceQTexture(brush_t *pb, qtexture_t *pOld, qtexture_t *pNew)
  4332. {
  4333. if (pb->patchBrush)
  4334. {
  4335. patchMesh_t *p = pb->pPatch;
  4336. if (p->d_texture == pOld)
  4337. {
  4338. p->d_texture = pNew;
  4339. }
  4340. }
  4341. }
  4342. void Patch_Clone(patchMesh_t *p, brush_t *pNewOwner)
  4343. {
  4344. }
  4345. void Patch_FromTriangle(vec5_t vx, vec5_t vy, vec5_t vz)
  4346. {
  4347. patchMesh_t* p = MakeNewPatch();
  4348. p->d_texture = Texture_ForName(g_qeglobals.d_texturewin.texdef.name);
  4349. p->width = 3;
  4350. p->height = 3;
  4351. p->type = PATCH_TRIANGLE;
  4352. // 0 0 goes to x
  4353. // 0 1 goes to x
  4354. // 0 2 goes to x
  4355. // 1 0 goes to mid of x and z
  4356. // 1 1 goes to mid of x y and z
  4357. // 1 2 goes to mid of x and y
  4358. // 2 0 goes to z
  4359. // 2 1 goes to mid of y and z
  4360. // 2 2 goes to y
  4361. vec5_t vMidXZ;
  4362. vec5_t vMidXY;
  4363. vec5_t vMidYZ;
  4364. for (int j = 0; j < 3; j++)
  4365. {
  4366. _Vector5Add(vx, vz, vMidXZ);
  4367. _Vector5Scale(vMidXZ, 0.5, vMidXZ);
  4368. //vMidXZ[j] = vx[j] + abs((vx[j] - vz[j]) * 0.5);
  4369. }
  4370. for (j = 0; j < 3; j++)
  4371. {
  4372. _Vector5Add(vx, vy, vMidXY);
  4373. _Vector5Scale(vMidXY, 0.5, vMidXY);
  4374. //vMidXY[j] = vx[j] + abs((vx[j] - vy[j]) * 0.5);
  4375. }
  4376. for (j = 0; j < 3; j++)
  4377. {
  4378. _Vector5Add(vy, vz, vMidYZ);
  4379. _Vector5Scale(vMidYZ, 0.5, vMidYZ);
  4380. //vMidYZ[j] = vy[j] + abs((vy[j] - vz[j]) * 0.5);
  4381. }
  4382. _Vector53Copy(vx, p->ctrl[0][0].xyz);
  4383. _Vector53Copy(vx, p->ctrl[0][1].xyz);
  4384. _Vector53Copy(vx, p->ctrl[0][2].xyz);
  4385. p->ctrl[0][0].st[0] = vx[3];
  4386. p->ctrl[0][0].st[1] = vx[4];
  4387. p->ctrl[0][1].st[0] = vx[3];
  4388. p->ctrl[0][1].st[1] = vx[4];
  4389. p->ctrl[0][2].st[0] = vx[3];
  4390. p->ctrl[0][2].st[1] = vx[4];
  4391. _Vector53Copy(vMidXY, p->ctrl[1][0].xyz);
  4392. _Vector53Copy(vx, p->ctrl[1][1].xyz);
  4393. _Vector53Copy(vMidXZ, p->ctrl[1][2].xyz);
  4394. p->ctrl[1][0].st[0] = vMidXY[3];
  4395. p->ctrl[1][0].st[1] = vMidXY[4];
  4396. p->ctrl[1][1].st[0] = vx[3];
  4397. p->ctrl[1][1].st[1] = vx[4];
  4398. p->ctrl[1][2].st[0] = vMidXZ[3];
  4399. p->ctrl[1][2].st[1] = vMidXZ[4];
  4400. _Vector53Copy(vy, p->ctrl[2][0].xyz);
  4401. _Vector53Copy(vMidYZ, p->ctrl[2][1].xyz);
  4402. _Vector53Copy(vz, p->ctrl[2][2].xyz);
  4403. p->ctrl[2][0].st[0] = vy[3];
  4404. p->ctrl[2][0].st[1] = vy[4];
  4405. p->ctrl[2][1].st[0] = vMidYZ[3];
  4406. p->ctrl[2][1].st[1] = vMidYZ[4];
  4407. p->ctrl[2][2].st[0] = vz[3];
  4408. p->ctrl[2][2].st[1] = vz[4];
  4409. //Patch_Naturalize(p);
  4410. brush_t *b = AddBrushForPatch(p);
  4411. }
  4412. /*
  4413. ==============
  4414. Patch_SetEpair
  4415. sets an epair for the given patch
  4416. ==============
  4417. */
  4418. void Patch_SetEpair(patchMesh_t *p, const char *pKey, const char *pValue)
  4419. {
  4420. if (g_qeglobals.m_bBrushPrimitMode)
  4421. {
  4422. SetKeyValue(p->epairs, pKey, pValue);
  4423. }
  4424. }
  4425. /*
  4426. =================
  4427. Patch_GetKeyValue
  4428. =================
  4429. */
  4430. const char* Patch_GetKeyValue(patchMesh_t *p, const char *pKey)
  4431. {
  4432. if (g_qeglobals.m_bBrushPrimitMode)
  4433. {
  4434. return ValueForKey(p->epairs, pKey);
  4435. }
  4436. return "";
  4437. }
  4438. //Real nitpicky, but could you make CTRL-S save the current map with the current name? (ie: File/Save)
  4439. /*
  4440. Feature addition.
  4441. When reading in textures, please check for the presence of a file called "textures.link" or something, which contains one line such as;
  4442. g:\quake3\baseq3\textures\common
  4443. So that, when I'm reading in, lets say, my \eerie directory, it goes through and adds my textures to the palette, along with everything in common.
  4444. Don't forget to add "Finer texture alignment" to the list. I'd like to be able to move in 0.1 increments using the Shift-Arrow Keys.
  4445. No. Sometimes textures are drawn the wrong way on patches. We'd like the ability to flip a texture. Like the way X/Y scale -1 used to worked.
  4446. 1) Easier way of deleting rows, columns
  4447. 2) Fine tuning of textures on patches (X/Y shifts other than with the surface dialog)
  4448. 2) Patch matrix transposition
  4449. 1) Actually, bump texture flipping on patches to the top of the list of things to do.
  4450. 2) When you select a patch, and hit S, it should read in the selected patch texture. Should not work if you multiselect patches and hit S
  4451. 3) Brandon has a wierd anomoly. He fine-tunes a patch with caps. It looks fine when the patch is selected, but as soon as he escapes out, it reverts to it's pre-tuned state. When he selects the patch again, it looks tuned
  4452. *1) Flipping textures on patches
  4453. *2) When you select a patch, and hit S, it should read in the selected patch texture. Should not work if you multiselect patches and hit S
  4454. 3) Easier way of deleting rows columns
  4455. *4) Thick Curves
  4456. 5) Patch matrix transposition
  4457. 6) Inverted cylinder capping
  4458. *7) bugs
  4459. *8) curve speed
  4460. Have a new feature request. "Compute Bounding Box" for mapobjects (md3 files). This would be used for misc_mapobject (essentially, drop in 3DS Max models into our maps)
  4461. Ok, Feature Request. Load and draw MD3's in the Camera view with proper bounding boxes. This should be off misc_model
  4462. Feature Addition: View/Hide Hint Brushes -- This should be a specific case.
  4463. */