/// <summary>
 /// Postprocesser to convert the texture referenced by <paramref name="terrain"/> into one used by GTKRadiant, if necessary.
 /// </summary>
 /// <param name="terrain">The <see cref="MAPTerrainEF2"/> to have its texture parsed.</param>
 private void PostProcessQuake3Texture(MAPTerrainEF2 terrain)
 {
     if (terrain.texture.Length >= 9 && terrain.texture.Substring(0, 9).Equals("textures/", StringComparison.InvariantCultureIgnoreCase))
     {
         terrain.texture = terrain.texture.Substring(9);
     }
 }
 /// <summary>
 /// Converts the passed <see cref="MAPTerrainMoHAA"/> into a <see cref="MAPTerrainEF2"/>
 /// with the same heightmap.
 /// </summary>
 /// <param name="mohTerrain">The <see cref="MAPTerrainMoHAA"/> to convert.</param>
 /// <returns><see cref="MAPTerrainEF2"/> with the same shader and heightmap as <paramref name="mohTerrain"/>.</returns>
 private MAPTerrainEF2 ConvertToEF2Terrain(MAPTerrainMoHAA mohTerrain)
 {
     if (mohTerrain.size == new Vector2(9, 9))
     {
         MAPTerrainMoHAA.Partition partition  = mohTerrain.partitions[0];
         MAPTerrainEF2             ef2Terrain = new MAPTerrainEF2()
         {
             side          = 9,
             texture       = partition.shader,
             textureShiftS = partition.textureShift[0],
             textureShiftT = partition.textureShift[1],
             texRot        = (float)partition.rotation,
             texScaleX     = partition.textureScale[0],
             texScaleY     = partition.textureScale[1],
             flags         = 1024,             // maybe don't hardcode this?
             sideLength    = 512,
             start         = new Vector3(mohTerrain.origin.X, mohTerrain.origin.Y, 0),
             IF            = Vector4.Zero,
             LF            = Vector4.Zero,
             heightMap     = new float[9, 9],
             alphaMap      = new float[9, 9]
         };
         for (int y = 0; y < ef2Terrain.heightMap.GetLength(0); ++y)
         {
             for (int x = 0; x < ef2Terrain.heightMap.GetLength(1); ++x)
             {
                 ef2Terrain.heightMap[y, x] = mohTerrain.vertices[(y * (int)mohTerrain.size.Y) + x].height + (float)mohTerrain.origin.Z;
             }
         }
         return(ef2Terrain);
     }
     return(null);
 }
