adam Posted March 25, 2016 Share Posted March 25, 2016 I'd like to be able to merge meshes of different colors and have them retain their colors. Is that possible? Quote Link to comment Share on other sites More sharing options...
adam Posted March 25, 2016 Author Share Posted March 25, 2016 Will I need to color the meshes through vertexData rather than the materials? Quote Link to comment Share on other sites More sharing options...
adam Posted March 25, 2016 Author Share Posted March 25, 2016 I tried setting the colors through vertexData. The colors aren't on the correct faces after the merge though. I'll create a PG. Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 I got it working here with simple box meshes: http://babylonjs-playground.com/#28XVKW#2 Meshes that are complex are not working. I'm thinking my colorVertices function needs some work. Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 If you uncomment the colorVertices function on line 67 in this PG, it won't load: http://www.babylonjs-playground.com/#21XUBV#17 and I get this error in the console - "WebGL: too many errors, no more errors will be reported to the console for this context." Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 I simplified the PG and made sure all the meshes had vertex color data and it seems to be working: http://www.babylonjs-playground.com/#21XUBV#20 Now I just have to figure out why it isn't working correctly in my project! Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 I got it to work in my project. Now I need to figure out how to set separate vertex color data for cloned meshes. You can see the issue here: http://www.babylonjs-playground.com/#21XUBV#23 I'm trying to make the 3 cloned cylinders separate colors, but they end up being the last color set because they are sharing the same vertex color data. Quote Link to comment Share on other sites More sharing options...
jerome Posted March 26, 2016 Share Posted March 26, 2016 not sure to understand well what you are trying to achieve, but have you taken a look at MeshBuilder.CreateCylinder with the parameters (used together) : subdivisions, hasRings, faceColors ? [EDIT] : example [EDIT 2] ooops, it eems you need a tube instead of a cylinder I intend to implement the "hasRings" feature also for the tube... some day (too busy currently). Actually, I'll do it for the ribbon ("hasStripes" ?), then it will be available for any ribbon based shape Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 26, 2016 Share Posted March 26, 2016 11 hours ago, adam said: I'd like to be able to merge meshes of different colors and have them retain their colors. Is that possible? In a project I am playing with I wanted the same thing. In the end I settled for not merging the meshes but 'gluing' them together by giving them a common parent. This was good enough for what I wanted but if you want to try merging meshes of different colours and retain their colours then here are somethings I though about but never attempted to do. A merged mesh is a single mesh so can have only one material applied unless you use multi-materials in this case how do you assign correct vertices to correct material? There is a tutorial on writing a custom mesh merge http://doc.babylonjs.com/tutorials/How_to_Merge_Meshes#use-your-own-merge-function Perhaps this could be adapted but again you would need to assign the correct uvs to the correct vertices and in this case you do have access to which colour originally went where but how do you keep and assign the different colours. Would one way be to set a colour map of some sort, ie u from 0 to 0.25 read red, 0.25 to 0.5 read green etc? At this point I am not even sure I know what I am talking about rather it is some vague idea. This may have helped or hindered you. As I said I went for a different option in the end so good luck. Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 2 hours ago, JohnK said: In the end I settled for not merging the meshes but 'gluing' them together by giving them a common parent. I've explored this and wasn't happy with the way the transparency looked. 4 hours ago, jerome said: not sure to understand well what you are trying to achieve I need to be able to clone/copy models that I have created in Blender, make them transparent, color them differently, and merge them together. I feel like I am 99% of the way to achieving this. I just need for the cloned models to be able to have their own vertex color data. Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 I tried creating new meshes instead of cloning (lines 67-69, 91-93). http://www.babylonjs-playground.com/#21XUBV#24 I also tried copying the geometry after I cloning the mesh. http://babylonjs-playground.com/#28XVKW#6 No luck. I'm not sure why it keeps referencing the same vertex color data. Quote Link to comment Share on other sites More sharing options...
adam Posted March 26, 2016 Author Share Posted March 26, 2016 I finally figured it out. http://babylonjs-playground.com/#28XVKW#7 http://www.babylonjs-playground.com/#21XUBV#26 mesh.geometry.copy(BABYLON.Geometry.RandomId()).applyToMesh(clonedMesh); JohnK 1 Quote Link to comment Share on other sites More sharing options...
adam Posted March 27, 2016 Author Share Posted March 27, 2016 I'd like to be able to set alpha of the vertex colors. Here I modified my colorVertices function so that it takes an alpha value and then I attempt to set the two end boxes to alpha of .5. http://babylonjs-playground.com/#28XVKW#8 Setting the alpha of the vertex color doesn't change the transparency though. Shouldn't that be possible? Quote Link to comment Share on other sites More sharing options...
jerome Posted March 27, 2016 Share Posted March 27, 2016 http://doc.babylonjs.com/classes/2.3/AbstractMesh#hasvertexalpha-boolean line 57 : http://babylonjs-playground.com/#28XVKW#9 adam 1 Quote Link to comment Share on other sites More sharing options...
adam Posted March 27, 2016 Author Share Posted March 27, 2016 hasVertexAlpha works correctly when the meshes aren't merged. http://babylonjs-playground.com/#28XVKW#10 After merging, the middle box is no longer opaque (viewing from bottom). http://babylonjs-playground.com/#28XVKW#11 Quote Link to comment Share on other sites More sharing options...
jerome Posted March 27, 2016 Share Posted March 27, 2016 as you can see the bottom of the blue box through the green box, I think it's still transparent Quote Link to comment Share on other sites More sharing options...
adam Posted March 27, 2016 Author Share Posted March 27, 2016 The middle box is supposed to have no transparency. The two end boxes are supposed to have .5 transparency. (merged version at every view angle) You can see the difference when you view the non-merged version here: http://babylonjs-playground.com/#28XVKW#12 and then the merged version: http://babylonjs-playground.com/#28XVKW#11 Quote Link to comment Share on other sites More sharing options...
jerome Posted March 27, 2016 Share Posted March 27, 2016 oops weird indeed I guess it's because when a mesh has alpha (whatever the alpha value on some vertices), it's globally processed as a full transparent mesh... so no z-sort for the facets between them http://doc.babylonjs.com/tutorials/Transparency_and_How_Meshes_Are_Rendered Quote Link to comment Share on other sites More sharing options...
adam Posted March 27, 2016 Author Share Posted March 27, 2016 This isn't a show stopper for me. I'll just keep my opaque meshes separate from my merged transparent meshes. It would have been nice to merge them all together. No big deal though. 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.