Refactored export package
Greetings. I want to openly announce the work I have been doing on refactoring the Python export scripts. The reasons for this is that the current exporter for Blender, tho functional, does not allow for any type of reuse by another application (Maya, Houdini, etc) with its current design. Additionally it is hard to configure for a pipeline. Any small tweaks I wish to make, to satisfy standards of my pipeline, would require a branch of the entire exporter module.
The package I have been working on abstracts the application's API calls from the actual architecture of how a JSON scene file is built. It is accompanied by unit tests to assist in verifying the integrity of the code base upon new updates. https://github.com/repsac/three.js_scene_utilities
I have constructed a class based hierarchy structure that will handle how the JSON scene is assembled. A user who wishes to write an exporter only needs to supply a single module containing functions of a pre-defined naming schema. This allows the user to focus solely on writing functions that return the proper data (object transformations, geometry vertices, material diffuse colours, etc). Here is an example of a dummy module with all the functions: https://github.com/repsac/three.js_scene_utilities/blob/master/lib/threejs_export/functions.py
Usage example:
import threejs_export
import custom_module # the module defined for a certain application
threejs_export.export(filepath, custom_module)
Currently I am working on a port of the Blender functionality. Additionally I am working on a Maya version as well but since the Maya module is being done at my job the company's policies dictate that it stays in-house. However, this is allowing me to experiment with 2 applications, of 2 different Python versions, to see how everything works out (because of this I have re-designed the entire package 3 times due to hard lessons learned). Upon completion of the Blender module I plan to add to the existing unit tests a Blender batch test that verifies my Blender test scenes export files that match the test JSON scenes.
I am not working in a branch of three.js because it is not known if this will be accepted or wanted by the three.js community. Additionally since it is a substantial change from the current exporters there is possible consideration that needs to happen on the "how and if" a change this large would be rolled out. Lastly, I have worked in production long enough to know the resistance that can come up when such a large change to anything is proposed. Because of this I am maintaining the code in my own repo until development is in good standing and there has been a consensus on whether or not this remains outside of the three.js repository.
Sorry for the long read but there was quite a bit that needed to be said, thanks.
The initial 1.0 release is ready for testing. Currently there is only an exporter for Blender.
The package contains 11 unit tests on the core library and 5 batch unit tests on Blender scenes. Additionally I resolved quite a few logic over-sites that I encountered when reviewing the original Blender exporter, as well as resolved an issue in which it seemed that animations are not exporting correctly.
I removed many of the custom attributes for shadows, double sided, and vertex colors since these settings already exist on nodes in a Blender scene. My personal position on this is that the actual attributes that determine the output of a rendered scene should match what gets exported to three.js as closely as possible to retain some consistency. Additional changes are mentioned here: https://github.com/repsac/three.js_scene_utilities/wiki/Changes-from-the-old-exporter
My next steps are to begin investigating the requirements of the 4.x format and either port the entire core to the 4.x format or implement a toggle so that a user can select the format they desire for the sake of backwards compatibility.
My next steps are to begin investigating the requirements of the 4.x format and either port the entire core to the 4.x format or implement a toggle so that a user can select the format they desire for the sake of backwards compatibility.
Added some basic "specs" to the wiki:
https://github.com/mrdoob/three.js/wiki/JSON-Geometry-format-4 https://github.com/mrdoob/three.js/wiki/JSON-Material-format-4 https://github.com/mrdoob/three.js/wiki/JSON-Object-Scene-format-4
It's still very much WIP though. Need to figure out how to implement bones, morphs, etc
thanks, anything will help
So I have started to look into this and seems like the ObjectLoader() is still very much a WIP. Is this a correct assumption? Outside of bones and morphs it even appears that things like textures aren't yet handled either. I didn't read every line of the ObjectLoader() but a quick glance that is what it seems so correct me if I am wrong.
Additionally, is it safe to continue asking questions and posting updates to this thread or would you rather I use Stackoverflow?
So I have started to look into this and seems like the ObjectLoader() is still very much a WIP. Is this a correct assumption?
Unfortunately, that's correct...
Additionally, is it safe to continue asking questions and posting updates to this thread or would you rather I use Stackoverflow?
Here is good :)
OK, in your earlier reply about it being a WIP I thought you were referring to just the wiki docs. So it seems that this is more than me just slinging some Python around, we need to design a JSON structure and develop the rest of the loader library as well.
Little more than what I had expected but at least I have a better understanding of what needs to happen.
I am looking into texture loading right now. And I am curious if there is a specific reason that TextureLoader() does not include a parse() method like MateriaLoader() or did nobody get that far yet? Basically I am working on ObjectLoader.parseTextures() and would like to keep some consistent logic with ObjectLoader.parseMaterials() and if the 2 can be kept close enough maybe abstract the core functionality to another method and only have parseTextures and parseMaterials serve as a dispatch point for the type of loader to use during the loop. Ideas?
or did nobody get that far yet?
Yep! no one tackled that one yet :)
Basically I am working on ObjectLoader.parseTextures() and would like to keep some consistent logic with ObjectLoader.parseMaterials()
Sounds good to me!
So I have a basic diffuse map working (hold your applause!) but I do want to ask about design and implementation of the JSON. This is an example of the JSON block for textures. Didn't see too much of a reason to change it too drastically.
"textures" : [
{
"uuid": "F430CF4-AD77-11E3-914E-00248C62C323",
"url": "concrete.co.png",
"wrap": [1000, 1000],
"repeat": [2, 2]
}
],
"materials": [
{
"uuid": "5C5C9C6A-4453-4827-869D-187C0BD53BCB",
"name": "planeMAT",
"type": "MeshPhongMaterial",
"color": 16777215,
"ambient": 16777215,
"emissive": 0,
"specular": 1118481,
"shininess": 30,
"side": 2,
"opacity": 1,
"transparent": false,
"wireframe": false,
"map": "F430CF4-AD77-11E3-914E-00248C62C323"
},
One thing I wanted to ask you about was the use of literal values of the integer equivalents that actually get assigned under the hood. In SceneLoader() there was lots of if-conditions that were swapping out strings for the actual values. In this example I have "wrap": [1000, 1000] instead of "wrap": ["repeat", "repeat"] as well as, for the material, using "side": 2 instead of "doubleSided": false. Part of me leans towards the readability of the JSON file but the other part of me seems to feel that instead of filling ObjectLoader() with seemingly endless conditionals to instead leave it to the Python packages to take the attribute in question from the application (ie Blender) and conform to the correct THREE compliant value. There are some attributes where it would seem to make sense to support literal values but I think if we went that route we would need to be aware of where to draw the line on how far to take that otherwise OjbectLoader() just gets filled with clutter.
With all that I wanted to ask where you stand on keeping a 1:1 match of JSON attributes to the attributes on the nodes. I am using "wrap" here but this maps to wrapS and wrapT. Could there be exceptions for cases like this or should a more direct mapping approach be taken?
I know you're at GDC so no rush on a response but since I am addressing textures the question comes up on whether or not the urlBaseType will be used in version 4. Just something to think about when you're flying home.
Regarding the json definition... what about something like this?
"images": [
{
"uuid": "A430CF4-AD77-11E3-914E-00248C62C323",
"url": "concrete.co.png"
}
],
"textures" : [
{
"uuid": "F430CF4-AD77-11E3-914E-00248C62C323",
"image": "A430CF4-AD77-11E3-914E-00248C62C323",
"wrap": ['repeat', 'repeat'],
"repeat": [2, 2]
}
],
"materials": [
{
"uuid": "5C5C9C6A-4453-4827-869D-187C0BD53BCB",
"name": "planeMAT",
"type": "MeshPhongMaterial",
"color": 16777215,
"ambient": 16777215,
"emissive": 0,
"specular": 1118481,
"shininess": 30,
"side": 2,
"opacity": 1,
"transparent": false,
"wireframe": false,
"map": "F430CF4-AD77-11E3-914E-00248C62C323"
},
As per the use of literal values... I think I would prefer the json to be fairly human readable. I suspect the problem in SceneLoader was implementation-wise. We should be able to do a map like:
var wrappings = {
'repeat': THREE.RepeatWrapping,
...
}
With all that I wanted to ask where you stand on keeping a 1:1 match of JSON attributes to the attributes on the nodes. I am using "wrap" here but this maps to wrapS and wrapT.
Never been a fan of wrapS and wrapT. I wouldn't mind changing those with a single texture.wrapping array like in your proposed json definition.
Ooh I like that idea by splitting out images and textures. It leaves room for exploring procedural textures down the road. I also prefer human readable values as much as possible. In lots of the production tools I have written I prefer the use of mapping (like your wrappings example).
some_var = some_dict.get('some_key', some_int)
That is in Python land and I am relatively new to JS and don't see a lot of mapping used in many of the JS files I looked at and was curious if there was a reason it wasn't being used (like performance) or if it was just a personal preferences thing.
Thanks for the feedback. I didn't want to get too far in the wrong direction on this so at this point I am asking more questions than writing code.
My pleasure! :)
Going to close this out since the whole exporter will be revisted a later time and probably just stay a personal project. I got derailed from ObjectLoader() by having to write a custom loader that fits into our pipeline, but for my personal work I still have an interest in improving on ObjectLoader().
@repsac just a heads up I'm working on a revision to the ObjectLoader https://github.com/mrdoob/three.js/pull/4621
thanks