JBlack_UTD Posted May 25, 2016 Share Posted May 25, 2016 I don't see a way to export a terrain material from Unity. Is there a method I could use to export an array of textures, and then create the terrain material later in babylonJS with those textures? Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted May 25, 2016 Share Posted May 25, 2016 Hi @JBlack_UTD please see: Docs: http://doc.babylonjs.com/extensions/Terrain PG: http://www.babylonjs-playground.com/#E6OZX#7 (same link can be found in the docs) for terrain material, please note that it's an extension and therefore must be included seperately from the main babylon.js in your project You can make a simple 2d image in any image editor, aproximately same size as your plane/ground and then apply different colors where you want them, which then turns into different textures on your scene Edit: with same "size" i ofc mean dimensions/shape. Tips: When working with the terrain material and pre-made 3d scene files, It's always a good idea to design your level first in 2d, e.g. choose where you want your roads, grass, etc to be. You can then import that image as a texture for your plane/ground in your 3d editor to use as a template to follow and apply any height changes you wish to have, place 3d objects, etc, before you then export to .babylon and then finally apply the texture('s) via the terrain material extension Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted May 25, 2016 Author Share Posted May 25, 2016 RIght, sorry - I wasn't specific enough. I've emulated the terrain material shader in Unity using shaderforge, and would ideally like to export that straight into BabylonJS. I've also manually created a terrain material in BabylonJS to understand how it works (via the extension). The disconnect is that the Unity exporter (via SceneBuilder.Material.cs) has DumpStandardMaterial and even DumpPBRMaterial , but not a DumpTerrainMaterial function. I'd be happy to make one, but the problem then becomes that the BabylonExport.Entities.dll doesn't seem to contain a definition for the terrain material (which is reasonable because it's an extension!). Should I be trying to add a custom definition akin to the entities, or should I be exporting data (such as paths) to BabylonJS so it can use the extension locally? And this goes for any custom shader/material that I might want to export from Unity to BabylonJS. I'm pretty far down the rabbit hole so I might as well... Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted May 25, 2016 Share Posted May 25, 2016 Oh, i don't suppose you can somehow export it as a normal material? sorry, i don't really know unity, so that's all i got JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 25, 2016 Share Posted May 25, 2016 Hey..you can edit and update the entities here: https://github.com/BabylonJS/Babylon.js/tree/master/Exporters/3ds%20Max/BabylonExport.Entities JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted May 25, 2016 Author Share Posted May 25, 2016 Cool! I've made my terrain material entity, a DumpTerrainMaterial function in SceneBuilder.Materials.cs, and then I check to see if the shader matches my emulated one in SceneBuilder.Meshes.cs: ...else if (renderer.sharedMaterial.shader.name.Equals("BabylonJS/Terrain")) { babylonMesh.materialId = DumpTerrainMaterial(renderer.sharedMaterial, renderer).id; } else { babylonMesh.materialId = DumpMaterial(renderer.sharedMaterial, renderer).id; } which produces... another standard material. Which is more than I had before! Before the above code wouldn't even give me that much. The material in BabylonJS shows up as an unlit white solid color, which tells me it's not getting texture/shader data. To be honest I don't know how any of the materials are getting shader data since I'm doing all this through a gulp server, and I don't see any .fx or .ts files anywhere. Somewhere along the way, I'm not telling BabylonJS enough to create a terrain material. Unless I'm mistaken, it's falling back to creating a standard material, and then it fails to load a texture because I'm trying to assign "diffuseTexture1" instead of just "diffuseTexture". Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 25, 2016 Share Posted May 25, 2016 Did you mentioned that you are exporting a TerrainMaterial like this:https://github.com/BabylonJS/Babylon.js/blob/master/materialsLibrary/materials/terrain/babylon.terrainMaterial.ts#L385 JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted May 31, 2016 Author Share Posted May 31, 2016 I feel like I am still missing a vital piece of information... this other question is along the same train of thought: I would love to be able to get Unity to export certain properties. Among the various things, such as name, id, and other properties that get serialized and sent to BabylonJS and parsed by the .max.js file, however, I don't see how the BabylonJS engine is getting type information. Let's say I wanted to use a shader I made for unity to work in BabylonJS. I have a .shader which is assigned to a .material that has a few various .png images that determine color information. All of those are types of assets that can be packaged (copied), parsed, and then re-created in BabylonJS. Where the disconnect is happening is if I want that custom shader to look the same. I can't come in and define my own material type - I have to conform to ones already available. How could I get BabylonJS to look at external files for material data? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 1, 2016 Share Posted June 1, 2016 Did you check what I did here: https://github.com/BabylonJS/Babylon.js/blob/master/Exporters/Unity%205/Unity3D2Babylon/SceneBuilder.Materials.cs#L186 Basically I try to find equivalent between unity material and stdMaterial (which is pretty flexible) Or here for PBR: https://github.com/BabylonJS/Babylon.js/blob/master/Exporters/Unity%205/Unity3D2Babylon/SceneBuilder.Materials.cs#L290 JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted June 1, 2016 Author Share Posted June 1, 2016 Yes I did! private BabylonTerrainMaterial DumpTerrainMaterial(Material material, Renderer renderer) { ///construct the material data ... if (material.HasProperty("_SplatMap")) { ... //copy material data and texture ... terrainMaterialsDictionary.Add(bMat.name, bMat); return bMat; } So I've emulated the functionality and it imports into Babylon with the mix, diffuse, and bump textures, except for instead of creating a terrain material, it creates a standard material. I've stepped through the code and it's even calling the functions inside babylon.terrainMaterial.js! Edit: although it isn't returning anything... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2016 Share Posted June 2, 2016 ok but did you check this? I mean adding the customType property? On 5/25/2016 at 4:05 PM, Deltakosh said: Did you mentioned that you are exporting a TerrainMaterial like this:https://github.com/BabylonJS/Babylon.js/blob/master/materialsLibrary/materials/terrain/babylon.terrainMaterial.ts#L385 JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted June 2, 2016 Author Share Posted June 2, 2016 Cool! So i added a customType string to the BabylonTerrainMaterial.cs file and it gave me this. babylon.max.js:4413 Uncaught TypeError: Cannot read property 'BabylonTerrainMaterial' of undefined I also tried passing just 'TerrainMaterial' and it gives the previously observed error. Edit: Because the customType has to be "BABYLON.TerrainMaterial" !! So it now imports into BabylonJS as a terrain material - exciting. Now I have to make it not black. Edit: which is apparently caused by alpha being 0. Set it to 1 and I can now see it. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2016 Share Posted June 2, 2016 YEAH! JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
JBlack_UTD Posted June 3, 2016 Author Share Posted June 3, 2016 Yay! So I'm getting all the expected data from the textures and materials. I've left the BabylonJS terrain shaders alone, and I'm wondering if it's causing the terrainMaterials to not get light from point lights. There's a screenshot attached showing the unity scene and then the BabylonJS with a bright point light and a small spot light. The exporter is tweaked a bit to mess with exponents and intensity, but everything should be conducive to emulate the lighting conditions from Unity to BabylonJS! Also the standard material that gets imported loses its diffuse color, but I think that's a different problem that I've inadvertently caused elsewhere. Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted June 4, 2016 Share Posted June 4, 2016 Hey JBlack_UTD, It is awesome to have unity exporting these materials !! I'll check if I did a mistake when computing lights. Coming back soon JBlack_UTD 1 Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted June 21, 2016 Share Posted June 21, 2016 I'm back :) To fix it quickly, can you give me the configuration of your scene please ? - plane's position, scale, width, height - light position - light type thanks ! (or the .babylon scene directly) 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.