David78 Posted December 11, 2014 Share Posted December 11, 2014 New Text Document.txtHi 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. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 11, 2014 Share Posted December 11, 2014 Could you share your code or create a repro case on playground? Quote Link to comment Share on other sites More sharing options...
David78 Posted December 11, 2014 Author Share Posted December 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 11, 2014 Share Posted December 11, 2014 Not all properties in Mesh are always assigned. Positions, indices are always going to be. normals are always going to be coming from Blender. colors, uvs, uvs2, skeletonIndices, skeletonWeights are all optional. Could be null as opposed to undefined, but I do not see a real difference. Quote Link to comment Share on other sites More sharing options...
David78 Posted December 11, 2014 Author Share Posted December 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 11, 2014 Share Posted December 11, 2014 HUmm.. you just use newMeshes[0] and not newMesh[0] Quote Link to comment Share on other sites More sharing options...
David78 Posted December 12, 2014 Author Share Posted December 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 12, 2014 Share Posted December 12, 2014 Perhaps newMeshes[0] is an empty object. Can you check this by display newMeshes[0].name? Quote Link to comment Share on other sites More sharing options...
David78 Posted December 13, 2014 Author Share Posted December 13, 2014 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. Quote Link to comment Share on other sites More sharing options...
David78 Posted December 13, 2014 Author Share Posted December 13, 2014 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 13, 2014 Share Posted December 13, 2014 There is no positions, normals, uvs, uvs2, colors, or indices properties in BABYLON.Mesh. These are transferred to the GPU on load. There are artifacts letf on the cpu, but you have to access them thru something like: newMeshes[0].getVerticesData(BABYLON.VertexBuffer.PositionKind) Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 13, 2014 Share Posted December 13, 2014 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. Quote Link to comment Share on other sites More sharing options...
David78 Posted December 14, 2014 Author Share Posted December 14, 2014 Thanks for the help. I need to manipulate the shape of the imported mesh and to also merge different meshes together, that's why I'd use VertexData as opposed to cloning. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.