reattiva / Urho3D-Blender

Blender to Urho3D mesh exporter
Other
123 stars 52 forks source link

Experimental Features #23

Closed Mike3D closed 9 years ago

Mike3D commented 9 years ago

I've pushed to my fork (https://github.com/Mike3D/Urho3D-Blender) some experimental features:

Note that I'm using a custom folder structure based on Scene name for my exports, so you can skip this by checking the "Use Urho standard folder" in the Export panel. Prefabs are exported to "TestScenes" and "TestObjects" folders. You can rename them without "Test" if needed.

Everything should work fine, but don't hesitate to report bugs and provide feedback. Happy testing.

Todo:

reattiva commented 9 years ago

Thanks, sincerely I don't have much time for the exporter. After a quick look I'd say I cannot import your code directly because it seems to be customized for your personal use (of course) and commits do not separate the features added. A pull request with only the cleaned, generic and important bits (and based on the latest master commit) would be perfect, otherwise I'll do a selective merge, it'll require some time. In the meantime, I'll leave this issue open so others can find your link and the list of features added.

For the documentation, the Github wiki seems good, less text more images is optimal.

Mmm, also not to be polemic, but you have removed a feature you have asked here https://github.com/reattiva/Urho3D-Blender/issues/2 .

Mike3D commented 9 years ago

It's better to have some intensive tests done before merging it to the main repo. That's why I did it that way. Once everything gets OK, I'll send a regular pull request after a thorough clean-up. Also I'd like to fine-tune the available options and features based on feedback.

Feature #2 is mandatory when we are merging all the objects together, but it doesn't make sense when we are exporting separate objects. For versatility purpose, we need the ability to:

That's why I've fine-tuned #2.

Basically we need to go as fast as possible when prototyping, and to be the most accurate when exporting the definitive objects. Both objectives might require fine-tuning the exporter if we don't want to impose rigid practices in blender (for example we could solve the issue by doing the weighting in blender and unparent/remove weight when needed).

If you think that some features can already be merged, let me know, I'll send a clean pull-request for them.

Mike3D commented 9 years ago

Everything cleaned-up, some bug fixes for tangents and scene prefabs, some code refactoring and updated to latest revision.

reattiva commented 9 years ago

I've added a branch 'features'. Some notes and questions:

Mike3D commented 9 years ago
Mike3D commented 9 years ago

I think we can close this issue as almost everything has been merged into the Master branch.

reattiva commented 9 years ago

Hello @Mike3D, about the dictionary in UrhoExportScene, maybe I'm missing something big but I really don't see the problem, I've done a test here: https://github.com/reattiva/Urho3D-Blender/blob/nodict/io_mesh_urho/export_scene.py I've done it quickly and the names have to be checked, but it seems good to me, what I am missing?

Mike3D commented 9 years ago

I think that at the begining I misunderstood Urho node hierarchy, which led me to rely on this solution. I'll check your file in-depth and do some tests, I'm pretty sure I have over-complicated things (as usual).

Mike3D commented 9 years ago

Hi reattiva,

Did you find a way to deal with the parent-child hierarchy? Currently it is left as-is with the dict and I don't find a good solution for it.

Mike3D commented 9 years ago

Hi reattiva,

I've started implementing new features: 1) full physics support inside Blender (https://github.com/Mike3D/Urho3D-Blender/blob/master/io_mesh_urho/Physics.jpg) and an option in the Export panel to either use these individual settings or apply settings from the active object to every objects (kind of batch) 2) techniques support (ability to set shader parameters in Blender by appending a flag to the material name and using custom settings set in the Material panel) 3) add other settings like zone and lighting parameters 4) create a button to launch the prefabs in the Editor ...

My goal is to almost skip the need for Urho Editor.

And now that files are nicely separated and we have full access to data for the prefabs, these features are easy to add.

If you find this worthless or off topic, let me know and I won't bother you anymore with these features. I'm also open to other suggestions and insights.

reattiva commented 9 years ago

Hi Mike, it is not worthless for sure. I have some time to write down some thoughts, here they come.

First, let me reply to your old question about the tangent export. Tangent space is a coordinate system, instead Normal map is only a rendering technique, so from my personal point of view, tangent space is much more important and I don't like to link them together. The other big problem when linking them is that you force an user to use the Blender material system, he could only want to generate the geometry and doing the material and textures in other tools (like the Urho editor). For an example on when you use tangent, I really don't know, maybe some water+foam effect on the border of a river. Another stupid example: bump map and normal map, in bump maps you use on a channel of an image, in normal map you use RGB channels to get a vector. So for bump map I need a different tecnique, but if tangent space is linked to normal map, I'm forced to configure it. Probably in Blender bump and normal map are done with the same settings, so it is not a good example, but I hope you get my idea: don't force unnecessary rules on the user. You said that you wanted an individual option per object, this is a good idea, I also thought about it and I think it can be done but it was too much work for me (see later).

