Error on click (scene.pick) when scene is loaded from file

Okay I didn’t know for the lines.
I will document myself on ribbon and plane.
Thank you for all your answers

Np let us know if you have mor issues

You can create LinesMesh objects if you want to get lines that can be picked :slight_smile:
Example of a LinesMesh: https://www.babylonjs-playground.com/#F1XXI#1

Oh nice one everyday is a good one to learn :wink:

2 Likes

Thanks for the LinesMesh tips.
In the .babylon file format how do I say that a mesh is a “LinesMesh” to have it imported as a line mesh ?
Can you give me an example of a .babylon format for a LinesMesh ?

You can do it the reverse way :slight_smile:
Just create a scene with a LinesMesh and then call scene.serialize() :wink:

Ok, that’s what I did and I saw that the serialized scene it’s not the same than the scene exported from the proprietary format I have.
I’m trying to adapt my exporter with what I’ve got from the scerialization. This could take a while, I’ll try to get help from people who know the proprietary format. Just for info, I’m working with CAD objects from TopSolid with a custom exporter.
I already changed a litle from the exporter and I put it in the original playground. I did not use line meshes for now, but I noticed that for a simple cube I exported the wrong data compare to a scerialized scene with a box.
However it’s not totally correct but that’s work on my end with the exporter.

I noticed something that was difficult to see without using scene.scerialize() : the exporter was built using the definition in FileFormat Map (.babylon) - Babylon.js Documentation and for a cube a localMatrix is scerialized however it’s not written anywhere in the documentation.
Maybe the documentation needs to be updated.

Thanks for the help !

1 Like

If you can update the doc I will love you forever :wink:

Keeping the doc up to date is a complicated task so any help is welcome :wink:

Hi B! So… yeah, that darned custom exporter has haunted you, eh? nod.

But, you are working on… essentially… the first TopSolid to .babylon exporter, right? Cool! Thanks!

We would LOVE to have TopSolid onboard with BabylonJS. Yeah! Good luck!

Give our thanks to the other author(s) of the custom exporter, too, and tell them to give you maximum friendly help… for free… for the good of humankind. :smiley:

1 Like

Okay I understand.
I’ll do the update when I’ll have all the info I need on the .babylon format. I hope it will be soon ^^

Hello @Wingnut !
Yep I am really new to the 3D world and this exporter is an open door to the unknown for me !
I asked help to the 3D expert in TopSolid, I hope he’ll have the time.
I’ll keep you posted if we finally get a correct result :wink:

1 Like

Great. Be sure to invite him and his friends… to join us here on the BJS forum… they are quite welcome, just like you.

That playground deals-with some basic “plotting” of a 3D mesh, and shows a little about how BabylonJS stores the data used to “render” it. The little blue boxes are just helpers… to allow you to more easily see where each vertex is located. They can be disabled at line 47.

Generally speaking, a BJS mesh needs vertices (called positions or positionKind), indices (pretend lines that can form triangles [faces] from various 3-vertex groups), and normals ( [normalKind]… one per vertex, mainly used for lighting calculations). Other optional mesh-making data-sets are colors/colorkind… one color per vertex, and UV/uvkind… used to map textures onto the mesh.

A vertexData object can be considered a little database. Just a place to store all that mesh-making data, and a few helpful tools.

I coded the original playground, but somebody added a function called computeNormalsToRef() which somehow aligns the lighting normals or something. Let’s not concern ourselves with that, yet.

In BabylonJS, mesh can be rendered “smooth-shaded” or “flat-shaded”. Most mesh-rendering defaults to smooth-shaded, but I believe our boxes… are flat-shaded by default - 24 verts instead of 8. This gives our boxes lots of features… like color-per-side and texture-per-side magic.

When a mesh is flat-shaded, it requires adding more lighting-normals… at each vertex of the model. But we can only have ONE lighting normal per vertex. So, when a programmer asks BabylonJS to do anymesh.convertToFlatShadedMesh(), it automatically adds more vertices… ATOP the previous vertices (at the exact same point-plot locations). (…but NOT for standard BJS boxes, which are already flat-shaded… as you know.) :slight_smile:

Look at line 132… vertexData.applyToMesh(blankmesh, 1); THAT is where we apply the database-of-mesh-making-data (the vertexData object)… to blankmesh. THAT makes it NOT “blank” anymore. You could say that we “populated” the blank mesh.

Line 134-135 are just lines that wait for the scene to be completely ready, and then wait 8 more seconds. Below those lines… I do a console report of total-vertices, then a convertToFlatShadedMesh(), then another total-vertices report.

Watch the JS console in the playground… when you run it. At about 8 seconds… I report the number of vertices… then do blankmesh.convertToFlatShaded()… then report the number of vertices again. Notice that it changed from 8… to 36.

The number of added vertices (and thus also added lighting normals)… depends upon the number of triangular “faces” that intersect at any vertex. If 3 triangles meet at a vertex point, 2 extra vertices are placed there, with their 2 extra lighting normals. If 5 triangles meet there, 4 verts/normals are added at that point.

The objective of flat-shading… is to have one lighting-normal for each triangular face… that intersects that vertex. For flat-shading, each of those intersect-at-vertex faces… needs different lighting from each other. That’s what gives the mesh a flat-shaded look.

A little extra info: BabylonJS uses color-per-vertex method… and NOT color-per-face (for colorKind data). That’s somewhat advanced stuff, but might be important to your TopSolid assistant.

That’s enough for now, and I’m no pro. This information MIGHT be useful for you and your assistants. I hope I haven’t accidentally told you wrong things. Play with that plotting playground and similar code… when you get a chance. Notice that SOME vertexData datakinds need 3 values for each vertex, some need 2 values each, etc.

All this information… might be important to your helpers and to the project. I HOPE it is helpful. It helped ME understand webGL rendering… a little bit. :slight_smile: Be well… talk again soon.

Addenda: https://www.babylonjs-playground.com/#104HTQ#9 There’s a pretty torus knot that gives before/after reports to console. This mesh changes from 4112 verts… to 24576 verts after the convert-to-flat. Wow. Don’t worry… BJS has the performance to handle it, and much more.