-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Closed
Labels
Description
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
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
donmccurdy commentedon Aug 4, 2018
Perhaps we should just use #5524 as the master list for loader requests?
Related:
mcharytoniuk commentedon Dec 15, 2019
@HeadClot you can take a look at this, I coded
.maploader, 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
.mapfile and renders the scene. I think it is also really convenient, because you don't have to compile the map, you can just load.mapfiles. 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 YZXmrdoob commentedon Dec 15, 2019
@mcharytoniuk I can take a look. Can you point me to the file that has the loading code?
mcharytoniuk commentedon Dec 15, 2019
@mrdoob Sure. This is the best resource IMO on
.mapfiles:http://www.gamers.org/dEngine/quake/QDP/qmapspec.html
In short terms:
.mapfiles are divided intoentities, eachentitycontains 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).entitymay containbrush(which is really a definition of a convex polyhedron).brushis 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.Brushesare 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.
.mapfile as plain text and extracts info about entities and brushes: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeMapParser.jsbrushvertices from half-spaces: https://github.com/personalidol/personalidol/blob/master/src/framework/classes/QuakeBrush.js (I usedO(n*n*n)algorithm, butO(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.jsConvexHull): 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
.maploader 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
.maploader 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 commentedon Mar 17, 2021
Merging into #5524. (Added entry
QuakeBSPLoader).