TrenchFold — TrenchBroom extension for Defold

Yes, we should look into this issue. I think we need to open up editor scripts a bit more to make them more flexible.

We do in fact include a luajit exe in both bob and in the editor (unpacked when the editor starts). We should maybe look into making these a bit more accessible. :thinking:

6 Likes

Sorry for the delay, something came up irl
The lua script worked correctly, and the map converted successfully (except for the textures, but I probably know where the problem is)
Tomorrow I’ll experiment a bit more with the extension.
Thank you

3 Likes

Just made a small part of E1M1 with it :sweat_smile: Someone had to do it
The extension works great :+1:

Scales are a bit off though, I should fix the scales first if I decide to finish it

17 Likes

Keep going! Would be funny to “port” Doom to run in Defold. :grin:

12 Likes

I did something similar with UE4, if I’m not mistaken what worked for me is having 32 Doom units as 1 meter.

4 Likes

I looked it up and confirm 32 units = 1 meter.

The player, and therefore the collision capsule, is 175cm tall, with a 50cm radius. The camera is at a height of 152.5cm with an FOV of 90º.

The speed then should be 1200 cm per second.

These calculations come from various wikis that talk about how Doom works and applying the 32:1 rule, so it really feels like Doom.

And since Quake uses the same units, anything made with Trenchbroom should work.

You can try this demo I made some time ago. I used Sketchup8 as a level editor but the result should be the same as long as you apply the 32:1 conversion.

7 Likes

Well, I installed Windows 10 in VirtualBox on my old mac, so hopefully all the related bugs are fixed. I added a powershell script running for the Windows environment, so now it’s also possible to use the editor extension on Windows.

9 Likes

Did you solve this problem? Was it on the extension side?

In my virtual Windows 10 environment everything works fine.
Could you check please, is it reproduced with version 1.4?

2 Likes

Matched!

Screenshot 2022-08-16 at 14.41.16

11 Likes

Release 1.5.

textureN

