Create a procedural door model

Hi there,

I’ve been building a door configurator for a while now and for the whole time i stuck with a working door model for one specific thickness. Here is what i can build right now:

Basically a boxGeometry for a flush door (no lips, left in the image) and a boxGeometry plus a seperate lip geometry that is set on top, left and right for a lipped door (with lip, right in the image). There are also cases where the lip has some roundness so i just use other blender models for the lip like this:

For now it was enaugh and i knew the day will come when i need to kick this implementation and search for something more flexible.

Spoiler: The day has come:D

so right now i am trying to build a door model that is very flexible and has a nice uv unwrapping. Plus it can display different lips on the outside. Obviously i have a lot more experince in threejs now but the task still is tricky as hell. I investigated a lot for this and with a huge knowledge of shaders that would probably be possible right?

But i do not have enaugh experience with it so i am trying simpler stuff. My first idea is to build 2D shapes with shapegeometry and extrude them for the basic shape and that works for the geom but not for the top part obviously…

Right now my idea is to use the extrudeGeom and cut the top part (with csg operations) to get the same lips as on the sides of the door leaf. Sorry for this complex description.. here is a codesandbox of what i mean:

https://codesandbox.io/p/devbox/extrudeuv-forked-4ldgv3?workspaceId=ws_4upUUxh89pkkeLqW8ZvNPo

What are your thoughts on this approach? i do not like it but it is going into the right direction. Whats hard with the approach:

  • cut the negative of the lip on the top of the door leaf
  • keep the uv for the top part correct
  • what about rounded lips?

If someone has a direction or a tip for my approach i would be very happy. Every Hint, Direction or ressource would help alot!!

Thanks

Tom

1 Like

The codesandbox is inaccessible. My expectation is that lips (with or without roundness) should be procedurally made-able. The following two quotes are something that I cannot visualize (I’m not familiar with door terminology), so: what is the basic shape, what is the top part, why lips on sides are different and need cutting, what is the negative of a lip? Also, what does very flexible mean?

Hey @PavelBoytchev ,

could you check if the codesandbox is working now?

https://codesandbox.io/p/devbox/extrudeuv-forked-4ldgv3?workspaceId=ws_4upUUxh89pkkeLqW8ZvNPo

i think through the codesandbox a lot of what i want to achieve gets clearer. But ill try to demonstrate it better and post again.

Thanks

Tom

So here are some images to explain my current idea a bit better. The process starts with a threejs shape (i made the images in Blender to demonstrate). In this case this would be a lipped door because of the overlap on the top.

What i want to do next is a extrusion of this shape. This extrusion value will be the door height. In the image below you can see what i mean with top part:

And here comes the ‘Problem‘. While the door is fully correct on the sides through the extrusion the top is just flat:

Thats why i would use csg to cut out the negative part (ill explain this coon) of the current lip:

then it would look like this:

And thats the result i want to get. But of course there is not only this lip, there are other shapes and even roundness in the mix.. and now here are 3 examples of what i mean as subtract negative shape from the top. Basically, a negative is a kind of stamp that you then have to remove from the top part of the door leaf. The first one is exactly what we saw in the images above:

that would be the negative of a shape with rounded lips:

and here is the negative of a more complex double lip:

Thanks. It is much more clear now. I have classes now, in 6-10 hours I will have a look. So you want a door with lips on some sides (not just 2, but more, e.g. left, right and top). And some lips have rounded fragments

Hey @PavelBoytchev ,

thanks for the support, take your time! In the mean time ill try some other approaches myself and provide them. So your understanding might get better of what i want to achieve.

Have a good day sir,

Tom

Maybe this topic will be helpful: ProfiledContourGeometry MultiMaterial
As you want to have complex profiles :thinking:

3 Likes

So, after spending some thinking time during the subway commute, I got several ideas. The easiest of them is to use miter cuts and join door lips as a picture frame. I tried with an imaginary lip profile, not realistic, but has positive and negative parts plus curves.

https://codepen.io/boytchev/full/RNrWKoe

image

5 Likes

In addition to the great techniques presented so far.. I’m gonna throw in my vote for the technique you mentioned initially, using the basic extrusion, then some CSG for the custom bits, like bevels, mitre, cutouts. That way, adding new cutouts etc, is mostly reduced to generating the cutting geometry, rather than dealing with extrusion paths and complex parameters. And you can still use the more complex extrusions to generate your cutting geometries.

For UV’s, You could just do a box uv unwrap on the final result: What’s the correct way to generate UVs for custom geometries? - #4 by manthrax

2 Likes

I like that approach a lot because it is very near to the real world on building a door Leaf. But in the real world you would not use this 45 degree cut in the corners between the horizontal and vertical elements. Here is how it would be done in the real world:

  • front surface thin layer that has the material of the door
  • 2 vertical elements left and right that can have different shapes (flush, lip, …)
  • 1 horizontal element at the top that also has the shape
  • 1 horizontal element at the bottom that is just a box to fill the bottom
  • back surface thin layer that has the back material of the door

