Jump to content

Material Namespaces from Blender


JCPalmer
 Share

Recommended Posts

Hey,

This is coming from couple other topics, one where Mira had a problem with the arbitrary names of MultiMaterials colliding when load separate .babylon files, and the action thread where I say I have my own version of the python Blender script.

 

In the collision thread I wrote suedo code which added a timestamp to the name to make it unique.  This is the simplest, but not the best, since the bug or neccessity to keep all the materials with unique names is unchanged.  I did not want layout some complicated change.

 

In my own version, I implemented a namespace approach, which turned out easier than I thought.  Upshot is I got the latest io_export_babylon.py from github and made the changes.  Do not have any multimaterials to test, maybe Mira can help.  I have attached it.

 

How it works is say you have a file:  /dir/dir/scene1.blend, or c:\dir\dir\scene1.blend.  If you also had a material 'red', it would be put in the .babylon file as 'scene1.red'.  If there was also a 'red' in a scene2.blend, it would end up as 'scene2.red'. 

 

I did lie a little just above, technically the namespace is the base file of the .babylon file not .blend file, but by default they are the same.  Enjoy!

 

Whoops, guess you are not allowed to upload a .py.  What now?

 

Jeff

Link to comment
Share on other sites

Jeff, hope you can work with DK on this through github. It is a useful fix and obviously necessary if you use the Import of additional meshes to a scene.

 

I try to avoid Multimaterials if possible through using a "texture atlas"  - but that can be a lot more work.

 

cheers, gryff :)

Link to comment
Share on other sites

Does any one have a blend file with multi-materials or know how to make a multi-material in blender?  Seems obvious that should be tested, since that actually prompted the fix.  I am pretty confident it should work, but probably no rush since you have to being using multiple Blend file to see the problem.

Link to comment
Share on other sites

Here are a couple of simple files Jeff. Gem has one object with 3 materials (shades of blue). Dodo has one object with 7 materials (bold basic colours). Both files have a light and a camera - so it should not matter which is loaded first.

 

Blend Files

 

They are in a zip file at my dropbox - which seems to be slow this morning :(

 

cheers, gryff :)

Link to comment
Share on other sites

Ok, got this to work.  Was a little tricky either missing having the multimaterial namespace not mentioned in the mesh, or getting the name space duplicated in the multimaterial def itself.  We are now ready to go.  Assume I do not know what this "pull request is".  tell me more.  I guess I need a github account?

Link to comment
Share on other sites

Jeff, I tested it with the two files I posted - worked well. I also tested it by merging the two blend files and exporting as a .babylon file - also seemed to work well.

 

From the merged file:

"multiMaterials":[{"name":"gem1.Multimaterial#0","id":"gem1.Multimaterial#0","materials":["gem1.top","gem1.mid","gem1.bottom"]},{"name":"gem1.Multimaterial#1","id":"gem1.Multimaterial#1","materials":["gem1.black","gem1.blue","gem1.red","gem1.green","gem1.purple","gem1.yellow","gem1.orange"]}]

And, even if I then tried to import a mesh from one of the original single files (heaven knows why)  I would get:

"multiMaterials":[{"name":"gem.Multimaterial#0","id":"gem.Multimaterial#0","materials":["gem.top","gem.mid","gem.bottom"]}]

a different Multimaterial.

 

cheers, gryff :)

Link to comment
Share on other sites

Gryff,

Good to know that I did not put up the wrong version of the file or something.  I appreciated the files I could not create myself.  This exercise brought to light that I have overweighted Blender export & the Babylon side of object creation over actually knowing how to make objects. For now, I have changed, and have started the character animation tutorial http://wiki.blender.org/uploads/6/66/Introduction_to_Character_Animation_19_Sept_2006.pdf .  It covers a lot more than animation.  It is old, but much more intense than the Gus the gingerbread man, which I did not fully finish.

 

There is a lot of ground to cover to do development, a little round robin is probably the only way to get up to speed on it.

 

Jeff

Link to comment
Share on other sites

For now, I have changed, and have started the character animation tutorial http://wiki.blender....9_Sept_2006.pdf .

 

Actually Jeff it is very very old - Blender 2.42. First version I ever tried was 2.48. A lot has changed both with the Interface and "under the hood".

 

There is a very nice series of 15 YouTube videos by BornCG (aka cgboorman) that assumes you know nothing and takes you through Blender.

 

Blender 2.6 Basics

 

I can give you more links if you want to useful videos.. And if you need something just ask - and if I have the time, will see what I can do.

 

cheers, gryff :)

Link to comment
Share on other sites

  • 1 year later...

I am revisiting the scene of the crime of my first PR.  Tower of Babel development was already underway, but this was just a patch to fix a problem with loading 2 .babylon files that each had a material of the same name.

 

I prefixed the name of the babylon file name to the name of the material, so if you had 2 blend files with the material 'red', the same names would not cause only the first to be loaded.  That is what BJS would do at the time.  I am not sure now that first wins with all the changes.

 

I am implementing the last change for the next release.  Here I wanted to give someone the option to share a material across .blend files, by optionally changing the name space (prefix).  See blue in panel (ignore red, not in official release).  Could be useful, especially materials with textures.  For TOB, was just going to put in check to implement:

      if(!scene.getMaterialByName(name) ){ new Material(name, )... }.

 

For .babylon, think the same logic should also be put in for both Material & multi-material.  Ok to add checking to respective parse() methods?

post-8492-0-24821000-1449687285.png

Link to comment
Share on other sites

DK, by your answer, I think I need to explain better.

 

Let's say you have 3 Make Human characters: Adam, Eve, & Steve, and you want each of them in their own Blend file from a work flow point of view.  Make Humans can have common meshes for teeth, tongue, eyes, eye browses, eye lashes, hair, & shoes.  You probably do not need teeth & tongue if they are more like 'stand-in' characters, with no lines, but they dramatically increase the realism in speech morphing.

 

The materials for those and therefore textures could be shared, if:

  • they all reference the material by same name, eg 'shared.teeth', instead of 'Adam.teeth', 'Eve.teeth', or 'Steve.teeth' (the default is 'Same as Filename') and,
  • It is checked first whether the material can already be found & only add if not.  Things can loaded in any order that way.

There is no real advantage to keeping the humans in the same blend file for instancing & cloning, since teeth, tongue, eye browses, & eye lashes all have shape keys.  Changing of a meshes vertices is impossible with clones & instances.   It is also far easier to deal with these meshes if they & their keys were merged with the body, prior to export (MHX2 properties tab has a button which does this).

 

Any clearer?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...