Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

[Released!] Custom tree importer

Discussion in 'Assets and Asset Store' started by larsbertram1, Aug 19, 2014.

  1. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    hey lars, tnx, the leaf texture was handpainted in photoshop, i was wondering ... what is the best way to "grow" trees.i mean make them them scale up at runtime? as if they pop up
     
  2. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    well: i did not mean the texture (which also looks beautiful) but the shape of the mesh...
    and growing trees is nothing you can do using the built in tree creator shaders: you would probably have to scale the trunk and branches from different pivots: 1 for the length, 1 for the width at each loop. where would your store those pivots in the vertex data? unity 5 offers uv3 and uv4…
    it might be enough to just scale the leaf planes.

    lars
     
  3. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    well the shape is just a pointy square mesh which is repeated 3 times and scaled a bit, hmm that vertex data stuff is chinese to me i hoped there was a more simpler function,;)
     
  4. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    if you think about a spine driven tree like those created by the tree creator then branches would grow
    1. along the spine as far as length is concerned
    2. from the center of each given control point as far as thickness is concerned.

    1. i do not have any idea how to do this within a (regular) shader (i am not into dx 11 shaders...) but at least one could scale the mesh from its pivot equals "branch from its origin". that will not very convincing i guess – as it is more some kind of "unfolding".
    2. you might simply scale the branch taking the control points as center for each loop of vertices to make it grow in thickness.
    [edited] shifting along the normals should do the job... so we only need one additional float parameter: initial thickness so we do not go to negative scale.

    however the final mesh of a tree does not contain any pivots for the branches but just one single one for the whole tree and it does not contain any control points either.

    so you would have to store all that additional data to the vertices of the tree (as that is all the shader has to base its calculation on – next to the mesh’s pivot and some transformation matrices).
    so each vertex had to contain [edited] 1 vector3 and one float components: one storing the branch’s pivot, the other storing the original thickness.

    lars


     
    Last edited: Oct 4, 2014
  5. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    Hi there,

    i would just like to show you a feature that will be implemented in the next upgrade which is: baked pivots for leaf planes.
    Passing information about the pivot of each leaf plane to the shader will allow us to create some fancy effects like rolling or tumbling leafs. or just let them grow over time like asked by Mister D.
    The attached video shows exactly that: leaf planes will grow and shrink over time.



    please note that this effect needs a special leaf shader. nevertheless I hope you like it.

    lars
     
    Baldinoboy likes this.
  6. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Hey Lars. Did not think this could get any better.

    Looking forward to the special leaf shader. Does it come with the Custom Tree Importer pack? Does the special leaf shader work on the terrain? Also does it have specular fixes like your AFS, Lux tree creator shaders do?

    Are there going to be major differences for importing? Will I have to change anything on previously imported afsTREEs?

    Thanks. Really looking forward to trying it.
     
  7. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    hi baldinoboy,
    the new leaf shader is in early development right now.
    it will probably be included in the next update of the advanced foliage shader package … but needs the custom tree importer to bake the needed information: so it will probably only work with manually modeled trees.
    but who knows: once unity has published the docs about the tree creator one might think about hacking it.

    nevertheless:
    - the shader will work on the terrain.
    - it will contain all fixes included in afs
    - nothing special on importing i guess: just one more control tag for the whole tree should be enough.

    lars
     
  8. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Awesome. Thanks for the answers.

    Working with custom trees anyway so excited to try the custom shader.
     
    Last edited: Nov 26, 2014
  9. RickF

    RickF

    Joined:
    Sep 12, 2012
    Posts:
    33
    Seriously considering purchasing this package to add some wind and bending animation to some custom foliage I have modeled.

    However this is for a mobile project and in order to keep things light we are also using custom shaders for our foliage materials. These particular shaders use custom lightmaps assigned to a 2nd UV set on each mesh. Reading the asset store documentation: "It combines all submeshes into one and adds the needed vertex colors and uv2." I am worried that my custom trees will not be compatible with this pipeline as I already have uv2 and it is being utilized for lightmapping. What does Unity's tree system use uv2 for? And could I use it for multiple purposes? Planning on having multiple individual trees atlasing their uv2 into a single texture map to share texture space among a number of trees.

    Will these custom shaders be a problem when trying to use custom trees with the importer/ unity's tree system? If so do you know of any workarounds?
     
  10. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    This script puts the bending information in the UV2. That is the primary purpose of this script.

    To use the trees made with this script you need to use the tree creator shaders. There is the normal ones and then fast versions. So they might be better for mobile use. I have not used them so Lars will have to let you know on that.

    The trees created with this script will work on the terrain with the tree creator shaders. Do not know the full extent of your shader but it probably will not work with the billboarding on the terrain. As for workarounds Lars will have to let you know.

    I think the tree creator trees are only for realtime rendering. With the upcoming multiple UVs in Unity 5 Lars might find a way to have a lightmap on the trees.

    So these trees will work on the terrain so the billboarding will be a major help on performance. Lars will have to correct any errors that I made;).
     
  11. RickF

    RickF

    Joined:
    Sep 12, 2012
    Posts:
    33
    Thanks. I will continue to look into it. Was really only hoping to use this in a small subset of trees, as our camera will be confined to a small area, and the number of trees not outrageous.
     
  12. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    hi rick,
    if you want lightmapping on your trees you cannot use the built in tree creator shaders.
    and of course you can not bake any bending information into uv2 either.
    but what you could do:
    - hacking the tree creator shaders to pick up bending information only from vertex colors. they use vertex color alpha to store ambient occlusion which in case of lightmapping just is not needed. so you could map bending usually stored in uv2.xy to blue and alpha.
    - hacking the tree importer to write bending information to vertex colors only.

    alternatively you can simply use the advanced foliage shaders (which support lightmapping and bending) but their bending currently is a bit restricted as we only have one value to store both bending values.

    lars
     
  13. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Hey lars. I am having a problem importing a tree with the script. At first it imported just fine. I still have the modified model and it works. It needed some tweaking though so I went back into Blender and added a few xp here and there. Now though it will not make a new modified mesh. It throws this error out. Changed values. Exported to different places. Nothing works. It must be a problem with the mesh but I cannot figure it out. Here is the error. Maybe it will tell you something



    It is a huge tree. A mighty Kapok:). Had to separate and pivot 562 objects. I think the highest level is six though and I have done that before and it worked.

    Thanks
     
  14. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    The only thing I can figure is that the "tweaks" added make the entire model too much for the script. I deleted the xw and xt from some of the leaves and it imports fine.
     
  15. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    hi baldinoboy,
    could you send me the original model (including the tweaks)?
    thanks, lars
     
  16. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    It is working now and I cannot recreate the problem. Added _xw00_xt02 to a few objects like it was before and re-exported it and it worked. Did not get the previous error. Will still send you the model in a pm but it is working for me so you probably will not get the error.
     
  17. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Hello Larsbertram1,

    I would like to ask if are there any solution (preset system, whatever) to sell my custom trees in as compatible with your asset. Let me to explain it: I would like make my stuff cross-platform and I would like to use my custom trees in Unity, but I don't want to remodel them in the Tree Creator. So I don't know if is there any options to save some kind of xml data from your importer what could turn my prepared custom trees to animated ones? I suspect that tree asset packs only work if your scripts are within them and that is a 'no go' as a solution. Thanks.
     
  18. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    hi emdenem,
    on import the script creates a new asset which mainly is a flattened mesh containing all information needed by the tree creator shaders like vertex colors and uvs.
    this new asset does not need the script anmore. it simply works.

    so in case you want to sell your custom trees: import them using the script. then export the generates asset.
    that is all.

    lars
     
    Em-de-Nem and Baldinoboy like this.
  19. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks, that sounds great.
     
  20. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Dear larsbertram1,
    I ordered the importer and I was playing for a while with it.
    I have some questions-suggestions, as it seems to be a very capable script with some additions.

    1. I think it needs example trees in the format of the original 3d modeler program (like Modo/Max/Blender, etc. examples in a Zip file or something.
    Reimporting FBX is not 100% (I was able to import to Max, but not into Blender directly).
    The imported trees to Max with correct scaling (real life sizes) did not worked after reexporting to Unity, what leads to the next point:

    2. Scaling of FBX input could be a problem; the example files contain mesh data with very various scaling from the default (and hated) 0.01 to .0005. The perfect examples would not include any scaling (as scaling affects the effect of the shader).

    It's all for now; Is it possible to make this things happen? I'm pretty sure these could be done, only the way of implementation is a question, but I will be happy to help you with some beta-testing.
     
  21. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Blender says it can import .fbx but I still can not get it to work. Ask Lars for a collada of one of the models and import that into blender.

    I do like all imports scale to be set correctly in the modeler. You can still do this with your models. They work fine imported at a scale of 1. All my models are.
     
  22. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks.

    I completely agree; that is why it is important to include correctly scaled files as demos; it is far easier to use an 'original' as a 'base helper' than 'reverse engineering' stuff why it doesn't work correctly.

    I definitely see the potential of this script; these small things makes life far easier.
     
  23. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Just wanted to post a webplayer of two of the larger trees from my pack that uses this script. TFPa21_treeimporter

    The Kapok tree was very challenging but worth it. Comes with a high tri count though(10000).
     
    Last edited: Feb 24, 2015
    HereVR, Em-de-Nem and Mister-D like this.
  24. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    nice work baldino!
     
  25. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    impressive work baldinoboy!
     
  26. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    unfortunately i am not a modeler.
    and i never had any other file format than fbx.
    most trees that are included in the package were "made" or edited with maya but i never saved those as .ma – but always as fbx.

    maya allows you to "freeze" any transform which means that the scale, rotation and position is set to zero and so does modo. this is best for the script. but it seems that fbx allows to also store the original values...
    so what can i do to help you?

    lars
     
    Em-de-Nem likes this.
  27. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Thanks guys. Would not be half as good without this script. Can not wait to try the leaf tumbling when 5 comes along.
     
  28. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Hello larsbertram1,

    thanks for the reply. I can help you with some source files soon if you need.
    I played a little with the script and I was able to get correct scales from Blender.
    Although I still was not able to get the leaves into correct position (they are detached from the branches after import).
    Maybe you can give some tips for me:)
    I'm quite busy now, so I will contact you in mail on the next week to ask for some help (if I will not be able to resolve it).
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    you will have to "reset" or "freeze" all transforms.
    may be baldinoboy can give you a hint as you also uses blender as far as i know.

    lars
     
    Em-de-Nem likes this.
  30. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Will give a quick tutorial for blender users. My way is not the easiest but I have done well with it so here you go. I actually create the model first combined. This helps with editing the size and rotation equally in edit mode so that the model will export correctly

    - If not already done rotate the model so blender will export it correctly. Rotate the model in edit mode negative 90 on the x axis - leave edit mode and rotate the model 90 on the x axis (make sure to rotate it with the pivot being the 3d cursor,Shift+C to move the 3d cursor to 0,0,0) After this is done the model rotation should show x90, y0, z0.

    - Separate the different meshes; trunk, branches, leaves in there own model first so you can remove the bark material from the leaves and leaf material from the bark. Also name each mesh (trunk,branch01,leaf01) while you have them together for an easier edit later. Also do a quick parenting of everything to the trunk.

    - Here comes the fun part. Separate each mesh. Select a vertex of the mesh(wireframe mode and box,sphere select to get those two sided leaves) - Ctrl+L - Press P - Select selection in the drop down - the edited mesh should be separated from the rest of the mesh. You can do the next step while you have this mesh close by or just wait after everything is separated.

    - Now setting the pivot point. In edit mode just select the stem of the leaf or whole end of a branch that is intersecting the bark - Shift S - Select Cursor to Selected in the drop down - leave edit mode - Ctrl+Shift+Alt+C - Select Origin to 3D Cursor - you now have the pivot point in place and that leaf branch should have the same scale(1,1,1) and rotation(90,0,0) of the rest of the tree.

    - Now parent everything appropriately - add in your empty root object - rotate 90 degress on the x axis - and parent the trunk to it - set all your edits(xw, xt, xp)- export it as usual with afsTREE(afsTREE_xlprl for tumbling) in the name.

    Hope this helps. Sorry for the super long and confusing tutorial. If other Blender users have other ways post them.
     
    Last edited: Jun 16, 2015
    Em-de-Nem likes this.
  31. danicrem

    danicrem

    Joined:
    Nov 9, 2014
    Posts:
    45
    The word document has issues. The left side of the text is outside the page border. I have problems with correcting this. Also a video tutorial on how to use this asset might be nice.
     
  32. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    it is .rtf – written in text edit.
    and i might think about i video when i find the time.
     
  33. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    hello lars, does the importer script work in unity5?
    "edit" just tried it in unity5 and it doesnt work
     
    Last edited: Mar 8, 2015
  34. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    i will have a look into it as soon as i find some time.
     
  35. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    it does work lars it was a mistake in my model, sorry i was to hasty
     
  36. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    is it normal the leaf shader doesnt work in deferred render mode in unity5 ?
    heres a screen
    treeshaderscreen.jpg
     
  37. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    S(h)ame experience.:(

    I hope they will fix it ASAP.
     
  38. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    ah, so its not only me, i was thinking there was a texture problem in my leaves.
     
  39. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    I asked Lars about this. He said the shadow map has to be identical in resolution and texture import settings so you do not get this problem in deferred.
     
  40. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    Thanks. Hmmmm. I will check it tomorrow.
     
  41. ryno_coder

    ryno_coder

    Joined:
    Nov 5, 2012
    Posts:
    21
    Hello, this looks like an awesome tool! I was wondering do you know if this tool will work with trees created in Plant Factory?

    I'm having difficulty importing fbx trees into Unity from Plant Factory - I've tried placing the fbx tree inside an "ambient-occlusion" folder. I also tried applying the bark and leaf shaders under the Nature folder and had no luck. Would AFS help in this matter or do you think this tool is what I need?

    Regards
     
  42. Em-de-Nem

    Em-de-Nem

    Joined:
    Mar 19, 2013
    Posts:
    104
    it is a different kind of 'animal'.;)
    You have to add the materials in your 3d modeling app as the readme says (it will get the proper shaders automatically by the script).
     
  43. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    as baldinoboy has written: shadow map must have the same resulotion.
    easiest would be to just assign the diffuse to the shadow map slot i guess.
     
    Mister-D likes this.
  44. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    When I put the diffuse in the shadow slot the artifacts go away but there is no shadow being cast. I just open the diffuse in gimp and drag the alpha channel to the main-delete the diffuse layer-export the texture as the shadow map. Set all the import settings the same as the diffuse except the Alpha Is Transparency setting if you enabled that in the diffuse.
     
  45. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,629
    actually that didnt work either, what did work was selecting the white from the alpha and shrink it by 1 or 2 pixels, now i have no artifacts no more
     
  46. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Finished my shield for the Unity Community Art Challenge and figured I might as well set it up for this importer and test it in Unity. Was not sure how it would work with the entire shield being considered a trunk with some branches being below the root or pivot of the object. Of course removed all trunk bending with xw00.

    Here is a webplayer: Nature Shield (14mb)
     
  47. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    nice – but the image effects ruins it... ;-(
     
  48. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Sorry. New to image effects so I am using them too much;).

    Here it is with less and weaker image effects: Nature Shield02 (14mb)
     
    Last edited: Mar 23, 2015
    Em-de-Nem likes this.
  49. Baldinoboy

    Baldinoboy

    Joined:
    Apr 14, 2012
    Posts:
    1,445
    Saw the new AFS 4 video. Looking amazing. Did you get the normal treecreator trees to bend with the same effects that you planned for custom tree importer trees?
     
  50. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,217
    not really, it is just a subset. custom tree importer trees will offer at least one more option: leaf tumbling – when i find the time to update the script ;-) first, i have to role out afs...
     
    Baldinoboy likes this.
unityunity