Пример #3
0
        /// <summary>
        /// Processes an <see cref="Entity"/> into a state where it can be output into a file that map editors can read.
        /// </summary>
        /// <param name="entity">The <see cref="Entity"/> to process.</param>
        /// <remarks>This method does not return anything, since the <see cref="Entity"/> object is modified by reference.</remarks>
        private void ProcessEntity(Entity entity)
        {
            int modelNumber = entity.modelNumber;

            // If this Entity has no modelNumber, then this is a no-op. No processing is needed.
            // A modelnumber of 0 indicates the world entity.
            if (modelNumber >= 0)
            {
                Model model = _bsp.models[modelNumber];
                if (_bsp.brushes != null)
                {
                    List <Brush> brushes = _bsp.GetBrushesInModel(model);
                    if (brushes != null)
                    {
                        foreach (Brush brush in brushes)
                        {
                            MAPBrush result = ProcessBrush(brush, entity.origin);
                            result.isWater |= (entity.className == "func_water");
                            if (_master.settings.brushesToWorld)
                            {
                                _bsp.entities.GetWithAttribute("classname", "worldspawn").brushes.Add(result);
                            }
                            else
                            {
                                entity.brushes.Add(result);
                            }
                            ++_itemsProcessed;
                            ReportProgress();
                        }
                    }
                }
                if (model.numLeafPatches > 0 && _bsp.markSurfaces != null && _bsp.patches != null)
                {
                    HashSet <Patch> patches            = new HashSet <Patch>();
                    List <long>     leafPatchesInModel = _bsp.GetReferencedObjects <long>(model, "markSurfaces");
                    foreach (long leafPatch in leafPatchesInModel)
                    {
                        if (leafPatch >= 0)
                        {
                            patches.Add(_bsp.patches[(int)leafPatch]);
                        }
                    }
                    foreach (Patch patch in patches)
                    {
                        if (_bsp.version != MapType.CoD || patch.patchType == 0)
                        {
                            MAPPatch mappatch = ProcessPatch(patch);
                            MAPBrush newBrush = new MAPBrush();
                            newBrush.patch = mappatch;
                            entity.brushes.Add(newBrush);
                        }
                    }
                }
                if (_bsp.faces != null)
                {
                    List <Face> surfaces = _bsp.GetFacesInModel(model);
                    foreach (Face face in surfaces)
                    {
                        if (face.displacement >= 0)
                        {
                            if (modelNumber != 0)
                            {
                                _master.Print("WARNING: Displacement not part of world in " + _bsp.MapNameNoExtension);
                            }
                            MAPDisplacement displacement = ProcessDisplacement(_bsp.dispInfos[face.displacement]);
                            MAPBrush        newBrush     = face.CreateBrush(_bsp, 32);
                            newBrush.sides[0].displacement = displacement;
                            // If we are not decompiling to VMF, vis will need to skip this brush.
                            newBrush.isDetail = true;
                            entity.brushes.Add(newBrush);
                        }
                        else if (face.flags == 2)
                        {
                            MAPPatch patch    = ProcessPatch(face);
                            MAPBrush newBrush = new MAPBrush();
                            newBrush.patch = patch;
                            entity.brushes.Add(newBrush);
                        }
                        else if ((_bsp.version == MapType.STEF2 || _bsp.version == MapType.STEF2Demo) && face.flags == 5)
                        {
                            if (modelNumber != 0)
                            {
                                _master.Print("WARNING: Terrain not part of world in " + _bsp.MapNameNoExtension);
                            }
                            MAPTerrainEF2 terrain  = ProcessEF2Terrain(face);
                            MAPBrush      newBrush = new MAPBrush();
                            newBrush.ef2Terrain = terrain;
                            entity.brushes.Add(newBrush);
                        }
                    }
                }

                // If this is model 0 (worldspawn) there are other things that need to be taken into account.
                if (modelNumber == 0)
                {
                    if (_bsp.lodTerrains != null)
                    {
                        foreach (LODTerrain lodTerrain in _bsp.lodTerrains)
                        {
                            MAPTerrainMoHAA terrain  = ProcessTerrainMoHAA(lodTerrain);
                            MAPBrush        newBrush = new MAPBrush();
                            newBrush.mohTerrain = terrain;
                            entity.brushes.Add(newBrush);
                        }
                    }
                }
                entity.Remove("model");
            }
        }
 /// <summary>
 /// Process the data in a <see cref="MAPTerrainEF2"/> into the passed <c>StringBuilder</c>.
 /// </summary>
 /// <param name="terrain">The <see cref="MAPTerrainEF2"/> to process.</param>
 /// <param name="sb">A <c>StringBuilder</c> object to append processed data from <paramref name="terrain"/> to.</param>
 private void ParseTerrain(MAPTerrainEF2 terrain, StringBuilder sb)
 {
     sb.Append("  terrainDef\r\n  {\r\n    TEX( ")
     .Append(terrain.texture)
     .Append(" ")
     .Append(terrain.textureShiftS.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.textureShiftT.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.texRot.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.texScaleX.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.texScaleY.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.flags)
     .Append(" 0 0 )\r\n    TD( ")
     .Append(terrain.sideLength.ToString("###0", format))
     .Append(" ")
     .Append(terrain.start.x.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.start.y.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.start.z.ToString("###0.##########", format))
     .Append(" )\r\n    IF( ")
     .Append(terrain.IF.x.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.IF.y.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.IF.z.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.IF.w.ToString("###0.##########", format))
     .Append(" )\r\n    LF( ")
     .Append(terrain.LF.x.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.LF.y.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.LF.z.ToString("###0.##########", format))
     .Append(" ")
     .Append(terrain.LF.w.ToString("###0.##########", format))
     .Append(" )\r\n    V(\r\n");
     for (int i = 0; i < terrain.heightMap.GetLength(0); ++i)
     {
         sb.Append("      ");
         for (int j = 0; j < terrain.heightMap.GetLength(1); ++j)
         {
             sb.Append(terrain.heightMap[i, j].ToString("###0.##########", format))
             .Append(" ");
         }
         sb.Append("\r\n");
     }
     sb.Append("    )\r\n    A(\r\n");
     for (int i = 0; i < terrain.alphaMap.GetLength(0); ++i)
     {
         sb.Append("      ");
         for (int j = 0; j < terrain.alphaMap.GetLength(1); ++j)
         {
             sb.Append(terrain.alphaMap[i, j].ToString("###0.##########", format))
             .Append(" ");
         }
         sb.Append("\r\n");
     }
     sb.Append("    )\r\n  }\r\n");
 }