-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FBX Converter now exports in a ObjectLoader compatible format #7046
Conversation
@mrdoob Is there anything I can do to help you test this? e.g. provide some FBX files? P.S. Thanks for all the awesome work you've done with three.js, it's immensely appreciated! |
@@ -2,13 +2,13 @@ | |||
* @author mrdoob / http://mrdoob.com/ | |||
*/ | |||
|
|||
THREE.Scene = function () { | |||
THREE.Scene = function (fog) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you must add optional parameters to the constructor, maybe the API should be
var scene = new THREE.Scene( { fog: fog } );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admittedly, I wasn't super thrilled about that change either. However, I did it this way to keep in line with how the rest of ObjectLoader works. If you look in ObjectLoader you'll see arguments to other objects are passed in a similar fashion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think required arguments would have a different API from optional arguments. That is just my opinion, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WestLangley Definitely inclined to agree with you. I only went with this approach because it's what THREE.HemisphereLight
does:
https://github.com/mrdoob/three.js/blob/dev/src/loaders/ObjectLoader.js#L549
https://github.com/mrdoob/three.js/blob/dev/src/lights/HemisphereLight.js#L15
However, I guess in the case of THREE.HemisphereLight
the object is a bit more specialised i.e. not likely to become littered with arbitrarily ordered optional parameters.
@mrdoob Your feedback on the matter would be appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Why do you need to pass fog
in the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't specifically want to pass fog
to the constructor, I just wanted to try continue supporting everything the existing FBX converter (i.e. SceneLoader
) supports. However, I noticed that ObjectLoader
seems to be passing all JSON options from data
as constructor arguments to the various objects being instantiated, even for optional parameters (in the case of HeimisphereLight
):
https://github.com/mrdoob/three.js/blob/dev/src/loaders/ObjectLoader.js#L506-L573
So I just followed suit.
There are several code style issues with this pull request that I'll need to iron out before merging - I used spaces instead of tabs, how did I even do that, I love tabs! I'll force push the changes soonish, however the functionality can still be assessed. |
82887b3
to
2ac434d
Compare
I've just force pushed:
and of course tested all the changes 😄 |
I trust you on the changes to the converter 😉
Does |
Yeah, I'm not overly fond of it either, however I can explain the logic behind it...
https://github.com/mrdoob/three.js/blob/master/src/loaders/MaterialLoader.js#L37 Consequently, if I'm putting some sort of reference (not necessarily a Of course, this is but one very specific way of resolving this issue. Perhaps a better solution would be instead of storing the references to other materials in the
I don't believe so, however the WebGL renderer was crashing because it expected some variables like ... By the way I'm not super fond of |
2ac434d
to
d71d2ec
Compare
@mrdoob I just blew away the commit making |
4df4d76
to
ccc78ba
Compare
@mrdoob I've just forced pushed a more self-contained implementation (as mentioned above). i.e. |
Please do not include build files in Pull Requests. See the Wiki article How to Contribute to three.js. |
whoops didn't mean to! |
ccc78ba
to
b35faa1
Compare
@WestLangley Fixed now. |
|
||
} else if ( data.quaternion !== undefined ) { | ||
|
||
object.quaternion.fromArray( data.quaternion ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quaternion
should have preference.
Perhaps the only option, depending on @mrdoob's decision.
Possibly, but as a general rule I wouldn't expect to see both in the one object anyway. |
uuid_key: str(uuid.uuid4()), | ||
name_key: 'Scene', | ||
'position': serialize_vector3((0,0,0)), | ||
'rotation': serialize_vector3((0,0,0)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The converter is up to you, but do you want to use quaternions
, instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair call. I didn't really change as much stuff as it looks like I did 😉
It was already using rotation, I just moved it to the new location:
https://github.com/mrdoob/three.js/pull/7046/files#diff-ccc8c41ed04893276377da090bf6f968L1980
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
three.js is quaternion-based. rotation
is provided for convenience.
Are you certain of the mapping between the way three.js represents Euler rotations and the way FBX does? I expect it is not a trivial assignment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WestLangley I haven't really touched any of the math at all, if it worked before it works now... assuming it worked before.
However, rotation
is only used once, and it's on the Scene
with values (0, 0, 0). Every where else is using either matrices or quaternions e.g.
https://github.com/Benjamin-Dobell/three.js/blob/fbx-objectloader/utils/converters/fbx/convert_to_threejs.py#L1770
I can verify that the quaternions and matrices work perfectly as I have a heap of FBX files with rotations on the root node.
dfbe8c9
to
322063f
Compare
Cyclic material reference detection is included
In addition to making the output ObjectLoader compatible, I've also added or imporved a bunch of functionality: - Fixed oddity whereby textures were output to a 'maps/' directory but only referenced by filename. The relative path is now stored in JSON. - Added texture filename collision detection which aborts conversion when two textures would be copied over each other. The abortion behaviour can be replaced with a printed warning by specifying --ignore-texture-collisions (-i). - Textures can now be saved to directories other than 'maps/' by specifying --texture-output-dir (-o). This path is relative to the output JSON file and file references in the JSON are updated accordingly. - Materials whose textures contain a non-empty alpha channel now automatically have 'transparent' set to true (Requires ImageMagick). This can be disabled by specifying --no-transparency-detection (-a). - Non web compatible textures are now automatically converted to PNG or JPEG files, the former if they contain alpha (Requires ImageMagick). If ImageMagick is not available a warning is reported and we gracefully fall back to the old behaviour. - Existing --pretty-print (-p) behaviour has now been extended to print JSON properties in the order 'metadata', 'type', 'uuid', <other keys>, 'data', 'children'. - Redirected errors and warnings to stderr rather than printing to stdout. - Fixed FBX -> three.js texture bindings. Also performed general refactoring which included: - Deleted lots of dead and commented-out code. - Made method naming consistent (using underscores). - Deleted unused/pointless variables. - Replaced manual path string manipulation with native python methods (which fixed a couple of obscure bugs).
The examples of this pullrequest are now built and visible in threejsworker. To view them, go to the following link: |
Could you remove the |
@mrdoob Some of them, sure. Others are required - well, not necessarily required as is, but something similar is necessary.
|
Would it be possible to not support |
I don't know what other people's FBX look like, but for me not supporting I haven't actually added I've actually been using this exact converter and |
|
Okay, just had a look at I see MaterialLoader now understands The issue is materials need a way to reference other materials This is necessary say if you have one So parsing materials basically needs to be done in two passes. First pass is loading material definitions - skipping over references to other materials. The second pass resolves the material references ( An alternative would be to define referenced materials ahead of the materials referencing them - however that's getting pretty finicky. |
I understand, but that's a bit of an optimisation. I just don't want to rush the format design for the sake of bringing the FBX converter up to speed. |
Understandable, that's why I hadn't really been pushing for this to be merged. Things are (or at least were) under quite a bit of flux. However, it did seem to me that referencing, rather than duplicating, was the "correct" solution given the way the rest of the file format works. Particularly, since one of the key features of this new format is the inclusion of If you don't mind, I'd prefer to try nail down some of the specifics of format, rather than release a sub-par converter. Of course, this pull request is just a proposal, I'm sure there are other approaches to achieve this. |
By the way, my original implementation didn't require introducing a new key in Basically I just introduced new This approach means that I basically swapped to the existing code because it seemed less disruptive at the time (no new object types). But with the recent |
322063f
to
f1e539a
Compare
851e339
to
beb39d8
Compare
beb39d8
to
06a5512
Compare
Had to make a few changes to three.js itself to get things working (namely adding a Reference object).
@mrdoob The very recent renaming of MeshFaceMaterial to MultiMaterial made my rebase a tad difficult, but I'll forgive you because you fixed the UV coordinate bug I was having with MeshFaceMaterial 😉
I've also made MultiMaterial a real Material. This was required because initMaterial needed to be called to setup things like material.precision (@mrdoob unless you already addressed this?) If this is unnecessary or undesirable I'll happily drop this commit.(DROPPED)