Origami Posted July 16, 2016 Share Posted July 16, 2016 Hey all! I'm fairly new to the babylon framework (and this is my first forum post--hey again!), but after coding in it nonstop for a few weeks, I have a decent handle on it. Or so I thought. I'm trying to give my objects textures, and while it works on babylon-created meshes, I get no love from my own imported OBJs or .Babylon files. I'm sure I'm just doing something incorrectly/missing a setting, but for the life of me, I can't figure it out. And of course, obligatory playground demonstrating this issue: http://www.babylonjs-playground.com/#XTJQS#1 //EDIT: And now I can't get my .babylon or .obj files to load from my server. I swear they were working before. Does anyone have any samples so we can replicate the issue? Thanks! testDog.babylon teddy.obj Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 17, 2016 Share Posted July 17, 2016 Hiya @Origami, welcome to the forum! I don't know much about .obj importing, but I DO know that your .babylon file has no UVs in it. I see only positions and indices. And, I'm not a modeling expert, either, so I can't remember why Blender/Max/Unity/whatever... would not export UVs by default. It is likely because it is un-textured in your modeling software. .babylon files are really .json files, and you can use online .json viewers to "tree-ify" or "pretty-fy" the contents of your .babylon files. I suggest you keep doing experiments and keep trying various exports... until you see UV's in your .babylon file. After that, applying textures SHOULD be a much more tolerable task. GameMonetize and Origami 2 Quote Link to comment Share on other sites More sharing options...
Origami Posted July 17, 2016 Author Share Posted July 17, 2016 Hey Wingnut! After reading through so many of your forum posts, I feel like I'm speaking with a celebrity! Niccccce. Do you have a sample .babylon file with the UVS in it (I see that it's 'just' float-formatted data for the vertexes)? I'd love to throw it into my app and see if that fixes the issue. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 17, 2016 Share Posted July 17, 2016 Thanks, but I'm really just a local blowhard. Good to have you with us. I already like your personality and spirit. I made my previous post a bit longer. I had to do an early save, because I somehow lost my cursor. Goofy forum software. Checking for decent demo... stby. Origami 1 Quote Link to comment Share on other sites More sharing options...
Origami Posted July 17, 2016 Author Share Posted July 17, 2016 Right on, right on! I'll see what i can do about applying a vanilla texture in Blender and exporting that, then overwriting it in my JS with the bumpTexture. If that ends up working, and it really is just the existence/lack of this attr within the .babylon's JSON structure, I'll probably end up writing a script that trawls through a folder of OBJs and inserts dummy texture floats. My team is getting a crapton of OBJs from modelers and it would be a tedious process to open each and every model, apply textures, and then export, to say the least. Thanks for the quick reply here, I'll get cracking and report back! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 17, 2016 Share Posted July 17, 2016 My pleasure and a good game plan, O! Be patient, though, as more experts might have better ideas. Although big, THIS PG uses a .babylon file with 'uvs' within it. Its .babylon file... https://cdn.rawgit.com/Wingnutt/misc/master/Perplexus_Components.babylon Hope this helps! Again, welcome aboard, and thanks for helping us with BJS, by driving BJS. Know where all your searchers are, right? Playground search, forum search, docs search? Holler if ya need urls. Addenda: Here's an obj loader demo... but don't ask me what the playground author was doing AFTER loading the .obj. .hdr... phew. Over my head. Quote Link to comment Share on other sites More sharing options...
gryff Posted July 17, 2016 Share Posted July 17, 2016 @Origami: 48 minutes ago, Origami said: My team is getting a crapton of OBJs from modelers and it would be a tedious process to open each and every model, apply textures, and then export, to say the least. Welcome to the forum @Wingnut is correct about the "teddy" file - it has no UVs and as it has no accompanying .mtl file it has no materials of any type. Not sure quite what you are doing, but you may have to insist that any model submitted to you is UVMapped and has materials/textures. Other possible issues are the size - the "teddy" is 30-40x the BJS standard cube, and the "origin" - the "teddy" is OK (origin 0,0,0 - between head and body) but I have seen 3d meshes where the origin is completely outside the mesh which would make rotating and scaling the mesh tricky. My work flow for creating textured 3D objects/meshes in Blender is typically this: Model Mesh ->Create UVs ->Create Textures(diffuse, normal, etc.). As you can see, the final textures I create are based on the UVMaps - not the other way around. cheers, gryff Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 17, 2016 Share Posted July 17, 2016 Drag and drop for previewhttp://www.babylonjs.com/sandbox/ Allow CrossOrign Allow CrossOrign Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted July 17, 2016 Share Posted July 17, 2016 the correct normal map need tangent vector and normal vector both need calculate per vertex before shader start make bump map we r not have tangent vector but we can calculate that . reference : http://ogldev.atspace.co.uk/www/tutorial26/tutorial26.html Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 17, 2016 Share Posted July 17, 2016 I think the problem here is that the mesh has no uv data ?http://www.babylonjs-playground.com/#LA4VD#3http://www.babylonjs-playground.com/#LA4VD#4http://www.babylonjs-playground.com/#LA4VD#6 Quote Link to comment Share on other sites More sharing options...
Origami Posted July 18, 2016 Author Share Posted July 18, 2016 Oh man, these are all great suggestions! Ahhh, I love this forum! I'll keep digging and see which one solves this Quote Link to comment Share on other sites More sharing options...
Origami Posted July 19, 2016 Author Share Posted July 19, 2016 Hey Babyl-allstars! So I've quashed some other bugs in the app and I've started trying to work through this issue, but I can't even seem to load any OBJ files into the scene at all. I keep getting the error: "o._addPendingData is not a function", which is being thrown in: "[email protected]:15". I've tried using both methods that look applicable: var loader = new BABYLON.AssetsManager(scene); var batman = loader.addMeshTask("batman", "", "assets/", "batman.obj"); and BABYLON.SceneLoader.ImportMesh("batmanface", "batman.obj", scene, function (meshes) { // ... }); Hell, I'm even trying to load the batman models, but I still get this error. And the only thread I've found on this gives creating a scene as a fix. But I definitely already have a scene, since the obj loading occurs on a click, while the rest of the scene is loaded before the click occurs. The syntax is identical to the playground, but it's not throwing the error. So I'm stuck with not being able to even test all these great suggestions for applying a texture to an OBJ, since I can't even get an OBJ to load. I guess I'll try tweaking the .babylon files and working on it from there, but I really would prefer to be able to use OBJs. Hmmmm... Quote Link to comment Share on other sites More sharing options...
Origami Posted July 19, 2016 Author Share Posted July 19, 2016 And as an update! In testing with the .babylon files that DO load, I added some UV mapping in Blender and the textures took right away. So @Wingnut's intuition (and likely many others on here) was correct. Now, to load these OBJs... Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 19, 2016 Share Posted July 19, 2016 Hello Something with your Code is wronghttp://www.babylonjs-playground.com/#4LXMG#1 You can copy paste the code here, or just try to figure it out by yourself"o._addPendingData is not a function", you try to add data to a function that already has data in it. Best@Wingnut can tell you details on this issue Good Luck Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 19, 2016 Share Posted July 19, 2016 Wasn't intuition. Was an examination of the .babylon file.... told the story. Ok, moving on. http://urbanproductions.com/wingy/babylon/khaled/objload01.htm Whack that. When its loaded, click the little gray box in the lower right. A filepicker should open. When it does, choose one of your many .obj files... on your computer. See if it loads-in. It might be small, so mousewheel-in to check. This still loads .obj files on my computer... but its an old style loader. It uses a separate objloader.js. Don't volunteer me for knowledge I don't have, Nabs. How about YOU tell us all where " you try to add data to a function that already has data in it. " is happening. Get specific. Quote Link to comment Share on other sites More sharing options...
Origami Posted July 20, 2016 Author Share Posted July 20, 2016 So I can load my obj in your site, that works fine. So I guess Nabroski is correct that the code is incorrect somehow? I'm just confused, because it loads .babylon files just fine and the syntax of sceneLoader.ImportMesh() is the same for both of them. As far as I can guess, I think the prototype chain for whatever 'o' isn't connected to the babylon prototype chain properly to get that method. Is it something about how the initialization for the mesh in the .obj file starts with 'o'? Hmmph. More digging & testing. I'm using babylon 2.4.0 & babylon.objFileLoader I picked up from the github repo. Is there still something I'm missing? Also, in case any of you guys are curious, I'm looking to use this method for auto-generating the UV mapping from the face normals to avoid blender's seam creation mini-game for what will likely be dozens (and growing) OBJs/.babylon files. Quote Link to comment Share on other sites More sharing options...
Origami Posted July 20, 2016 Author Share Posted July 20, 2016 @Nabroski I'm using your example and it looks like I missed a comma in the filename in my jumping back and forth between git branches. I feel embarrassed, but there's nothing for it but to move on. So now it clears the initial o._addPendingData error, but it still kicks into the onFailure callback after loading the first mesh (my OBJ only has one mesh). My code looks like: BABYLON.SceneLoader.ImportMesh( "", serverPath, filename, scene, function(meshes) { console.log("success!"); /*...followed by doing stuff with the meshes... */ }, function(evt) { console.log(evt, "is loaded") }, function(errorEvt) { console.log("error:", errorEvt) } ) And I don't get to "success!". All I see is the log for "is loaded" for the only mesh of the object and then the errorEvt is logged. And the errorEvt looks to just be the scene object itself. Is there a particular attribute in here I should be looking for to debug through this? Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 20, 2016 Share Posted July 20, 2016 Hello your code is valid you missing a comma or something /somewhere elsehttp://www.babylonjs-playground.com/#4LXMG#2 Best Quote Link to comment Share on other sites More sharing options...
Origami Posted July 20, 2016 Author Share Posted July 20, 2016 @Nabroski, you don't know how very right you are. In my jumping around from git branch to branch like the nascent code monkey I am, the ObjLoader script inclusion was dropped from my index.html. After spotting that this afternoon, I've been able to make great progress. Your help with creating progress/failure functions was key in my narrowing the lurking variables here. Thank you guys for such a great community (and library!) Nabroski and GameMonetize 2 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.