three.js icon indicating copy to clipboard operation
three.js copied to clipboard

Open discussion on the new Blender exporter features.

Open repsac opened this issue 12 years ago • 65 comments

Before the next release of three I want to openly discuss the features of the new Blender exporter. Originally this addon was just my side project so I added features that were only supported by an experimental loader that I was working on. Now that it is merged it does introduce options that users won't be familiar with and/or the current ObjectLoader does not support.

Textures (default=False)

This is kind of stating the obvious but I will mention it anyways for clarity. Tho I have the feeling that the new exporter will probably be a big push to get texture support resolved.

Bones and Skinning export (default=False)

Currently exporting of bones and skinning data is two separate boolean options (my reasoning). It does seem logical to possibly only having skinning as an option which implies that bones would be exported as well.

Mix Colors (default=False)

In the Wiki of the original repo the exporter came from I give a visual example of what this does. Under the hood the option includes colorDiffuse in the material, otherwise it omits it. I noticed this difference while developing the exporter and it seemed like possibly a feature someone might use, but then again this may not be something that is intended and even supported in the future.

Embed animation (default=True)

There is nothing in the ObjectLoader that supports external animation files. However as a pipeline TD abstracting my assets from animation data is favorable. This option could be commented out until there is a better native implementation in the three loader. It also is possible to make an example scene to demonstrate how external skeletal animation data could be supported.

Embed geometry (default=True)

Similar concept to the aforementioned option. A feature of the now deprecated SceneLoader() that I did like.

Importer

Starting to widdle away at it. Not a high priority but it would be nice to be able to take scenes exported from other 3D apps (for three) and directly import them, tho there should be some realistic expectations of what this will support.

repsac avatar Nov 06 '14 04:11 repsac

Very nice work! Having a good asset pipeline is very important for an engine, and I've always felt that three.js could improve in this direction.

Importer: The only use case I see is if you want to take assets from other apps and use them without their consent. Because otherwise you could just ask for a COLLADA or FBX version of the asset - these formats were invented for the exchange of assets. So I'm not sure this is needed.

Animation: Do you have options for how to sample the animation? Some exporters sample the animation curves at a fixed rate (e.g., 30fps), others keep the original keyframes (which may be randomly positioned at arbitrary positions along the time line).

Embed animation: I like this option.

Round Off: You might want to have different settings for normal, position, and UV values.

Face Materials: I'm not sure about the future of MeshFaceMaterial - do you have an option for splitting multi-material meshes into several meshes, each with only one material? They would still need to share the bones. I didn't have a look at your implementation, I've just seen it mentioned here.

crobi avatar Nov 09 '14 17:11 crobi

Geometry: It would be nice to be able to export models with multiple objects and be able to keep their vertices and face separate in the export. That way, there'd be a way to tie a different material to each of the geometry groups. Not sure if this is compatible with the current JSONLoader. If not, I'd like to make that suggestion to the right person.

neverhood311 avatar Nov 10 '14 18:11 neverhood311

@crobi

Importer: My personal experiences with FBX and COLLADA aside; I don't think this is a "use without their consent" issue. Sometimes you don't get the file type that you want. You may, and again something else I have experienced, may be handling assets well after their creation and the source (person or file) may not be accessible.

Animation: This logic was copied from the original exporter. The logic can be viewed here

Face Materials: The only thing I did different from the original exporter was make face materials an option.

Round Off: That is doable.

@neverhood311 How does this differ from the the Embed Geometry feature (which is the same as in the original exporter) already in place?

repsac avatar Nov 11 '14 15:11 repsac

Seems promising, thanks a ton!

Happened to encounter a use case for importing today, given export from three itself works: am working with vizicities and adding manually created things to the scene there (as a workaround only now though but perhaps ther are other cases for that too). Might be nice to be able to save the relevant generated geom from vizi, import to blender, and hence be able to fit other models there well .. then export the manually made additional part and use together with the generated things in the live app.

antont avatar Nov 11 '14 18:11 antont

Yeah the importer certainly shouldn't be seen as any official format for asset exchange but a useful tool for those corner case scenarios that do indeed come up, and usually do at the most inconvenient of times in the most inconvenient of scenarios.

repsac avatar Nov 11 '14 18:11 repsac

@repsac You're right. By using the Embed Meshes option as well as the Scene option, I was able to tie each separate mesh to its respective material. I guess I now have no suggestions for the exporter.

neverhood311 avatar Nov 12 '14 15:11 neverhood311

OK, glad we could clear that up.

repsac avatar Nov 12 '14 16:11 repsac

Ok, a little off topic but was not sure where to bring this up. When I use the exporter in blender 2.7 the json file is full of null or 0 values:

{
    "metadata": {
        "formatVersion" : 3.1,
        "generatedBy"   : "Blender 2.7 Exporter",
        "vertices"      : 0,
        "faces"         : 0,
        "normals"       : 0,
        "colors"        : 0,
        "uvs"           : [],
        "materials"     : 0,
        "morphTargets"  : 0,
        "bones"         : 0
    },
        "scale" : 1.000000,
        "vertices" : [],
        "faces"    : [],
        "uvs"      : [],
        "normals"  : [],
        "skinIndices"  : [],
        "skinWeights"  : [],
        "morphTargets" : [],
        "bones"      : [],
        "animations" : [],
        "colors"    : [],
        "materials" : [
        ]
}

Was going to log an issue but thought I would bring it up here in case it is user error. Any ideas?