For flush doors it would look like this (very simple to build):

for lipped doors it looks like this and in the upper right and left corners i get the problem why my idea is to work with csg:

While your approach works for the overall structure as shown in the codesandbox here:

https://codesandbox.io/p/sandbox/exdrudedoorleaf-forked-j5cd9w

the uvs are off for the extrudegeometries:

Of course this is just a demo but i am trying to describe what i need as best as possible because that helps every reader and even myself of what i need:)

What is great about your approach is that basically every lip would be possible around the door without any csg!! What is not possible with this approach would be different lips on the left and the right. I have to think about this further.. Agian thanks @PavelBoytchev that helps a lot already!

Thats a great point actually!! For most doors that would work.

With that in mind i could actually create the real structure of the door and use Pavels approach not for the lip but for the cutter that shapes the lip. This would also have the problem, that i could not create different lips for left and right but then ill have to split the cutter for those cases.

Thank you too @manthrax for thinking about my problem.

I will build a demo of that aswell and look what approach will be more flexible

1 Like

Could you make a GLTF (with Blender, e.g.) that shows a door with different lips? If there is no top lip, the left and right could be different lips without any problem.

As for textures, you have to either fix the texture coordinates, or to use UV-less texture (that doesn’t care about UVs).

Yes i will!

uhh i do not know how this works but is it like using the vertice position of the generated object to apply textures just like in blender when i use generated instead uv?

Hey @PavelBoytchev ,

here are two glbs representing the ‘real world‘ door structure. I did not compress them so there are no problems with presicion. In the glb files the doors have different layers as described earlier plus a chip layer on both sides. I added it because in some cases the chip board would be visible:

but in most cases it is hidden by a material like so (thick black layer around):

Sorry for getting into more details but if thats too far, we can ommit that!

First model is a flush door with a lip on one side:

door_leaf_structure_diff_lips.glb (13.5 KB)

second model is a lipped door with a special lip on the other side. Used if there are two lipped doors in one frame to fit them next to each other:

door_leaf_structure_diff_lips_v2.glb (15.9 KB)

The first door can be made - the class for creating a lip has parameters whether the miter cut ends, so if they are not cut, the result is as in the model.

The second door has one corner that is not cut at 45 degrees , so this corner cannot be made with the current class.

But both doors can be made of boxes. With good UVs two attached boxes are indistinguishable perceived as a single object.

1 Like

So here is the other approach i was aiming for:

Building the base of the door leaf consisting of:

  • Front material layer
  • Front chip layer
  • Middle parts (Left, right, top, bottom)
  • Back chip layer
  • Back material layer

I then create a added geometry out of this by adding each layer to one geometry with csg.

and if the user wants a lip there needs to be generated a custom cutter on the left, right, top. to cut from this:

But as i thougth this is really buggy.. i dont know what exactly is the problem. In my local code i can use multiple materials for the base (door leaf) and the subtraction in the codesandbox it does not work..:

https://codesandbox.io/p/devbox/exdrudedoorleaf-forked-rdvpxk?workspaceId=ws_4upUUxh89pkkeLqW8ZvNPo

But you can play with the values in leva to see it somehow works but is buggy.. also i cannot use multi material in codesandbox for some reason so i gave the whole mesh a testUV material.

It looks like this approach also is not the best..

True.

Yes thats what i’ve been doing before:

where the lip consist of a left, right, top, upper left and upper right part and i place them next to each other

Edit: the problem here is that i created the lip parts in blender and uv mapped them perfectly so i do not have any issues. for different lip types there is a lot to do in blender thats why i want to do it procedurally

I’m not sure how you get distorted UVs. Here is a version with procedurally manipulated UVs:

https://codepen.io/boytchev/pen/emJpaXm

image

but even without manipulation, the texture is not that distorted (comment lines 169-171 to remove UV fixing)

2 Likes

My last post in this thread, just for completeness:

The previous demo was for procedurally fixed UVs. Of course, there are flaws, as UV mapping is art and sometimes it needs manual intervention. But for many cases automatic mapping is visually acceptable.

Below is a completely different approach - using 3D textures that do not care about UV coordinates. Here is a demo with artificial procedural wood. There are two doors, the darker one is made of several parts, the brighter one is made of two plates. The 3D texture tries to keep pattern continuity across edges. This is vanilla Three.js, so I’m not sure whether it is easy to react-ify it.

https://codepen.io/boytchev/full/VYevOea

image

5 Likes

Hey @PavelBoytchev,

thanks a ton for helping me out here! Although i am not 100% sure which approach i want to go for, your approach / code helped me a lot to understand more how i get where i want!!

I marked your code as the solution because it does basically everything that i asked for!

I will check for all the small edge cases there are in the real world and build a mix out of your code and my csg version to adress all possible cases there are!

Again i cannot thank you enough for the help and the new possibilities i learned <3

Greetings Tom

2 Likes