Skip to content

Commit

Permalink
#5711: First Q3 brush exporter implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 29, 2021
1 parent a34ace1 commit 0d4c032
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion include/ibrush.h
Expand Up @@ -182,7 +182,7 @@ class IFace
* This is not what is actually saved to the .map file, but it makes
* texture manipulations in the Surface Inspector much more human-readable.
*/
virtual ShiftScaleRotation getShiftScaleRotation() = 0;
virtual ShiftScaleRotation getShiftScaleRotation() const = 0;
virtual void setShiftScaleRotation(const ShiftScaleRotation& scr) = 0;

// Transforms this face plane with the given transformation matrix
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/Face.cpp
Expand Up @@ -442,7 +442,7 @@ void Face::setTexdef(const TexDef& texDef)
SetTexdef(projection);
}

ShiftScaleRotation Face::getShiftScaleRotation()
ShiftScaleRotation Face::getShiftScaleRotation() const
{
TextureProjection curProjection = _texdef;

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/brush/Face.h
Expand Up @@ -142,7 +142,7 @@ class Face :
// The incoming values are measured in pixels and will be scaled internally.
void setTexdef(const TexDef& texDef);

ShiftScaleRotation getShiftScaleRotation() override;
ShiftScaleRotation getShiftScaleRotation() const override;
void setShiftScaleRotation(const ShiftScaleRotation& scr) override;

/**
Expand Down
76 changes: 34 additions & 42 deletions radiantcore/map/format/primitivewriters/LegacyBrushDefExporter.h
Expand Up @@ -20,9 +20,7 @@ class LegacyBrushDefExporter
{
const IBrush& brush = brushNode->getIBrush();

// Brush decl header
stream << "{" << std::endl;
stream << "brushDef" << std::endl;
// Curly braces surround the brush contents
stream << "{" << std::endl;

// Iterate over each brush face, exporting the tokens from all faces
Expand All @@ -31,21 +29,20 @@ class LegacyBrushDefExporter
writeFace(stream, brush.getFace(i), brush.getDetailFlag());
}

// Close brush contents and header
stream << "}" << std::endl << "}" << std::endl;
// Close brush contents
stream << "}" << std::endl;
}

/*
brushDef
{
( -64 64 64 ) ( 64 -64 64 ) ( -64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0
( -64 64 64 ) ( 64 64 -64 ) ( 64 64 64 ) ( ( 0.015625 0 0 ) ( 0 0.015625 0 ) ) common/caulk 0 0 0
( 64 64 64 ) ( 64 -64 -64 ) ( 64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0
( 64 64 -64 ) ( -64 -64 -64 ) ( 64 -64 -64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0
( 64 -64 -64 ) ( -64 -64 64 ) ( 64 -64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0
( -64 -64 64 ) ( -64 64 -64 ) ( -64 64 64 ) ( ( 0.015625 0 -0 ) ( -0 0.015625 0 ) ) common/caulk 0 0 0
}
*/
/*
{
( 16 192 96 ) ( 16 128 96 ) ( 0 192 96 ) shared_vega/trim03a 0 0 0 0.125 0.125 134217728 0 0
( 0 208 96 ) ( 0 208 80 ) ( 16 192 96 ) common/caulk 0 0 0 0.5 0.5 134217728 0 0
( 0 208 80 ) ( 0 208 96 ) ( 0 112 96 ) shared_vega/trim03a 64 0 90 0.125 0.125 134217728 0 0
( 0 112 80 ) ( 16 128 80 ) ( 0 192 80 ) common/caulk 0 0 0 0.5 0.5 134217728 0 0
( 16 128 96 ) ( 16 128 80 ) ( 0 112 96 ) shared_vega/trim03a 64 0 90 0.125 0.125 134217728 0 0
( 16 128 80 ) ( 16 128 96 ) ( 16 192 80 ) common/caulk 0 0 0 0.5 0.5 134217728 0 0
}
*/

private:

Expand All @@ -59,6 +56,9 @@ class LegacyBrushDefExporter
return;
}