nickspiel avatar Nov 15 '14 08:11 nickspiel

This looks like it was done with the current exporter, not the one in the dev branch (which is what is being discussed here)

repsac avatar Nov 15 '14 22:11 repsac

Good work here, @repsac!

I am having some issues though - And I am not sure if I am just making a silly mistake ...

I have a material in blender with it's diffuse color set to #00478A. After exporting the model the diffuse color looks like this:

"colorDiffuse": [0.0,0.05040802434694802,0.2033217221993464],

This doesn't look like the correct color to me, so I used an online converter to check and found that #00478A should come out to something more like [0,0.28,0.54].

zinefer avatar Dec 12 '14 15:12 zinefer

Ok, so I did some digging and I found that the intensity is used to calculate the final diffuse color ... This is probably common knowledge but I am really new to 3d.

However, even with the intensity set to 1 I still do not get the expected color values.

"colorDiffuse": [0.0,0.06301002949476242,0.2541521489620209]

What am I missing?

zinefer avatar Dec 12 '14 16:12 zinefer

@zinefer This appears to be a gamma-space vs. linear-space issue.

WestLangley avatar Dec 12 '14 17:12 WestLangley

@zinefer Good questions all around and I don't have all the answers. I vast majority of the logic you are referring to was migrated from the original exporter. This logic has been in place since before I started using three. https://github.com/mrdoob/three.js/blob/master/utils/exporters/blender/2.65/scripts/addons/io_mesh_threejs/export_threejs.py#L1324

Any logic I am uniquely responsible for is based around the refactoring of the legacy code base resulting in its current design. The "how and why" of why certain properties are queried, modified, and stored is something I can't always provide an answer on.

repsac avatar Dec 12 '14 19:12 repsac

This does indeed seem to be related to gamma. ~~After figuring out the intensity thing my colors started to 'look' correct after export, even though the values are a bit unexpected.~~

Thank you, @WestLangley and @repsac.

EDIT: Scratch that, the colors are still darker than they should be. Change display device to none inside the scene tab of blender and your color tab will display the same values that it will output when exported.

zinefer avatar Dec 12 '14 19:12 zinefer

@zinefer np. These discussions are really helpful. Honestly I had so much on my plate with this exporter refactor I didn't take the time to look into the specifics of everything.

repsac avatar Dec 13 '14 01:12 repsac

@repsac I'd also like to see an option for not applying global transforms. I just created another issue for it (https://github.com/mrdoob/three.js/issues/5841) before someone pointed this thread out to me.

Also, how do I try out the dev branch exporter? When I try to load it from the init.py file in Blender, the module doesn't appear.

Densaugeo avatar Jan 01 '15 23:01 Densaugeo

Hmm, I wonder if loading from file only works if the entire addon is encompassed in a single .py file.

Anyways; the is the old install guide for the exporter (used to be under a personal repo called threeio) https://github.com/repsac/threeio/wiki/Installation

So just replace threeio with io_three

repsac avatar Jan 01 '15 23:01 repsac

@repsac I have just noticed that your exporter uses a different logic for exporting skeletal animations than the master branch. In master, the logic was completely changed by commit e4ad4cb135bbf55224df6aaab351400fa822fe9a. The changes were mostly authored by me in my own branch, but someone else did a pull request. I remember that my changes fixed some bugs with exporting skeletal animations, but don't remember which ones. Are you aware of that change?

At least one bug was related to meshes with global transformations, this might affect #5841. Also, my changes improved the performance of the export by an order of magnitude (complex models took almost a minute to export with the old exporter). If you like, I can try to remember what problems I tried to fix with my changes.

Note: I have compared your mesh.py against export_threejs.py on master.

crobi avatar Jan 04 '15 20:01 crobi

Are you aware of that change?

No. I quit using the old exporter a long time ago and probably didn't see the issue/PR probably because it was buried in all the other github spam that it was most likely deleted.

repsac avatar Jan 04 '15 21:01 repsac

No. I quit using the old exporter a long time ago and probably didn't see the issue

Off the top of my head (issues that were present before the above mentioned commit, some might not apply to you since the master and dev branch diverged):

  • Animations are broken if the mesh and/or skeleton contain global transformations. Load a model with skinning animations, rotate the whole scene (e.g., by typing CTRL+A, R, Y, 9, 0, ENTER in blender), then export the model. I use this a lot, in order to make sure my models are correctly aligned. Our application requires z up and models facing along positive x, and a simple flipyz option does not cover all cases.
  • The exporter does not handle animations with euler rotations.
  • The exporter tries to save space by only writing those keyframe properties that changed. For example, assume your animation has a rotation keyframe at t=0 and t=2, but not at t=1. The exported keyframes with index 0 and 2 will then contain a rot member, whereas the keyframe with index 1 will not have any rot member. Problem is, animation curves can contain keyframes with non-integer time values, and the exporter only iterates over all integer time values. If your animation has rotation keyframes at t=0.99 and t=1.01, then you have two options:
    • resampling: The output keyframe with index 1 should interpolate the two input keyframes with t=0.99 and t=1.01 and save the value. This is what my code did (I just ask blender to sample the animation at t=1.00, not bothering with how animation curves are defined internally) .
    • no resampling: The exporter should not iterate over all integer time values, but instead enumerate all original animation curve keyframes. Sounds like a lot of work, since you have to understand all the details about how animation curves work in blender.

crobi avatar Jan 05 '15 09:01 crobi