Import .obj model to scene

My obj format model has only one rectangle, which is a line.
like this in blender

I imported this model into the babylon sandbox and found that it became a rectangular face instead of a line.

I would like to ask how do I import this model so that it is presented as a rectangular line instead of a face
This is my test model:
111.zip (371 Bytes)

Looking forward to your reply. Thank you

Draw lines in your code:
https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/lines
or
https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/param/greased_line

    const points = [
        -3, -3, 0,
        3, -3, 0,
        3, 3, 0,
        -3, 3, 0,
        -3, -3, 0,
    ]

    const line = BABYLON.CreateGreasedLine("line", {
        points
    }, {
        width: 0.05
    })

or draw a plane in Blender and cut out the inner part to get a thinner outer border.

All meshes needs to have faces (except of 1px thick lines drawn by the GPU).

Thanks for your reply! I think there may be some mistakes in my description. I hope to import the model (wire frame or line) from outside to BABYLON, but it turns into a face after it is imported into babylon.
I hope you can import the line to babylon normally

Please pay attention to this sentence.

No, you can’t import a line mesh because a line mesh doesn’t exist. A mesh is ALWAYS constructed from vertices and faces.

Wireframe is another thing but you will still have faces in your mesh and you will see the triangles (faces).

Here is you object in Bledner:

Even if you didn’t add faces to it it is still interpreted as a quad and will be drawn using two trangles on the gpu.

What you can do is add an outer/inner border, add the faces and then it will be rendered as “lines”:

Is babylon unable to parse the ‘line’ data of other modeling software and convert it to babylon’s LinesMesh when it is imported?

As far as I know the answer is no.

EDIT: This is not true, see: Import .obj model to scene - #13 by roland

Ok, I see. Thank you very much for your reply!

1 Like

Actually you can do something like this but it requires a bit of cheating in Blender :slight_smile:
These are curves from Blender visualized using GreasedLine

1 Like

Well. We hope to import lines built by other modeling software, such as AUTOCAD, into BABYLON for processing, but at present, it is impossible to achieve this

We should support it: Fix #13851 by deltakosh · Pull Request #13928 · BabylonJS/Babylon.js · GitHub

If you can setup a repro in the Playground, we can take a look.

2 Likes

Hello!

It works indeed :slight_smile:

I tried the same code before but there was not an mtl file available on the server and it created the mesh with zero vertices, this is why I incorrectly answered here (Import .obj model to scene - #8 by roland). I reexported it from Blender to generate the mtl file and voila! mesh.getVerticesData(BABYLON.Constants.PositionKind) now returns the positions correctly. I think the SceneLoader should load the geometry alone from the obj file even if the mtl file is not available.

Does this mean that we need to know that the imported model is a ‘line’ in order to do this?

Now we are working on a function to import models built by other modeling software into babylon environment, including stl, obj, gltf and other formats. Normal 3D models can be successfully imported directly through the babylon api. If you import ‘lines’, it seems that there is now no way to tell whether the imported model is’ lines’ or 3D.

@hbwow123 what the latest exchanges emphasize is that the loader supports obj containing lines so it should be all good in your case.

If not Can you share a repro not working ?

(@roland is doing just this in the previous shader)

1-There is actually a model already imported into the scene, but the data structure is a ‘line’ data structure, rendered as a triangle so it cannot be seen.
2-We already know that the import is a ‘line’, so based on the result returned by the import, use GreasedLine to recreate the ‘line’.

Does this mean that if we don’t know if the imported model is a ‘line’, we can’t handle it?

This is because the mesh does not have a material pushing the fillmode to lines:

1 Like

Can we judge whether we’re importing a two-dimensional line or a three-dimensional body?

If it’s three-dimensional body, we don’t need it. a material pushing the fillmode to lines

Good question, I think the loader should create a line material in this case.

We want to import any model (including 2D lines, 3D) into babylon scene and it will display properly.

However, we tested that the 3D model could be imported normally, but the 2D line could not be imported normally.
Unfortunately,there is no way to judge whether the imported model is 2D or 3D.

Do you have any good ideas?

Look forward to your help, thanks very much!

If you use GLB it is possible to include metadata with such information to distinguish between 2d and 3d