This is only my point of view of the exporter. Initially I've written it to export geometry, skeletons and animations with an object per file in mind. This was my objective, it was and it is what I have the strength and time to support. Later, the material export was added, it was not too much of work and with the new Blender paint features it made sense. When it was suggested to insert the scene export I refused because I knew it was too much work for me, moreover, as you have seen, the structure of the exporter was not good enough (a side note: this was my first Blender addon and my first Python program; in my opinion Python is good for little programs, but for bigger works I prefer some more strict language, like C; Python likes unit testing which does not work well with "sorry, no time").

It seems you are very dedicated to this exporter. I really appreciated it. You are working hard on the scene exporter, but as I said I have to leave it to you. I'll try to do some support but don't expect much, sorry. Maybe your idea for this exporter is more useful and much bigger than mine. I can only hinder you and I don't want it, so in this case you have to build it on your fork, if it works good then I'll be glad to trash this one. Be sure that if you can support the scene exporter and you want to work on this repository, I'll be glad and if you want I'll add you as a contributor (to push commits directly). Ok, that's it, I hope it makes sense.


About the parent-child hierarchy.

This is new to me, was something that was working but I've removed ? I guess you want to replicate the parent-child hierarchy of Blender in the Urho scene nodes. In this csae you can do this (probably, not tested):

# Clear the children (not necessary)
for uSceneModel in uScene.modelsList:
    uSceneModel.childrenList.clear()
# Populate
for uSceneModel in uScene.modelsList:
    if uSceneModel.parentObjectName:
        parentFound = False
        # Scan the list again in search of the parent
        for parent in uScene.modelsList:
            if parent.objectName == uSceneModel.parentObjectName:
                parentFound = True
                # Add this model as a child of the parent 
                # (better use a set for childrenList)
                if uSceneModel not in parent.childrenList:
                    parent.childrenList.append(usceneModel)
                break;
        # If the parent is not in the list remove it from the model
        if not parentFound:
            uSceneModel.parentObjectName = None
def Traverse(model, parent):
    # Here add a node for model

    # Continue with children
    for child in childrenList:
        Traverse(child, model)
for uSceneModel in uScene.modelsList:
    # Only objects with no parents
    if usm.parentObjectName is None:
        Traverse(uSceneModel, None):

About the individual option per object.

This is my idea if you want to give it a try. It is very simple: use a different TOptions class for every object.

After a lot of good work, and yes! You should be able to remove the tangent generation individually for each object.

Mike3D commented 9 years ago

Hi reattiva,

Thanks for detailed explanations. It is important for me to have your insights. And as time is precious, I don't want to make you loose yours.

For tangents, I got it to work, although I haven't created the option yet.

I don't think pushing commits directly is a good idea as my code needs supervision by a pro. I prefer to push to my fork, drop you a notification about the changes and let you comment, select and decide.


About the parent-child hierarchy.

Your current solution for preserving parent-child hierarchy works perfectly (there is no need to do the same procedure as with bones). I was refering to the nodict branch. The dict has been removed everywhere except when we parent a child to its parent node instead of to the root node (line 382 of export_scene.py).


About the individual option per object.

Thanks for detailed steps, I'll keep this for later, for now I think it's only useful for a couple of settings, but it may evolve.


Cheers

Mike3D commented 9 years ago

Hi reattiva,

I've pushed my latest modifications to https://github.com/Mike3D/Urho3D-Blender

Summary:

Some settings may appear over-tweaked, I personaly like to have full control and put the maximum tasks on auto-pilot.

Mike3D commented 9 years ago

Last modifications:

Mike3D commented 9 years ago

Last modifications:

reattiva commented 9 years ago

Hi Mike, the user interface for Object and Materials seems massive, maybe it should be moved in a new file. Now it is still good, but if it needs to grow better move it.

Mike3D commented 9 years ago

Hi reattiva,

Thanks for reply.

Yes, I also though of moving almost everything related to prefabs (both UI and xml content) to a new file (or even 2 files depending on final number of lines) to:

I'll try do this today and push some bug fixes either. Then I'll do some real-life tests for a couple of days to check if everything is OK.

Mike3D commented 9 years ago

Hi reattiva,

I've updated documentation, added missing option to selectively toggle physics, and added support for 'instances', which allows to replicate full Blender scene in Urho.

Concept:

It works fine, however I'm stuck at getting orientation (tOptions.orientation) to work. Urho models are already rotated and scaled (position and rotation=(0,0,0), scale =(1,1,1)), while loc/rot/scale for the empties are retrieved before scaling and orientation transform.

I've put an example file (based on GameKit sample), would be great if you could have a look and/or point me in the right direction.

reattiva commented 9 years ago

Ok, give me some time.

Mike3D commented 9 years ago

Many thanks, no need to rush.

reattiva commented 9 years ago

Mike, I give it a look.

reattiva commented 9 years ago

Scratch that link, I just remembered bones have different axes than objects axes. It should be: if in Blender you have a translation t=[x,y,z] and a rotation quaternion q=[w,x,y,z], then in Urho they should be t'=[x, z, y] and q'=[w, -x, -z, -y].

Mike3D commented 9 years ago

Many thanks for insights reattiva, I'll try this today.

Mike3D commented 9 years ago

Awesome! rotation_euler was the culprit, works perfectly with matrix_local.to_euler(). A big thank.