BabarJulien Posted September 17, 2018 Share Posted September 17, 2018 Hi all, in current versiont of BabylonJs, as in the preview release, LinesMesh does not support "createInstance". Is there a fundamental reason for that because of how LinesMesh works ? Or is it just because nobody took the time to do it ? (I prefer ask before eventually trying to implement it by myself ) Thanks, Julien Quote Link to comment Share on other sites More sharing options...
jerome Posted September 17, 2018 Share Posted September 17, 2018 Meanwhile you could use the LineSystem maybe http://doc.babylonjs.com/how_to/parametric_shapes#line-system http://doc.babylonjs.com/api/classes/babylon.meshbuilder#createlinesystem BabarJulien 1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 17, 2018 Share Posted September 17, 2018 BABYLON.Mesh supports instances. If you specify your positions the way Meshbiulder.CreateLinesystem() does from the lines argument, you can use a BABYLON.Mesh. var i = 0; for (var l = 0; l < lines.length; l++) { var points = lines[l]; for (var p = 0; p < points.length; p++) { positions[i] = points[p].x; positions[i + 1] = points[p].y; positions[i + 2] = points[p].z; i += 3; } } I already mentioned that LinesMesh uses ShaderMaterial, and that does not support instances. BabarJulien 1 Quote Link to comment Share on other sites More sharing options...
BabarJulien Posted September 17, 2018 Author Share Posted September 17, 2018 thanks @jerome and @JCPalmer for your answers, I'll try to use LinesSystem instead then ! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 17, 2018 Share Posted September 17, 2018 Yes, an actual linesystem is more efficient than instances, since it is only one mesh. It closely resembles a MergedMesh. It takes more memory, but if none of your lines never move / rotate / scale, then instances are not necessary. If you have to beat up on a resource, memory is about the safest choice. Quote Link to comment Share on other sites More sharing options...
BabarJulien Posted September 17, 2018 Author Share Posted September 17, 2018 Hmmm @JCPalmer, it seems that I can get my lines rendered as expected using a BABYLON.Mesh and using a standard material with wireframe and emissive color. But still, the picking does not seems to work, and not only because of possible 0-side AABB if the lines are axis-aligned. If the mesh is not a LinedMesh, the mesh is supposed to be made of triangular faces, each triangle made of 3 consecutives points in the geometry positions (copied from VertexData if I understood correctly). I might have explained what I'm trying to achieve first : I'm implementing a kind-of 2d editor which display and manipulates objects coming from CAD data and that are mainly made of lines. I'm facing memory usage issue when creating all the meshes, so I'm trying to reduce my memory footprint. As some of thses objects are just other instance of already existing objects (but with different transform), using instance instance of cloning those meshes did sound a good avenue... But it does not seems to be that simple ? Maybe @Deltakosh have some insight on how to reduce my memory consumption? (Btw @Deltakosh I've been trying the preview release with the performance improvements, but it actually seems to be slower for me to create a lot of BABYLON objects between two frames than with the 3.2... If you're interested in, I can make some profiling to give you an hint of why) Quote Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2018 Share Posted September 18, 2018 So yeah definitely interested by the profiling The LinesMesh has a cool feature to help with picking (mesh.intersectionThreshold) but it does not support instancing. That is something we can work on for next release (we are about to ship 3.3) so feel free to open an issue for that Quote Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2018 Share Posted September 18, 2018 Also, you may be interested by this bug we found in Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=881977 Quote Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2018 Share Posted September 18, 2018 Wait..actually I will fix the CreateInstance function for linesMesh..Stay tuned Quote Link to comment Share on other sites More sharing options...
Guest Posted September 19, 2018 Share Posted September 19, 2018 Ok PR is on..will be in next nightly Now LinesMesh support create Instance BabarJulien 1 Quote Link to comment Share on other sites More sharing options...
BabarJulien Posted September 20, 2018 Author Share Posted September 20, 2018 Hi @Deltakosh Here are the shots of the profiling I did. The exact same operation with exact same code is used. Only the babylon and babylon-material version changed. (using chrome 69.0.3497.100 on a win10 Pro). 3.2 : 3.0-rc.1 : As you can see, it takes much more time with the 3.0-rc1 version, and it seems that the extra-time is in "SparseMove" and "SparseSlice" which are V8 functions I guess. If I dig a bit deeper, those are called from set parent setter of Node : + If I compare this function between 3.2 and 3.0, the changes are about the _scene.rootNodes: In case of many many nodes, having just an array can be suboptimal for storing all the nodes that have no parent. Note that even if I specifiy the parent in the Mesh constructor, the node is pushed in the rootNodes array during Node base class construction, and then removed when the parent is set during Mesh construction. One way to prevent that would be add an extra parameter to the AbstractMesh, TransformNode and Node constructor in order to prevent the node to be adding to the rootNodes array if a non-null parent is passed in the Mesh cosntructor (or if the source has a non-null parent). Another, less impacting, option would be to pop the last element of rootNodes after the call to super in the Mesh constructor (if the parent is not null). Not that those changes would not reduce the time spent in "indexOf", but it could save a call to rootNodes .splice. (by the way, if the order in the rootNodes array does not matter, you'd better swap the last element of the array with the one at rootNodeIndex, and then call rootNodes.pop() instead of splice, it is likely to be faster and would less stress the GC as splice creates and returns a new array containing the deleted elements). Having a boolean member "isInRootNode" might also help to prevent the call of rootNodes.indexOf is not necessary. I'm gonna try the LinesMesh instance now Quote Link to comment Share on other sites More sharing options...
BabarJulien Posted September 20, 2018 Author Share Posted September 20, 2018 @Deltakosh , in the attached patch there is my proposing for tackling this perf regression. I tested it on my side and it works. I tried to run gulp in the bayblon repo but it crashes at some point when testing with Phantom. But the crash also happens in the master and preview branches, so it does not come from my changes. 0001-rootNodes-perf-Issue.patch Quote Link to comment Share on other sites More sharing options...
Guest Posted September 20, 2018 Share Posted September 20, 2018 I like it! this is really good udpate Please create a PR Quote Link to comment Share on other sites More sharing options...
BabarJulien Posted September 20, 2018 Author Share Posted September 20, 2018 @Deltakosh https://github.com/BabylonJS/Babylon.js/pull/5212 I changed it a litlle bit from what I did in the patch I posted here. 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.