// ( 16 192 96 ) ( 16 128 96 ) ( 0 192 96 ) shared_vega/trim03a 0 0 0 0.125 0.125 134217728 0 0
// ( Point 1 ) ( Point 2 ) ( Point 3 ) path/to/material shiftS shiftT rotate scaleS scaleT DetailFlag 0 0

// Each face plane is defined by three points

stream << "( ";
Expand Down Expand Up @@ -88,28 +88,6 @@ class LegacyBrushDefExporter
stream << " ";
stream << ") ";

// Write TexDef
Matrix4 texdef = face.getTexDefMatrix();
stream << "( ";

stream << "( ";
writeDoubleSafe(texdef.xx(), stream);
stream << " ";
writeDoubleSafe(texdef.yx(), stream);
stream << " ";
writeDoubleSafe(texdef.tx(), stream);
stream << " ) ";

stream << "( ";
writeDoubleSafe(texdef.xy(), stream);
stream << " ";
writeDoubleSafe(texdef.yy(), stream);
stream << " ";
writeDoubleSafe(texdef.ty(), stream);
stream << " ) ";

stream << ") ";

// Write Shader (without quotes)
const std::string& shaderName = face.getShader();

Expand All @@ -121,16 +99,30 @@ class LegacyBrushDefExporter
{
if (string::starts_with(shaderName, GlobalTexturePrefix_get()))
{
// brushDef has an implicit "textures/" not written to the map, cut it off
stream << "" << shader_get_textureName(shaderName.c_str()) << " ";
// Q3 has an implicit "textures/" not written to the map, cut it off
stream << shader_get_textureName(shaderName.c_str()) << " ";
}
else
{
stream << "" << shaderName << " ";
stream << shaderName << " ";
}
}

// Export (dummy) contents/flags
// Write Texture Shift/Scale/Rotation
auto shiftScaleRotate = face.getShiftScaleRotation();

writeDoubleSafe(shiftScaleRotate.shift[0], stream);
stream << " ";
writeDoubleSafe(shiftScaleRotate.shift[1], stream);
stream << " ";
writeDoubleSafe(shiftScaleRotate.rotate, stream);
stream << " ";
writeDoubleSafe(shiftScaleRotate.scale[0], stream);
stream << " ";
writeDoubleSafe(shiftScaleRotate.scale[1], stream);
stream << " ";

// Export contents flags and the two zeroes at the end
stream << detailFlag << " 0 0";

stream << std::endl;
Expand Down
10 changes: 9 additions & 1 deletion test/MapExport.cpp
Expand Up @@ -134,7 +134,15 @@ TEST_F(MapExportTest, exportQuake3Brush)

// Quake 3 format (after #5711) should be writing the old brushDef format without
// brushDef header, using the shift/scale/rotation tex def syntax
auto brushTextIndex = text.find(R"BRUSH(TODO)BRUSH");
auto brushTextIndex = text.find(R"BRUSH(// brush 0
{
( 64 128 -256 ) ( 64 -128 256 ) ( 64 128 256 ) darkmod/numbers/1 32 32 0 4 8 0 0 0
( -64 -128 -256 ) ( -64 128 256 ) ( -64 -128 256 ) darkmod/numbers/1 32 32 0 4 8 0 0 0
( -64 128 -256 ) ( 64 128 256 ) ( -64 128 256 ) darkmod/numbers/1 32 32 0 2 8 0 0 0
( 64 -128 -256 ) ( -64 -128 256 ) ( 64 -128 256 ) darkmod/numbers/1 32 32 0 2 8 0 0 0
( -64 128 256 ) ( 64 -128 256 ) ( -64 -128 256 ) darkmod/numbers/1 32 32 0 4 2 0 0 0
( -64 128 -256 ) ( 64 -128 -256 ) ( 64 128 -256 ) darkmod/numbers/1 32 32 0 4 2 0 0 0
})BRUSH");

EXPECT_NE(brushTextIndex, std::string::npos) << "Could not locate the exported brush in the expected format";
}
Expand Down

0 comments on commit 0d4c032

Please sign in to comment.