Added the textureN property to entities to allow set additional material textures 1-7. The next patterns are available:

  • /path/to/texture.png — a specific texture.
  • /path/to/prefix_*_suffix.png — a specific path where * is texture0 original name.
  • /path/to/alternative/* — a specific folder with the same texture file name.
  • prefix_*_suffix.png — the same folder.
  • prefix_*_suffix — the same folder and extension.

Script properties overriding

Added override of script properties with #component_id.property. Now you can avoid using the automatically generated properties.script if you just need to set the property value in your own script.

_color to color

Added automatic conversion of property name from _color to color. TrenchBroom only shows the colour picker if the property ends in _color, but in the script we often want name the property just a color.

10 Likes

I guess the answer is yes but, is it posible to import JUST the collisions?

Let’s say I want to make a Resident Evil clone, I make a mansion with Trenchbroom and I just need the collisions because, in-game, only the characters and high quality pre-rendered images will be shown.

Can this be accomplished?

The only way to export collisions separately is using a clip texture at the moment.

I didn’t think about the case when you have a textured brush but don’t want to export it as a textured mesh :thinking:. Is it your case?

Another way that mentioned before is to have two layers with collisions and textured brushes, and just hide the second layer before export.

1 Like

When I wrote the post I was thinking about untextured meshes yes, but now I believe it could be impractical because having some sort of “debug” texture would come in handy.

But if you can have two different layers, then that’s great. In Unreal Engine is posible to import collision volumes having the prefix UCX in their names.

Anyway, if you want to tweak something in texture flags for your purposes, you can do it easily here. Including adding custom prefixes for the textures you want to export as collisions.

The idea with prefixes or advanced settings is good, but I just don’t understand where to place it now, since the extension has no any UI other than Defold Editor’s context menu and TrenchBroom’s entities and faces.

Should we add the clip_ prefix for textures that we don’t want to export as meshes? May be it’s a good idea?

2 Likes

Not sure if this is the right place to ask, but using my own Trenchbroom map is causing my game to crash.

I made a simple map file (literally just a box) in Trenchbroom and loaded it into Defold using the instructions on the extension’s GitHub page, but when I build the game I get this error:

Assertion failed: (edge.LengthSquared() > 1.19209290e-7F * 1.19209290e-7F), function Set, file b2PolygonShape.cpp, line 146.
INFO:CRASH: Successfully wrote Crashdump to file: /Users/mak/Library/Application Support/Defold/_crash
ERROR:CRASH: CALL STACK:

# 0 pc     0x281a54 dmengine _ZN7dmCrashL7HandlerEiP9__siginfoPv+36
# 1 pc      0x80c1d libc++abi.dylib _sigtramp+29
# 2 pc      0x1e30f libc++abi.dylib __pthread_kill+11
# 3 pc      0x55f7b libc++abi.dylib pthread_kill+263
# 4 pc     0x1e7ca5 libxpc.dylib abort+123
# 5 pc     0x1e6fbe libxpc.dylib err+0
# 6 pc     0x2d6893 dmengine _ZN14b2PolygonShape3SetEPK6b2Vec2i.cold.2+35
# 7 pc      0xe32c9 dmengine _ZN14b2PolygonShape3SetEPK6b2Vec2i+505
# 8 pc      0x82166 dmengine _ZN9dmPhysics17NewPolygonShape2DEPNS_9Context2DEPKfj+358
# 9 pc      0x671aa dmengine _ZN12dmGameSystem16AcquireResourcesEPNS_14PhysicsContextEPN10dmResource16SResourceFactoryEPKvjPNS_23CollisionObjectResourceEPKc+1690
#10 pc      0x674f6 dmengine _ZN12dmGameSystem24ResCollisionObjectCreateERKN10dmResource20ResourceCreateParamsE+118
#11 pc      0x35e50 dmengine _ZN10dmResource3GetEPNS_16SResourceFactoryEPKcPPv+2064
#12 pc      0x2b148 dmengine _ZN12dmGameObjectL16AcquireResourcesEPN10dmResource16SResourceFactoryEPNS_8RegisterEPN15dmGameObjectDDF13PrototypeDescEPNS_9PrototypeEPKc+328
#13 pc      0x2ad6b dmengine _ZN12dmGameObjectL19ResGameObjectCreateERKN10dmResource20ResourceCreateParamsE+91
#14 pc      0x35e50 dmengine _ZN10dmResource3GetEPNS_16SResourceFactoryEPKcPPv+2064
#15 pc      0x2a4b7 dmengine _ZN12dmGameObjectL16AcquireResourcesEPKcPN10dmResource16SResourceFactoryEPNS_8RegisterEPN15dmGameObjectDDF14CollectionDescES1_PPNS_16CollectionHandleE+391
#16 pc      0x2a080 dmengine _ZN12dmGameObjectL19ResCollectionCreateERKN10dmResource20ResourceCreateParamsE+48
#17 pc      0x35e50 dmengine _ZN10dmResource3GetEPNS_16SResourceFactoryEPKcPPv+2064
#18 pc       0x7b4d dmengine _ZN8dmEngine4InitEPNS_6EngineEiPPc+9197
#19 pc       0x8b5a dmengine _Z14dmEngineCreateiPPc+170
#20 pc       0x96ef dmengine _ZN8dmEngine7RunLoopEPKNS_13RunLoopParamsE+95
#21 pc       0x9662 dmengine _Z11engine_mainiPPc+98

It sounds like something is going wrong when Defold tries to load the .convexshape file?

I’m on macOS with Defold version 1.4.1, and Trenchbroom extension version 1.5.

That’s from this code here:

	// Compute normals. Ensure the edges have non-zero length.
	for (int32 i = 0; i < m_vertexCount; ++i)
	{
		int32 i1 = i;
		int32 i2 = i + 1 < m_vertexCount ? i + 1 : 0;
		b2Vec2 edge = m_vertices[i2] - m_vertices[i1];
--> 	b2Assert(edge.LengthSquared() > b2_epsilon * b2_epsilon);
		m_normals[i] = b2Cross(edge, 1.0f);
		m_normals[i].Normalize();
	}

Seems like some edge in the mesh has a length of 0, somehow.

Here’s the data from that map file, if you’re interested (or if anyone else is). It’s using the textures that come with the Trenchbroom extension.

There doesn’t seem to be any zero length edges in the map file, the OBJ file, or the generated convex shape.

// Game: Defold
// Format: Quake2
// entity 0
{
"classname" "worldspawn"
"_tb_textures" "textures/retro"
// brush 0
{
( -288 48 -48 ) ( -288 49 -48 ) ( -288 48 -47 ) retro/CONCRETE_1A 16 0 0 1 1
( -256 -128 -48 ) ( -256 -128 -47 ) ( -255 -128 -48 ) retro/CONCRETE_1A 16 0 0 1 1
( -256 48 -48 ) ( -255 48 -48 ) ( -256 49 -48 ) retro/CONCRETE_1A 16 -16 0 1 1
( -128 176 48 ) ( -128 177 48 ) ( -127 176 48 ) retro/CONCRETE_1A 16 -16 0 1 1
( -128 176 -16 ) ( -127 176 -16 ) ( -128 176 -15 ) retro/CONCRETE_1A 16 0 0 1 1
( 256 176 -16 ) ( 256 176 -15 ) ( 256 177 -16 ) retro/CONCRETE_1A 16 0 0 1 1
}
}

It’s working now, for some reason deleting the old box and drawing a new one made it work. Maybe there’s something wrong with the default box?

1 Like

I tried your map data, everything looks fine. Maybe the size is too big, it’s a 500+ m floor platform… Perhaps you would like to adjust the textel_size parameter to get the correct scale. But I’m not sure that this is a reason of the crash.

Please, attach the reproducing project here to understand what’s going wrong.

What is default box btw?

I don’t have that version anymore, but it was basically an empty project.

The “default box” I’m referring to is the first object that you see in Trenchbroom after making a new Defold map. I think it’s called a brush in Trenchbroom.

My broken map was just an empty project with a slightly modified “default box”, I changed its position and length/width.

1 Like