Skip to content

Quake 2 .map loader #11604

@HeadClot

Description

@HeadClot
Description of the problem

Hey everyone,

First off I know this will sound like weird request for an asset loader.
I am using the awesome free and open source map editor called Trenchbroom to make levels for a project of mine.

I would like to be able to load these maps as well as user defined parts of these maps into three.JS with their textures properly mapped and the level geometry fully intact.

Thank you for your time,

HeadClot

Activity

donmccurdy

donmccurdy commented on Aug 4, 2018

@donmccurdy
Collaborator
mcharytoniuk

mcharytoniuk commented on Dec 15, 2019

@mcharytoniuk
Contributor

@HeadClot you can take a look at this, I coded .map loader, but it's a part of a bigger project: https://github.com/personalidol/personalidol . If you (or anyone) would like to help extracting this into the standalone THREE.js loader, I would really appreciate that (I would love to, but I am really busy at the moment). :)

It does not use BSP, etc, just computes vertices and textures from the .map file and renders the scene. I think it is also really convenient, because you don't have to compile the map, you can just load .map files. Textures are preserved from Trenchbroom, but I am still working on texture offsets and rotations. Coordinates are translatef from Trenchbroom's XYZ to THREEjs's YZX

mrdoob

mrdoob commented on Dec 15, 2019

@mrdoob
Owner

@mcharytoniuk I can take a look. Can you point me to the file that has the loading code?

mcharytoniuk

mcharytoniuk commented on Dec 15, 2019

@mcharytoniuk
Contributor

@mrdoob Sure. This is the best resource IMO on .map files:
http://www.gamers.org/dEngine/quake/QDP/qmapspec.html

In short terms:
.map files are divided into entities, each entity contains either metadata that is game related (for example which additional model needs to be loaded and placed on the map or origin and intensity of a point light; some metadata may change a way in which the mesh should be rendered; metadata may also contain game triggers which are not rendering-related, but need to be preserved for further use).
entity may contain brush (which is really a definition of a convex polyhedron).

brush is a collection of half-spaces defined by 3 clockwise points (some sources state otherwise, but I checked and using those points clockwise produces correct normal vector). You can get polyhedron vertices by intersecting all of those half-spaces. Brushes are defined that way because Quake used BSP to render scenes and it's easier to use half-spaces with BSP than a list of vertices.

Also Quake uses different coordinates system than THREE, so everything needs to be translated at some point before rendering.

  1. Parser that loads the .map file as plain text and extracts info about entities and brushes: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeMapParser.js
  2. Class that keeps entity metadata: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeEntity.js
  3. Class that generates brush vertices from half-spaces: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeBrush.js (I used O(n*n*n) algorithm, but O(n*log(n)) also exists; I didn't use it because it wasn't the performance bottleneck in my case and it makes the code less maintainable, because it's more convoluted). I also wrote some tests: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeBrush.test.js
  4. Class that creates geometries from vertices (uses ConvexHull): https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeBrushGeometry.js . It is worth to note that textures are using global coordinates and each face can contain a different texture.

I think that .map loader would require some custom loader, because it must not only create meshes, but also must provide a way to access the game metadata that may be attached to each object.

Trenchbroom map editor has an option to export map as .obj, but it dismisses the metadata, so it makes the map unusable in game engies, but it's good for map previews. This is why .map loader would be a good thing.

If you need me to prepare some PoC, or document something further I'd be happy to. I would be happy to help some more, but I do not want to declare any deadlines at the moment - time is my only issue now. :D

Mugen87

Mugen87 commented on Mar 17, 2021

@Mugen87
Collaborator

Merging into #5524. (Added entry QuakeBSPLoader).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrdoob@mcharytoniuk@HeadClot@donmccurdy@Mugen87

        Issue actions