2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
23 // writes quake3 map format from internal objects
\r
26 static int g_count_entities;
\r
27 static int g_count_brushes;
\r
30 extern int g_MapVersion;
\r
32 void Float_Write(float data, IDataStream *out)
\r
34 if (data == (int)data)
\r
35 out->printf("%i ", (int)data);
\r
37 out->printf("%f ", data);
\r
40 void Patch_Write(patchMesh_t *pPatch, IDataStream *out)
\r
45 // write shader name and matrix dimensions
\r
46 str = pPatch->pShader->getName();
\r
47 if (strchr(str, ' '))
\r
49 Sys_FPrintf(SYS_WRN, "WARNING: Patch_Write: shader names with spaces are not allowed, ignoring '%s'\n", str);
\r
50 str = SHADER_NOT_FOUND;
\r
52 if(!strncmp(str, "textures/", 9)) str+=9;
\r
53 out->printf("patchDef2\n{\n%s\n( %i %i 0 0 0 )\n",
\r
54 str, pPatch->width, pPatch->height);
\r
58 for(i=0; i<pPatch->width; i++)
\r
61 for(j=0; j<pPatch->height; j++)
\r
65 Float_Write(pPatch->ctrl[i][j].xyz[0], out);
\r
66 Float_Write(pPatch->ctrl[i][j].xyz[1], out);
\r
67 Float_Write(pPatch->ctrl[i][j].xyz[2], out);
\r
68 Float_Write(pPatch->ctrl[i][j].st[0], out);
\r
69 Float_Write(pPatch->ctrl[i][j].st[1], out);
\r
75 out->printf(")\n}\n");
\r
78 void Face_Write (face_t *face, IDataStream *out, bool bAlternateTexdef = false)
\r
89 Float_Write(face->planepts[i][j], out);
\r
94 if(bAlternateTexdef)
\r
96 // write alternate texdef
\r
97 out->printf("( ( ");
\r
99 Float_Write(face->brushprimit_texdef.coords[0][i], out);
\r
100 out->printf(") ( ");
\r
102 Float_Write(face->brushprimit_texdef.coords[1][i], out);
\r
103 out->printf(") ) ");
\r
106 // write shader name
\r
107 str = face->texdef.GetName();
\r
108 if (strchr(str, ' '))
\r
110 Sys_FPrintf(SYS_WRN, "WARNING: Face_Write: shader names with spaces are not allowed, ignoring '%s'\n", str);
\r
111 str = SHADER_NOT_FOUND;
\r
113 if(!strncmp(str, "textures/", 9)) str+=9;
\r
115 // Strip all remaining paths.
\r
116 // FIXME: Hydra - this is actually a HalfLife specific bit, not Q2 map format specific.
\r
117 if (g_MapVersion == MAPVERSION_HL)
\r
120 while ( pos = (char*)strchr( str, '/' ) ) {
\r
121 str = pos+1; // to speed optimize, change the "while" to an "if"
\r
124 out->printf("%s ", str);
\r
126 if(!bAlternateTexdef)
\r
129 out->printf("%i %i %i %f %f ",
\r
130 (int)face->texdef.shift[0],
\r
131 (int)face->texdef.shift[1],
\r
132 (int)face->texdef.rotate,
\r
133 face->texdef.scale[0],
\r
134 face->texdef.scale[1]);
\r
137 if (g_MapVersion == MAPVERSION_Q3)
\r
139 // write surface flags
\r
140 out->printf("%i %i %i\n",
\r
141 face->texdef.contents,
\r
142 face->texdef.flags,
\r
143 face->texdef.value);
\r
146 if ( (g_MapVersion == MAPVERSION_HL) || (g_MapVersion == MAPVERSION_Q2) )
\r
148 // write surface flags if non-zero values.
\r
149 if (face->texdef.contents || face->texdef.flags || face->texdef.value)
\r
151 out->printf("%i %i %i\n",
\r
152 face->texdef.contents,
\r
153 face->texdef.flags,
\r
154 face->texdef.value);
\r
164 void Primitive_Write (brush_t *pBrush, IDataStream *out)
\r
166 if ( (g_MapVersion == MAPVERSION_Q2) && (pBrush->patchBrush) )
\r
168 Sys_FPrintf(SYS_WRN, "WARNING: Primitive_Write: Patches are not supported in Quake2, ignoring Brush %d\n", g_count_brushes++);
\r
172 out->printf("// brush %i\n", g_count_brushes++);
\r
173 out->printf("{\n");
\r
174 if(pBrush->patchBrush)
\r
175 Patch_Write(pBrush->pPatch, out);
\r
176 else if(pBrush->bBrushDef)
\r
178 out->printf("brushDef\n{\n");
\r
179 for(face_t *face = pBrush->brush_faces; face != NULL; face = face->next)
\r
180 Face_Write (face, out, true);
\r
181 out->printf("}\n");
\r
184 for(face_t *face = pBrush->brush_faces; face != NULL; face = face->next)
\r
185 Face_Write (face, out);
\r
186 out->printf("}\n");
\r
190 void Entity_Write(entity_t *pEntity, IDataStream *out)
\r
193 CPtrArray *brushes = (CPtrArray*)pEntity->pData;
\r
194 out->printf("// entity %i\n", g_count_entities++);
\r
195 out->printf("{\n");
\r
196 for(pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next)
\r
197 out->printf("\"%s\" \"%s\"\n", pEpair->key, pEpair->value);
\r
198 g_count_brushes = 0;
\r
199 for(int i=0; i<brushes->GetSize(); i++)
\r
200 Primitive_Write((brush_t*)brushes->GetAt(i), out);
\r
201 out->printf("}\n");
\r
204 void Map_Write (CPtrArray *map, IDataStream *out)
\r
206 g_count_entities = 0;
\r
207 for(int i=0; i<map->GetSize(); i++)
\r
208 Entity_Write((entity_t*)map->GetAt(i), out);
\r
211 void Map_WriteQ3 (CPtrArray *map, IDataStream *out)
\r
213 g_MapVersion = MAPVERSION_Q3;
\r
214 Map_Write (map,out);
\r
217 void Map_WriteHL (CPtrArray *map, IDataStream *out)
\r
219 g_MapVersion = MAPVERSION_HL;
\r
220 Map_Write (map,out);
\r
223 void Map_WriteQ2 (CPtrArray *map, IDataStream *out)
\r
225 g_MapVersion = MAPVERSION_Q2;
\r
226 Map_Write (map,out);
\r