Jump to content

How to access all imported mesh data.


David78
 Share

Recommended Posts

New Text Document.txt

Hi to all,

 

First off, I wish to thank gratefully the creators of this wonderful framework that makes working with 3d on the web very easy and intuitive. 

 

I have just started using it and it is all okay; the issue is that I have created some models in blender and exported them to babylon and accessing some of the mesh data yields the "undefined" response. I've opened the file using an editor and see that it's a JSON object with various properties.

 

Some properties can be accessed like these ones:

 

 newMesh[0].position or newMesh[0].checkCollisions 

 

and so on.

 

Trying to access other properties however yields the "undefined" response, such as:

 

newMesh[0].useFlatShading or  newMesh[0].positions or  newMesh[0].uvs

 

and so on.

 

Why is this so? What would be the proper way to access all the properties of an imported object from blender?

 

Thanks in advance.

Link to comment
Share on other sites

Hi there, I appreciate all the work you've done as well as your swift response.

 

Here is the code I use to load the models:

    if (BABYLON.Engine.isSupported()) {        var canvas = document.getElementById("renderCanvas");        var engine = new BABYLON.Engine(canvas, true);scene = new BABYLON.Scene(engine);BABYLON.SceneLoader.ImportMesh("", "", "flowers.babylon", scene, function (newMeshes, particleSystems)            // Wait for textures and shaders to be ready{           scene.executeWhenReady(function () {camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 50, -200), scene);camera.attachControl(canvas, true);light = new BABYLON.DirectionalLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);//trying to access some properties:alert(newMeshes[0].position+"  "+newMeshes[0].checkCollisions);//<-this works okay. :)alert(newMeshes[0].useFlatShading+" "+newMeshes[0].positions+"  "+newMeshes[0].uvs);//<-this just tells me "undefined"...                // Once the scene is loaded, just register a render loop to render it                engine.runRenderLoop(function() {                    scene.render();                });            });        }, function (progress) {            // To do: give progress feedback to user        });    }

I hope that helps, it really is the exact code used from the blog post. Starting to get my way around it, before I begin building something.

Link to comment
Share on other sites

Hmmm...Alright, what do you mean when you say that "Not all properties in Mesh are always assigned."?

 

Do you mean that when imported from blender, their values are going to be  null? If that is what you mean, then that isn't the case in this instance. For example, the property "useFlatShading" is set to "false" and the "positions" and "uvs" are arrays that are both full of values (when the file "flowers.babylon" is perused using an editor). The properties that have no value simply show an empty response when accessed, for example, saying:

 

 alert(newMeshes[0].instances);

 

Outputs an empty result; but calling the other properties that I've highlighted respond with "undefined", even though these properties are assigned when one looks at the file from an editor.

Link to comment
Share on other sites

I'm sorry about that, it was a typo as in the original code, I did in fact use newMeshes[0]; I've just corrected this error in my earlier posts. The issue still stands; it still responds with "undefined" for some properties, but correctly displays other properties as well as their values.

 

Would it help if I uploaded the .babylon file somewhere? I tried uploading here but the system did not allow me to upload that type of file. 

Link to comment
Share on other sites

That doesn't seem to be the case, displaying newMeshes[0].name alerts "vase", which is one of the two meshes I've imported from blender...I've attached the .babylon file but changed the extension to .txt so that I could upload it. I've attached it to my original post. If you look at it, you'll see that it does have the properties with set values that I'm trying to access. 

Link to comment
Share on other sites

Here is a list of properties that I cannot access, even though in the file they are defined and they do have set values:

 

useFlatShading. (in the file: "useFlatShading:" false)

 

positions. (in the file: "positions:"-> a huge array with floats) 

 

normals.(in the file: "positions:"-> a huge array with floats) 

 

indices.(in the file: "positions:"-> a huge array with floats) 

 

uvs.(in the file: "positions:"-> a huge array with floats) 

 

It's weird that I can't access those values, yet the mesh is loaded properly and the flower and the vase are properly displaying.

 

I saw that one can get the vertex data from a mesh using this:

var ver_dat=new BABYLON.VertexData.ExtractFromGeometry(newMeshes[0]);

trying to access the vertex data works fine when one writes:

 

alert(vert_dat.positions) etc

 

but not when one writes:

 

alert(newMeshes[0].positions)

 

I feel like it's something obvious that I'm not seeing somewhere (I am a newbie after all...)....anyways, another way would be to just use the extracted vertex data to form a new mesh, but I don't exactly know how to go about doing that. After getting the vertex data from mesh A, how would I use this to make a new mesh B, so that from mesh B I can access all the mesh properties that I currently cannot from the original mesh A?

 

Thanks.

Link to comment
Share on other sites

There is also no useFlatShading property.  BabaylonFileLoader checks for it.  When true, it flattens the normals out using BABYLON.Mesh.convertToFlatShadedMesh() method, then re-transmits them to the GPU.  You should not be taking every data structure in a .babylon to mean that is how they are represented in JS, though the simple one might be.

 

You should look at the source code (either .ts or .js) to see how things are represented in memory.  Here:  https://github.com/BabylonJS/Babylon.js/tree/master/Babylon/Mesh

 

FYI, look into either cloning or instancing to make copies of entire meshes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...